/* SCC Playground — theme-aware styling. No external fonts/assets.
   Sibling of msx-edu-psg; shares its structure, shifts the accent from synth
   violet to the burnt orange/amber of a Konami cartridge label. */

:root {
  --bg: #f7f4f1;
  --bg-panel: #ffffff;
  --bg-sunken: #f0eae5;
  --bg-hover: #f3e7dd;
  --bg-active: #fadfcc;
  --text: #2b211b;
  --text-dim: #6d5c50;
  --text-faint: #9d8c80;
  --border: #e8ded6;
  --border-strong: #d3c3b7;
  --accent: #c25a2a;
  --accent-strong: #9c4318;
  --accent-soft: #fbe8dc;
  --ch-0: #c25a2a;
  --ch-1: #b8892b;
  --ch-2: #4f8f63;
  --ch-3: #3d72a6;
  --ch-4: #8a5aa8;
  --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(60, 35, 20, 0.08), 0 4px 16px rgba(60, 35, 20, 0.06);

  /* component-specific (read by canvas via getComputedStyle) */
  --scope-bg: #1a1310;
  --scope-grid: rgba(255, 255, 255, 0.07);
  --scope-line: #e8a361;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16110e;
    --bg-panel: #211a15;
    --bg-sunken: #130e0b;
    --bg-hover: #302419;
    --bg-active: #40291a;
    --text: #f2e9e2;
    --text-dim: #c0ab9c;
    --text-faint: #8a7869;
    --border: #35291f;
    --border-strong: #48382b;
    --accent: #e0813f;
    --accent-strong: #f0a066;
    --accent-soft: #3a2415;
    --ch-0: #e0813f;
    --ch-1: #d9ae4b;
    --ch-2: #6cbb86;
    --ch-3: #6aa3dd;
    --ch-4: #b184d6;
    --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: #120d0a;
    --scope-grid: rgba(255, 255, 255, 0.06);
    --scope-line: #e8a361;
  }
}

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

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);
  /* Sticky so the transport is reachable from anywhere on a long page — the
     one control a reader wants without hunting is "make it stop". */
  position: sticky; top: 0; z-index: 20;
}
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.btn-transport { padding: 0.4rem 0.9rem; font-size: 0.9rem; min-width: 5.6rem; }
.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand-link { display: flex; align-items: center; gap: 0.85rem; text-decoration: none; color: inherit; }
.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; }
.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); }

.site-nav { 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); }
.site-nav { align-items: center; gap: 0.4rem; }
.nav-group { display: flex; flex-wrap: wrap; gap: 0.15rem; }
/* The chain and the off-chain pages are different kinds of destination, so the
   nav separates them rather than running all nine names together. */
.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);
}

/* --- Layout ------------------------------------------------------------- */
#main { flex: 1; width: min(1080px, 100%); margin: 0 auto; padding: 1.2rem 1.4rem 2rem; }
.focus-page { display: flex; flex-direction: column; gap: 1.1rem; }
.phase-note {
  font-size: 0.8rem; color: var(--text-dim);
  background: var(--accent-soft); border: 1px solid var(--border);
  padding: 0.6rem 0.9rem; border-radius: 8px; margin: 0;
}
.phase-note b { color: var(--text); }
.page-title { font-size: 1.5rem; margin: 0.2rem 0 -0.4rem; letter-spacing: -0.01em; }
.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 {
  font-family: var(--mono); font-size: 0.86em; background: var(--bg-sunken);
  padding: 0.05rem 0.3rem; border-radius: 4px; color: var(--text);
}

.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;
}
.sub-title { font-size: 1.1rem; margin: 0.6rem 0 -0.4rem; }

/* --- Chain navigation ----------------------------------------------------- */
/* The seven-stage walk, shown twice: pips at the top for "where am I", and a
   pair of prev/next cards at the bottom for "where 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 --------------------------------------------------------- */
.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); }
.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);
}
.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; }
.frac { display: inline-flex; flex-direction: column; text-align: center; vertical-align: middle; }
.frac b { font-weight: 600; padding: 0 0.3rem; }
.frac i { font-style: normal; border-top: 1px solid currentColor; padding: 0.05rem 0.3rem 0; }
.formula-note { font-size: 0.78rem; color: var(--text-dim); margin-left: auto; }
.formula-note.is-frozen { color: var(--danger); font-weight: 650; }

.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); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.rack-slim { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.rack-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* --- Challenges ----------------------------------------------------------- */
.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 { color: var(--text-dim); }
.challenge.done .challenge-task b { color: var(--text-dim); }

/* --- 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: 180px; }

/* --- 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-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.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; white-space: nowrap;
}
.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; }

/* Per-channel accent stripe. */
.panel-channel { border-top: 3px solid var(--ch-0); }
.panel-channel.ch-1 { border-top-color: var(--ch-1); }
.panel-channel.ch-2 { border-top-color: var(--ch-2); }
.panel-channel.ch-3 { border-top-color: var(--ch-3); }
.panel-channel.ch-4 { border-top-color: var(--ch-4); }
.panel-channel.ch-0 .panel-title { color: var(--ch-0); }
.panel-channel.ch-1 .panel-title { color: var(--ch-1); }
.panel-channel.ch-2 .panel-title { color: var(--ch-2); }
.panel-channel.ch-3 .panel-title { color: var(--ch-3); }
.panel-channel.ch-4 .panel-title { color: var(--ch-4); }

/* --- The five-channel rack ----------------------------------------------- */
.rack {
  display: grid; gap: 0.7rem;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.panels-master { grid-template-columns: minmax(240px, 320px); }
.panels-wide { grid-template-columns: 1fr; }

.panel.compact { padding: 0.65rem 0.7rem; gap: 0.5rem; }
.panel.compact .panel-head { gap: 0.3rem; }
.panel.compact .panel-title { font-size: 0.88rem; }
.panel.compact .panel-tag { font-size: 0.62rem; padding: 0.05rem 0.3rem; }
.panel.compact .wave-body { flex-direction: column; gap: 0.35rem; }
.panel.compact .wave-canvas { height: 86px; }
.panel.compact .wave-side { flex: none; max-width: none; }
.panel.compact .harm-canvas { height: 42px; }
.panel.compact .readout { gap: 0.3rem; flex-wrap: wrap; }
.panel.compact .readout-freq { font-size: 1rem; }
.panel.compact .readout-note { font-size: 0.68rem; }
.panel.compact .ctl-label { font-size: 0.7rem; }
.panel.compact .vol-body { gap: 0.5rem; }
.panel.compact .vol-ladder { width: 20px; padding: 3px 4px; gap: 1px; }
.panel.compact .chk { font-size: 0.72rem; }
.panel.compact .panel-note { font-size: 0.66rem; }

.shape-select {
  font-size: 0.72rem; padding: 0.2rem 0.3rem;
}
.shared-note {
  background: var(--accent-soft); border-radius: 5px; padding: 0.3rem 0.4rem;
}

.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); }
.panel-pitch.frozen .readout-freq { color: var(--danger); }

.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; }
select {
  width: 100%; padding: 0.35rem 0.5rem; border-radius: 7px;
  border: 1px solid var(--border-strong); background: var(--bg-panel); color: var(--text);
  font-family: var(--sans); font-size: 0.85rem;
}
.chk { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-dim); cursor: pointer; }
.chk input { accent-color: var(--accent); }

/* --- Waveform panel ------------------------------------------------------ */
.panel-wave { gap: 0.8rem; }
.wave-body { display: flex; gap: 0.9rem; align-items: stretch; }
.wave-canvas {
  flex: 1 1 auto; min-width: 0; height: 190px; display: block;
  background: var(--scope-bg); border-radius: 9px; cursor: crosshair;
  touch-action: none; border: 1px solid transparent;
}
.wave-canvas:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.wave-canvas.locked { cursor: not-allowed; }
.wave-side { flex: 0 0 34%; max-width: 260px; display: flex; flex-direction: column; gap: 0.3rem; }
.wave-side-label { font-size: 0.7rem; color: var(--text-faint); font-family: var(--mono); }
.harm-canvas { flex: 1; width: 100%; display: block; background: var(--scope-bg); border-radius: 9px; }

.wave-shapes { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.shape-btn {
  font: inherit; font-size: 0.76rem; font-weight: 600; cursor: pointer;
  padding: 0.3rem 0.6rem; border-radius: 7px;
  background: var(--bg-sunken); border: 1px solid var(--border); color: var(--text-dim);
}
.shape-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--text); background: var(--bg-hover); }
.shape-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Volume panel -------------------------------------------------------- */
.vol-body { display: flex; gap: 0.8rem; align-items: stretch; }
.vol-ladder {
  width: 34px; flex: none; background: var(--scope-bg); border-radius: 6px;
  padding: 5px 6px; display: flex; flex-direction: column; gap: 2px; justify-content: flex-end;
}
.vol-rung { flex: 1; border-radius: 2px; background: rgba(255, 255, 255, 0.08); }
.vol-rung.lit { background: var(--ch-0); }
.ch-1 .vol-rung.lit { background: var(--ch-1); }
.ch-2 .vol-rung.lit { background: var(--ch-2); }
.ch-3 .vol-rung.lit { background: var(--ch-3); }
.ch-4 .vol-rung.lit { background: var(--ch-4); }
.vol-ctls { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 0.5rem; }
.panel-channel.off .readout, .panel-channel.off .vol-ctls .ctl { opacity: 0.5; }

/* --- Master -------------------------------------------------------------- */
.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;
}

/* --- 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: 20ch;
}
.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; }

/* The featured Tune callout — the site's payoff, sold louder than a grid card. */
.feature-tune {
  display: flex; align-items: center; gap: 1.5rem;
  border: 1px solid var(--accent); border-radius: 14px;
  background: var(--accent-soft); box-shadow: var(--shadow);
  padding: 1.3rem 1.5rem; overflow: hidden;
}
.feature-tune-body { display: flex; flex-direction: column; gap: 0.55rem; flex: 1 1 60%; min-width: 0; }
.feature-tag {
  align-self: flex-start; font-size: 0.66rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--accent-strong); background: var(--bg-panel);
  border: 1px solid var(--accent); border-radius: 999px; padding: 0.15rem 0.55rem;
}
.feature-tune h3 { margin: 0; font-size: 1.2rem; letter-spacing: -0.01em; }
.feature-tune p { margin: 0; font-size: 0.9rem; color: var(--text-dim); line-height: 1.6; max-width: 68ch; }
.feature-tune p code {
  font-family: var(--mono); font-size: 0.86em; background: var(--bg-panel);
  padding: 0.05rem 0.3rem; border-radius: 4px; color: var(--text);
}
.btn-cta {
  align-self: flex-start; margin-top: 0.35rem;
  display: inline-flex; align-items: center; text-decoration: none;
  font: inherit; font-weight: 650; font-size: 1rem;
  padding: 0.6rem 1.2rem; border-radius: 8px;
  background: var(--accent); color: #fff; border: 1px solid var(--accent-strong);
}
.btn-cta:hover { background: var(--accent-strong); }
/* A decorative "recording" trace on the right; hidden when the panel gets narrow. */
.feature-scope {
  flex: 0 0 240px; width: 240px; height: 80px; color: var(--accent);
  opacity: 0.55; align-self: stretch; margin: auto 0;
}
@media (max-width: 720px) {
  .feature-scope { display: none; }
  .feature-tune { padding: 1.1rem 1.2rem; }
}

.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; }
.card-link.is-soon { color: var(--text-faint); font-weight: 600; }

.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 ---------------------------------------------------------- */
/* The block diagram doubles as the site map: every block is a real link. */
.signal-path {
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--scope-bg); padding: 0.5rem; box-shadow: var(--shadow);
  overflow-x: auto;
}
.signal-path svg { display: block; width: 100%; min-width: 620px; height: auto; }
.sp-clock { fill: var(--text-faint); font-family: var(--mono); font-size: 10px; }
.sp-arrowhead { fill: var(--text-faint); opacity: 0.6; }
.sp-wire { stroke: var(--text-faint); stroke-width: 1.2; fill: none; opacity: 0.55; }
.sp-wire-join { opacity: 0.3; }

.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: 9.5px; }
.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; }

/* The mini waveform is a stroked polyline; the fills are separate elements, so
   the channel colour is applied to each property separately rather than to both
   at once (which would flood the waveform's interior). */
.sp-mini { fill: none; stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.sp-ch-0 .sp-mini { stroke: var(--ch-0); }
.sp-ch-1 .sp-mini { stroke: var(--ch-1); }
.sp-ch-2 .sp-mini { stroke: var(--ch-2); }
.sp-ch-3 .sp-mini { stroke: var(--ch-3); }
.sp-ch-4 .sp-mini { stroke: var(--ch-4); }
.sp-ch-0 .sp-vol-fill, .sp-ch-0 .sp-glow { fill: var(--ch-0); }
.sp-ch-1 .sp-vol-fill, .sp-ch-1 .sp-glow { fill: var(--ch-1); }
.sp-ch-2 .sp-vol-fill, .sp-ch-2 .sp-glow { fill: var(--ch-2); }
.sp-ch-3 .sp-vol-fill, .sp-ch-3 .sp-glow { fill: var(--ch-3); }
.sp-ch-4 .sp-vol-fill, .sp-ch-4 .sp-glow { fill: var(--ch-4); }
.sp-vol-fill { stroke: none; opacity: 0.3; }
/* The live level glow — opacity is driven from the running core. */
.sp-glow { stroke: none; opacity: 0; pointer-events: none; }
.sp-voice.is-off { opacity: 0.4; }
.sp-voice.is-shared .sp-block-wave rect { stroke-dasharray: 4 3; }

.sp-block-sum rect, .sp-block-dac rect { fill: var(--bg-sunken); }
.sp-dac-fill { fill: var(--accent); opacity: 0.35; stroke: none; }
.sp-block-dac text { fill: var(--accent-strong); }

/* --- Tune page: loading, transport, write activity ------------------------ */
.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: 60ch; 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);
}

.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; margin-top: 0.7rem; }
.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: 5.5rem 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; }

/* --- Driver timeline ------------------------------------------------------ */
/* The envelope generator the chip lacks, drawn by hand: five rows of 4-bit
   volume, played back at 50 Hz straight into the volume registers. */
.panel-driver { border-top: 3px solid var(--accent); }
.driver-canvas {
  width: 100%; height: 190px; display: block; border-radius: 8px;
  background: var(--scope-bg); border: 1px solid var(--border);
  touch-action: none; cursor: crosshair;
}
.driver-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Channel selector above the editor: one channel is edited full-height. */
.driver-chan { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.driver-chan-label { font-size: 0.78rem; color: var(--text-dim); font-weight: 600; }

/* The all-five overview: small, non-editable context, click a row to select. */
.driver-overview-wrap { display: flex; flex-direction: column; gap: 0.25rem; }
.driver-overview-label { font-size: 0.72rem; color: var(--text-faint); font-weight: 600; }
.driver-overview {
  width: 100%; height: 74px; display: block; border-radius: 8px;
  background: var(--scope-bg); border: 1px solid var(--border); cursor: pointer;
}
.driver-bar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.driver-frame {
  font-family: var(--mono); font-size: 0.72rem; color: var(--text-faint);
  margin-left: auto;
}
.driver-shapes { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.driver-shapes-label { font-size: 0.78rem; color: var(--text-dim); font-weight: 600; }
.driver-env { display: flex; gap: 0.3rem; flex-wrap: wrap; }

/* --- Deform register ------------------------------------------------------ */
.panel-deform { border-top: 3px solid var(--warn-border); }
.panel-deform .panel-tag code { font-size: inherit; background: none; padding: 0; }
.deform-value { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.deform-hex {
  font-family: var(--mono); font-size: 1.15rem; font-weight: 700;
  color: var(--text-faint); min-width: 3.4rem;
}
.deform-hex.nonzero { color: var(--danger); }
/* Eight bits in a row is 420px, so they wrap rather than widen the panel. */
.deform-bits { display: flex; gap: 0.7rem; flex-wrap: wrap; }
/* Grouped by feature: the byte is four unrelated things, not eight switches. */
.deform-group { display: flex; flex-direction: column; gap: 2px; }
.deform-group-label {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); font-weight: 650;
}
.deform-group-bits { display: flex; gap: 3px; }

/* Bits 7-6 are one 2-bit mode selector, so they also get shown as four modes. */
.deform-modes {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.4rem;
}
.deform-mode-btn {
  font: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 1px;
  padding: 0.4rem 0.55rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-sunken); color: var(--text-dim);
}
.deform-mode-btn:hover { border-color: var(--accent); }
.deform-mode-btn.active {
  background: var(--accent-soft); border-color: var(--accent); color: var(--text);
}
.deform-mode-btn.unreachable { opacity: 0.45; }
.dm-bits {
  font-family: var(--mono); font-size: 0.72rem; font-weight: 700; color: var(--accent-strong);
}
.dm-name { font-size: 0.8rem; font-weight: 650; color: var(--text); }
.deform-mode-btn.unreachable .dm-name { color: var(--text-dim); }
.dm-row { font-size: 0.68rem; line-height: 1.35; }
.dm-row i { font-style: normal; font-family: var(--mono); color: var(--text-faint); margin-right: 0.2rem; }

/* The demo strip: the three affordances that make an invisible register visible. */
.demo-bar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.demo-factor { font-size: 0.72rem; color: var(--text-faint); }
.demo-out {
  margin: 0; font-size: 0.82rem; line-height: 1.6; color: var(--text-dim);
  padding: 0.55rem 0.8rem; border-radius: 8px;
  background: var(--bg-sunken); border-left: 3px solid var(--accent); max-width: 80ch;
}
.demo-out b { color: var(--text); font-family: var(--mono); }
.deform-bit {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font: inherit; cursor: pointer; padding: 0.2rem 0.3rem;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg-sunken); color: var(--text-dim); min-width: 3.1rem;
}
.deform-bit b { font-family: var(--mono); font-size: 0.9rem; }
.deform-bit span { font-size: 0.55rem; letter-spacing: 0.02em; }
.deform-bit:hover { border-color: var(--accent); color: var(--text); }
.deform-bit.on { background: var(--accent); color: #fff; border-color: var(--accent-strong); }
/* Set but with no audible or visible consequence — say so by fading it. */
.deform-bit.inert { opacity: 0.5; }
.deform-mode, .deform-effect {
  font-size: 0.78rem; color: var(--text-dim); margin: 0; line-height: 1.5; max-width: 76ch;
}
.deform-mode { color: var(--text); }
.deform-effects { display: flex; flex-direction: column; gap: 0.4rem; }
.deform-effect {
  border-left: 3px solid var(--warn-border); padding-left: 0.6rem;
}
.deform-wart {
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  border-radius: 8px; padding: 0.6rem 0.7rem;
  display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-start;
}
.deform-wart p { margin: 0; font-size: 0.78rem; color: var(--warn-text); line-height: 1.5; }
.deform-read { font-family: var(--mono); font-size: 0.72rem; color: var(--text-faint); }
.deform-read.hot { color: var(--danger); font-weight: 650; }

/* --- Piano --------------------------------------------------------------- */
.tools-hint {
  margin: 0 0 0.2rem; font-size: 0.8rem; color: var(--text-dim); line-height: 1.55;
  max-width: 78ch;
}
.tools-hint b { color: var(--text); }
.piano-tools { display: flex; align-items: center; gap: 0.6rem; margin-bottom: -0.5rem; flex-wrap: wrap; }
.piano-tools-label { font-size: 0.8rem; color: var(--text-dim); font-weight: 600; }
.seg {
  display: inline-flex; gap: 2px; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: 8px; padding: 2px;
}
.seg-btn {
  font: inherit; font-weight: 650; font-size: 0.8rem; cursor: pointer;
  min-width: 2.4rem; padding: 0.25rem 0.5rem; border: 1px solid transparent;
  border-radius: 6px; background: transparent; color: var(--text-dim);
}
.seg-btn:hover { background: var(--bg-hover); color: var(--text); }
.seg-btn.active { background: var(--bg-panel); box-shadow: var(--shadow); }
.seg-btn.ch-0.active { color: var(--ch-0); }
.seg-btn.ch-1.active { color: var(--ch-1); }
.seg-btn.ch-2.active { color: var(--ch-2); }
.seg-btn.ch-3.active { color: var(--ch-3); }
.seg-btn.ch-4.active { color: var(--ch-4); }

.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; flex-direction: column; align-items: center; justify-content: flex-end;
}
.pkey-white.pressed { background: var(--accent-soft); }
.pkey-black {
  height: 62%; z-index: 2; border-color: #000;
  background: linear-gradient(#33251b, #1a1210); border-radius: 0 0 4px 4px;
  display: flex; align-items: flex-end; justify-content: center;
}
.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; }

/* Which computer key plays this note — printed on the key itself, because a
   sentence under the keyboard is a mapping you have to hold in your head. */
.pkey-key {
  font-family: var(--mono); font-size: 0.62rem; font-weight: 650;
  color: var(--text-dim); pointer-events: none; padding-bottom: 2px;
  line-height: 1;
}
.pkey-black .pkey-key { color: #b39c8b; padding-bottom: 4px; }
.pkey-white.pressed .pkey-key { color: var(--accent-strong); }
.pkey-black.pressed .pkey-key { color: #fff; }

/* --- Memory inspector ---------------------------------------------------- */
.mem-details {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.4rem 0.9rem 0.8rem;
}
.mem-details > summary {
  cursor: pointer; font-weight: 600; font-size: 0.86rem; color: var(--text-dim);
  padding: 0.35rem 0; list-style-position: inside;
}
.mem-details[open] > summary { margin-bottom: 0.3rem; color: var(--text); }
.mem-intro { font-size: 0.78rem; color: var(--text-dim); margin: 0 0 0.8rem; max-width: 72ch; line-height: 1.55; }

.mem-inspector { display: flex; flex-direction: column; gap: 0.9rem; overflow-x: auto; }
.mem-section { display: flex; flex-direction: column; gap: 2px; }
.mem-head {
  display: flex; gap: 0.6rem; align-items: baseline; margin: 0 0 0.15rem;
  font-size: 0.8rem; font-weight: 650;
}
.mem-sub { font-family: var(--mono); font-size: 0.68rem; color: var(--text-faint); font-weight: 400; }
.mem-ch-0 .mem-head > span:first-child { color: var(--ch-0); }
.mem-ch-1 .mem-head > span:first-child { color: var(--ch-1); }
.mem-ch-2 .mem-head > span:first-child { color: var(--ch-2); }
.mem-ch-3 .mem-head > span:first-child { color: var(--ch-3); }
.mem-ch-4 .mem-head > span:first-child { color: var(--ch-4); }
.mem-section.mirrored .mem-head > span:first-child { color: var(--text-faint); }

.mem-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 1px 2px; border-radius: 5px;
}
.mem-row.dimmed { opacity: 0.35; }
.mem-addr { font-family: var(--mono); font-size: 0.7rem; color: var(--text-faint); width: 2.1rem; flex: none; }
.mem-cells { display: flex; gap: 2px; }
.mem-name { font-size: 0.74rem; color: var(--text-dim); }
.mem-cell {
  font-family: var(--mono); font-size: 0.72rem; font-weight: 620;
  width: 1.95rem; height: 1.5rem; flex: none; cursor: pointer;
  color: var(--accent-strong); background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: 4px; padding: 0;
}
.mem-cell.zero { color: var(--text-faint); font-weight: 400; }
.mem-cell:hover { border-color: var(--accent); }
.mem-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.mem-cell.readonly { opacity: 0.5; }
.mem-cell.flash { animation: memflash 0.4s ease-out; }
@keyframes memflash { from { background: var(--accent-soft); } to { background: var(--bg-sunken); } }

.mem-bits { display: flex; gap: 3px; margin-left: 0.3rem; }
.mem-bit {
  width: 1.5rem; height: 1.5rem; flex: none; cursor: pointer;
  font-family: var(--mono); font-size: 0.74rem; color: var(--text-faint);
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 4px; padding: 0;
}
.mem-bit:hover { border-color: var(--accent); }
.mem-bit.on { background: var(--accent); color: #fff; border-color: var(--accent-strong); }
.mem-bit.inert { opacity: 0.45; }

/* --- MSX page: the mapper, the probe, the listing ------------------------- */
/* The cartridge, not the chip: four bank registers and an address decoder. */
.mapper, .probe {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.8rem 1rem; box-shadow: var(--shadow);
}
.map-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.map-table th {
  text-align: left; font-size: 0.72rem; font-weight: 650; color: var(--text-faint);
  padding: 0 0.6rem 0.3rem 0; border-bottom: 1px solid var(--border);
}
.map-table td { padding: 0.3rem 0.6rem 0.3rem 0; border-bottom: 1px solid var(--border); }
.map-table tr:last-child td { border-bottom: none; }
.map-table code { font-family: var(--mono); font-size: 0.88em; color: var(--text-dim); }
.map-what { color: var(--text-dim); }
.map-what b { color: var(--text); }
.map-table tr.is-chip { background: var(--accent-soft); }
.map-table tr.is-chip .map-what b, .map-table tr.is-chip code { color: var(--accent-strong); }
.map-val { white-space: nowrap; }

.hex-in {
  font-family: var(--mono); font-size: 0.85rem; font-weight: 650;
  width: 2.9rem; padding: 0.2rem 0.35rem; text-align: center; text-transform: uppercase;
  background: var(--bg-sunken); color: var(--accent-strong);
  border: 1px solid var(--border-strong); border-radius: 6px;
}
.hex-in-wide { width: 4.6rem; font-size: 1rem; }
.hex-in:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hex-h { font-family: var(--mono); font-size: 0.75rem; color: var(--text-faint); margin-left: 0.1rem; }
.btn-tiny {
  font: inherit; font-size: 0.7rem; font-weight: 650; cursor: pointer;
  padding: 0.15rem 0.4rem; margin-left: 0.35rem; border-radius: 6px;
  background: var(--bg-sunken); border: 1px solid var(--border-strong); color: var(--text-dim);
}
.btn-tiny:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--bg-hover); }

.mapper-status {
  margin: 0.7rem 0 0; font-size: 0.8rem; color: var(--text-dim); line-height: 1.55;
  padding-left: 0.6rem; border-left: 3px solid var(--border-strong);
}
.mapper-status.is-live { border-left-color: var(--accent); color: var(--text); }
.mapper-status code { font-family: var(--mono); font-size: 0.9em; }

.probe-in { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.probe-label { font-size: 0.8rem; font-weight: 650; color: var(--text-dim); }
.probe-field { display: inline-flex; align-items: baseline; }
.probe-quick { display: flex; gap: 0.15rem; flex-wrap: wrap; margin-left: auto; }
.probe-out {
  margin: 0.7rem 0 0; font-size: 0.82rem; line-height: 1.6; color: var(--text-dim);
  padding: 0.5rem 0.7rem; border-radius: 8px; background: var(--bg-sunken);
  border-left: 3px solid var(--border-strong); max-width: 78ch;
}
.probe-out b { color: var(--text); }
.probe-out code { font-family: var(--mono); font-size: 0.9em; color: var(--accent-strong); }
.probe-out.is-hit { border-left-color: var(--accent); background: var(--accent-soft); }
.probe-out.is-bank { border-left-color: var(--ch-3); }
.probe-out.is-miss { border-left-color: var(--warn-border); }

/* --- Code view ------------------------------------------------------------ */
.panel-code { border-top: 3px solid var(--accent); }
.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: #e6dcd2; tab-size: 8;
}
.code-block .c-op { color: #f0a066; font-weight: 650; }
.code-block .c-num { color: #9fc7a6; }
.code-block .c-lbl { color: #e8c96a; font-weight: 650; }
.code-block .c-cmt { color: #8a7869; }

/* --- 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); }

.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 caption {
  caption-side: top; text-align: left; font-size: 0.78rem; color: var(--text-faint);
  padding: 0 0 0.35rem;
}
.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 .is-none { color: var(--text-faint); }
.ref-table .is-live code { color: var(--text); }
.ref-table tr.is-inert { opacity: 0.6; }
.ref-table-tight td, .ref-table-tight th { padding: 0.2rem 0.55rem; }
.tag-inert {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.05rem 0.4rem; margin-left: 0.3rem; white-space: nowrap;
}

.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.5rem 0.7rem; 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-out.is-frozen { border-left-color: var(--danger); }
.calc .btn { align-self: flex-start; }

.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 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-hint { font-size: 0.7rem; color: var(--text-faint); text-align: right; }
.gal-canvases { display: flex; gap: 0.4rem; }
.gal-wave { flex: 1 1 60%; height: 84px; border-radius: 8px; display: block; min-width: 0; }
.gal-harm { flex: 1 1 40%; height: 84px; border-radius: 8px; display: block; min-width: 0; }
.gal-foot { display: flex; align-items: center; gap: 0.5rem; justify-content: space-between; }
.gal-bytes { font-family: var(--mono); font-size: 0.66rem; color: var(--text-faint); }

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

/* --- Footer -------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border); background: var(--bg-panel);
  padding: 1rem 1.4rem; font-size: 0.78rem; color: var(--text-dim); text-align: center;
}
.footer-links { margin: 0.3rem 0 0; }
.footer-links a { color: var(--accent-strong); text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }
.footer-sep { color: var(--text-faint); margin: 0 0.4rem; }

/* The rack drops to fewer columns rather than squeezing the editors below the
   width where 32 bars are still drawable. */
@media (max-width: 1000px) {
  .rack { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .rack-slim { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .rack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rack-slim { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chain-nav { grid-template-columns: 1fr; }
  .chain-next { text-align: left; }
  /* Narrow: brand and transport share the top row and the nav scrolls sideways
     under them, so the sticky header costs two short rows instead of four tall
     ones — it has to stay small enough to be worth sticking. */
  .site-header { padding: 0.5rem 0.9rem; gap: 0.5rem; }
  .brand { order: 1; flex: 1; min-width: 0; }
  .logo { width: 30px; height: 30px; }
  h1 { font-size: 1.05rem; }
  .tagline { display: none; }
  .header-actions { order: 2; }
  .btn-transport { padding: 0.35rem 0.7rem; font-size: 0.85rem; min-width: 4.9rem; }
  .site-nav { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .nav-group { flex-wrap: nowrap; }
  .nav-group-alt { border-left: none; padding-left: 0; }
  .activity-row { grid-template-columns: 4.5rem 1fr 2.4rem; }
  .activity-hint { display: none; }
  .wave-body { flex-direction: column; }
  .wave-side { flex: none; max-width: none; }
  .harm-canvas { height: 90px; }
}
@media (max-width: 460px) {
  .rack { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .driver-canvas { height: 150px; }
  .driver-frame { margin-left: 0; }
  .deform-bit { min-width: 2.7rem; padding: 0.2rem 0.15rem; }
  .readout-freq { font-size: 1.25rem; }
  .site-header { gap: 0.6rem; }
  .page-title { font-size: 1.25rem; }
  .mem-cell { width: 1.7rem; font-size: 0.66rem; }
}
