/* =============================================================================
   MicroFreak Trainer — visual system  ("Two Editions")

   IDENTITY: the app is skinned as the hardware itself. The DARK theme is the
   original Anthracite MicroFreak (charcoal body, off-white silkscreen print);
   the LIGHT theme is the Vocoder edition (warm white body, charcoal print). Both
   are real product variants, so both themes are deliberately designed, not
   inverted. Dark is the primary / expressive theme.

   SIGNATURE: the 5x7 modulation-matrix dot grid, used as the masthead identity
   mark, with its LED-node + amber-phosphor language echoed structurally in the
   OLED readout and the lit sequencer steps.

   PALETTE (named):
     Anthracite #15171c · Graphite #1e2128 · Carbon #14161b · Silk #ECE6D6
     Signal Amber #F2A93B · Indigo #7C86FF · Coral #FF6B5E   (dark)
     Bone #E6E1D6 · Paper #F5F1E8 · Carbon-ink #23262e
     Bronze #9c6512 · Amber-fill #E0962A · Indigo #4A52D6 · Coral #C0392B (light)

   TYPE: Space Grotesk (geometric display, echoes Arturia silkscreen) +
   IBM Plex Sans (engineered-for-technical body) + IBM Plex Mono (step grid,
   OLED readout, MIDI data). Everything routes through tokens.

   THEMING: every color is a custom property. Light is :root default;
   html[data-theme="dark"] overrides. theme.js flips the attribute pre-paint.
   ============================================================================= */

:root {
  /* ---- type tokens ---- */
  --font-display: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body:    "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, monospace;

  /* type scale */
  --fs-h1: clamp(1.6rem, 1.1rem + 1.8vw, 2.15rem);
  --fs-h2: 1.05rem;
  --fs-lg: 1.05rem;
  --fs-md: 0.95rem;
  --fs-sm: 0.85rem;
  --fs-xs: 0.74rem;

  /* shape + spacing */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 6px;
  --sp-1: 6px;
  --sp-2: 12px;
  --sp-3: 18px;
  --sp-4: 24px;

  /* ---- LIGHT palette = Vocoder edition (warm white body, charcoal print) ---- */
  --bg:        #e6e1d6;
  --panel:     #f5f1e8;
  --panel-2:   #eae4d7;
  --ink:       #23262e;
  --muted:     #5f5a4e;
  --faint:     #6b6657;   /* darkened from #847e6f: AA-legible mono microcopy on cream */
  --line:      #d3ccba;
  --line-soft: #e2dcce;
  --line-hover:#b6ae9a;

  /* signal amber (instrument LED) + indigo routing, tuned per theme */
  --accent:     #9c6512;   /* emphasis text / borders */
  --accent-fill:#e0962a;   /* solid button bg (amber LED) */
  --accent-on:  #2a1c05;   /* dark text on the amber fill */
  --accent-2:   #4a52d6;   /* indigo (black keys, secondary routing) */
  --accent2-on: #ffffff;
  --hot:        #c0392b;
  --accent-glow: rgba(224,150,42,0.20);

  /* keyboard keys (SVG panel + builder palette) */
  --white-key:     #ffffff;
  --white-key-ink: #1a1c24;
  --black-key:     #23262e;

  /* the OLED / scope stays dark in BOTH themes (it is a screen) */
  --scope-bg:   #0a0d0a;
  --scope-edge: #1d2620;
  --phosphor:   #f2a93b;   /* amber-phosphor text on the OLED */

  /* SVG device panel — Vocoder white body */
  --device-body:        #f3efe6;
  --device-edge:        #cdc6b6;
  --device-sec:         #6f6a5e;
  --device-screen:      #0a0d0a;
  --device-screen-edge: #b6afa0;
  --device-ctrl:        #ffffff;
  --device-ctrl-edge:   #c6bfb0;
  --device-touch:       #ece7dc;
  --device-touch-zig:   #c2bbac;
  --device-mtx:         #c6bfb0;
  --device-klbl:        #6a6356;
  --device-blbl:        #2a2620;
  --device-wkey:        #ffffff;
  --device-wkey-edge:   #c9c3b5;
  --device-wkey-lbl:    #8a8675;
  --device-bkey:        #23262e;
  --device-bkey-edge:   #11131a;
  --device-bkey-lbl:    #cfc9ba;

  /* dot-grid node colors (matrix mark) */
  --node-off: #cdc6b6;
  --node-on:  #e0962a;

  color-scheme: light;
  font-family: var(--font-body);
}

html[data-theme="dark"] {
  /* ---- DARK palette = original Anthracite edition ---- */
  --bg:        #15171c;
  --panel:     #1e2128;
  --panel-2:   #14161b;
  --ink:       #ece6d6;   /* silk silkscreen */
  --muted:     #9a9483;
  --faint:     #6f6a5e;
  --line:      #2c2f37;
  --line-soft: #23262d;
  --line-hover:#3d4049;

  --accent:     #f2a93b;
  --accent-fill:#f2a93b;
  --accent-on:  #2a1c05;
  --accent-2:   #7c86ff;
  --accent2-on: #0c0f2b;
  --hot:        #ff6b5e;
  --accent-glow: rgba(242,169,59,0.22);

  --white-key:     #ece6d6;
  --white-key-ink: #1a1c24;
  --black-key:     #14161b;

  --scope-bg:   #0a0d0a;
  --scope-edge: #2a2e33;
  --phosphor:   #f2a93b;

  --device-body:        #14161b;
  --device-edge:        #2c2f37;
  --device-sec:         #9a9483;
  --device-screen:      #0a0d0a;
  --device-screen-edge: #2c2f37;
  --device-ctrl:        #20232b;
  --device-ctrl-edge:   #3a3f48;
  --device-touch:       #14161b;
  --device-touch-zig:   #3a3f48;
  --device-mtx:         #2c2f37;
  --device-klbl:        #9a9483;
  --device-blbl:        #ece6d6;
  --device-wkey:        #ece6d6;
  --device-wkey-edge:   #b8b2a2;
  --device-wkey-lbl:    #2a2c34;
  --device-bkey:        #101216;
  --device-bkey-edge:   #000000;
  --device-bkey-lbl:    #cfc9ba;

  --node-off: #34373f;
  --node-on:  #f2a93b;

  color-scheme: dark;
}

/* ---- DJ palette = club / visualizer edition (deep violet body, neon pop) ----
   A third theme: a purple -> electric-blue world. Token COLOR values stay SOLID
   hex (color-mix and highway.js's hex parser both need a real color); the
   purple->blue gradient is applied as a separate background LAYER on body and on
   the primary buttons, scoped to this theme, never as a token value. */
html[data-theme="dj"] {
  --bg:        #0e0a1f;
  --panel:     #181230;
  --panel-2:   #120d28;
  --ink:       #ede9ff;
  --muted:     #a99fd8;
  --faint:     #7a6fb0;
  --line:      #2c2350;
  --line-soft: #221a42;
  --line-hover:#463a78;

  --accent:     #a78bfa;   /* violet, emphasis text / borders (legible on dark) */
  --accent-fill:#7c3aed;   /* solid violet (buttons get a gradient layer on top) */
  --accent-on:  #ffffff;
  --accent-2:   #3b82f6;   /* electric blue (black keys, secondary routing) */
  --accent2-on: #ffffff;
  --hot:        #fb7185;   /* rose (stop / miss) */
  --accent-glow: rgba(124,58,237,0.30);

  --white-key:     #ede9ff;
  --white-key-ink: #1a1330;
  --black-key:     #120d28;

  /* OLED / scope = club visualizer: deep indigo-black with neon-cyan phosphor */
  --scope-bg:   #0a0617;
  --scope-edge: #2c2350;
  --phosphor:   #22d3ee;   /* electric cyan glow on the OLED + highway */

  --device-body:        #140e2e;
  --device-edge:        #2c2350;
  --device-sec:         #a99fd8;
  --device-screen:      #0a0617;
  --device-screen-edge: #2c2350;
  --device-ctrl:        #1c1540;
  --device-ctrl-edge:   #3a2f68;
  --device-touch:       #140e2e;
  --device-touch-zig:   #3a2f68;
  --device-mtx:         #2c2350;
  --device-klbl:        #a99fd8;
  --device-blbl:        #ede9ff;
  --device-wkey:        #ede9ff;
  --device-wkey-edge:   #9d93c8;
  --device-wkey-lbl:    #2a2440;
  --device-bkey:        #0d0820;
  --device-bkey-edge:   #000000;
  --device-bkey-lbl:    #cfc9ba;

  --node-off: #2c2350;
  --node-on:  #a78bfa;

  color-scheme: dark;
}

/* DJ headline: purple -> electric-blue gradient as a background LAYER (the --bg
   token stays a solid color underneath so color-mix(--bg ...) keeps working). */
html[data-theme="dj"] body {
  background-image: linear-gradient(160deg, #241152 0%, #120b2e 52%, #0b1640 100%);
  background-attachment: fixed;
}
html[data-theme="dj"] button.primary,
html[data-theme="dj"] .practice-cta,
html[data-theme="dj"] .landing-cta {
  background-image: linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  position: relative;
  min-height: 100vh;
}

/* A single, confident hardware-edge wash. No busy wallpaper: identity is
   carried by the matrix mark, the OLED, and the lit steps, not the background. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1200px 620px at 88% -16%, var(--accent-glow), transparent 62%),
    radial-gradient(1000px 560px at -8% 112%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 60%);
  opacity: 0.6;
}

/* Audio-reactive background layer (reactive-bg.js). Sits above the static wash
   but below all content (the .wrap is positioned, so it paints on top). Kept
   low-opacity so UI text stays readable; opacity tuned per theme. */
#reactiveBg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  opacity: 0.6;
}
html[data-theme="light"] #reactiveBg { opacity: 0.5; }
html[data-theme="dj"] #reactiveBg { opacity: 0.72; }

.wrap { max-width: 1640px; margin: 0 auto; padding: 30px clamp(16px, 3vw, 48px) 88px; position: relative; }

/* ============================== MASTHEAD ============================== */
.masthead {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
}
.mast-id { display: flex; align-items: center; gap: 18px; min-width: 0; }

/* signature: the 5x7 modulation-matrix dot grid as the identity mark */
.mtx-mark { width: 56px; height: auto; flex: 0 0 auto; display: block; }
.mtx-mark .nd { fill: var(--node-off); transition: fill 0.2s ease; }
.mtx-mark .nd.on {
  fill: var(--node-on);
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--node-on) 70%, transparent));
  animation: mtx-light 2.6s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 0.12s);
}
@keyframes mtx-light { 0%, 100% { opacity: 1; } 46% { opacity: 0.45; } }

.mast-words { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mast-kicker {
  font-family: var(--font-mono); font-size: var(--fs-xs);
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--faint);
}
.wordmark {
  margin: 0; font-family: var(--font-display); font-weight: 700;
  font-size: var(--fs-h1); line-height: 0.96; letter-spacing: -0.02em;
}
.wordmark .mf { color: var(--ink); }
.wordmark .tr { color: var(--accent); }

.mast-aside { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex: 0 1 auto; flex-wrap: wrap; min-width: 0; }
.edition-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: var(--fs-xs); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
  white-space: nowrap;
}
.edition-badge::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-fill);
  box-shadow: 0 0 6px var(--accent-fill);
}
.edition-badge::after { content: "Original edition"; }
:root .edition-badge::after { content: "Vocoder edition"; }
html[data-theme="dark"] .edition-badge::after { content: "Original edition"; }
html[data-theme="dj"] .edition-badge::after { content: "DJ edition"; }

/* theme toggle pill */
.theme-toggle {
  flex: 0 0 auto;
  font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1;
  color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mast-lede-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px 24px; flex-wrap: wrap; margin: 14px 0 0;
}
.mast-lede {
  margin: 0; color: var(--muted); max-width: 78ch; font-size: var(--fs-md);
  flex: 1 1 360px;
}

/* secondary/ghost CTA: outlined accent, sits beside the lede. Deliberately
   quieter than the amber-filled ▶ Play primary so it never competes with it. */
.cta-ghost {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1;
  letter-spacing: 0.03em; text-decoration: none; white-space: nowrap;
  color: var(--accent); background: transparent;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 999px; padding: 9px 16px;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.cta-ghost:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.cta-ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================== LANDING ==============================
   Full-viewport welcome over the global reactive background. The schematic hero
   self-plays a riff visually (app.js), no audio before the CTA. Tokens only, so
   it reads correctly in every edition (light / dark / dj). */
.landing {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 40px clamp(16px, 4vw, 64px);
  position: relative;
}
.landing[hidden] { display: none; }
.landing-inner {
  width: 100%; max-width: 1080px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: clamp(16px, 3vh, 32px);
  animation: landing-in 0.5s ease both;
}
.landing-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; }
.landing-head .mast-words { align-items: flex-start; }
.landing .wordmark { font-size: clamp(1.9rem, 1.2rem + 3.4vw, 3rem); }
.landing-panel { width: 100%; max-width: 760px; }
.landing-panel .mf-svg { width: 100%; height: auto; max-height: min(46vh, 420px); }
.landing-lede { margin: 0; color: var(--muted); font-size: var(--fs-lg); max-width: 52ch; }
.landing-ticks {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 14px;
  font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--faint);
  letter-spacing: 0.04em;
}
.landing-ticks li { display: inline-flex; align-items: center; gap: 10px; }
.landing-ticks li + li::before {
  content: "·"; color: var(--accent); opacity: 0.7; margin-right: 4px;
}
.landing-cta {
  font-family: var(--font-display); font-weight: 700; font-size: 1.1rem;
  background: var(--accent-fill); color: var(--accent-on);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 14px 32px; cursor: pointer; white-space: nowrap;
  box-shadow: 0 0 0 3px var(--accent-glow);
  transition: filter 0.12s ease, box-shadow 0.12s ease;
}
.landing-cta:hover { filter: brightness(1.06); box-shadow: 0 0 0 4px var(--accent-glow), 0 8px 24px var(--accent-glow); }
.landing-cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@keyframes landing-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .landing-inner { animation: none; } }

/* ---- trainer thin top bar (the masthead, slimmed) ---- */
.mtx-mark-sm { width: 34px; }
.wordmark-sm { font-size: 1.2rem; line-height: 1; }
.edition-field { display: inline-flex; align-items: center; gap: 8px; }
.edition-lbl {
  font-family: var(--font-mono); font-size: var(--fs-xs); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--faint);
}

/* ============================== PANELS ============================== */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-top: 18px;
}
.panel-quiet {
  background: color-mix(in srgb, var(--panel) 60%, transparent);
  border-color: var(--line-soft);
}
/* the song/synth panel is the hero: an amber LED hairline at the top edge */
.stage-main { position: relative; overflow: hidden; }
.stage-main::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent-2) 80%, var(--accent)));
  opacity: 0.85;
}

/* ============================== STAGE LAYOUT ==========================
   One layout: the trainer column on the left, the MIDI panel + live visualizer
   stacked in the right rail on wide screens; everything single-column on narrow.
   Grid-area names resolve once the wide layout defines matching template-areas. */
.stage {
  display: grid; grid-template-columns: 1fr;
  gap: 18px; align-items: start; margin-top: 18px;
}
/* grid/flex items default to min-width:auto (= min-content); without this a wide
   child (e.g. the base-select song button) expands the 1fr track and scrolls the
   page sideways on mobile. min-width:0 lets the columns shrink to the viewport. */
.stage > * { margin-top: 0; min-width: 0; }
.stage-main { grid-area: main; }
.stage-side { grid-area: side; display: flex; flex-direction: column; gap: 18px; }
.stage-side > .panel { margin-top: 0; }
.viz-panel  { grid-area: viz; display: flex; flex-direction: column; }
#vizWrap { display: flex; flex-direction: column; }
/* the in-panel connect proxy was only for the old dedicated Visualizer view,
   which no longer has an entry point; the main MIDI panel owns connection. */
.viz-connect { display: none; }

@media (min-width: 1180px) {
  .stage {
    grid-template-columns: minmax(0, 1fr) minmax(330px, 430px);
    grid-template-areas: "main side" "main viz";
    grid-template-rows: auto auto;
  }
}

/* ============================== CONTROLS ============================== */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 0 0 auto; }
label.field {
  display: flex; flex-direction: column; gap: 5px;
  font-size: var(--fs-xs); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--faint); font-family: var(--font-mono);
}

select, button {
  font: inherit; font-family: var(--font-body);
  color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 13px; cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
select {
  text-transform: none; letter-spacing: normal;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  min-width: 150px; padding-right: 34px;
  /* custom caret, tinted to the Vocoder (light) muted ink by default */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235f5a4e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
/* caret retinted to the Anthracite (dark) muted silk */
html[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239a9483' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
/* caret retinted to the DJ muted lavender */
html[data-theme="dj"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a99fd8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
select:disabled { opacity: 0.45; cursor: not-allowed; }
select option { color: var(--ink); background: var(--panel); }
select optgroup { color: var(--muted); background: var(--panel); font-style: normal; }
select:hover, button:hover { border-color: var(--line-hover); }
select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-color: transparent;
}
button.primary { background: var(--accent-fill); color: var(--accent-on); font-weight: 600; border: 1px solid transparent; }
button.primary:hover { filter: brightness(1.06); border-color: transparent; box-shadow: 0 0 0 3px var(--accent-glow); }
button.stop { background: transparent; color: var(--hot); border-color: color-mix(in srgb, var(--hot) 45%, transparent); }
button.stop:hover { background: color-mix(in srgb, var(--hot) 12%, transparent); border-color: var(--hot); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line-soft); }
button.ghost:hover { color: var(--ink); border-color: var(--line-hover); background: color-mix(in srgb, var(--ink) 4%, transparent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
.remember { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.82rem; cursor: pointer; }
.remember input { accent-color: var(--accent-fill); }

/* ===== OPEN select = MicroFreak OLED patch browser =====
   Progressive enhancement. Only browsers with the customizable-select API
   (Chromium 135+) opt into the themed open list; everywhere else the native
   popup + the custom caret defined above keep working unchanged. The app is
   Chrome/Edge only, so this is the live treatment, not a fringe path. */
@supports (appearance: base-select) {
  select, ::picker(select) { appearance: base-select; }

  /* closed control keeps the field look, but drop the background-image caret
     (both themes) and use the tintable ::picker-icon so we don't double up. */
  select, html[data-theme="dark"] select, html[data-theme="dj"] select { background-image: none; }
  select { padding-right: 30px; }
  select::picker-icon { color: var(--faint); font-size: 0.72em; transition: transform 0.15s ease; }
  select:open::picker-icon { transform: rotate(180deg); }
  select:hover::picker-icon { color: var(--accent); }
  .sb-f select, html[data-theme="dark"] .sb-f select, html[data-theme="dj"] .sb-f select { background-image: none; padding-right: 30px; }
  /* closed song control: ellipsize the cloned title so it never blows out width */
  .song-pick #song .opt-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* the closed control echoes the open list: it shows the current song's LED
     difficulty meter via the cloned <selectedcontent>. */

  /* the open popover = the synth's amber OLED menu: dark screen, thin accent edge */
  ::picker(select) {
    background: var(--scope-bg);
    border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--scope-edge));
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 18px 44px rgba(0,0,0,0.5);
  }

  ::picker(select) option {
    font-family: var(--font-mono); font-size: var(--fs-sm);
    color: color-mix(in srgb, var(--phosphor) 80%, var(--ink));
    background: transparent;
    display: flex; align-items: center; gap: 12px;
    padding: 7px 10px; margin: 1px 0;
    border-radius: 6px; border-left: 2px solid transparent;
    cursor: pointer;
  }
  ::picker(select) option::checkmark { display: none; }   /* the amber bar is the indicator */
  ::picker(select) option .opt-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  ::picker(select) option.opt-masked .opt-name { color: var(--faint); letter-spacing: 0.14em; }

  /* hover / keyboard focus / current selection => amber LED row */
  ::picker(select) option:hover,
  ::picker(select) option:focus,
  ::picker(select) option:checked {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    border-left-color: var(--accent);
    color: var(--phosphor);
  }

  /* LED difficulty meter, reusing the step-grid LED on/off language */
  .opt-pips { flex: 0 0 auto; letter-spacing: 2px; font-size: 0.74em; line-height: 1; }
  .opt-pips .pip-on { color: var(--accent); text-shadow: 0 0 5px var(--accent-glow); }
  .opt-pips .pip-off { color: color-mix(in srgb, var(--phosphor) 24%, transparent); }

  /* tier headers: uppercase, letterspaced, muted panel labels */
  ::picker(select) optgroup {
    font-family: var(--font-mono); font-style: normal;
    font-size: var(--fs-xs); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.18em;
    color: var(--faint);
    padding: 9px 10px 3px;
  }
}

/* Primary transport = the core loop, read left to right:
   Song ▾ (+ New/Edit)  →  ▶ Practice  →  ▶ Play  ■ Stop.
   Voice + the sound/preset tips and MIDI connect tuck into the .tweaks drawers
   below, so this row stays uncluttered and Practice reads as the obvious action. */
.transport { gap: 12px; align-items: flex-end; justify-content: center; }
.transport label.field { margin-right: 2px; }
/* center the supporting input rows so the trainer column reads as one tidy stack */
.tweaks { justify-content: center; }
.meta { justify-content: center; }

/* song picker + its compact New/Edit control share one group */
.song-pick { display: flex; align-items: flex-end; gap: 8px; min-width: 0; flex-wrap: wrap; }
.song-pick label.field { min-width: 0; }
/* a base-select <select> sizes its button to the widest option; cap + clip it so
   a long song title can't blow out the transport (and the page) horizontally. */
.song-pick #song { max-width: min(100%, 340px); overflow: hidden; }
.song-edit {
  font-size: var(--fs-sm); padding: 8px 12px; white-space: nowrap;
  background: transparent; color: var(--muted); border-color: var(--line-soft);
}
.song-edit:hover { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.song-edit-sep { opacity: 0.5; padding: 0 1px; }

/* faint flow arrows between the loop stages; cosmetic, hidden when the row wraps.
   bottom-aligned + nudged up so they sit on the Play/Stop button line. */
.transport-arrow { color: var(--faint); font-family: var(--font-mono); opacity: 0.6; align-self: flex-end; padding-bottom: 10px; }

/* ---- tweak drawers: Sound (voice + tips) and MIDI connect, one click away ---- */
.tweaks { gap: 10px; align-items: flex-start; margin-top: 12px; }
.drawer {
  margin-top: 0; flex: 0 1 auto; min-width: 0;
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
}
.drawer > summary {
  list-style: none; cursor: pointer; padding: 9px 14px;
  font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: 500;
  letter-spacing: 0.04em; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::before {
  content: "▸"; color: var(--faint); font-size: 0.8em;
  transition: transform 0.15s ease;
}
.drawer[open] > summary::before { transform: rotate(90deg); }
.drawer > summary:hover { color: var(--accent); }
.drawer > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-xs); }
.drawer[open] > summary { color: var(--ink); border-bottom: 1px solid var(--line-soft); }
.drawer-body { padding: 14px; display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.drawer-tips { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 220px; color: var(--muted); font-size: var(--fs-sm); line-height: 1.5; }
.drawer-tips .preset-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* theme dropdown (replaces the old cycle button): a real <select>, so it inherits
   the app's OLED base-select treatment (themed caret/picker-icon + amber popup)
   and matches the Song/Voice dropdowns exactly. We only trim its width for the
   masthead and keep the mono face used by the other masthead chrome. */
.theme-select {
  min-width: 0; width: auto;
  font-family: var(--font-mono); font-size: var(--fs-sm);
}

/* segmented control */
.seg {
  display: inline-flex;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  padding: 3px; gap: 3px;
}
.seg .chip-btn { background: transparent; border: 1px solid transparent; color: var(--muted); border-radius: var(--radius-xs); padding: 5px 11px; }
.seg .chip-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); border-color: transparent; }
.seg .chip-btn:disabled { opacity: 0.4; }

/* ---- meta / song info ---- */
.meta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; color: var(--muted); font-size: var(--fs-md); align-items: center; }
.meta b { color: var(--ink); }
.meta:first-of-type b#songTitle { font-size: var(--fs-lg); font-family: var(--font-display); letter-spacing: -0.01em; }
.tag {
  background: transparent; border: 1px solid var(--line-soft); color: var(--faint);
  border-radius: 999px; padding: 2px 11px; font-size: var(--fs-xs);
  letter-spacing: 0.04em; font-family: var(--font-mono);
}

/* ============================== STEP GRID ============================== */
/* Uniform-footprint cells: a rest, a single note, and a 4-note chord are the
   EXACT same size. overflow:clip + non-content-sized grid + the label living in
   its own clipped track keep the box constant. Styled as hardware step buttons
   with a small LED that lights amber on the playhead step. */
.grid, .sb-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px; margin-top: 14px;
}
.sb-grid { margin-top: 0; }
@media (min-width: 640px) {
  .grid, .sb-grid { grid-template-columns: repeat(16, minmax(0, 1fr)); }
}

.cell, .sb-cell {
  aspect-ratio: 1 / 1.1;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  display: grid;
  grid-template-rows: 1fr auto;     /* note region (flexes) + fixed step-number row */
  align-items: center; justify-items: center;
  gap: 0; min-width: 0; min-height: 0;
  overflow: clip;                   /* content can never expand the box */
  font-size: 0.72rem; color: var(--ink);
  position: relative;
}
/* the step LED (top center). Absolute, so it never affects cell sizing. */
.cell::before {
  content: ""; position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--line-hover); opacity: 0.5;
  transition: background 0.08s ease, box-shadow 0.08s ease, opacity 0.08s ease;
}
.sb-cell { padding: 0; }
.sb-cell:hover { border-color: var(--line-hover); }

/* note label: clipped to its row, never grows the cell */
.cell .n, .sb-cell-n {
  grid-row: 1; width: 100%; min-width: 0; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow: clip; font-weight: 600; white-space: nowrap; line-height: 1;
}
.cell .n { font-size: 0.72rem; padding-top: 6px; }
.sb-cell-n { font-size: 0.66rem; }
.cell .s, .sb-cell-s {
  grid-row: 2; color: var(--faint); font-family: var(--font-mono);
  line-height: 1.3; padding-bottom: 3px;
}
.cell .s { font-size: 0.6rem; }
.sb-cell-s { font-size: 0.58rem; }

.cell.rest, .sb-cell.rest { opacity: 0.6; }
.cell.rest .n, .sb-cell.rest .sb-cell-n { color: var(--muted); }

/* playhead: amber LED + inset ring, drawn inset so it can't nudge neighbors */
.cell.on { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-glow), 0 0 12px var(--accent-glow); }
.cell.on::before { background: var(--accent); opacity: 1; box-shadow: 0 0 7px var(--accent); }
.sb-cell.sel { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-glow); }

/* chord steps: one small clipped line per note, stacked, size stays constant */
.cell.chord .n, .sb-cell.chord .sb-cell-n { gap: 0; color: var(--accent); letter-spacing: -0.02em; }
.cell.chord .n { font-size: 0.56rem; line-height: 1.1; }
.sb-cell.chord .sb-cell-n { font-size: 0.5rem; line-height: 1.12; }
.cell.chord .n .ln, .sb-cell.chord .sb-cell-n .ln { max-width: 100%; overflow: clip; }

/* ============================== DISCLOSURES ============================== */
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; font-family: var(--font-display); }
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
pre { background: var(--scope-bg); color: var(--ink); border: 1px solid var(--scope-edge); border-radius: 8px; padding: 14px; overflow-x: auto; font-size: var(--fs-sm); line-height: 1.6; font-family: var(--font-mono); }

.midi-status { font-size: var(--fs-sm); color: var(--muted); margin-top: 12px; line-height: 1.55; }
.midi-status.ok { color: var(--accent); }
.midi-status.err { color: var(--hot); }

/* ============================== SPOTIFY CARD ==========================
   A quiet sidebar card: small square album art beside the Spotify embed, an
   Open-in-Spotify link, one honest line of copy. All tokens, both themes. */
.spotify-card[hidden] { display: none; }
.spotify-h { margin-bottom: 12px; font-size: var(--fs-h3, 1.05rem); }
.spotify-row { display: flex; gap: 12px; align-items: flex-start; }
.spotify-art {
  flex: 0 0 auto; width: 72px; height: 72px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--panel-2);
}
.spotify-embed { flex: 1 1 auto; min-width: 0; }
.spotify-embed iframe { display: block; width: 100%; border: 0; border-radius: 12px; }
.spotify-open {
  display: inline-block; margin-top: 12px;
  font-family: var(--font-mono); font-size: var(--fs-xs);
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); text-decoration: none;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 999px; padding: 6px 12px;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.spotify-open:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.spotify-open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spotify-note { margin: 10px 2px 0; color: var(--faint); font-size: 0.8rem; line-height: 1.5; }
@media (max-width: 520px) {
  .spotify-row { flex-direction: column; }
  .spotify-art { width: 64px; height: 64px; }
}

footer { margin-top: 36px; color: var(--faint); font-size: var(--fs-sm); text-align: center; }
footer a { color: var(--accent); }
footer code { color: var(--ink); font-family: var(--font-mono); }
.reveal-btn { font-size: 0.8rem; padding: 6px 11px; background: transparent; color: var(--muted); border-color: var(--line-soft); }
.reveal-btn:hover { color: var(--ink); border-color: var(--line-hover); }
.hint { color: var(--faint); font-size: 0.82rem; margin: 10px 2px 0; line-height: 1.5; }
.sect-h { margin: 0 0 14px; font-family: var(--font-display); font-size: var(--fs-h2); font-weight: 600; letter-spacing: -0.01em; }
.roll { width: 100%; height: 220px; display: block; background: var(--scope-bg); border: 1px solid var(--scope-edge); border-radius: 12px; }
.viz-controls { align-items: flex-end; }

/* ---- in-app guide ---- */
.guide {
  margin-top: 18px; border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  border-left: 3px solid var(--accent); padding: 16px 18px;
}
.guide-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.guide-head strong { font-family: var(--font-display); }
.guide-text { font-size: var(--fs-lg); margin: 12px 0; min-height: 2.6em; color: var(--ink); }
details.basics, details.panel { padding: 18px 22px; }
details > summary { font-size: 1rem; margin: 0; }
details[open] > summary { margin-bottom: 8px; }
.info-list { margin: 14px 0 0; padding-left: 20px; color: var(--ink); }
.info-list li { margin: 8px 0; line-height: 1.5; }

/* ---- photo skin + overlay ---- */
.view-label { color: var(--faint); font-size: var(--fs-xs); letter-spacing: 0.07em; text-transform: uppercase; font-family: var(--font-mono); }
.chip-btn { font-size: var(--fs-sm); padding: 6px 11px; }
.viz-modes { align-items: center; margin-bottom: 10px; }
/* the auto-generated mode picker holds many chips; give it its own full-width
   line and let the chips wrap, so it can never push past the panel / off-screen. */
#vizModePicker { flex: 1 1 100%; flex-wrap: wrap; max-width: 100%; min-width: 0; }
.seg .viz-mode.active { background: var(--accent-fill); color: var(--accent-on); border-color: transparent; font-weight: 600; }
.ph-wrap { position: relative; width: 100%; }
.ph-img { width: 100%; display: block; border-radius: 14px; }
.ph-overlay { position: absolute; inset: 0; }
.ph-overlay.ph-calibrating { cursor: crosshair; background: rgba(0,0,0,0.18); }
.ph-key { position: absolute; border-radius: 3px; background: transparent; transition: background 0.05s; }
.ph-key.active { background: color-mix(in srgb, var(--accent-fill) 50%, transparent); box-shadow: 0 0 10px var(--accent-fill); }
.ph-ctrl { position: absolute; width: 44px; height: 44px; transform: translate(-50%, -50%); border-radius: 50%; }
.ph-ctrl.ctrl-active { box-shadow: 0 0 0 3px var(--accent), 0 0 16px var(--accent); animation: mf-pulse 1.2s ease-in-out infinite; }
.ph-ctrl-sq { width: 34px; height: 26px; border-radius: 6px; }
.ph-knob-ptr { position: absolute; width: 3px; height: 15px; background: var(--accent); border-radius: 2px; transform-origin: bottom center; box-shadow: 0 0 6px var(--accent); pointer-events: none; z-index: 4; }
.ph-keylabel { position: absolute; transform: translate(-50%, -50%); font-size: 9px; font-weight: 700; color: #1a1c24; background: rgba(236,230,214,0.9); border-radius: 3px; padding: 0 2px; pointer-events: none; display: none; z-index: 5; }
.ph-keylabel-b { color: #ece6d6; background: rgba(16,18,22,0.9); }
.ph-overlay.show-labels .ph-keylabel { display: block; }

/* fullscreen visualizer */
#vizWrap:fullscreen { background: var(--scope-bg); padding: 18px; display: flex; flex-direction: column; }
#vizWrap:fullscreen .roll { height: calc(100vh - 90px); }

/* ---- visualizer cruise nav (prev / next / auto) ---- */
.viz-modes { flex-wrap: wrap; gap: 8px; }
.viz-nav { gap: 2px; }
.viz-nav .chip-btn { padding: 5px 9px; }
.viz-actions { display: inline-flex; gap: 6px; margin-left: auto; }
/* entry point to the standalone "visualize anything" app (separate served page) */
.viz-anything { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); }
.viz-anything:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); border-color: var(--accent); }
.viz-anything-hint { margin: 10px 0 0; font-size: var(--fs-sm); color: var(--muted); max-width: 62ch; }
.viz-anything-hint code { font-family: var(--font-mono); color: var(--phosphor); background: color-mix(in srgb, var(--scope-bg) 60%, transparent); padding: 1px 6px; border-radius: 4px; }
.seg .chip-btn.active { background: var(--accent-fill); color: var(--accent-on); border-color: transparent; font-weight: 600; }

/* ---- immersive visualizer view (mirrors Practice-mode overlay) ---- */
.viz-immersive { margin-top: 18px; }
.viz-immersive[hidden] { display: none; }
body.viz-open { overflow: hidden; }
body.viz-open .masthead,
body.viz-open .mast-lede-row,
body.viz-open footer,
body.viz-open .stage,
body.viz-open .highway-view,
body.viz-open .wrap > details.panel { display: none; }
body.viz-open .wrap { padding-top: 14px; padding-bottom: 14px; }
body.viz-open .viz-immersive {
  display: flex; flex-direction: column; margin: 0;
  height: calc(100dvh - 28px);
}
body.viz-open .viz-imm-canvas { flex: 1 1 auto; height: auto; min-height: 0; }
.viz-imm-bar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.viz-imm-title { margin: 0 auto 0 0; font-family: var(--font-display); font-size: var(--fs-h2); font-weight: 600; color: var(--ink); }
.viz-imm-ctrls { align-items: center; }
.viz-imm-name {
  min-width: 7.5em; text-align: center; color: var(--phosphor);
  font-family: var(--font-mono); font-size: var(--fs-sm); letter-spacing: 0.04em;
  text-shadow: 0 0 10px color-mix(in srgb, var(--phosphor) 45%, transparent);
}
.viz-imm-canvas {
  width: 100%; height: min(62vh, 600px); min-height: 320px; display: block;
  background: var(--scope-bg); border: 1px solid var(--scope-edge); border-radius: var(--radius);
}
.viz-imm-hint { margin-top: 8px; }
@media (max-width: 560px) {
  .viz-imm-bar { gap: 10px; }
  .viz-imm-title { flex: 1 1 100%; margin: 0 0 4px; }
  .viz-actions { margin-left: 0; }
}

/* ============================== SVG DEVICE PANEL ============================== */
/* the schematic is the trainer's hero: generous breathing room around it */
.panel-svg { margin-top: 18px; padding: clamp(10px, 2.5vw, 34px) clamp(8px, 3.5vw, 56px); }
.mf-svg { display: block; margin: 0 auto; width: auto; max-width: 100%; height: auto; max-height: 60vh; border-radius: 14px; }
.mf-body { fill: var(--device-body); stroke: var(--device-edge); stroke-width: 2; }
.p-brand { fill: var(--ink); font-size: 19px; font-weight: 700; letter-spacing: 0.5px; font-family: var(--font-display); }
.p-sec { fill: var(--device-sec); font-size: 11px; letter-spacing: 1.5px; font-family: var(--font-mono); }
.p-screen { fill: var(--device-screen); stroke: var(--device-screen-edge); stroke-width: 1.5; }
.p-scope { fill: none; stroke: var(--accent); stroke-width: 2; }
/* OLED readout text (relocated from the old floating row): amber-phosphor mono,
   large note that shrinks for a chord + a small step counter beneath it. */
.p-oled-note {
  fill: var(--phosphor); font-family: var(--font-mono); font-weight: 600;
  font-size: 30px; text-anchor: middle;
  filter: drop-shadow(0 0 3px color-mix(in srgb, var(--phosphor) 55%, transparent));
}
.p-oled-note.is-chord { font-size: 17px; letter-spacing: 0.4px; }
.p-oled-pos {
  fill: color-mix(in srgb, var(--phosphor) 60%, transparent);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.5px; text-anchor: middle;
}
.p-sec-rule { stroke: var(--device-edge); stroke-width: 1.5; }
.p-touch { fill: var(--device-touch); stroke: var(--device-edge); stroke-width: 1.5; }
.p-touch-zig { fill: none; stroke: var(--device-touch-zig); stroke-width: 1.5; }
.p-mtx { fill: var(--device-mtx); }
.p-knob-body { fill: var(--device-ctrl); stroke: var(--device-ctrl-edge); stroke-width: 2; }
.p-knob-ind { stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; }
.p-klbl { fill: var(--device-klbl); font-size: 9.5px; letter-spacing: -0.2px; text-anchor: middle; font-family: var(--font-mono); }
.p-btn-body { fill: var(--device-ctrl); stroke: var(--device-ctrl-edge); stroke-width: 1.5; }
.p-blbl { fill: var(--device-blbl); font-size: 12px; text-anchor: middle; font-family: var(--font-mono); }
.p-wkey { fill: var(--device-wkey); stroke: var(--device-wkey-edge); stroke-width: 1; }
.p-bkey { fill: var(--device-bkey); stroke: var(--device-bkey-edge); stroke-width: 1; }
.p-kklbl { fill: var(--device-wkey-lbl); font-size: 10px; text-anchor: middle; font-family: var(--font-mono); }
.p-kklbl-b { fill: var(--device-bkey-lbl); font-size: 8px; text-anchor: middle; font-family: var(--font-mono); }
.p-wkey.active { fill: var(--accent-fill); }
.p-bkey.active { fill: var(--accent-2); }

/* control highlight (interactive tutorials) */
.ctrl-active .p-knob-body,
.ctrl-active .p-btn-body,
.ctrl-active > circle.p-knob-body {
  stroke: var(--accent); stroke-width: 3;
  filter: drop-shadow(0 0 7px var(--accent));
}
.ctrl-active .p-blbl, .ctrl-active .p-klbl { fill: var(--accent); }
.ctrl-active { animation: mf-pulse 1.2s ease-in-out infinite; }
@keyframes mf-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

@media (prefers-reduced-motion: reduce) {
  .ctrl-active, .ph-ctrl.ctrl-active, .mtx-mark .nd.on { animation: none; }
  select, button, .theme-toggle, .mtx-mark .nd, .cell::before { transition: none; }
}

/* ===== docs viewer (docs.html) ===== */
.docs-wrap { max-width: 1120px; margin: 0 auto; display: flex; gap: 30px; padding: 28px clamp(16px, 3vw, 40px) 80px; align-items: flex-start; position: relative; }
.docs-nav { flex: 0 0 224px; position: sticky; top: 24px; }
.docs-topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.docs-home { display: inline-block; color: var(--muted); font-size: var(--fs-sm); text-decoration: none; font-family: var(--font-mono); }
.docs-home:hover { color: var(--ink); }
.docs-nav nav { display: flex; flex-direction: column; gap: 2px; }
.docs-nav nav a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: var(--fs-md); }
.docs-nav nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 4%, transparent); }
.docs-nav nav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.docs-content { flex: 1 1 auto; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 34px; line-height: 1.7; }
.docs-content > :first-child { margin-top: 0; }
.docs-content h1 { margin: 0 0 14px; font-family: var(--font-display); font-size: 1.7rem; letter-spacing: -0.02em; }
.docs-content h2 { margin: 30px 0 12px; font-family: var(--font-display); font-size: 1.25rem; border-top: 1px solid var(--line-soft); padding-top: 22px; }
.docs-content h3 { margin: 22px 0 8px; font-size: 1.02rem; color: var(--accent); font-family: var(--font-display); }
.docs-content p, .docs-content li { color: var(--ink); }
.docs-content ul, .docs-content ol { padding-left: 22px; }
.docs-content li { margin: 5px 0; }
.docs-content a { color: var(--accent); }
.docs-content code { background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 5px; padding: 1px 5px; font-size: 0.88em; font-family: var(--font-mono); }
.docs-content pre { background: var(--scope-bg); border: 1px solid var(--scope-edge); border-radius: 8px; padding: 14px; overflow-x: auto; }
.docs-content pre code { background: none; border: none; padding: 0; }
.docs-content blockquote { margin: 14px 0; padding: 6px 16px; border-left: 3px solid var(--accent); color: var(--muted); background: color-mix(in srgb, var(--accent) 5%, transparent); border-radius: 0 8px 8px 0; }
.docs-content table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: var(--fs-md); }
.docs-content th, .docs-content td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
.docs-content th { background: var(--panel-2); }
.docs-content strong { color: var(--ink); }
@media (max-width: 760px) {
  .docs-wrap { flex-direction: column; }
  .docs-nav { position: static; flex-basis: auto; width: 100%; }
  .docs-nav nav { flex-direction: row; flex-wrap: wrap; }
}

/* ===== song builder (songbuilder.js) ===== */
body.sb-lock { overflow: hidden; }
.sb-overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  padding: clamp(8px, 3vh, 40px) clamp(8px, 3vw, 32px); overflow-y: auto;
}
.sb-overlay.open { display: flex; align-items: flex-start; justify-content: center; }
.sb-modal {
  width: 100%; max-width: 920px; margin: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; max-height: calc(100vh - clamp(16px, 6vh, 80px));
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
}
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.sb-h { margin: 0; font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.sb-icon { background: transparent; border: 1px solid var(--line-soft); color: var(--muted); border-radius: var(--radius-sm); padding: 6px 10px; line-height: 1; }
.sb-icon:hover { color: var(--ink); border-color: var(--line-hover); }
.sb-body { padding: 18px 20px; overflow-y: auto; }

.sb-fields { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.sb-f { display: flex; flex-direction: column; gap: 5px; font-size: var(--fs-xs); letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); flex: 1 1 160px; font-family: var(--font-mono); }
.sb-f-sm { flex: 0 0 96px; }
.sb-f-wide { flex: 1 1 100%; }
.sb-f input, .sb-f select { text-transform: none; letter-spacing: normal; font: inherit; font-family: var(--font-body); color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; }
.sb-f select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235f5a4e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
html[data-theme="dark"] .sb-f select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239a9483' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
html[data-theme="dj"] .sb-f select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a99fd8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
.sb-f select:hover { border-color: var(--line-hover); }
.sb-f input:focus-visible, .sb-f select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-color: transparent; }

.sb-block { border-top: 1px solid var(--line-soft); padding-top: 16px; margin-top: 16px; }
.sb-block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sb-block-head h3 { margin: 0; font-size: 0.95rem; font-weight: 600; font-family: var(--font-display); }
.sb-hint { color: var(--faint); font-size: 0.82rem; margin: 8px 2px; line-height: 1.5; }

.sb-mini { font-size: 0.8rem; padding: 6px 11px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.sb-mini:hover { border-color: var(--line-hover); }
.sb-mini.danger { color: var(--hot); border-color: color-mix(in srgb, var(--hot) 45%, transparent); background: transparent; }
.sb-mini.danger:hover { background: color-mix(in srgb, var(--hot) 12%, transparent); border-color: var(--hot); }
.sb-mini:disabled { opacity: 0.4; cursor: not-allowed; }

/* commit + advance: the primary step-entry action, sits under the keys */
.sb-palette-foot { display: flex; justify-content: flex-end; margin-top: 10px; }
.sb-next { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); font-weight: 600; }
.sb-next:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* section tabs */
.sb-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.sb-tab { font-size: 0.82rem; padding: 6px 12px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line-soft); border-radius: 999px; }
.sb-tab:hover { color: var(--ink); border-color: var(--line-hover); }
.sb-tab.active { color: var(--accent-on); background: var(--accent-fill); border-color: transparent; font-weight: 600; }

.sb-sec-box { background: color-mix(in srgb, var(--ink) 1.5%, transparent); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 14px; }
.sb-sec-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.sb-len { display: flex; align-items: center; gap: 8px; }
.sb-len-lbl { font-size: var(--fs-xs); letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); font-family: var(--font-mono); }
.sb-len-val { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 6ch; text-align: center; font-size: var(--fs-sm); font-family: var(--font-mono); }

/* note palette */
.sb-palette { margin-top: 12px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.sb-oct-ctrl { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.sb-oct-val { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 5ch; text-align: center; font-size: var(--fs-sm); font-family: var(--font-mono); }
.sb-keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
@media (min-width: 560px) { .sb-keys { grid-template-columns: repeat(12, 1fr); } }
.sb-key { padding: 12px 4px; font-size: 0.82rem; font-weight: 600; background: var(--white-key); color: var(--white-key-ink); border: 1px solid var(--device-wkey-edge); border-radius: 6px; min-height: 44px; font-family: var(--font-mono); }
.sb-key.black { background: var(--black-key); color: #cfc9ba; border-color: #000; }
.sb-key:hover { filter: brightness(0.95); }
.sb-key.on { background: var(--accent-fill); color: var(--accent-on); border-color: transparent; box-shadow: 0 0 0 2px var(--accent-glow); }
.sb-key.black.on { background: var(--accent-2); color: var(--accent2-on); }

/* arrangement */
.sb-arr { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; min-height: 38px; }
.sb-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: var(--fs-sm); }
.sb-chip-label { color: var(--ink); }
.sb-chip-btn { background: transparent; border: 1px solid transparent; color: var(--muted); border-radius: 999px; padding: 2px 8px; font-size: 0.9rem; line-height: 1; min-width: 28px; }
.sb-chip-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.sb-chip-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.sb-arr-add { font: inherit; font-family: var(--font-body); color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; max-width: 320px; }

/* saved list */
.sb-saved { display: flex; flex-direction: column; gap: 6px; }
.sb-saved-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); }
.sb-saved-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-size: var(--fs-md); }
.sb-empty { color: var(--faint); font-size: var(--fs-sm); margin: 4px 2px; }

/* footer */
.sb-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line-soft); }
.sb-foot-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sb-status { font-size: var(--fs-sm); color: var(--muted); flex: 1 1 200px; min-width: 0; }
.sb-status.ok { color: var(--accent); }
.sb-status.err { color: var(--hot); }

@media (max-width: 560px) {
  .sb-foot { flex-direction: column; align-items: stretch; }
  .sb-foot-btns { justify-content: space-between; }
  .masthead { align-items: flex-start; }
  .mast-id { gap: 12px; }
  .mtx-mark { width: 44px; }
  /* transport stacks: the flow arrows only make sense in the wide single-row
     layout, so drop them; each drawer takes the full width and stacks. */
  .transport-arrow { display: none; }
  .song-pick { width: 100%; }
  .song-pick label.field { flex: 1 1 100%; }
  .song-pick #song { width: 100%; }
  .tweaks .drawer { flex: 1 1 100%; }
}

/* ============================== PRACTICE (HIGHWAY) ============================
   "Disco Hero" falling-notes practice mode. The canvas (highway.js) carries the
   game art; this is just the chrome + surface. Tokens only, both themes. */
/* Practice is the page's primary call-to-action: the single loud, amber-filled
   button, sitting right beside the song picker and naming the selected song.
   ▶ Play is demoted to a quiet outlined accent so it never competes. */
.practice-cta {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 1px;
  background: var(--accent-fill); color: var(--accent-on);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 20px; line-height: 1.1; cursor: pointer;
  font-family: var(--font-display); white-space: nowrap;
  box-shadow: 0 0 0 3px var(--accent-glow);
  transition: filter 0.12s ease, box-shadow 0.12s ease;
}
.practice-cta:hover { filter: brightness(1.06); box-shadow: 0 0 0 4px var(--accent-glow), 0 6px 18px var(--accent-glow); }
.practice-cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.practice-cta-main { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.practice-cta-sub { font-size: var(--fs-xs); font-family: var(--font-mono); opacity: 0.82; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }

.transport-secondary { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.play-2nd { background: transparent; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); font-weight: 600; }
.play-2nd:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); }

/* .stage sets display:grid, which would beat the [hidden] UA rule; this
   attribute selector has higher specificity so Practice can hide the trainer. */
.stage[hidden] { display: none; }

/* Practice runs full-viewport: hide the trainer chrome so the highway (which now
   contains the keybed) fits a half-size window with no page scroll. */
body.practice-open { overflow: hidden; }
body.practice-open .masthead,
body.practice-open .mast-lede-row,
body.practice-open footer,
body.practice-open .wrap > details.panel { display: none; }
body.practice-open .wrap { padding-top: 14px; padding-bottom: 14px; }
body.practice-open .highway-view {
  display: flex; flex-direction: column; margin: 0;
  height: calc(100dvh - 28px);
}
body.practice-open .highway-canvas {
  flex: 1 1 auto; height: auto; min-height: 0; max-height: none;
}

.highway-view { margin-top: 18px; }
.highway-bar { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.highway-title { margin: 0 auto 0 0; font-family: var(--font-display); font-size: var(--fs-h2); font-weight: 600; color: var(--ink); }
.highway-modes .chip-btn { color: var(--muted); }
.highway-modes .chip-btn[aria-pressed="true"] { background: var(--accent-fill); color: var(--accent-on); border-color: transparent; font-weight: 600; }
.highway-tempo { gap: 6px; }
.highway-tempo input[type="range"] { width: 150px; accent-color: var(--accent-fill); cursor: pointer; }
.highway-tempo #tempoVal { color: var(--ink); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.highway-canvas {
  width: 100%; height: min(58vh, 560px); min-height: 340px; display: block;
  background: var(--scope-bg); border: 1px solid var(--scope-edge);
  border-radius: var(--radius); touch-action: none;
}
.highway-hint { margin-top: 8px; }
.highway-hint kbd {
  font-family: var(--font-mono); font-size: 0.9em; color: var(--ink);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border: 1px solid var(--line-soft); border-radius: 4px; padding: 1px 5px;
}

/* end-of-run results */
.highway-end {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(4px);
}
.highway-end[hidden] { display: none; }
.highway-end-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 36px; text-align: center; max-width: 380px; width: 100%;
  box-shadow: 0 24px 60px color-mix(in srgb, var(--scope-bg) 50%, transparent);
}
.highway-stars { font-size: 2.6rem; letter-spacing: 8px; color: var(--phosphor); text-shadow: 0 0 14px color-mix(in srgb, var(--phosphor) 55%, transparent); }
.highway-acc { font-size: 3rem; font-weight: 600; color: var(--ink); font-family: var(--font-display); line-height: 1.1; margin-top: 6px; }
.highway-end-line { color: var(--accent); font-size: var(--fs-md); margin-top: 4px; }
.highway-best { color: var(--muted); font-size: var(--fs-sm); margin: 8px 0 20px; }
.highway-end-actions { justify-content: center; }

@media (max-width: 560px) {
  .highway-bar { gap: 10px; }
  .highway-title { flex: 1 1 100%; margin: 0 0 4px; }
  .highway-tempo input[type="range"] { width: 110px; }
}
