/* MSX Audio Play — retro-modern, theme-aware chrome + an always-dark 80s device
   panel for the visualizers. No external fonts or assets. */

:root {
  --bg: #f5f4fa;
  --bg-panel: #ffffff;
  --bg-sunken: #eeecf6;
  --bg-hover: #e8e5f3;
  --bg-active: #e2dcf6;
  --text: #211c2e;
  --text-dim: #625b73;
  --text-faint: #8b849b;
  --border: #ddd8e8;
  --border-strong: #c7c0da;
  --accent: #6d54c7;
  --accent-strong: #573fac;
  --accent-soft: #ebe6fa;
  --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(30, 20, 45, 0.08), 0 4px 16px rgba(30, 20, 45, 0.06);

  /* the device panel is always dark — a piece of 80s hardware on the page */
  --dev-bg: #0d0f16;
  --dev-bg2: #12141d;
  --dev-bezel: #1b1e29;
  --dev-line: #262a38;
  --dev-label: #6f7891;
  --phos: #7dffc4;         /* phosphor green (scope) */
  --phos-dim: #2c6b52;
  --neon-cyan: #52e0ff;
  --vu-lo: #57e08a;        /* VU green */
  --vu-mid: #ffd23f;       /* VU amber */
  --vu-hi: #ff5c5c;        /* VU red */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0e15;
    --bg-panel: #17151f;
    --bg-sunken: #100f18;
    --bg-hover: #211e2d;
    --bg-active: #2a2440;
    --text: #e9e6f2;
    --text-dim: #a49dba;
    --text-faint: #6f6885;
    --border: #262232;
    --border-strong: #362f47;
    --accent: #9d86e6;
    --accent-strong: #b6a3f0;
    --accent-soft: #221c39;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
  }
}

* { 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);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Header ---- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.9rem 1.4rem;
  border-bottom: 1px solid var(--border); background: var(--bg-panel); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.logo { width: 42px; height: 42px; flex-shrink: 0; filter: drop-shadow(0 1px 1px rgba(0,0,0,.15)); }
.logo-body { fill: var(--accent); }
.logo-bars rect { fill: #d6f9e7; }
.site-header h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
.tagline { margin: 0; font-size: 0.85rem; color: var(--text-dim); }
.tagline strong { color: var(--accent); }
.header-badges { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.badge {
  font-size: 0.72rem; padding: 0.3rem 0.6rem; border-radius: 999px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  color: var(--text-dim); white-space: nowrap;
}
.badge-link { text-decoration: none; color: var(--accent); font-family: var(--mono); }
.badge-link:hover { background: var(--accent-soft); }

/* ---- Main ---- */
/* No `min-height: 0` here: it would let #main shrink below the player's content,
   which then overflows and paints over the footer. Letting it size to content makes
   a tall player grow the page and scroll normally. The empty-state dropzone still
   fills the viewport via its own flex:1 + min-height. */
#main { flex: 1; display: flex; flex-direction: column; }

/* ---- Dropzone ---- */
.dropzone {
  flex: 1; margin: 1.6rem; border: 2.5px dashed var(--border-strong); border-radius: 16px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
  background: var(--bg-panel); min-height: 58vh;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.005); }
.dz-inner { text-align: center; padding: 2rem; max-width: 540px; }
.dz-icon { width: 92px; height: 92px; margin-bottom: 0.4rem; }
.dz-bars rect { fill: var(--accent); }
.dz-primary { font-size: 1.4rem; font-weight: 600; margin: 0.3rem 0 0.1rem; }
.dz-secondary { margin: 0 0 1rem; color: var(--text-dim); }
.dz-formats { font-size: 0.8rem; color: var(--text-faint); line-height: 1.7; }
.dz-formats code {
  font-family: var(--mono); background: var(--bg-sunken); padding: 0.05rem 0.35rem;
  border-radius: 4px; border: 1px solid var(--border); font-size: 0.75rem;
}
.link-btn { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }

/* ---- ZIP picker ---- */
.zip-picker { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.6rem; }
.zp-inner { width: 100%; max-width: 540px; }
.zp-title { font-size: 1.1rem; font-weight: 600; margin: 0 0 0.15rem; }
.zp-zipname { font-family: var(--mono); color: var(--accent); }
.zp-sub { margin: 0 0 1rem; color: var(--text-dim); font-size: 0.9rem; }
.zp-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.zp-item {
  width: 100%; display: flex; align-items: center; gap: 0.6rem; font: inherit; text-align: left; cursor: pointer;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.65rem 0.85rem; color: var(--text); transition: background .12s, border-color .12s;
}
.zp-item:hover { background: var(--bg-hover); border-color: var(--accent); }
.zp-item::before { content: "🎵"; }
.zp-file { font-family: var(--mono); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.zp-size { font-size: 0.78rem; color: var(--text-faint); font-family: var(--mono); flex-shrink: 0; }

/* ---- Player ---- */
.player { flex: 1; display: flex; flex-direction: column; gap: 1rem; padding: 1.4rem; max-width: 960px; width: 100%; margin: 0 auto; }
.now-playing { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.np-meta { display: flex; align-items: center; gap: 0.6rem; min-width: 0; flex-wrap: wrap; }
.np-title { font-weight: 600; font-size: 1.1rem; letter-spacing: -0.01em; }
.np-file { font-family: var(--mono); font-size: 0.78rem; color: var(--text-faint); }
.chip {
  font-size: 0.72rem; font-family: var(--mono); background: var(--accent-soft);
  color: var(--accent-strong); border: 1px solid var(--accent); border-radius: 6px; padding: 0.12rem 0.45rem;
}

.btn {
  font: inherit; font-size: 0.82rem; cursor: pointer; background: var(--accent); color: #fff;
  border: 1px solid var(--accent-strong); padding: 0.4rem 0.75rem; border-radius: 8px;
  transition: background .12s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }

/* ---- The device (always dark) ---- */
.device {
  background: linear-gradient(180deg, var(--dev-bg2), var(--dev-bg));
  border: 1px solid #000; border-radius: 14px; padding: 4px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.04);
}
.device-bezel {
  background: var(--dev-bg); border: 1px solid var(--dev-line); border-radius: 10px;
  padding: 0.9rem; display: flex; flex-direction: column; gap: 0.9rem;
}
.scope-label {
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.14em; color: var(--dev-label);
  text-transform: uppercase; display: block; margin-bottom: 0.35rem;
}
.vu-hint { color: var(--dev-line); letter-spacing: 0.04em; text-transform: none; }

/* ---- Cartridge Bay: sound chips drawn as retrowave cartridges in a slot expander ---- */
.cart-bay {
  position: relative; border-radius: 10px; padding: 0.8rem 0.9rem 0.35rem;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(123,47,247,0.16), transparent 60%),
    linear-gradient(180deg, #0a0618, #0b0714);
  border: 1px solid var(--dev-line);
  /* retrowave perspective grid glowing up from the deck */
  overflow: hidden;
}
.cart-bay::before {
  content: ""; position: absolute; inset: auto 0 0 0; height: 46%; pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(82,224,255,0.10) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(0deg, rgba(255,61,129,0.10) 0 1px, transparent 1px 16px);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000);
          mask-image: linear-gradient(180deg, transparent, #000);
}
.cart-strip {
  position: relative; z-index: 1; display: flex; gap: 0.55rem; align-items: flex-end;
  justify-content: center; flex-wrap: wrap;
}
.cart-deck {
  position: relative; z-index: 1; height: 12px; margin-top: -6px; border-radius: 3px;
  background: linear-gradient(180deg, #201436, #0c0818);
  border: 1px solid var(--dev-line); box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
}

.cart-slot {
  position: relative; width: 74px; aspect-ratio: 100 / 132;
  display: grid; grid-template-areas: "stack";
}
.cart-slot > * { grid-area: stack; }

/* empty slot: just a dark connector mouth */
.cart-empty {
  align-self: end; display: flex; flex-direction: column; align-items: center; gap: 4px;
  height: 60%; justify-content: flex-end; padding-bottom: 6px;
}
.cart-empty-mouth {
  width: 78%; height: 8px; border-radius: 2px;
  background: repeating-linear-gradient(90deg, #14101f 0 2px, #060409 2px 4px);
  border: 1px solid #241a33; box-shadow: inset 0 2px 3px rgba(0,0,0,0.7);
}
.cart-empty-label {
  font-family: var(--mono); font-size: 0.42rem; letter-spacing: 0.14em; color: #3a3350;
}

/* an inserted cartridge */
.cartridge { opacity: 0; visibility: hidden; }
.cart-slot.revealed .cart-empty { opacity: 0; }
.cart-slot.revealed .cartridge {
  visibility: visible; animation: cart-insert 0.5s cubic-bezier(.2,.9,.25,1.05) both;
}
@keyframes cart-insert {
  from { opacity: 0; transform: translateY(-16px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
.cart-svg {
  width: 100%; height: 100%; display: block;
  filter: saturate(0.55) brightness(0.62);
  transition: filter 0.18s ease;
}
.cart-slot.active .cart-svg {
  filter: saturate(1.12) brightness(1.12)
          drop-shadow(0 0 5px color-mix(in srgb, var(--accent) 65%, transparent));
}

/* SVG text + LED, themed per cartridge via --accent (CSS wins over presentation attrs) */
.cart-title { fill: var(--accent); font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-anchor: middle; }
.cart-sub   { fill: #9c93b8; font-family: var(--mono); font-size: 6px; letter-spacing: 1.4px; text-anchor: middle; }
.cart-tagbox{ fill: color-mix(in srgb, var(--accent) 18%, #0b0620); stroke: var(--accent); stroke-opacity: 0.4; }
.cart-tag   { fill: var(--accent); font-family: var(--mono); font-size: 4.6px; letter-spacing: 1.6px; text-anchor: middle; opacity: 0.85; }
.cart-pwr   { fill: #4a4360; font-family: var(--mono); font-size: 4.6px; letter-spacing: 1px; }

.cart-led { fill: #241d33; }
.cart-led-ring { stroke: #241d33; stroke-width: 1; }
.cart-slot.active .cart-led {
  fill: var(--accent);
  filter: drop-shadow(0 0 3px var(--accent));
  animation: cart-pulse 1.1s ease-in-out infinite;
}
.cart-slot.active .cart-led-ring { stroke: var(--accent); stroke-opacity: 0.5; }
.cart-slot.active .cart-pwr { fill: color-mix(in srgb, var(--accent) 70%, #4a4360); }
@keyframes cart-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  .cart-slot.revealed .cartridge { animation: none; }
  .cart-slot.active .cart-led { animation: none; }
}
@media (max-width: 520px) {
  .cart-slot { width: 58px; }
}

/* scopes */
.scopes { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.scope-cell { background: #07090e; border: 1px solid var(--dev-line); border-radius: 8px; padding: 0.5rem 0.6rem 0.35rem; }
.scope-canvas { width: 100%; height: 120px; display: block; image-rendering: pixelated; }

/* sub-song browser */
.track-panel { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 0.6rem 0.8rem 0.7rem; }
.tracks-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.tracks-head .scope-label { margin-bottom: 0; color: var(--text-dim); }
.track-count { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0; text-transform: none; color: var(--text-dim); }
.track-filters { display: flex; gap: 0.3rem; margin-left: auto; }
.tfilter {
  font: inherit; font-size: 0.72rem; font-family: var(--mono); cursor: pointer; color: var(--text-dim);
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px; padding: 0.12rem 0.6rem;
}
.tfilter:hover { border-color: var(--accent); color: var(--text); }
.tfilter.active { background: var(--accent); color: #fff; border-color: var(--accent-strong); }
.track-scan { font-family: var(--mono); font-size: 0.68rem; color: var(--accent); letter-spacing: 0.02em; }
.track-list {
  list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.25rem;
}
.track-row {
  display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-family: var(--mono); font-size: 0.78rem;
  padding: 0.28rem 0.5rem; border-radius: 7px; border: 1px solid transparent; color: var(--text);
}
.track-row:hover { background: var(--bg-hover); }
.track-row.playing { background: var(--accent-soft); border-color: var(--accent); }
.track-idx { color: var(--text-dim); font-size: 0.72rem; min-width: 1.4em; text-align: right; }
.track-tag { font-size: 0.62rem; border-radius: 4px; padding: 0.04rem 0.3rem; line-height: 1.5; }
.tag-music { background: rgba(109,84,199,0.18); color: var(--accent); }
.tag-sfx { background: var(--bg-sunken); color: var(--text-dim); }
.track-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-row.playing .track-name { color: var(--accent-strong); font-weight: 600; }
.track-dur { color: var(--text-dim); font-variant-numeric: tabular-nums; font-size: 0.72rem; }
.track-list[data-filter="music"] .track-row:not(.k-music) { display: none; }
.track-list[data-filter="sfx"] .track-row:not(.k-sfx) { display: none; }

/* piano-roll */
.piano-panel { background: #07090e; border: 1px solid var(--dev-line); border-radius: 8px; padding: 0.5rem 0.6rem 0.4rem; }
.piano-canvas { width: 100%; height: 150px; display: block; image-rendering: pixelated; border-radius: 4px; }

/* VU meters */
.vu-panel { background: #07090e; border: 1px solid var(--dev-line); border-radius: 8px; padding: 0.55rem 0.65rem 0.7rem; }
/* One group per chip. Grouping matters once a VGM brings four chips and 28 bars:
   a flat grid gives no way to tell which bar belongs to which chip. `--chip` is the
   device's colour from the shared model (js/viz/vu.js) — the same colour the
   piano-roll uses, so a note in the roll and its meter read as the same voice. */
.vu-grid { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: flex-start; }
.vu-group {
  --chip: #7dffc4;
  border: 1px solid color-mix(in srgb, var(--chip) 22%, transparent);
  border-top: 2px solid color-mix(in srgb, var(--chip) 70%, transparent);
  border-radius: 8px; padding: 0.3rem 0.4rem 0.4rem;
  background: color-mix(in srgb, var(--chip) 4%, transparent);
}
.vu-group-head { display: flex; align-items: baseline; gap: 0.4rem; margin-bottom: 0.25rem; padding-left: 0.1rem; }
.vu-group-name {
  font-family: var(--mono); font-size: 0.56rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: color-mix(in srgb, var(--chip) 85%, white 15%);
}
.vu-group-badge {
  font-family: var(--mono); font-size: 0.48rem; letter-spacing: 0.06em;
  color: #b5722f; border: 1px solid rgba(181,114,47,0.45); border-radius: 3px; padding: 0 0.2rem;
}
.vu-group-cells { display: grid; grid-auto-flow: column; gap: 0.25rem; }
.vu-cell {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem; cursor: pointer;
  min-width: 26px;
  border-radius: 6px; padding: 0.3rem 0.15rem 0.2rem; border: 1px solid transparent; transition: border-color .12s, background .12s;
}
.vu-cell:hover { background: rgba(255,255,255,0.03); }
/* Display-only cells (VGM: libvgm muting isn't wired to the UI), so don't offer
   a click affordance the engine can't honour. */
.vu-cell.vu-static { cursor: default; }
.vu-cell.vu-static:hover { background: none; }
.vu-cell.muted { opacity: 0.4; }
.vu-cell.muted .vu-name { text-decoration: line-through; }
.vu-cell.silenced { opacity: 0.3; }
.vu-cell.soloed { border-color: var(--neon-cyan); background: rgba(56,232,255,0.08); }
.vu-cell.soloed .vu-name { color: var(--neon-cyan); }
/* OPLL rhythm-mode drum voices: warm-tinted to read as percussion, not melody */
.vu-cell.vu-drum .vu-name { color: #ffb37a; }
.vu-cell.vu-drum.active .vu-name { color: #ffd0a8; }
.vu-meter {
  width: 14px; height: 74px; background: #05070b; border: 1px solid #1b2130; border-radius: 3px;
  position: relative; overflow: hidden;
}
.vu-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; transition: height .05s linear; }
.vu-name { font-family: var(--mono); font-size: 0.6rem; color: var(--dev-label); letter-spacing: 0.03em; }
.vu-cell.active .vu-name { color: #cdd6ea; }

/* ---- Transport ---- */
.transport {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 0.7rem 0.9rem;
}
.transport-buttons { display: flex; align-items: center; gap: 0.4rem; }
.tbtn {
  font-size: 1rem; line-height: 1; cursor: pointer; background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 9px; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center; transition: background .12s, transform .05s;
}
.tbtn:hover { background: var(--bg-hover); }
.tbtn:active { transform: translateY(1px); }
.tbtn-play { background: var(--accent); color: #fff; border-color: var(--accent-strong); width: 48px; height: 48px; font-size: 1.15rem; }
.tbtn-play:hover { background: var(--accent-strong); }
.transport-info { display: flex; align-items: center; gap: 0.9rem; font-family: var(--mono); font-size: 0.85rem; color: var(--text-dim); }
.time { font-variant-numeric: tabular-nums; font-size: 1rem; color: var(--text); }
.song-sel { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.78rem; }
.song-step {
  font: inherit; cursor: pointer; background: var(--bg-sunken); border: 1px solid var(--border-strong);
  border-radius: 5px; width: 20px; height: 20px; color: var(--text); line-height: 1;
}
.song-step:hover { background: var(--bg-hover); }
.loop-badge { font-size: 0.78rem; color: var(--text-faint); }
.transport-actions { display: flex; gap: 0.5rem; }

/* ---- WAV export popover ---- */
.export-wrap { position: relative; }
.export-panel {
  position: absolute; bottom: calc(100% + 8px); right: 0; z-index: 20;
  width: 260px; padding: 0.8rem; background: var(--bg-panel);
  border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 0.6rem;
}
/* little arrow anchoring the popover to the button */
.export-panel::after {
  content: ""; position: absolute; top: 100%; right: 24px; width: 10px; height: 10px;
  background: var(--bg-panel); border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong); transform: translateY(-50%) rotate(45deg);
}
.ep-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; }
.ep-field {
  display: flex; flex-direction: column; gap: 0.2rem;
  font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em;
}
.ep-field input, .ep-field select {
  font: inherit; font-size: 0.82rem; font-family: var(--mono); color: var(--text);
  background: var(--bg-sunken); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 0.3rem 0.35rem; width: 100%;
}
.ep-field input:focus, .ep-field select:focus { outline: none; border-color: var(--accent); }
.ep-check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--text-dim); }
.ep-check input { accent-color: var(--accent); }
.ep-actions { display: flex; gap: 0.5rem; }
.ep-actions .btn { flex: 1; }
/* OPL4 ROM popover (reuses .export-panel chrome) */
.rom-status { font-size: 0.8rem; color: var(--text); margin: 0; }
.rom-status.is-loaded { color: var(--accent); }
.rom-help { font-size: 0.72rem; line-height: 1.45; color: var(--text-dim); margin: 0; }
.rom-help code { font-family: var(--mono, monospace); font-size: 0.95em; }
.ep-progress { display: flex; flex-direction: column; gap: 0.35rem; }
.ep-bar { height: 6px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.ep-bar span {
  display: block; height: 100%; width: 40%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  animation: ep-marquee 1.1s ease-in-out infinite;
}
@keyframes ep-marquee { 0% { transform: translateX(-110%); } 100% { transform: translateX(360%); } }
.ep-status { font-family: var(--mono); font-size: 0.72rem; color: var(--text-faint); }

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

/* ---- Fit the whole player into the viewport on roomy screens ----
   Keeps the stacked layout, but the device grows to fill the height left over
   after the fixed chrome, and its big panels (scopes / piano roll) flex so they
   shrink on shorter screens instead of pushing the page into a scroll. Guarded by
   a min-height so genuinely tiny windows fall back to normal scrolling, and
   `overflow-y: auto` on the shell means an over-short window still scrolls rather
   than clipping. */
@media (min-width: 641px) and (min-height: 560px) {
  body { height: 100dvh; min-height: 0; overflow-y: auto; }
  #main { min-height: 0; }

  .player { min-height: 0; gap: 0.55rem; padding: 0.8rem 1.1rem; }
  .now-playing, .track-panel, .transport { flex: 0 0 auto; }
  .track-list { max-height: 64px; }

  /* the device fills the remaining height; its inner panels distribute it */
  .device { flex: 1 1 auto; min-height: 0; display: flex; }
  .device-bezel { flex: 1; min-height: 0; gap: 0.5rem; padding: 0.6rem; }

  /* trim the cartridge bay so it doesn't crowd out the scopes/piano roll */
  #chipsRow { flex: 0 0 auto; }
  .cart-bay { padding: 0.4rem 0.9rem 0.28rem; }
  .cart-slot { width: 60px; }

  .scopes { flex: 1.1 1 0; min-height: 0; grid-template-rows: 1fr; }
  .scope-cell { display: flex; flex-direction: column; min-height: 0; }
  .scope-canvas { flex: 1 1 0; height: auto; min-height: 56px; max-height: 130px; }

  .piano-panel { flex: 1.25 1 0; min-height: 0; display: flex; flex-direction: column; }
  .piano-canvas { flex: 1 1 0; height: auto; min-height: 68px; max-height: 168px; }

  .vu-panel { flex: 0 0 auto; padding: 0.35rem 0.65rem 0.4rem; }
  .vu-meter { height: 40px; }
  .vu-cell { gap: 0.15rem; padding: 0.2rem 0.1rem 0.15rem; min-width: 20px; }
  .vu-group { padding: 0.25rem 0.3rem 0.3rem; }

  .transport { padding: 0.5rem 0.9rem; }
  .site-header { padding: 0.6rem 1.4rem; }
  .site-footer { padding: 0.45rem 1.4rem; font-size: 0.72rem; }
  .site-footer p { margin: 0.12rem 0; }
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .scopes { grid-template-columns: 1fr; }
  .player { padding: 0.9rem; }
  .dropzone { margin: 0.8rem; min-height: 60vh; }
  .transport { justify-content: center; }
  .tbtn { width: 44px; height: 44px; }
  .tbtn-play { width: 52px; height: 52px; }
}
