/* OPLL Playground — theme-aware styling. No external fonts/assets.
   Family sibling of msx-edu-psg / msx-edu-scc; accent shifted to FM-PAC teal. */

:root {
  --bg: #eef3f3;
  --bg-panel: #ffffff;
  --bg-sunken: #e4ecec;
  --bg-hover: #dcebea;
  --bg-active: #cfeae7;
  --text: #12211f;
  --text-dim: #4a5d5b;
  --text-faint: #7f9391;
  --border: #d5e2e1;
  --border-strong: #b7cccb;
  --accent: #0e8a86;
  --accent-strong: #0a6c69;
  --accent-soft: #d6f0ee;
  --mod: #d08a2a;          /* modulator signal (warm, contrasts the teal carrier) */
  --warn-bg: #fdf3d8;
  --warn-border: #e8c96a;
  --warn-text: #7a5a00;
  --danger: #b5473a;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 1px 3px rgba(10, 40, 38, 0.08), 0 4px 16px rgba(10, 40, 38, 0.06);

  /* component-specific (read by canvas via getComputedStyle) */
  --scope-bg: #08201f;
  --scope-grid: rgba(255, 255, 255, 0.07);
  --scope-line: #43cfc7;
  --scope-mod: #e0a24a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1615;
    --bg-panel: #12201f;
    --bg-sunken: #0a1413;
    --bg-hover: #1a2c2a;
    --bg-active: #123a36;
    --text: #e6f2f0;
    --text-dim: #9db6b3;
    --text-faint: #6b817f;
    --border: #203230;
    --border-strong: #2e433f;
    --accent: #2bb3ab;
    --accent-strong: #57d0c7;
    --accent-soft: #0f2e2b;
    --mod: #e0a24a;
    --warn-bg: #2e2711;
    --warn-border: #5e4f1e;
    --warn-text: #e0c56a;
    --danger: #e28175;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
    --scope-bg: #061716;
    --scope-grid: rgba(255, 255, 255, 0.06);
    --scope-line: #43cfc7;
    --scope-mod: #e0a24a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

/* Keyboard users get a clear focus ring everywhere; mouse users don't. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
a:focus-visible, button:focus-visible { outline-offset: 2px; }

@media (max-width: 680px) {
  .site-header { padding: 0.7rem 0.9rem; gap: 0.6rem; }
  .site-nav { order: 3; width: 100%; }
  #main { padding: 1rem 0.9rem 2rem; }
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

/* --- Header ------------------------------------------------------------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.logo { width: 40px; height: 40px; flex: none; }
.logo-body { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.logo-wave { stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
.tagline { margin: 0; font-size: 0.82rem; color: var(--text-dim); }
.header-badges { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.badge {
  font-size: 0.74rem; padding: 0.3rem 0.6rem; border-radius: 999px;
  background: var(--bg-sunken); color: var(--text-dim); border: 1px solid var(--border);
  text-decoration: none;
}
.badge-link:hover { background: var(--bg-hover); color: var(--accent-strong); }

/* --- Layout ------------------------------------------------------------- */
#main { flex: 1; width: min(1000px, 100%); margin: 0 auto; padding: 1.2rem 1.4rem 2rem; }
.phase-note {
  font-size: 0.85rem; color: var(--text-dim);
  background: var(--accent-soft); border: 1px solid var(--border);
  padding: 0.6rem 0.9rem; border-radius: 8px; margin: 0 0 1.2rem;
}
.phase-note b { color: var(--text); }
.stage { display: flex; flex-direction: column; gap: 1.1rem; }

/* --- Scope -------------------------------------------------------------- */
.scope-wrap {
  border: 1px solid var(--border-strong); border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow); background: var(--scope-bg);
}
.scope { display: block; width: 100%; height: 220px; }
.viz-row { display: grid; grid-template-columns: 1.7fr 1fr; gap: 1rem; }
.viz-row .scope-wrap { min-width: 0; }
.adsr-canvas { height: 220px; }
@media (max-width: 720px) { .viz-row { grid-template-columns: 1fr; } }

/* --- Operator pair (★ the FM star widget) ------------------------------- */
.pair-wrap { display: block; }
.pair-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  flex-wrap: wrap; padding: 0.5rem 0.8rem;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
.pair-title { font-weight: 650; font-size: 0.9rem; }
.pair-arrow { color: var(--accent); font-weight: 700; }
.pair-toggle { font-size: 0.78rem; }
.pair-canvas { display: block; width: 100%; height: 250px; background: var(--scope-bg); }
@media (max-width: 720px) { .pair-canvas { height: 200px; } }

/* --- Phase wheel (the FM mechanism, in slow motion) --------------------- */
.wheel-wrap { display: block; }
.wheel-controls { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.wheel-rate { font-size: 0.72rem; color: var(--text-faint); font-family: var(--mono); }
.wheel-canvas { display: block; width: 100%; height: 260px; background: var(--scope-bg); }
.wheel-readout {
  font-family: var(--mono); font-size: 0.78rem; color: var(--text-dim);
  background: var(--bg-panel); border-top: 1px solid var(--border);
  padding: 0.45rem 0.8rem; display: flex; gap: 0.4rem 1.6rem;
  flex-wrap: wrap; align-items: baseline;
}
.wheel-readout b { color: var(--text); font-weight: 650; }
.wheel-readout > span { white-space: nowrap; }
.wheel-pale { color: var(--text-faint); }
.wheel-pale b { color: var(--text-dim); }
.wheel-verb { color: var(--mod); margin-left: auto; }
/* The verb is the one part whose text changes length as the modulator swings.
   Reserving the widest option ("lingering behind") keeps the row from re-wrapping
   and the bar from growing a line and snapping back. */
.wheel-slot { display: inline-block; min-width: 17ch; }
@media (max-width: 720px) { .wheel-canvas { height: 300px; } }

/* --- Panels ------------------------------------------------------------- */
.panels {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}
.panel {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 0.9rem 1rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 0.7rem;
}
.panel-pitch { border-top: 3px solid var(--accent); }
.panel-env { border-top: 3px solid var(--mod); }
.panel-op-mod { border-top: 3px solid var(--mod); }
.panel-op-car { border-top: 3px solid var(--accent); }
.op-sub {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint); border-bottom: 1px solid var(--border);
  padding-bottom: 0.2rem; margin-top: 0.2rem;
}
.chk-row { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.2rem; }
.chk { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--text-dim); cursor: pointer; }
.chk input { accent-color: var(--accent); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; }
.panel-title { font-weight: 650; font-size: 0.95rem; }
.panel-tag {
  font-family: var(--mono); font-size: 0.7rem; color: var(--text-faint);
  background: var(--bg-sunken); padding: 0.1rem 0.4rem; border-radius: 5px;
}
.readout { display: flex; align-items: baseline; gap: 0.5rem; }
.readout-freq { font-size: 1.5rem; font-weight: 640; font-family: var(--mono); letter-spacing: -0.02em; }
.readout-note { font-size: 0.8rem; color: var(--text-dim); font-family: var(--mono); }
.ctl { display: flex; flex-direction: column; gap: 0.25rem; }
.ctl-label { font-size: 0.78rem; color: var(--text-dim); display: flex; justify-content: space-between; }
.ctl-label b { color: var(--text); font-family: var(--mono); }
.ctl-sub { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-faint); }
.ctl-sub code { font-family: var(--mono); color: var(--text-dim); }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

/* --- Master ------------------------------------------------------------- */
.panel-master { border-top: 3px solid var(--border-strong); }
.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--border-strong);
  background: var(--bg-panel); color: var(--text); border-radius: 8px;
  padding: 0.5rem 0.8rem; font-weight: 600;
}
.btn:hover { background: var(--bg-hover); }
.btn-play { background: var(--accent); color: #fff; border-color: var(--accent-strong); font-size: 1rem; }
.btn-play:hover { background: var(--accent-strong); }
.btn-play.playing { background: var(--danger); border-color: var(--danger); }
.master-hint { font-size: 0.74rem; color: var(--text-faint); margin: 0; }
kbd {
  font-family: var(--mono); font-size: 0.72rem; background: var(--bg-sunken);
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 4px; padding: 0.05rem 0.3rem;
}

/* --- Piano -------------------------------------------------------------- */
.piano-mount { width: 100%; }
.piano-board { position: relative; height: 120px; user-select: none; touch-action: none; }
.pkey { position: absolute; top: 0; padding: 0; cursor: pointer; font: inherit; border: 1px solid var(--border-strong); }
.pkey-white {
  height: 100%; background: linear-gradient(var(--bg-panel), var(--bg-sunken));
  border-radius: 0 0 5px 5px; display: flex; align-items: flex-end; justify-content: center;
}
.pkey-white.pressed { background: var(--accent-soft); }
.pkey-black {
  height: 62%; z-index: 2; border-color: #000;
  background: linear-gradient(#183330, #08201f); border-radius: 0 0 4px 4px;
}
.pkey-black.pressed { background: linear-gradient(var(--accent-strong), var(--accent)); }
.pkey-label { font-size: 0.6rem; color: var(--text-faint); pointer-events: none; padding-bottom: 3px; }

/* A page-hosted keyboard (the `[data-shell-keyboard]` slot). On pages you play
   rather than read, the keys are the primary control, so they get a frame of
   their own and more height instead of sitting at the foot of the tool strip. */
.keys-stage {
  margin: 0.2rem 0 1.2rem;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-top: 3px solid var(--accent); border-radius: 12px;
  padding: 0.2rem 1rem 1rem; box-shadow: var(--shadow);
}
.keys-stage .tools-hint { max-width: none; }
.keys-stage .piano-board { height: 150px; }
.keys-stage .pkey-label { font-size: 0.66rem; }

/* --- Register inspector ------------------------------------------------- */
.reg-section { margin-top: 1.4rem; }
.section-title { font-size: 1rem; margin: 0 0 0.7rem; display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
.section-sub { font-size: 0.78rem; font-weight: 400; color: var(--text-faint); }
.reg-inspector {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0.8rem;
}
.reg-group {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.5rem 0.6rem; box-shadow: var(--shadow);
}
.reg-group-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.82rem; font-weight: 650; margin-bottom: 0.4rem; color: var(--text-dim);
}
.reg-group-head code { font-family: var(--mono); font-size: 0.72rem; color: var(--text-faint); }
.reg-group-body { display: flex; flex-direction: column; gap: 3px; }
.reg-row {
  display: grid; grid-template-columns: 2.2rem auto 1.6rem; grid-template-rows: auto auto;
  align-items: center; gap: 0.1rem 0.4rem;
  padding: 0.2rem 0.3rem; border-radius: 6px; background: var(--bg-sunken);
  transition: opacity 0.15s;
}
.reg-row.dim { opacity: 0.32; }
.reg-addr { font-family: var(--mono); font-size: 0.78rem; color: var(--accent-strong); font-weight: 650; }
.reg-hex { font-family: var(--mono); font-size: 0.78rem; color: var(--text); text-align: right; }
.reg-bits { display: inline-flex; gap: 2px; }
.reg-bit {
  width: 1.05rem; height: 1.05rem; padding: 0; cursor: pointer;
  background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: 3px;
  font-size: 0; transition: background 0.1s, border-color 0.1s;
}
.reg-bit.on { background: var(--accent); border-color: var(--accent-strong); }
.reg-bit:hover { border-color: var(--accent); }
.reg-label { grid-column: 1 / -1; font-size: 0.68rem; color: var(--text-faint); line-height: 1.3; }

/* --- Patch panel + ROM gallery (Phase 4) -------------------------------- */
.patch-panel {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  border-top: 3px solid var(--accent); padding: 0.8rem 0.9rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 0.6rem;
}
.patch-status { margin: 0; font-size: 0.8rem; color: var(--text-dim); }
.patch-status b { color: var(--text); }
.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.preset-label { font-size: 0.76rem; color: var(--text-faint); }
.preset-chip {
  font: inherit; font-size: 0.76rem; cursor: pointer; padding: 0.2rem 0.55rem;
  background: var(--bg-sunken); color: var(--text-dim);
  border: 1px solid var(--border-strong); border-radius: 999px;
}
.preset-chip:hover { background: var(--bg-hover); color: var(--accent-strong); border-color: var(--accent); }

.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 0.5rem;
}
.inst-tile {
  display: flex; flex-direction: column; gap: 0.3rem; cursor: pointer;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 9px; padding: 0.4rem 0.45rem 0.45rem;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.inst-tile:hover { border-color: var(--accent); background: var(--bg-hover); }
.inst-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inst-tile.active {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.inst-user { border-style: dashed; border-color: var(--mod); }
.inst-user.active { box-shadow: inset 0 0 0 1px var(--mod); border-style: solid; }
.inst-fp {
  display: block; width: 100%; height: 40px; border-radius: 5px;
  background: var(--scope-bg); border: 1px solid var(--border);
}
.inst-meta { display: flex; align-items: baseline; gap: 0.35rem; min-width: 0; }
.inst-idx {
  font-family: var(--mono); font-size: 0.66rem; color: var(--text-faint);
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 0.28rem;
}
.inst-name {
  font-size: 0.78rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.inst-copy {
  font: inherit; font-size: 0.66rem; cursor: pointer; align-self: flex-start;
  padding: 0.12rem 0.4rem; color: var(--accent-strong);
  background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: 5px;
}
.inst-copy:hover { background: var(--accent); color: #fff; border-color: var(--accent-strong); }
.gallery-hint { margin: 0; font-size: 0.74rem; color: var(--text-faint); line-height: 1.4; }
.gallery-hint b { color: var(--text-dim); }

/* --- Voices mixer (Phase 5) --------------------------------------------- */
.voices-section { margin-top: 1.4rem; }
.voices-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.6rem;
}
.chan-strip {
  display: flex; flex-direction: column; gap: 0.4rem;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-top: 3px solid var(--accent); border-radius: 10px;
  padding: 0.5rem 0.55rem 0.6rem; box-shadow: var(--shadow);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.chan-strip.sounding { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.chan-head { display: flex; align-items: baseline; justify-content: space-between; }
.chan-id { font-weight: 650; font-size: 0.9rem; }
.chan-tag { font-family: var(--mono); font-size: 0.66rem; color: var(--text-faint); }
.chan-inst {
  font: inherit; font-size: 0.76rem; width: 100%; padding: 0.2rem 0.3rem;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 6px;
}
.chan-ctl { display: flex; flex-direction: column; gap: 0.15rem; }
.chan-ctl span { font-size: 0.72rem; color: var(--text-dim); display: flex; justify-content: space-between; }
.chan-ctl span b { color: var(--text); font-family: var(--mono); font-size: 0.72rem; }
.chan-key {
  font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer;
  padding: 0.35rem 0.5rem; margin-top: 0.1rem; user-select: none;
  background: var(--bg-sunken); color: var(--text-dim);
  border: 1px solid var(--border-strong); border-radius: 7px;
}
.chan-key:hover { background: var(--bg-hover); }
.chan-key.on { background: var(--accent); color: #fff; border-color: var(--accent-strong); }

/* --- Rhythm ------------------------------------------------------------- */
.rhythm-section { margin-top: 1.4rem; }
.panel-rhythm { border-top: 3px solid var(--mod); }
.rhythm-mode { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; cursor: pointer; }
.rhythm-mode input { accent-color: var(--mod); width: 1.05rem; height: 1.05rem; }
.rhythm-mode-hint { color: var(--text-faint); font-weight: 400; font-size: 0.76rem; }
.drum-pads {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 0.55rem;
  opacity: 0.45; pointer-events: none; transition: opacity 0.15s;
}
.drum-pads.armed { opacity: 1; pointer-events: auto; }
.drum-pad-cell { display: flex; flex-direction: column; gap: 0.35rem; }
.drum-pad {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  font: inherit; cursor: pointer; user-select: none; touch-action: none;
  background: var(--bg-sunken); color: var(--text-dim);
  border: 1px solid var(--border-strong); border-radius: 9px;
  padding: 0.55rem 0.3rem 0.45rem;
  transition: background 0.08s, color 0.08s, border-color 0.08s, transform 0.05s;
}
.drum-pad:hover { background: var(--bg-hover); }
.drum-pad:active { transform: translateY(1px); }
.drum-glyph { font-size: 1.15rem; line-height: 1; }
.drum-name { font-size: 0.76rem; font-weight: 600; color: var(--text); }
.drum-bit { font-family: var(--mono); font-size: 0.62rem; color: var(--text-faint); }
.drum-pad.hit {
  background: var(--mod); border-color: var(--mod);
  color: #fff; box-shadow: 0 0 0 3px color-mix(in srgb, var(--mod) 30%, transparent);
}
.drum-pad.hit .drum-name, .drum-pad.hit .drum-bit { color: #fff; }
.drum-vol { accent-color: var(--mod); }
.rhythm-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; flex-wrap: wrap; }
.beat-btn.playing { background: var(--mod); color: #fff; border-color: var(--mod); }
.rhythm-reg { font-family: var(--mono); font-size: 0.72rem; color: var(--text-dim); background: var(--bg-sunken); padding: 0.15rem 0.45rem; border-radius: 5px; }

/* === Phase 7: the multi-page split ====================================== */

/* --- Header nav + transport -------------------------------------------- */
.brand-link { display: flex; align-items: center; gap: 0.85rem; text-decoration: none; color: inherit; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.btn-transport { padding: 0.4rem 0.9rem; font-size: 0.9rem; min-width: 5.4rem; }
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.nav-group { display: flex; flex-wrap: wrap; gap: 0.15rem; }
.nav-link {
  font-size: 0.84rem; font-weight: 600; color: var(--text-dim); text-decoration: none;
  padding: 0.35rem 0.6rem; border-radius: 7px; white-space: nowrap;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }
.nav-group-alt {
  padding-left: 0.45rem; margin-left: 0.15rem;
  border-left: 1px solid var(--border-strong);
}
.nav-group-alt .nav-link { color: var(--text-faint); }
.nav-group-alt .nav-link:hover { color: var(--text); }
.nav-soon { cursor: default; opacity: 0.55; }
.nav-soon:hover { background: none; color: var(--text-dim); }
.nav-soon em {
  font-style: normal; font-size: 0.62em; text-transform: uppercase;
  letter-spacing: 0.05em; margin-left: 0.3rem; color: var(--text-faint);
}

/* --- Focus-page layout -------------------------------------------------- */
.focus-page { display: flex; flex-direction: column; gap: 1.1rem; }
.page-title { font-size: 1.5rem; margin: 0.2rem 0 -0.4rem; letter-spacing: -0.01em; }
.page-title .page-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; margin-right: 0.4rem; vertical-align: 0.05em;
  border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 0.85rem; font-weight: 700;
}
.page-intro { font-size: 0.92rem; color: var(--text-dim); line-height: 1.6; margin: 0; max-width: 72ch; }
.page-intro b { color: var(--text); }
.page-intro code, .mem-intro code, .reg-intro code, .note-box code, .card code, .hero-sub code {
  font-family: var(--mono); font-size: 0.86em; background: var(--bg-sunken);
  padding: 0.05rem 0.3rem; border-radius: 4px; color: var(--text);
}
.sub-title { font-size: 1.1rem; margin: 0.6rem 0 -0.2rem; }

/* --- Chain navigation (pips + prev/next) -------------------------------- */
.chain-dots { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chain-dot {
  display: flex; align-items: center; gap: 0.35rem; text-decoration: none;
  font-size: 0.76rem; color: var(--text-dim); font-weight: 600;
  padding: 0.25rem 0.55rem 0.25rem 0.3rem; border-radius: 999px;
  border: 1px solid var(--border);
}
.chain-dot:hover { background: var(--bg-hover); color: var(--text); }
.chain-dot .dot-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.15rem; height: 1.15rem; border-radius: 50%;
  background: var(--bg-sunken); color: var(--text-faint);
  font-family: var(--mono); font-size: 0.66rem;
}
.chain-dot.here { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.chain-dot.here .dot-n { background: var(--accent); color: #fff; }
.chain-dot.soon { opacity: 0.5; }
.chain-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem;
  margin-top: 0.6rem; padding-top: 1.1rem; border-top: 1px solid var(--border);
}
.chain-link {
  display: flex; flex-direction: column; gap: 0.1rem; text-decoration: none;
  padding: 0.7rem 0.9rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-panel); color: inherit;
}
.chain-link:hover { border-color: var(--accent); background: var(--bg-hover); }
.chain-next { text-align: right; }
.chain-dir { font-size: 0.7rem; color: var(--text-faint); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.chain-title { font-weight: 650; font-size: 0.95rem; }
.chain-lede { font-size: 0.76rem; color: var(--text-dim); }
.chain-link.is-soon { opacity: 0.55; }
.chain-end { display: block; }

/* --- Prose blocks + challenges ------------------------------------------ */
.note-box {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 0.8rem 1rem; background: var(--bg-panel);
}
.note-box h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.note-box p { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--text-dim); line-height: 1.6; max-width: 74ch; }
.note-box p:last-child { margin-bottom: 0; }
.note-box b { color: var(--text); }
.warn-box { border-left-color: var(--warn-border); background: var(--warn-bg); }
.warn-box h3, .warn-box b { color: var(--warn-text); }
.warn-box p { color: var(--warn-text); }

.formula {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.7rem 1rem;
}
.formula-body { font-family: var(--mono); font-size: 1rem; display: inline-flex; align-items: center; gap: 0.3rem; }
.formula-note { font-size: 0.78rem; color: var(--text-dim); margin-left: auto; }

.mini-table { border-collapse: collapse; font-size: 0.8rem; margin-top: 0.5rem; }
.mini-table th, .mini-table td { padding: 0.25rem 0.7rem 0.25rem 0; text-align: left; border-bottom: 1px solid var(--border); }
.mini-table th { color: var(--text-faint); font-size: 0.72rem; font-weight: 650; }
.mini-table td { font-family: var(--mono); color: var(--text-dim); }
.mini-table td:first-child { color: var(--text); }
.mini-table b { color: var(--accent-strong); }

.challenges { border: 1px solid var(--border-strong); border-radius: 12px; padding: 0.8rem 1rem; background: var(--bg-panel); }
.challenges-head { margin: 0 0 0.5rem; font-size: 0.95rem; }
.challenge-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.challenge { display: flex; align-items: flex-start; gap: 0.6rem; }
.challenge-mark {
  flex: none; width: 1.15rem; height: 1.15rem; margin-top: 0.1rem;
  border: 2px solid var(--border-strong); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.25s, border-color 0.25s;
}
.challenge.done .challenge-mark { background: var(--accent); border-color: var(--accent); }
.challenge.done .challenge-mark::after { content: '✓'; color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 1; }
.challenge-body { display: flex; flex-direction: column; }
.challenge-task { font-size: 0.85rem; color: var(--text); line-height: 1.5; }
.challenge-task code { font-family: var(--mono); font-size: 0.88em; }
.challenge-hint { font-size: 0.74rem; color: var(--text-faint); }
.challenge.done .challenge-task, .challenge.done .challenge-task b { color: var(--text-dim); }

/* --- Shared tool strip (piano + register inspector) --------------------- */
.tools-hint { font-size: 0.78rem; color: var(--text-dim); line-height: 1.6; margin: 0.4rem 0 0; max-width: 76ch; }
.tools-hint b { color: var(--text); }
.reg-details { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-panel); padding: 0.2rem 0.4rem; }
.reg-details > summary {
  cursor: pointer; font-size: 0.85rem; font-weight: 600; padding: 0.5rem 0.6rem;
  color: var(--text-dim);
}
.reg-details > summary:hover { color: var(--text); }
.reg-details[open] > summary { color: var(--text); }
.reg-intro { font-size: 0.8rem; color: var(--text-dim); line-height: 1.55; margin: 0 0.6rem 0.6rem; max-width: 78ch; }

/* --- Landing ------------------------------------------------------------ */
.landing { display: flex; flex-direction: column; gap: 1.6rem; }
.hero { display: flex; flex-direction: column; gap: 0.7rem; align-items: flex-start; }
.hero-hook { font-size: clamp(1.5rem, 4vw, 2.3rem); margin: 0.4rem 0 0; letter-spacing: -0.02em; line-height: 1.15; max-width: 22ch; }
.hero-sub { font-size: 1rem; color: var(--text-dim); line-height: 1.65; margin: 0; max-width: 68ch; }
.hero-sub b { color: var(--text); }
.hero-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.2rem; }
.btn-hero { padding: 0.6rem 1.2rem; }
.btn-hero-alt {
  display: inline-flex; align-items: center; text-decoration: none;
  font: inherit; font-weight: 600; padding: 0.6rem 1.2rem; font-size: 1rem;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--bg-panel); color: var(--text);
}
.btn-hero-alt:hover { background: var(--bg-hover); border-color: var(--accent); }
.hero-note { font-size: 0.78rem; color: var(--text-faint); margin: 0; max-width: 68ch; min-height: 2.4em; }
.path-caption { font-size: 0.8rem; color: var(--text-faint); margin: -0.8rem 0 0; text-align: center; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 1rem; }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; background: var(--bg-panel); box-shadow: var(--shadow); }
.card h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.card p { margin: 0 0 0.6rem; font-size: 0.85rem; color: var(--text-dim); line-height: 1.6; }
.card p:last-child { margin-bottom: 0; }
.card cite { font-style: italic; }
.card-link { color: var(--accent-strong); text-decoration: none; font-weight: 650; font-size: 0.82rem; }
a.card-link:hover { text-decoration: underline; }

.chain-index { display: flex; flex-direction: column; gap: 0.7rem; }
.chain-index h3 { margin: 0; font-size: 1.15rem; }
.chain-index-sub { margin: -0.3rem 0 0.2rem; font-size: 0.85rem; color: var(--text-dim); max-width: 68ch; }
.chain-cards { list-style: none; margin: 0.3rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0.6rem; }
.chain-card-link {
  display: flex; align-items: flex-start; gap: 0.6rem; text-decoration: none;
  color: inherit; padding: 0.7rem 0.8rem; height: 100%;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-panel);
}
a.chain-card-link:hover { border-color: var(--accent); background: var(--bg-hover); }
.chain-card.is-soon { opacity: 0.55; }
.chain-card-n {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  font-family: var(--mono); font-size: 0.75rem; font-weight: 700;
}
.chain-card-link b { display: block; font-size: 0.9rem; }
.chain-card-lede { display: block; font-size: 0.75rem; color: var(--text-dim); line-height: 1.45; }

/* --- Signal-path diagram (hero + navigator) ----------------------------- */
.signal-path {
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--scope-bg); padding: 0.6rem; box-shadow: var(--shadow); overflow-x: auto;
}
.signal-path svg { display: block; width: 100%; min-width: 680px; height: auto; }
.sp-clock { fill: var(--text-faint); font-family: var(--mono); font-size: 10px; }
.sp-arrowhead { fill: var(--text-faint); opacity: 0.7; }
.sp-wire { stroke: var(--text-faint); stroke-width: 1.2; fill: none; opacity: 0.6; }
.sp-wire-join, .sp-wire-feed { opacity: 0.35; }
.sp-wire-fb { opacity: 0.5; }
.sp-tiny { fill: var(--text-faint); font-family: var(--mono); font-size: 8px; }
.sp-block rect { fill: var(--bg-panel); stroke: var(--border-strong); stroke-width: 1; transition: stroke 0.15s, fill 0.15s; }
.sp-block text { fill: var(--text); font-family: var(--mono); font-size: 11px; }
.sp-block .sp-label { fill: var(--text-dim); font-size: 9px; }
.sp-block:hover rect { stroke: var(--accent); fill: var(--bg-hover); }
.sp-block:focus-visible rect { stroke: var(--accent); stroke-width: 2; }
.sp-block { cursor: pointer; outline: none; }
.sp-block-mod rect { stroke: color-mix(in srgb, var(--mod) 55%, var(--border-strong)); }
.sp-fm-link { cursor: pointer; }
.sp-wire-fm { stroke: var(--mod); stroke-width: 2; opacity: 0.9; }
.sp-fm-label { fill: var(--mod); font-family: var(--mono); font-size: 10px; font-weight: 700; }
.sp-fm-link:hover .sp-wire-fm { stroke-width: 3; }
.sp-glow { pointer-events: none; opacity: 0; stroke: none; }
.sp-block-mod .sp-glow { fill: var(--mod); }
.sp-block-car .sp-glow { fill: var(--accent); }
.sp-block-sum rect, .sp-block-dac rect { fill: var(--bg-sunken); }
.sp-dac-fill { fill: var(--accent); opacity: 0.4; stroke: none; }
.sp-block-inst rect { fill: var(--bg-sunken); border-radius: 8px; }
.sp-block-rhythm rect { fill: var(--bg-sunken); stroke: color-mix(in srgb, var(--mod) 45%, var(--border-strong)); }

.footer-links { margin: 0.4rem 0 0; }
.footer-sep { margin: 0 0.4rem; opacity: 0.5; }

/* Explore: the focus-voice line + the highlighted strip. */
.focus-line { font-size: 0.8rem; color: var(--accent-strong); font-weight: 600; margin: 0; }
.chan-strip.is-focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* === Phase 8: MSX code view + Reference ================================= */

.panel-note { font-size: 0.72rem; color: var(--text-faint); margin: 0; line-height: 1.45; }
.panel-note b { color: var(--text-dim); font-weight: 650; }
.panel-note code { font-family: var(--mono); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

.panel-code { border-top: 3px solid var(--accent); display: flex; flex-direction: column; gap: 0.6rem; }
.code-bar { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.code-bar .btn { margin-left: auto; }
.code-block {
  margin: 0; padding: 0.8rem 0.9rem; border-radius: 10px; overflow-x: auto;
  background: var(--scope-bg); border: 1px solid var(--border-strong);
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.55;
  color: #d8ded9; tab-size: 8; max-height: 30rem;
}
.code-block .c-op { color: #63c8bf; font-weight: 650; }
.code-block .c-num { color: #d9b06a; }
.code-block .c-cmt { color: #6f8380; }

/* --- Reference page ----------------------------------------------------- */
.toc { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.toc a {
  font-size: 0.78rem; font-weight: 600; text-decoration: none; color: var(--text-dim);
  padding: 0.25rem 0.6rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-panel);
}
.toc a:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--bg-hover); }
#main > section { display: flex; flex-direction: column; gap: 0.7rem; scroll-margin-top: 5rem; }

.table-wrap { overflow-x: auto; }
.ref-table {
  width: 100%; border-collapse: collapse; font-size: 0.82rem;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px;
}
.ref-table th {
  text-align: left; font-size: 0.72rem; font-weight: 650; color: var(--text-faint);
  padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.ref-table td {
  padding: 0.35rem 0.7rem; border-bottom: 1px solid var(--border);
  color: var(--text-dim); vertical-align: top;
}
.ref-table tr:last-child td { border-bottom: none; }
.ref-table td:first-child { color: var(--text); white-space: nowrap; }
.ref-table code { font-family: var(--mono); font-size: 0.9em; color: var(--accent-strong); }
.ref-table b { color: var(--text); }
.ref-table em { font-style: normal; font-size: 0.9em; color: var(--text-faint); }
.ref-table-tight td, .ref-table-tight th { padding: 0.25rem 0.5rem; text-align: center; }
.ref-table-tight td:first-child, .ref-table-tight th:first-child { text-align: left; }
.ref-table-tight td:last-child, .ref-table-tight th:last-child { text-align: left; }

.calc-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 1rem; align-items: start; }
.calc-rows { display: flex; flex-direction: column; gap: 0.45rem; }
.calc-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; font-size: 0.82rem; color: var(--text-dim); }
.calc-row input {
  width: 7.5rem; font-family: var(--mono); font-size: 0.88rem; font-weight: 650;
  padding: 0.25rem 0.4rem; text-align: right;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 6px;
}
.calc-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.calc-out {
  margin: 0; font-size: 0.8rem; line-height: 1.6; color: var(--text-dim);
  padding: 0.6rem 0.8rem; border-radius: 8px; background: var(--bg-sunken);
  border-left: 3px solid var(--accent); min-height: 4.4em;
}
.calc-out b { color: var(--text); }
.calc-out code { font-family: var(--mono); font-size: 0.9em; color: var(--accent-strong); }
.calc .btn { align-self: flex-start; }

.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0.8rem; }
.gal-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 0.7rem 0.8rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 0.5rem;
}
.gal-head { display: flex; align-items: baseline; gap: 0.5rem; justify-content: space-between; }
.gal-head b { font-size: 0.9rem; }
.gal-harm { height: 76px; border-radius: 8px; display: block; width: 100%; }
.gal-dec { font-family: var(--mono); font-size: 0.72rem; color: var(--text-dim); }
.gal-foot { display: flex; align-items: center; gap: 0.5rem; justify-content: space-between; flex-wrap: wrap; }
.gal-bytes { font-family: var(--mono); font-size: 0.64rem; color: var(--text-faint); }

@media (max-width: 860px) {
  .calc-grid { grid-template-columns: 1fr; }
}

/* === Tune page (the VGM player) ======================================== */
.loader { display: flex; flex-direction: column; gap: 0.7rem; }
.drop-zone {
  border: 2px dashed var(--border-strong); border-radius: 12px;
  padding: 1.6rem 1.2rem; text-align: center; background: var(--bg-sunken);
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-main { margin: 0 0 0.3rem; font-size: 1rem; font-weight: 600; }
.drop-sub { margin: 0; font-size: 0.8rem; color: var(--text-dim); }
.link-btn {
  font: inherit; font-size: inherit; background: none; border: none; padding: 0;
  color: var(--accent-strong); font-weight: 650; cursor: pointer; text-decoration: underline;
}
.loader-alt { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.loader-note { font-size: 0.76rem; color: var(--text-faint); max-width: 62ch; line-height: 1.5; }
.loader-note code { font-family: var(--mono); font-size: 0.9em; }
.load-error {
  margin: 0; padding: 0.6rem 0.9rem; border-radius: 8px; font-size: 0.82rem;
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text);
}

#nowPlaying { display: flex; flex-direction: column; gap: 1.1rem; }
.tune-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; justify-content: space-between; }
.tune-title { margin: 0; font-size: 1.15rem; }
.tune-sub { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--text-dim); }
.tune-chips { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.chip-tag {
  font-size: 0.7rem; font-family: var(--mono); padding: 0.2rem 0.5rem;
  border-radius: 999px; background: var(--bg-sunken);
  border: 1px solid var(--border); color: var(--text-faint);
}
.chip-tag.is-ours { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); font-weight: 650; }
.chip-tag.is-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }

.transport { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.seek {
  flex: 1; min-width: 120px; height: 6px; border-radius: 999px;
  background: var(--bg-sunken); border: 1px solid var(--border); overflow: hidden;
}
.seek-fill { display: block; height: 100%; width: 0; background: var(--accent); }
.tune-time { font-family: var(--mono); font-size: 0.78rem; color: var(--text-dim); }

.activity { border: 1px solid var(--border); border-radius: 12px; padding: 0.8rem 1rem; background: var(--bg-panel); }
.activity-head {
  margin: 0 0 0.6rem; font-size: 0.9rem;
  display: flex; align-items: baseline; gap: 0.6rem; justify-content: space-between; flex-wrap: wrap;
}
.activity-rate { font-family: var(--mono); font-size: 0.78rem; color: var(--accent-strong); font-weight: 650; }
.activity-bars { display: flex; flex-direction: column; gap: 0.3rem; }
.activity-row { display: grid; grid-template-columns: 6rem 1fr 2.6rem auto; align-items: center; gap: 0.5rem; }
.activity-label { font-size: 0.76rem; color: var(--text-dim); font-weight: 600; }
.activity-track { height: 10px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.activity-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }
.activity-n { font-family: var(--mono); font-size: 0.72rem; color: var(--text-faint); text-align: right; }
.activity-hint { font-size: 0.7rem; color: var(--text-faint); }
.activity-note { margin: 0.6rem 0 0; font-size: 0.75rem; color: var(--text-faint); line-height: 1.55; max-width: 74ch; }
.activity-note code { font-family: var(--mono); font-size: 0.9em; }

@media (max-width: 680px) {
  .activity-row { grid-template-columns: 5rem 1fr 2.4rem; }
  .activity-hint { display: none; }
}

/* --- Footer ------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border); padding: 1rem 1.4rem;
  font-size: 0.76rem; color: var(--text-faint); text-align: center;
}
.site-footer a { color: var(--accent-strong); }
