:root {
  --bg: #050505;
  --panel: rgba(12, 11, 10, 0.9);
  --ink: #f0e6d2;
  --muted: rgba(240, 230, 210, 0.5);
  --faint: rgba(197, 162, 111, 0.38);
  --gold: #c5a26f;
  --gold-hot: #e8d4a8;
  --line: rgba(197, 162, 111, 0.28);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Focus rings for keyboard users */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--gold-hot);
  outline-offset: 2px;
}
button:focus-visible,
.file-btn:focus-visible,
input[type="range"]:focus-visible,
.seg button:focus-visible {
  outline: 2px solid var(--gold-hot);
  outline-offset: 2px;
}

/* Stage coach toast (Flow / first-run) */
.stage-coach {
  position: absolute;
  left: 50%;
  bottom: calc(4.2rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 6;
  max-width: min(92vw, 22rem);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 7, 6, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--gold-hot);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.stage-coach[hidden] { display: none !important; }

/* iPhone start gate — big tap target when autoplay is blocked */
.start-gate {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(5, 5, 5, 0.15), rgba(5, 5, 5, 0.55) 70%);
}
.start-gate[hidden],
.start-gate:not(.is-visible) {
  display: none !important;
}
.start-gate.is-visible {
  pointer-events: auto;
}
.start-gate-btn {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-width: min(86vw, 18rem);
  padding: 1.15rem 1.4rem 1.25rem;
  border-radius: 20px;
  border: 1px solid rgba(197, 162, 111, 0.55);
  background: linear-gradient(160deg, rgba(197, 162, 111, 0.28), rgba(8, 7, 6, 0.88));
  color: var(--gold-hot);
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}
.start-gate-btn:active {
  transform: scale(0.98);
}
.start-gate-kicker {
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.start-gate-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--gold-hot);
}
.start-gate-hint {
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: rgba(240, 230, 210, 0.65);
  max-width: 14rem;
  line-height: 1.35;
}
.mobile-reload {
  pointer-events: auto;
  display: block;
  margin-top: 0.4rem;
  width: 100%;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
  border: 1px solid rgba(197, 162, 111, 0.35);
  background: rgba(5, 5, 5, 0.45);
  color: var(--gold-hot);
  font-family: inherit;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .panel {
    transition: none !important;
  }
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(360px, 100%);
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #050505;
}
#viz {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  z-index: 2;
  left: 1rem;
  right: 1rem;
  top: 1rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  pointer-events: none;
}
.brand, .readout {
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(5, 5, 5, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  max-width: min(50%, 20rem);
}
.brand a {
  pointer-events: auto;
  color: var(--gold);
  text-decoration: none;
  font-size: 0.55rem;
  letter-spacing: 0.32em;
  font-weight: 500;
}
.brand h1 {
  margin: 0.4rem 0 0;
  font-size: clamp(1.2rem, 3vw, 1.85rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.05;
  text-transform: uppercase;
}
.brand p {
  margin: 0.35rem 0 0;
  font-size: 0.55rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.readout { text-align: right; }
/* Track title lives on the Transmissions button — don't duplicate in readout */
.track-name {
  display: none;
}
.life-stage {
  margin-top: 0;
  font-size: clamp(0.7rem, 1.6vw, 0.9rem);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
}
/* Meta path is noisy — stage line is enough */
.readout small {
  display: none;
}
.life-bar {
  margin-top: 0.55rem;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.life-bar > i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6b5344, var(--gold), #fff4e0);
  transition: width 0.12s linear;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(5, 5, 5, 0.72);
  border: 2px dashed rgba(197, 162, 111, 0.45);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
}
.drop-overlay[hidden] { display: none !important; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 1.15rem;
  transform: translateX(-50%);
  z-index: 2;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(5, 5, 5, 0.65);
  backdrop-filter: blur(12px);
  font-size: 0.52rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  max-width: calc(100% - 2rem);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.panel {
  min-height: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  padding: 1rem 1rem 1.4rem;
  scrollbar-width: thin;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
}
.panel-head h2 {
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}
.status {
  font-size: 0.52rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.status.on {
  color: #0a0a0a;
  background: linear-gradient(90deg, var(--gold), var(--gold-hot));
  border-color: transparent;
  font-weight: 700;
}

.btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}
button, .file-btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 0.85rem 0.75rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}
button:disabled { opacity: 0.35; cursor: not-allowed; }
button.primary {
  color: #0a0a0a;
  background: linear-gradient(135deg, var(--gold), #fff4e0, var(--gold-hot));
}
button.secondary {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}
button.secondary.active {
  color: #0a0a0a;
  background: linear-gradient(135deg, var(--gold), var(--gold-hot));
  border-color: transparent;
}
button.full, .file-btn {
  width: 100%;
  margin-bottom: 0.5rem;
  display: block;
}
.file-btn {
  color: #0a0a0a;
  background: linear-gradient(135deg, var(--gold-hot), var(--gold));
  cursor: pointer;
}
.file-btn input { display: none; }

.block {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.85rem;
  margin-bottom: 0.65rem;
}
.block label {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  text-align: center;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-hot);
  margin-bottom: 0.55rem;
}
.block label strong {
  color: #fff4e0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}
.block label .lab-ico {
  opacity: 0.95;
  color: var(--gold-hot);
  flex-shrink: 0;
}
.block label.sub {
  margin-top: 0.65rem;
  font-size: 0.55rem;
  color: rgba(232, 212, 168, 0.88);
}
.block label.sub strong {
  font-size: 0.7rem;
  color: #fff4e0;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.58rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
}
.seg button {
  padding: 0.55rem 0.25rem;
  font-size: 0.55rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 600;
}
.seg button.active {
  color: #0a0a0a;
  background: linear-gradient(135deg, var(--gold), var(--gold-hot));
  border-color: transparent;
}

#scope {
  display: block;
  width: 100%;
  height: 64px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  margin-bottom: 0.5rem;
}
.meters {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.35rem;
}
.meter {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--gold-hot));
  border-radius: inherit;
}

.fine {
  font-size: 0.6rem;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
  margin-top: 0.75rem;
}
.fine a { color: var(--gold); text-decoration: none; }

/* iPhone Safari: solid sheet (backdrop-filter is a major GPU tax) */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 900px) {
    .panel,
    .panel.is-open {
      backdrop-filter: none !important;
      -webkit-backdrop-filter: none !important;
      background: rgba(8, 7, 6, 0.94) !important;
    }
    .panel-sheet-bar,
    .panel.is-open .panel-sheet-bar {
      background: rgba(8, 7, 6, 0.96) !important;
    }
    .hud .brand,
    .hud .readout,
    .track-pick {
      backdrop-filter: none !important;
      -webkit-backdrop-filter: none !important;
      background: rgba(5, 5, 5, 0.88) !important;
    }
  }
}

/* Mobile — visuals first: full-bleed stage, controls as bottom sheet */
@media (max-width: 900px) {
  html, body {
    overflow: hidden;
    height: 100%;
    height: 100dvh;
  }
  #app {
    position: fixed;
    inset: 0;
    display: block;
    height: 100%;
    height: 100dvh;
    grid-template-columns: none;
  }

  /* Stage fills the whole viewport — never shrink for panel */
  .stage {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    z-index: 1;
  }

  /* HUD — brand left; title + tiny stage + viz flick top-right */
  .hud {
    top: max(0.4rem, env(safe-area-inset-top, 0px));
    left: 0.45rem;
    right: 0.45rem;
    gap: 0.4rem;
    align-items: flex-start;
  }
  .hud-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.32rem;
    max-width: min(62%, 13.5rem);
    pointer-events: none;
  }
  .brand {
    padding: 0.38rem 0.5rem;
    border-radius: 12px;
    max-width: min(36%, 8.5rem);
    background: rgba(5, 5, 5, 0.4);
    border-color: rgba(197, 162, 111, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  .readout {
    padding: 0.38rem 0.55rem 0.42rem;
    border-radius: 12px;
    max-width: 100%;
    width: 100%;
    background: rgba(5, 5, 5, 0.42);
    border-color: rgba(197, 162, 111, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    text-align: right;
  }
  .brand h1 {
    margin-top: 0.15rem;
    font-size: 0.88rem;
    line-height: 1.05;
  }
  .brand a {
    font-size: 0.45rem;
    letter-spacing: 0.2em;
  }
  /* Stage detail (Tunnel · Storm) — quiet secondary line */
  .life-stage {
    font-size: 0.42rem;
    letter-spacing: 0.08em;
    font-weight: 500;
    margin-top: 0.12rem;
    color: var(--muted);
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .life-bar { margin-top: 0.28rem; height: 2px; }

  .hint {
    bottom: calc(3.6rem + env(safe-area-inset-bottom, 0px));
    font-size: 0.48rem;
    padding: 0.4rem 0.7rem;
    background: rgba(5, 5, 5, 0.4);
  }

  html, body {
    overscroll-behavior: none;
    touch-action: manipulation;
  }
  html.sheet-open,
  body.sheet-open {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  /* Bottom sheet — handle fixed; body scrolls (Spatial / FX never “stick” the page) */
  .panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    width: 100%;
    height: auto;
    max-height: min(78dvh, 620px);
    display: flex;
    flex-direction: column;
    border-left: 0;
    border-top: 1px solid rgba(197, 162, 111, 0.32);
    border-radius: 18px 18px 0 0;
    /* Frosted glass — stage visible, controls still readable */
    background: rgba(8, 7, 6, 0.72);
    /* Lighter blur — full 24px glass was a major iPhone cost */
    backdrop-filter: blur(12px) saturate(1.05);
    -webkit-backdrop-filter: blur(12px) saturate(1.05);
    padding: 0;
    overflow: hidden;
    /* Peek handle only when collapsed */
    transform: translateY(calc(100% - 3.85rem - env(safe-area-inset-bottom, 0px)));
    transition: transform 0.38s var(--ease), background 0.28s var(--ease);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.32);
    overscroll-behavior: contain;
  }
  .panel.is-open {
    transform: translateY(0);
    overflow: hidden; /* scroll lives on .panel-scroll, not whole panel */
    background: rgba(8, 7, 6, 0.68);
    backdrop-filter: blur(14px) saturate(1.08);
    -webkit-backdrop-filter: blur(14px) saturate(1.08);
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.36);
  }

  /* Fixed chrome — never scrolls away */
  .panel-sheet-bar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 auto;
    padding: 0.4rem 0.85rem 0.45rem;
    position: relative;
    z-index: 3;
    background: rgba(8, 7, 6, 0.4);
    border-bottom: 1px solid rgba(197, 162, 111, 0.16);
    min-height: 3.15rem;
  }
  .panel.is-open .panel-sheet-bar {
    background: rgba(8, 7, 6, 0.36);
  }

  /* Only this region scrolls — Play → Spatial → FX → wave */
  .panel-scroll {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    overscroll-behavior-y: contain;
    /* pan-y alone blocks range sliders (horizontal drag) on iOS — use manipulation */
    touch-action: manipulation;
    padding: 0.35rem 0.85rem max(1.1rem, env(safe-area-inset-bottom, 0px));
    scrollbar-width: thin;
  }
  /* Explicit: sliders must accept horizontal touch */
  .panel-scroll input[type="range"] {
    touch-action: manipulation;
    width: 100%;
    min-height: 2rem;
    margin: 0.15rem 0 0.45rem;
  }
  .panel-scroll .fx-presets,
  .panel-scroll .spatial-seg {
    touch-action: manipulation;
  }
  .panel-handle {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.32rem;
    width: 100%;
    min-height: 2.85rem;
    border: 0;
    background: transparent;
    color: var(--gold-hot);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.25rem 0.5rem;
    text-align: center;
    line-height: 1.25;
    -webkit-tap-highlight-color: transparent;
  }
  .panel-handle-grip {
    display: block;
    width: 2.75rem;
    height: 0.32rem;
    border-radius: 999px;
    background: rgba(232, 212, 168, 0.45);
    box-shadow: 0 0 0 1px rgba(197, 162, 111, 0.15);
  }
  .panel-handle-label {
    display: block;
    width: 100%;
    text-align: center;
    color: var(--gold-hot);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: none;
    white-space: nowrap;
  }
  .panel:not(.is-open) .panel-handle-label {
    color: var(--gold-hot);
  }
  .panel.is-open .panel-handle-label {
    color: var(--muted);
  }
  .panel-quick {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
    align-items: center;
  }
  .panel-quick-left {
    grid-column: 1;
  }
  /* Invisible spacer so title stays optically centered vs play buttons */
  .panel-quick-right {
    grid-column: 3;
    width: calc(2 * 2.55rem + 0.3rem);
    min-height: 1px;
    pointer-events: none;
    visibility: hidden;
  }
  .panel-quick button {
    min-width: 2.55rem;
    min-height: 2.55rem;
    padding: 0.5rem 0.45rem;
    font-size: 0.55rem;
    border-radius: 12px;
  }

  /* Light veil — glass sheet is the main frosted layer */
  #app:has(.panel.is-open) .stage::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background: rgba(5, 5, 5, 0.1);
    pointer-events: none;
  }

  /* Control blocks stay legible on glass without blocking the stage */
  .panel.is-open .block {
    background: rgba(5, 5, 5, 0.5);
    border-color: rgba(197, 162, 111, 0.28);
    /* no nested backdrop-filter — stacks kill mid-range iPhones */
  }
  .panel.is-open button.secondary {
    background: rgba(5, 5, 5, 0.48);
  }
  .panel.is-open .panel-handle-label {
    color: var(--gold-hot);
    opacity: 0.92;
  }
  .panel.is-open .block label,
  .panel.is-open .block label.sub {
    color: rgba(240, 230, 210, 0.88);
  }
}

/* Desktop: sheet chrome hidden; free-track + viz under readout */
.panel-sheet-bar { display: none; }
@media (min-width: 901px) {
  .panel-scroll {
    /* Desktop: no nested scroll shell — panel itself scrolls */
    display: contents;
  }
}
.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  max-width: min(50%, 20rem);
  pointer-events: none;
}
.hud-right .readout {
  max-width: 100%;
  pointer-events: none;
}

/* Free track picker (top-right) */
.track-pick-wrap {
  position: relative;
  width: 100%;
  pointer-events: auto;
  z-index: 5;
}
.track-pick {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.18rem;
  width: 100%;
  padding: 0.45rem 0.7rem 0.5rem;
  border-radius: 14px;
  border: 1px solid rgba(197, 162, 111, 0.4);
  background: linear-gradient(145deg, rgba(197, 162, 111, 0.18), rgba(5, 5, 5, 0.62));
  color: var(--gold-hot);
  font-family: inherit;
  cursor: pointer;
  text-align: right;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.track-pick:hover,
.track-pick.is-open {
  border-color: rgba(232, 212, 168, 0.55);
  background: linear-gradient(145deg, rgba(197, 162, 111, 0.28), rgba(5, 5, 5, 0.72));
}
.track-pick-kicker {
  font-size: 0.48rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.track-pick-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
}
.track-pick-ico {
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
  opacity: 0.9;
}
#trackPickTitle {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--gold-hot);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 11rem;
}
.track-pick-chev {
  font-size: 0.75rem;
  opacity: 0.75;
  transition: transform 0.2s var(--ease);
}
.track-pick.is-open .track-pick-chev {
  transform: rotate(180deg);
}
.track-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  width: min(100vw - 1.2rem, 17rem);
  min-width: 14rem;
  max-height: min(60dvh, 22rem);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.45rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(10, 9, 8, 0.96);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
  z-index: 40;
}
/* Portaled to body when open — always above mobile sheet (z 20) */
body > .track-menu {
  position: fixed;
  z-index: 200;
  max-height: min(55dvh, 22rem);
}
.track-menu[hidden] { display: none !important; }
.track-menu-head {
  padding: 0.4rem 0.55rem 0.5rem;
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}
.track-menu-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  width: 100%;
  padding: 0.65rem 0.7rem;
  margin-bottom: 0.28rem;
  border-radius: 11px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.track-menu-item:hover,
.track-menu-item:focus-visible {
  background: rgba(197, 162, 111, 0.12);
  border-color: rgba(197, 162, 111, 0.35);
  outline: none;
}
.track-menu-item.active {
  background: linear-gradient(135deg, rgba(197, 162, 111, 0.28), rgba(197, 162, 111, 0.1));
  border-color: rgba(197, 162, 111, 0.45);
}
.track-menu-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--gold-hot);
}
.track-menu-sub {
  font-size: 0.5rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.track-menu-note {
  margin: 0.25rem 0.35rem 0.15rem;
  font-size: 0.48rem;
  line-height: 1.4;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: center;
}

.viz-flick {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(5, 5, 5, 0.55);
  color: var(--gold-hot);
  font-family: inherit;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.viz-flick:hover {
  border-color: rgba(197, 162, 111, 0.55);
  background: rgba(197, 162, 111, 0.12);
}
.viz-flick-ico {
  width: 0.9rem;
  height: 0.9rem;
}
.viz-flick-chev {
  opacity: 0.65;
  font-size: 0.95rem;
}

@media (max-width: 900px) {
  .panel-sheet-bar { display: flex; }

  .hud-right {
    max-width: min(64%, 14.5rem);
    gap: 0.3rem;
  }

  /* Free track picker — primary top-right control */
  .track-pick {
    min-height: 2.85rem;
    padding: 0.42rem 0.7rem 0.48rem;
  }
  .track-pick-kicker {
    font-size: 0.5rem;
    letter-spacing: 0.14em;
    color: rgba(232, 212, 168, 0.75);
  }
  #trackPickTitle {
    font-size: 0.78rem;
    max-width: 10.5rem;
  }
  .track-menu {
    width: min(100vw - 1rem, 16.5rem);
  }
  .track-menu-item {
    min-height: 2.75rem;
    padding: 0.7rem 0.75rem;
  }
  .track-menu-title {
    font-size: 0.78rem;
  }

  /* Viz flick — secondary under free tracks */
  .viz-flick {
    width: 100%;
    justify-content: flex-end;
    min-height: 2.2rem;
    padding: 0.4rem 0.65rem;
    border: 1px solid rgba(197, 162, 111, 0.35);
    background: rgba(5, 5, 5, 0.45);
    font-size: 0.55rem;
    letter-spacing: 0.14em;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
  }
  .viz-flick:active {
    transform: scale(0.97);
    background: rgba(197, 162, 111, 0.2);
  }
  .viz-flick-ico {
    width: 0.85rem;
    height: 0.85rem;
    opacity: 0.85;
  }
}


/* Visual mode icons */
.seg.seg-viz {
  grid-template-columns: repeat(6, 1fr);
  gap: 0.28rem;
}
.stage.mode-flow {
  cursor: crosshair;
  touch-action: none; /* drag fluid without scrolling page */
  -webkit-user-select: none;
  user-select: none;
}
.stage.mode-flow #viz {
  touch-action: none;
  pointer-events: auto;
}
.seg.seg-viz button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.22rem;
  padding: 0.5rem 0.1rem 0.45rem;
  min-height: 3rem;
  font-size: 0.48rem;
}
.seg.seg-viz .viz-ico {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
  opacity: 0.72;
  flex-shrink: 0;
}
.seg.seg-viz button.active .viz-ico {
  opacity: 1;
}
.seg.seg-viz button span {
  line-height: 1;
}
