/* PSG Playground — theme-aware styling. No external fonts/assets.
   Sibling of tape-peek; shares its structure, shifts the accent to synth violet. */

:root {
  --bg: #f4f2f7;
  --bg-panel: #ffffff;
  --bg-sunken: #edeaf2;
  --bg-hover: #e9e4f2;
  --bg-active: #e6dcf7;
  --text: #221d2b;
  --text-dim: #635a70;
  --text-faint: #948aa2;
  --border: #e0dae8;
  --border-strong: #c8bfd6;
  --accent: #7a5cc0;
  --accent-strong: #5f43a0;
  --accent-soft: #ece4fa;
  --ch-a: #7a5cc0;
  --ch-b: #c05c9a;
  --ch-c: #5c8ac0;
  --env: #3ba38a;
  --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(40, 25, 60, 0.08), 0 4px 16px rgba(40, 25, 60, 0.06);

  /* component-specific (read by canvas via getComputedStyle) */
  --scope-bg: #14101c;
  --scope-grid: rgba(255, 255, 255, 0.07);
  --scope-line: #b98cf0;
  --meter-on: #b98cf0;
  --meter-off: rgba(120, 100, 150, 0.18);
  --meter-env: #3ba38a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #130f1a;
    --bg-panel: #1c1626;
    --bg-sunken: #100c17;
    --bg-hover: #271e34;
    --bg-active: #33244a;
    --text: #ece7f4;
    --text-dim: #afa3c2;
    --text-faint: #7a6f8e;
    --border: #2c2338;
    --border-strong: #3c3049;
    --accent: #a985e8;
    --accent-strong: #c0a3f2;
    --accent-soft: #2a1f3e;
    --ch-a: #a985e8;
    --ch-b: #e589c0;
    --ch-c: #82b4ea;
    --env: #4cc4a6;
    --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: #0d0a14;
    --scope-grid: rgba(255, 255, 255, 0.06);
    --scope-line: #b98cf0;
    --meter-on: #b98cf0;
    --meter-off: rgba(150, 130, 190, 0.15);
  }
}

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

/* Section navigation in the header */
.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.active { background: var(--accent-soft); color: var(--accent-strong); }

/* --- Layout ------------------------------------------------------------- */
#main { flex: 1; width: min(1080px, 100%); margin: 0 auto; padding: 1.2rem 1.4rem 2rem; }
.phase-note {
  font-size: 0.8rem; color: var(--text-dim);
  background: var(--accent-soft); border: 1px solid var(--border);
  padding: 0.5rem 0.8rem; border-radius: 8px; margin: 0 0 1.2rem;
}
.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: 200px; }

/* --- Panels ------------------------------------------------------------- */
.panels {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 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; }
.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;
}
/* Per-channel accent stripe on tone + amp panels. */
.panel-tone, .panel-amp { border-top: 3px solid var(--ch-a); }
.panel-tone.ch-1, .panel-amp.ch-1 { border-top-color: var(--ch-b); }
.panel-tone.ch-2, .panel-amp.ch-2 { border-top-color: var(--ch-c); }
.panels-mix { grid-template-columns: minmax(220px, 340px); }

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

/* Amplitude panel + meter */
.amp-body { display: flex; gap: 0.8rem; align-items: stretch; }
.meter { width: 46px; height: 96px; flex: none; background: var(--scope-bg); border-radius: 6px; }
.amp-ctls { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 0.6rem; }

/* Noise (R6) + LFSR view */
.panel-noise { border-top: 3px solid var(--ch-b); }
.lfsr { display: flex; gap: 2px; margin: 0.15rem 0; }
.lfsr-bit {
  flex: 1 1 0; min-width: 0; height: 22px;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 2px;
  transition: background 0.08s;
}
.lfsr-bit.on { background: var(--ch-b); border-color: var(--ch-b); }
.lfsr-bit.tap { box-shadow: inset 0 -3px 0 var(--accent); }  /* feedback tap (bit 3) */
.lfsr-bit.out { box-shadow: inset 0 -3px 0 var(--env); }     /* output (bit 0) */
.lfsr-cap { font-size: 0.68rem; color: var(--text-faint); line-height: 1.45; }
.lfsr-cap i { font-style: italic; }
.lfsr-cap .tap-out { color: var(--env); font-weight: 600; }
.lfsr-cap .tap-fb { color: var(--accent); font-weight: 600; }

/* Mixer (R7, active-low 3×2 grid) */
.panel-mixer { border-top: 3px solid var(--border-strong); }
.mixer-grid {
  display: grid; grid-template-columns: 1.6rem 1fr 1fr;
  gap: 0.4rem 0.7rem; align-items: center; justify-items: center;
  margin: 0.1rem 0 0.2rem;
}
.mix-col { font-size: 0.72rem; font-weight: 650; color: var(--text-dim); }
.mix-row-label { font-family: var(--mono); font-weight: 650; justify-self: center; }
.mix-row-label.ch-0 { color: var(--ch-a); }
.mix-row-label.ch-1 { color: var(--ch-b); }
.mix-row-label.ch-2 { color: var(--ch-c); }
.mix-cell { display: inline-flex; cursor: pointer; position: relative; }
.mix-cell input { position: absolute; opacity: 0; width: 0; height: 0; margin: 0; }
.mix-led {
  width: 1.7rem; height: 1.7rem; border-radius: 6px;
  background: var(--bg-sunken); border: 1px solid var(--border-strong);
  transition: background 0.12s, border-color 0.12s; position: relative;
}
.mix-led::after {
  content: ''; position: absolute; inset: 0.5rem; border-radius: 50%;
  background: var(--text-faint); opacity: 0.3; transition: background 0.12s, opacity 0.12s;
}
.mix-cell input:checked + .mix-led { background: var(--accent-soft); border-color: var(--accent); }
.mix-cell input:checked + .mix-led::after { background: var(--accent); opacity: 1; }
.mix-cell input:checked + .mix-led.led-noise { border-color: var(--ch-b); background: var(--bg-active); }
.mix-cell input:checked + .mix-led.led-noise::after { background: var(--ch-b); }
.mix-cell input:focus-visible + .mix-led { outline: 2px solid var(--accent); outline-offset: 2px; }
.mix-cell:hover .mix-led { border-color: var(--accent); }
.mixer-note { font-size: 0.72rem; color: var(--text-faint); margin: 0; line-height: 1.45; }
.mixer-note b { color: var(--text-dim); font-weight: 650; }

/* Envelope (R11–R13) */
.panel-env { border-top: 3px solid var(--env); }
.panels-env { grid-template-columns: minmax(280px, 2fr) minmax(200px, 1fr); }
.env-view {
  display: block; width: 100%; height: 92px;
  background: var(--scope-bg); border-radius: 8px;
}
.env-shapes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.env-shape {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 0.3rem 0.1rem; cursor: pointer;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-dim);
}
.env-shape:hover { border-color: var(--env); }
.env-shape.sel { background: var(--accent-soft); border-color: var(--env); color: var(--text); }
.env-glyph { font-family: var(--mono); font-size: 0.92rem; letter-spacing: -1px; line-height: 1; }
.env-code { font-family: var(--mono); font-size: 0.62rem; color: var(--text-faint); }
.env-shape.sel .env-code { color: var(--env); font-weight: 650; }
.btn-retrig { font-size: 0.78rem; padding: 0.4rem; }
.ctl-label [data-time] { color: var(--text-faint); font-weight: 400; }

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

/* --- Piano -------------------------------------------------------------- */
.piano-tools { display: flex; align-items: center; gap: 0.6rem; margin-bottom: -0.4rem; }
.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.82rem; cursor: pointer;
  min-width: 2.1rem; 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-a); }
.seg-btn.ch-1.active { color: var(--ch-b); }
.seg-btn.ch-2.active { color: var(--ch-c); }

.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(#2a2233, #150f1d); 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; }

/* --- Register inspector ------------------------------------------------- */
.reg-section { margin-top: 1.6rem; }
.section-title { font-size: 1rem; margin: 0 0 0.7rem; display: flex; gap: 0.6rem; align-items: baseline; }
.section-sub { font-size: 0.78rem; font-weight: 400; color: var(--text-faint); }
.reg-inspector {
  display: grid; gap: 3px;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.7rem; box-shadow: var(--shadow); overflow-x: auto;
}
.reg-row {
  display: grid; grid-template-columns: 2.6rem 1.8rem minmax(0, 1fr) auto; align-items: center; gap: 0.6rem;
  padding: 0.1rem 0.2rem; border-radius: 5px;
}
.reg-name {
  font-size: 0.76rem; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reg-row.flash { animation: regflash 0.4s ease-out; }
@keyframes regflash { from { background: var(--accent-soft); } to { background: transparent; } }
.reg-id { font-family: var(--mono); font-size: 0.78rem; color: var(--text-dim); }
.reg-hex {
  font-family: var(--mono); font-size: 0.82rem; font-weight: 640; color: var(--accent-strong);
  background: var(--bg-sunken); border-radius: 4px; text-align: center; padding: 0.05rem 0;
}
.reg-bits { display: flex; gap: 3px; }
.reg-bit {
  width: 1.55rem; height: 1.55rem; flex: none; cursor: pointer;
  font-family: var(--mono); font-size: 0.78rem; color: var(--text-faint);
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 4px;
}
.reg-bit:hover:not(.unused) { border-color: var(--accent); }
.reg-bit.on { background: var(--accent); color: #fff; border-color: var(--accent-strong); }
.reg-bit.unused { opacity: 0.3; cursor: default; }
.reg-tone .reg-id { color: var(--ch-a); }
.reg-noise .reg-id { color: var(--ch-b); }
.reg-env .reg-id { color: var(--env); }
.reg-row.dimmed { opacity: 0.4; }

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

/* --- Mode switch (Learn / Explore / Reference) -------------------------- */
/* --- Landing page ------------------------------------------------------- */
.landing { display: flex; flex-direction: column; gap: 1.2rem; }
.hero { text-align: center; padding: 1.4rem 0 0.4rem; }
.hero-title { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0 0 0.6rem; letter-spacing: -0.02em; }
.hero-lead { font-size: 1rem; color: var(--text-dim); margin: 0 auto; max-width: 56ch; }
.hero-cta { display: flex; gap: 0.7rem; justify-content: center; flex-wrap: wrap; margin-top: 1.1rem; }
.hero-cta .btn { font-size: 0.95rem; text-decoration: none; display: inline-flex; align-items: center; }
.hero-hint { text-align: center; font-size: 0.85rem; color: var(--text-dim); margin: 0; }
.hero-hint a, .landing-about a { color: var(--accent-strong); }
.landing-about { border-top: 1px solid var(--border); padding-top: 1.1rem; }
.landing-about p { font-size: 0.9rem; color: var(--text-dim); max-width: 70ch; margin: 0 auto; text-align: center; }

/* --- Focus page --------------------------------------------------------- */
.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-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 { font-family: var(--mono); font-size: 0.86em; background: var(--bg-sunken); padding: 0.05rem 0.3rem; border-radius: 4px; color: var(--text); }
.page-intro-wide { margin-bottom: 0.4rem; }

.reg-details {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.4rem 0.8rem;
}
.reg-details > summary {
  cursor: pointer; font-weight: 600; font-size: 0.86rem; color: var(--text-dim);
  padding: 0.35rem 0; list-style-position: inside;
}
.reg-details[open] > summary { margin-bottom: 0.5rem; color: var(--text); }
.reg-details .reg-inspector { border: none; box-shadow: none; padding: 0; }

.page-chain-nav {
  display: flex; justify-content: space-between; gap: 1rem;
  border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 0.2rem;
}
.page-chain-nav a { color: var(--accent-strong); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.page-chain-nav a:hover { text-decoration: underline; }
.chain-next { margin-left: auto; text-align: right; }

/* --- Signal-path diagram ------------------------------------------------- */
.signal-path-mount { margin: 0 0 1.2rem; }
.signal-path {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.7rem 0.9rem; box-shadow: var(--shadow);
}
.sp-svg { display: block; width: 100%; height: auto; max-height: 210px; }
.sp-wire { fill: none; stroke: var(--border-strong); stroke-width: 2; stroke-dasharray: 5 4; }
.signal-path.flowing .sp-wire,
.sp-svg.flowing .sp-wire { animation: sp-flow 0.6s linear infinite; stroke: var(--accent); }
@keyframes sp-flow { to { stroke-dashoffset: -18; } }
.sp-block { cursor: pointer; }
.sp-rect {
  fill: var(--bg-sunken); stroke: var(--block, var(--border-strong)); stroke-width: 1.5;
  transition: fill 0.12s, stroke-width 0.12s;
}
.sp-block:hover .sp-rect { fill: var(--bg-hover); stroke-width: 2.5; }
.sp-block.hl .sp-rect { fill: var(--accent-soft); stroke-width: 2.5; }
.sp-block:focus-visible { outline: none; }
.sp-block:focus-visible .sp-rect { stroke: var(--accent); stroke-width: 3; }
.sp-label {
  fill: var(--text); font-family: var(--sans); font-size: 13px; font-weight: 650;
  text-anchor: middle; dominant-baseline: middle; pointer-events: none;
}
.sp-tag {
  fill: var(--text-faint); font-family: var(--mono); font-size: 9px;
  text-anchor: middle; dominant-baseline: middle; pointer-events: none;
}

/* --- Reference ---------------------------------------------------------- */
.reference { display: flex; flex-direction: column; gap: 1.6rem; }
.ref-intro h2 { margin: 0 0 0.3rem; font-size: 1.4rem; }
.ref-intro p { margin: 0; color: var(--text-dim); font-size: 0.9rem; max-width: 62ch; }
.ref-block > h3 { font-size: 1.05rem; margin: 0 0 0.7rem; display: flex; gap: 0.5rem; align-items: baseline; }
.ref-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.ref-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; background: var(--bg-panel); }
.ref-table th, .ref-table td { text-align: left; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--border); }
.ref-table th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); background: var(--bg-sunken); }
.ref-table tr:last-child td { border-bottom: none; }
.rt-id { font-family: var(--mono); font-weight: 650; color: var(--accent-strong); }
.rt-oct, .rt-mask code { font-family: var(--mono); color: var(--text-dim); }
.ref-table .reg-tone .rt-id { color: var(--ch-a); }
.ref-table .reg-noise .rt-id { color: var(--ch-b); }
.ref-table .reg-env .rt-id { color: var(--env); }

.ref-clock { max-width: 260px; margin-bottom: 0.9rem; }
.ref-calcs { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.calc { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.85rem 0.95rem; box-shadow: var(--shadow); }
.calc h4 { margin: 0 0 0.7rem; font-size: 0.9rem; }
.calc-out { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.7rem; }
.calc-out > div { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.82rem; color: var(--text-dim); }
.calc-out b { font-family: var(--mono); font-size: 0.95rem; color: var(--text); }

.ref-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.7rem; }
.gal-cell { margin: 0; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem; }
.gal-canvas { display: block; width: 100%; height: auto; background: var(--scope-bg); border-radius: 5px; }
.gal-cell figcaption { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.35rem; }
.gal-cell figcaption code { font-family: var(--mono); color: var(--accent-strong); font-weight: 650; }
.ref-foot { font-size: 0.82rem; color: var(--text-dim); margin: 0.7rem 0 0; }

.ref-sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem 1.6rem; }
.src-group h4 { margin: 0 0 0.5rem; font-size: 0.9rem; }
.src-group ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.55rem; }
.src-group li { font-size: 0.84rem; line-height: 1.4; }
.src-group a { color: var(--accent-strong); text-decoration: none; font-weight: 600; }
.src-group a:hover { text-decoration: underline; }
.src-note { display: block; color: var(--text-faint); font-size: 0.78rem; }

/* --- MSX row: presets + code view --------------------------------------- */
.panels-msx { grid-template-columns: minmax(200px, 1fr) minmax(280px, 1.6fr); }
.panel-presets { border-top: 3px solid var(--accent); }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 0.5rem; }
.preset-btn {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
  padding: 0.6rem 0.4rem; cursor: pointer; font: inherit;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-dim); text-align: center;
}
.preset-btn:hover { border-color: var(--accent); color: var(--text); background: var(--bg-hover); }
.preset-emoji { font-size: 1.35rem; line-height: 1; }
.preset-name { font-size: 0.74rem; font-weight: 600; }

.panel-code { border-top: 3px solid var(--accent-strong); }
.code-tabs { display: flex; gap: 0.3rem; }
.code-tab {
  font: inherit; font-size: 0.78rem; font-weight: 600; cursor: pointer;
  padding: 0.3rem 0.7rem; border-radius: 6px 6px 0 0;
  background: var(--bg-sunken); border: 1px solid var(--border); border-bottom: none;
  color: var(--text-dim);
}
.code-tab.active { background: var(--scope-bg); color: var(--scope-line); border-color: var(--border-strong); }
.code-out {
  margin: 0; padding: 0.7rem 0.8rem; border-radius: 0 8px 8px 8px;
  background: var(--scope-bg); color: #cbb6ec;
  font-family: var(--mono); font-size: 0.74rem; line-height: 1.5;
  overflow-x: auto; max-height: 260px; overflow-y: auto;
  border: 1px solid var(--border-strong);
}
.code-note { font-size: 0.72rem; color: var(--text-faint); margin: 0; line-height: 1.45; }
.code-note code { font-family: var(--mono); color: var(--text-dim); }

@media (max-width: 560px) {
  .readout-freq { font-size: 1.25rem; }
  .reg-row { grid-template-columns: 2.4rem 1.8rem minmax(0, 1fr) auto; gap: 0.4rem; }
  .site-header { gap: 0.6rem; }
  .nav-link { font-size: 0.8rem; padding: 0.3rem 0.45rem; }
  .page-title { font-size: 1.25rem; }
}
