/* =========================
   Global reset / page lock
========================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

/* =========================
   Page layout
========================= */
body {
  background: #0a0a0a;
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  color: #fff;

  height: 100vh;
  display: flex;
  flex-direction: column;

  padding: 12px;
}

.is-hidden {
  display: none !important;
}

/* =========================
   Topbar (center camera btn + right YT input)
========================= */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 8px;
  flex: 0 0 auto;
  z-index: 10;
  min-height: 72px;
}

.hit-display {
  flex: 1 1 auto;
  min-width: 240px;
  max-width: min(680px, calc(50vw - 180px));
  margin-right: auto;
  margin-left: 8px;
  min-height: 24px;

  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.hit-display.is-empty::before {
  content: "";
}

.hit-text-item {
  position: relative;
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
}

.hit-text-item:not(:last-child)::after {
  content: "\3001";
  color: rgba(255, 255, 255, 0.65);
  margin-left: 2px;
}

/* Sound */
.sound-rack {
  position: absolute;
  left: 0;
  top: 0;

  display: flex;
  align-items: flex-start;
  gap: 12px;

  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);

  height: auto;

  flex-wrap: wrap;

  max-width: min(900px, 70vw);

  z-index: 10;
}
.zone-block {
  display: flex;
  flex-direction: column;
  gap: 8px;

  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.25);
}


.zone-header {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  opacity: 0.95;
}


.zone-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zone-row {
  display: grid;
  grid-template-columns: 90px 150px;
  align-items: center;
  gap: 10px;
}

.zone-label {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.92;
}

.rack-select {
  background: rgba(0, 0, 0, 0.75);
  color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  padding: 6px 10px;
  outline: none;
}


.rack-select option,
.control-select option {
  background: #0a0a0a;
  color: #ffffff;
}


.rack-select:focus,
.control-select:focus {
  border-color: rgba(255, 255, 255, 0.38);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}
#toggle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 84px;
}

#toggle:hover {
  transform: translate(-50%, calc(-50% - 1px));
}

#toggle:active {
  transform: translate(-50%, -50%) scale(0.98);
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);

  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  color: rgba(255, 255, 255, 0.95);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;

  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);

  cursor: pointer;
  user-select: none;

  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease;
}

.topbar-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.52),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.topbar-btn:active {
  transform: translateY(0px) scale(0.98);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.settings-wrap {
  position: relative;
  display: flex;
  align-items: center;
  z-index: 20;
  flex: 0 0 auto;
}

.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 1000;

  width: min(760px, 92vw);
  max-height: 70vh;
  overflow-y: auto;

  padding: 14px;
  border-radius: 16px;
  background: rgba(15, 15, 18, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
}

.settings-panel.is-hidden {
  display: none;
}

.settings-panel-header {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.runtime-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.debug-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.debug-controls:first-of-type {
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-control-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px;
  align-items: center;
}

.settings-control-label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 700;
}

.settings-control-inputs {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
  align-items: center;
}

.settings-control-inputs input[type="range"] {
  width: 100%;
}

.settings-number-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.75);
  color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  padding: 6px 8px;
  outline: none;
}

.settings-number-input:focus {
  border-color: rgba(255, 255, 255, 0.38);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.settings-toggle-row {
  grid-template-columns: 160px auto;
}

.settings-switch {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms ease,
    filter 160ms ease;
}

.settings-switch:hover {
  filter: brightness(1.05);
}

.settings-switch:active {
  transform: scale(0.98);
}

.settings-switch-track {
  position: relative;
  width: 58px;
  height: 32px;
  border-radius: 999px;
  background: #4caf50;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 6px 20px rgba(0, 0, 0, 0.25);
  transition:
    background 180ms ease,
    box-shadow 180ms ease;
}

.settings-switch-thumb {
  position: absolute;
  top: 3px;
  left: 29px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #eef5ea;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  transition:
    left 180ms ease,
    background 180ms ease;
}

.settings-switch[data-enabled="false"] .settings-switch-track {
  background: rgba(255, 255, 255, 0.18);
}

.settings-switch[data-enabled="false"] .settings-switch-thumb {
  left: 3px;
  background: rgba(255, 255, 255, 0.94);
}

.settings-panel .sound-rack {
  position: static;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;

  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.settings-panel .zone-block {
  height: 100%;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 14px;
  padding: 12px;
}

.settings-panel .zone-header {
  color: #fff;
  font-weight: 700;
  margin-bottom: 10px;
}

.settings-panel .zone-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  align-items: center;
}

.settings-panel .zone-label {
  color: #fff;
  font-size: 14px;
}

.settings-panel .rack-select {
  width: 100%;
}

.media-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: auto;
  max-width: min(900px, calc(100vw - 280px));
  margin-left: auto;
  min-width: min(520px, 100%);
}

.midi-library-panel {
  display: block;
  width: 100%;
}

.midi-library-row,
.yt-input-row {
  display: grid;
  gap: 10px;
  align-items: center;
}

.midi-library-row {
  width: 100%;
  grid-template-columns:
    minmax(120px, 80px)
    minmax(110px, 30px)
    minmax(180px, 20px)
    minmax(200px, 220px);
  justify-content: end;
}

.yt-input-row {
  grid-template-columns: minmax(0, 1fr) 56px;
  min-width: 0;
}

.midi-control,
.yt-url,
.yt-load-btn {
  min-height: 42px;
}

.midi-control {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.75);
  color: rgba(255, 255, 255, 0.95);
  outline: none;
}

.midi-control:focus,
.yt-url:focus {
  border-color: rgba(255, 255, 255, 0.38);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.midi-song-query {
  width: 100%;
}

.midi-category {
  width: 100%;
}

.midi-song-select {
  width: 100%;
}

.yt-url {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  outline: none;
}

.yt-load-btn {
  width: 56px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  cursor: pointer;
}

.yt-load-btn:hover {
  background: rgba(255, 255, 255, 0.26);
}

/* =========================
   Main content area
========================= */
.layout {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: flex;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: #17cd4a;
  overflow: hidden;
  border-radius: 20px;
  z-index: 1;
}


.camera-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #ff0000;
  overflow: hidden;
  border-radius: inherit;
}


#webcam,
#output {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  transform-origin: center;
}



#webcam {
  object-fit: cover;
  display: block;
  background: #c5c2c2;
  border-radius: inherit;
}


#output {
  pointer-events: none;
  border-radius: inherit;
}

/* =========================
   YouTube Player (floating top-right)
========================= */
.player-card {
  position: absolute;
  right: 0;
  top: 0;
  width: min(500px, 26vw);
  min-width: 420px;
  z-index: 5;
}

.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 11.5;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.player,
.player iframe {
  width: 100%;
  height: 100%;
}

.overlay-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.overlay-play i {
  font-size: 48px;
}

.controls-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
}

.btn,
.fullscreen-btn {
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
}

.volume-container {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.seek-container {
  flex: 1 1 160px;
}

.slider {
  width: 120px;
  height: 4px;
  border-radius: 999px;
  appearance: none;
  outline: none;
}

.slider.seek {
  width: 100%;
}

@media (max-width: 1100px) {
  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    min-height: unset;
  }

  #toggle {
    position: static;
    justify-self: end;
    transform: none;
  }

  #toggle:hover {
    transform: translateY(-1px);
  }

  #toggle:active {
    transform: scale(0.98);
  }

  .media-tools {
    grid-column: 1 / -1;
    width: 100%;
    max-width: none;
    margin-left: 0;
    min-width: 0;
    align-self: stretch;
    align-items: stretch;
  }

  .hit-display {
    min-width: 0;
    max-width: none;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  .midi-library-row {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .midi-library-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .yt-input-row {
    grid-column: 1 / -1;
  }

  .midi-control,
  .yt-url {
    width: 100%;
  }

  .midi-library-panel,
  .media-tools {
    align-items: stretch;
  }

  .player-card {
    width: min(100%, 440px);
    min-width: 0;
  }
}

@media (max-width: 960px) {
  html,
  body {
    overflow: auto;
  }

  body {
    height: auto;
    min-height: 100vh;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .settings-wrap,
  .hit-display,
  .media-tools {
    grid-column: 1 / -1;
  }

  .hit-display {
    min-height: auto;
  }

  .midi-library-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .midi-song-select,
  .yt-input-row {
    grid-column: 1 / -1;
  }

  .layout {
    flex-direction: column;
    gap: 12px;
  }

  .stage {
    min-height: 52vh;
  }

  .player-card {
    position: static;
    align-self: stretch;
    width: 100%;
  }

  .video-wrapper {
    aspect-ratio: 16 / 9.5;
  }
}

.slider::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
}

.control-select {
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(255, 255, 255, 1);
  color: #000;
  border-radius: 10px;
  padding: 6px 8px;
  outline: none;
}

.time {
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
  white-space: nowrap;
}

/* =========================
   Mobile safety
========================= */
@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding-top: 0;
  }

  .topbar-btn {
    position: static;
    transform: none;
  }

  #toggle {
    justify-self: stretch;
  }

  .hit-display {
    width: 100%;
    flex-wrap: wrap;
  }

  .sound-rack {
    position: static;
    height: auto;
    padding: 8px 10px;
    max-width: none;
    width: 100%;
  }

  .player-card {
    width: 100%;
    max-width: 100%;
  }
  .settings-panel {
    width: 92vw;
  }

  .settings-panel .sound-rack {
    grid-template-columns: 1fr;
  }

  .hit-text-item {
    font-size: 16px;
  }

  .settings-control-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .settings-control-inputs {
    grid-template-columns: 1fr;
  }

  .midi-library-row {
    grid-template-columns: 1fr;
  }

  .midi-song-select,
  .yt-input-row {
    grid-column: auto;
  }

  .yt-input-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .controls-bar {
    gap: 8px;
  }

  .control-select,
  .time,
  .volume-container,
  .seek-container {
    width: 100%;
  }
}