:root {
  --bg: #14161a; --panel: #1c2027; --ink: #e7e9ee; --dim: #9aa3b2; --line: #2c313b;
  --accent: #6ea8fe; --correct: #57caa0; --flipped: #d8b35a; --wrong: #e06c75;
  --coll: #2a3550; --tonic: #3a5bd0;
  /* LOCAL compare (another speller's spelling): cyan, apart from the tier palette; a darker teal on the light staff */
  --compare: #4dd0e1; --compare-on-light: #00798c;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  /* Base UI zoom: the desktop debugger renders at 80% so the whole layout breathes (this was the density
     that read well at 80% browser zoom). Browser zoom still stacks on top. The phone layout resets to 1:1. */
  --ui-scale: 0.8;
}
* { box-sizing: border-box; }
html { height: 100%; zoom: var(--ui-scale); }
/* The app fills the viewport: fixed toolbars top and bottom, the music and panel regions splitting the
   space between them and scrolling inside their own boxes, so the page itself never scrolls. The height is
   divided by the zoom so the scaled body still fills exactly 100vh (0.8 * 100vh/0.8 = 100vh). */
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; height: calc(100vh / var(--ui-scale)); display: flex; flex-direction: column; overflow: hidden; }

/* One steady row: fixed-width menus, the status line takes what is left and truncates (full text in its
   tooltip). It wraps only on narrow screens. */
#toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: nowrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
#toolbar > * { flex: none; white-space: nowrap; }
#toolbar strong { font-size: 16px; letter-spacing: .3px; }
#toolbar .sub { color: var(--dim); font-size: 12px; }
#toolbar label { color: var(--dim); font-size: 12px; }
#toolbar select { background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font-size: 12px; text-overflow: ellipsis; }
#fixture { width: 190px; }
#mode { width: 150px; }
.spacer { flex: 0 0 0; }
#toolbar #status { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: right; font-size: 12px; color: var(--dim); }
@media (max-width: 1000px) { #toolbar { flex-wrap: wrap; row-gap: 6px; } }
#status .correct { color: var(--accent); }   /* combined exact+flipped */
#status .exact { color: var(--correct); }
#status .flipped { color: var(--flipped); }
#status .wrong { color: var(--wrong); }
.dim { color: var(--dim); }

#transport { display: flex; align-items: center; gap: 12px; padding: 12px 16px 4px; }
#transport button { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; width: 34px; height: 30px; cursor: pointer; font-size: 15px; line-height: 1; }
#transport button:hover { border-color: var(--accent); }
#transport button.play { background: var(--tonic); border-color: var(--accent); }
#scrub { flex: 1; accent-color: var(--accent); }
.pos { color: var(--dim); font-variant-numeric: tabular-nums; min-width: 84px; text-align: right; }
#transport .ctl { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 12px; white-space: nowrap; }
#transport .ctl input[type=range] { width: 96px; accent-color: var(--accent); }
#transport .ctl .pos { min-width: 34px; text-align: left; }
#transport .side-ctl { gap: 3px; }
#transport .side-ctl button { width: auto; min-width: 27px; padding: 0 6px; }
#transport .side-ctl button.active { background: var(--tonic); border-color: var(--accent); }
#transport .side-ctl #side-state { min-width: 52px; margin-left: 3px; }

.strip { display: flex; gap: 2px; padding: 6px 16px 12px; overflow-x: auto; }
.strip-cell { flex: 0 0 8px; height: 22px; border: 0; border-radius: 2px; padding: 0; cursor: pointer; opacity: .8; }
.strip-cell:hover { opacity: 1; }
.strip-cell.cursor { outline: 2px solid var(--ink); outline-offset: 1px; opacity: 1; }
.tier-correct { background: var(--correct); }
.tier-flipped { background: var(--flipped); }
.tier-wrong   { background: var(--wrong); }
.tier-unread  { background: var(--dim); }

/* music panels: staff over piano roll, both horizontally-scrolling inside their own box (never the page).
   The region takes ~40% of the height left between the toolbars; the staff keeps a fixed band and the
   roll fills the rest, scrolling vertically for tall pieces. */
#music { display: flex; flex-direction: column; gap: 10px; padding: 8px 16px 0; flex: 58 1 0; min-height: 0; }
#staff, #pianoroll { padding: 0; overflow-x: auto; }
#staff { background: #f4f4f6; border-radius: 8px; flex: 0 0 auto; height: 140px; overflow-y: auto; }   /* fits a grand staff */
#pianoroll { background: var(--panel); flex: 1 1 0; min-height: 0; overflow-y: auto; }
/* Centre the engraving horizontally when it is narrower than the band (e.g. zoomed out on a phone). */
#staff svg { display: block; margin: 0 auto; }
.staff-empty { padding: 10px 14px; color: #888; font-size: 12px; }

/* three cards in one row: scoring (widest — carries the surface rows + scoring table) · spiral · the
   wider 3D tonnetz. minmax(0,…) lets the table columns shrink instead of forcing the page wider. */
#panels {
  display: grid;
  /* set from the slots (slots.ts): the spiral of fifths is narrow wherever it sits */
  grid-template-columns: var(--slot-cols, minmax(0, 1fr) minmax(140px, 0.55fr) minmax(0, 1fr));
  gap: 14px; padding: 8px 16px 12px; align-items: stretch;
  flex: 42 1 0; min-height: 0;
}
/* two-up once a single row would get too cramped (small laptop / landscape tablet) */
@media (max-width: 1040px) and (min-width: 721px) { #panels { grid-template-columns: 1fr 1fr; overflow-y: auto; } }

/* Panel switcher: hidden on wide screens (all panels shown); shown on phones (one panel at a time). */
#panel-tabs { display: none; }

/* --- Phone layout: the page scrolls, and the side panels switch one-at-a-time from the tab bar --- */
@media (max-width: 720px) {
  html { zoom: normal; }   /* the phone layout is touch-sized already; render it 1:1, not scaled down */
  body { height: auto; overflow-y: auto; }
  #toolbar, #transport { flex-wrap: wrap; row-gap: 8px; }
  #toolbar #status { flex-basis: 100%; white-space: normal; text-align: left; }
  #music { flex: none; }
  #staff { height: 160px; }
  #pianoroll { flex: none; height: 260px; }
  #panels { display: block; flex: none; overflow: visible; padding-top: 6px; }
  #panels > .panel { min-height: 66vh; }
  #scoring, #wheel { overflow-y: visible; }        /* the page scrolls now, not each card */
  #panel-tabs { display: flex; gap: 6px; padding: 8px 16px 0; }
  #panel-tabs button {
    flex: 1 1 0; background: var(--panel); color: var(--dim); border: 1px solid var(--line);
    border-radius: 7px; padding: 9px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; cursor: pointer;
  }
  #panel-tabs button.active { background: var(--tonic); color: var(--ink); border-color: var(--accent); }
}

/* the speller's surface, compact: a small left label + a 7-cell letter row, two rows (frame / surface). */
.surface-block { margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.surface-row { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 6px; }
.surface-row-label { font-size: 9px; text-transform: uppercase; letter-spacing: .4px; color: var(--dim); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; min-width: 0; min-height: 0; }
/* text-heavy cards scroll inside the fixed-height row rather than pushing it taller */
#scoring, #wheel { overflow-y: auto; }
.panel-title { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--dim); margin-bottom: 10px; }

/* 3D tonnetz: the card is a flex column whose canvas host has a ZERO flex-basis and an absolutely
   positioned <canvas>, so the canvas never contributes intrinsic height. Without this, three.js's
   renderer.setSize() stamps the drawing-buffer height onto the <canvas>, the browser adopts it as the
   canvas's intrinsic height (a % height can't resolve against a content-sized parent), and the tonnetz
   card latches tall and props the whole row open. With basis:0 the card's intrinsic height is just its
   title, so the row height is set by the scoring/spiral cards and the canvas fills whatever's left. */
#tonnetz { display: flex; flex-direction: column; min-height: 0; }
.tonnetz-canvas { position: relative; flex: 1 1 0; min-height: 0; border-radius: 8px; overflow: hidden; background: #1a1a2e; }
.tonnetz-canvas canvas { position: absolute; inset: 0; display: block; width: 100% !important; height: 100% !important; }
/* 3D lattice buttons (sym. chords, inactive nodes, z range), one row along the canvas's bottom edge, with
   the plane caption above them */
.lattice-ctrls { position: absolute; left: 6px; right: 6px; bottom: 6px; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--dim); pointer-events: none; }
.lattice-ctrls > * { pointer-events: auto; }
.lattice-ctrls[hidden] { display: none; }
.lattice-btns { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px; }
.lattice-btn { font: inherit; color: var(--dim); background: rgba(20, 22, 26, .78); border: 1px solid var(--line); border-radius: 5px; padding: 3px 9px; cursor: pointer; line-height: 1.3; }
.lattice-btn:hover:not(:disabled), .lattice-btn:focus-visible { color: var(--ink); border-color: var(--accent); }
.lattice-btn[aria-pressed="true"] { color: var(--ink); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 28%, rgba(20, 22, 26, .85)); }
.lattice-btn:disabled { opacity: .4; cursor: default; }
.lattice-z { display: inline-flex; align-items: center; gap: 2px; background: rgba(20, 22, 26, .78); border: 1px solid var(--line); border-radius: 5px; padding: 1px; }
.lattice-z .lattice-btn { border-color: transparent; background: transparent; padding: 2px 8px; font-size: 13px; line-height: 1.1; }
.lattice-z-val { min-width: 34px; text-align: center; color: var(--ink); font-variant-numeric: tabular-nums; }
.lattice-caption { background: rgba(20, 22, 26, .78); border: 1px solid var(--line); border-radius: 5px; padding: 3px 7px; color: var(--ink); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
/* torus view: its own canvas over the lattice's, plus the lattice / torus toggle */
.torus-host { position: absolute; inset: 0; }
.tonnetz-mode { position: absolute; top: 8px; right: 8px; z-index: 2; padding: 3px 10px; font: inherit; font-size: 11px;
  color: #dbe9ff; background: rgba(12, 12, 20, .7); border: 1px solid #3a3f5c; border-radius: 5px; cursor: pointer; }
.tonnetz-mode:hover { background: rgba(40, 44, 70, .85); }
.torus-controls { position: absolute; left: 10px; bottom: 8px; z-index: 2; display: flex; flex-direction: column; gap: 4px;
  max-width: calc(100% - 20px); font-size: 10px; letter-spacing: .3px; color: #9aa3c4;
  opacity: .35; transition: opacity .25s ease; }
/* quiet until the pointer is over the view */
.torus-host:hover .torus-controls, .torus-controls:focus-within { opacity: .9; }
/* hidden while the lattice folds or unfolds; fades in once the torus is closed */
.torus-controls.waiting { opacity: 0 !important; visibility: hidden; pointer-events: none; transition: none; }
.torus-controls-row { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; }
.torus-controls label { display: flex; align-items: center; gap: 6px; }
.torus-controls button { padding: 1px 0; font: inherit; letter-spacing: inherit; color: #6b7394; background: none; border: 0; cursor: pointer; transition: color .15s; }
.torus-controls button:hover { color: #b9c2e2; }
.torus-controls button.active { color: #dbe4ff; }
.torus-controls button[hidden] { display: none; }
.torus-controls input[type=range] { -webkit-appearance: none; appearance: none; width: 64px; height: 12px; margin: 0; background: none; cursor: pointer; }
.torus-controls input[type=range]::-webkit-slider-runnable-track { height: 2px; border-radius: 1px; background: rgba(154, 163, 196, .3); }
.torus-controls input[type=range]::-moz-range-track { height: 2px; border-radius: 1px; background: rgba(154, 163, 196, .3); }
.torus-controls input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 8px; height: 8px; margin-top: -3px; border-radius: 50%; background: #c8d2f2; border: 0; }
.torus-controls input[type=range]::-moz-range-thumb { width: 8px; height: 8px; border-radius: 50%; background: #c8d2f2; border: 0; }
.torus-controls button { padding: 2px 8px; font: inherit; color: #8d93ad; background: transparent; border: 1px solid #3a3f5c; border-radius: 4px; cursor: pointer; }
.torus-controls button.active { color: #dbe9ff; background: rgba(143, 176, 255, .18); border-color: #8fb0ff; }

/* live coiled Tonnetz: MIDI pc spokes plus persistent speller-selected spellings */
.live-tonnetz { display: flex; flex-direction: column; min-height: 0; background: #fff; color: #222; border-color: #d6d6d6; }
.live-header { width: 100%; max-width: 940px; margin: 0 auto; }
.live-help { font-size: 10px; text-transform: none; letter-spacing: 0; margin-left: 8px; color: #777; }
.live-scale { display: flex; gap: 4px; width: 100%; max-width: 940px; margin: 0 auto 5px; }
.live-scale-cell { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 1px; }
.live-scale-adjust { height: 11px; padding: 0; border: 0; background: transparent; color: #999; cursor: pointer; font-size: 7px; line-height: 10px; }
.live-scale-adjust:hover { color: var(--scale-color, #555); background: #f2f2f2; }
.live-scale-badge { flex: 1 1 0; min-width: 0; padding: 3px 2px; border: 1px solid var(--scale-color); border-radius: 4px; color: var(--scale-color); text-align: center; font-size: 12px; font-weight: 700; line-height: 1.1; }
.live-scale-badge.empty { border-color: #c9c9c9; color: #aaa; font-weight: 500; }
.live-toolbar { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 940px; min-height: 26px; margin: 0 auto 5px; color: #777; font-size: 11px; }
.live-status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-last { margin-left: auto; color: #333; }
.live-coords-toggle { display: flex; align-items: center; gap: 4px; color: #555; white-space: nowrap; cursor: pointer; }
.live-coords-toggle input { margin: 0; accent-color: var(--accent); }
.live-z-slider { display: flex; align-items: center; gap: 5px; color: #555; white-space: nowrap; }
.live-z-slider input { width: 72px; margin: 0; accent-color: var(--accent); }
/* Compact panel: the 7-letter surface array and the z spread / rotation sliders only earn their space
   in the large expanded view, so hide them until the panel is expanded. */
.live-scale, .live-z-slider { display: none; }
#live-tonnetz.panel-modal .live-scale, #live-tonnetz.panel-modal .live-z-slider { display: flex; }
.live-reset { background: #fff; color: #555; border: 1px solid #c7c7c7; border-radius: 5px; padding: 3px 8px; cursor: pointer; font-size: 11px; }
.live-reset:hover { border-color: var(--accent); color: #222; }
/* Top-toolbar MIDI button: override the fixed 34x30 square that #transport button imposes. */
#transport button.midi-btn { width: auto; padding: 0 10px; font-size: 12px; white-space: nowrap; }
#transport button#instrument { width: auto; padding: 0 10px; font-size: 12px; white-space: nowrap; }
#transport button#instrument[aria-pressed="true"] { border-color: var(--accent); }
#transport button.midi-btn:disabled { opacity: .7; cursor: default; border-color: var(--line); }
#transport button#midi-enable.connected { color: #56d364; border-color: #2f7a3d; background: color-mix(in srgb, #3fb950 12%, var(--panel)); }
/* The cards that keep their own position for overlays in the corner. */
#live-tonnetz, #tonnetz, #spirals { position: relative; }
/* The corner menu picking each card's view, left of the expand button and the `i` (main.ts). */
.view-pick { position: absolute; top: 5px; right: 52px; z-index: 5; max-width: 9.5em; background: var(--panel); color: var(--dim); border: 1px solid var(--line); border-radius: 5px; padding: 1px 4px; font-size: 11px; cursor: pointer; opacity: .8; }
.view-pick:hover, .view-pick:focus { opacity: 1; border-color: var(--accent); color: var(--ink); }
/* spirals: the pitch-class and letter windings of the line of fifths, on the paper's light background */
.spirals { flex-direction: column; min-height: 0; background: #fffefb; color: #222; border-color: #d6d6d6; }
.spirals-host { flex: 1 1 0; min-height: 0; width: 100%; }
.spirals-svg { display: block; width: 100%; height: 100%; }
.spirals-flash { animation: spirals-flash 0.7s ease-out forwards; transform-box: fill-box; transform-origin: center; }
@keyframes spirals-flash { from { opacity: 1; transform: scale(0.7); } to { opacity: 0; transform: scale(2.4); } }
.live-svg-host { flex: 1 1 0; width: 100%; max-width: 940px; min-height: 0; margin: 0 auto; border-radius: 8px; overflow: hidden; background: #fff; }
.live-tonnetz-svg { display: block; width: 100%; height: 100%; }
.live-coord-label-bg { fill: #fff; fill-opacity: .9; pointer-events: none; }
.live-coord-label { font-size: 4.2px; fill: #596273; pointer-events: none; }
/* Expanded panel: a large card centred over the dimmed page (modal.ts). */
.panel-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 14, 0.35); }
#panels > .panel.panel-modal { position: fixed !important;   /* the help `i` sets an inline position: relative */ inset: 10% 15%; z-index: 51; min-height: 0; padding: 16px 22px 20px; border-radius: 14px; box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5); }
.panel-modal .live-header, .panel-modal .live-svg-host, .panel-modal .live-scale, .panel-modal .live-toolbar { max-width: none; }
.panel-modal .view-pick { display: none; }
@media (max-width: 720px) { #panels > .panel.panel-modal { inset: 5% 4%; } }   /* phones keep the room */
body.live-only { background: #fff; }
#live-page { height: 100vh; padding: 18px; }
.live-only .live-tonnetz { width: 100%; height: 100%; min-height: 0; }

/* spiral of fifths — the card stretches to the row height (set by the taller scoring column), so make it
   a flex column and center the spiral+legend group in the space below the title/controls. The svg must be
   pinned square (aspect-ratio + flex-shrink:0): a viewBox svg with height:auto otherwise stretches to fill
   the column's main axis, eating the free space so nothing can center and the graphic pins to the bottom. */
#wheel { display: flex; flex-direction: column; }
/* Fill the leftover column space as a centred square: flex takes the height under the controls, and the
   svg's own viewBox (preserveAspectRatio) draws the largest square that fits, centred. Grows on tall
   screens, shrinks to fit on short ones, never overflows. */
.spiral { display: block; flex: 1 1 0; min-height: 220px; width: 100%; }
.spiral .note-dot { fill: var(--ink); stroke: #171b22; stroke-width: 1; }
.wheel-legend { text-align: center; font-size: 12px; color: var(--dim); margin: 8px 0 auto; line-height: 1.5; }
.wheel-legend b { color: var(--ink); }
.note-dot-key { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); vertical-align: middle; }

/* spiral what-if controls (range / centre) — one compact line directly above the wheel */
.spiral-ctl { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.spiral-ctl.disabled { opacity: .55; }
.ctl-group { display: flex; align-items: center; gap: 4px; }
/* thin rule between the range and centre sides, so the two steppers read as separate controls */
.ctl-group + .ctl-group { padding-left: 10px; border-left: 1px solid var(--line); }
.ctl-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--dim); margin-right: 2px; }
.ctl-group button { width: 20px; height: 20px; flex: 0 0 20px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 5px; cursor: pointer; font-size: 13px; line-height: 1; padding: 0; }
.ctl-group button:hover:not(:disabled) { border-color: var(--accent); }
.ctl-group button:disabled { opacity: .4; cursor: default; }
.ctl-val { min-width: 28px; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink); cursor: help; }
.ctl-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; cursor: help; }
.ctl-seg button { height: 20px; padding: 0 8px; background: var(--bg); color: var(--dim); border: 0; cursor: pointer; font-size: 11px; line-height: 20px; font-variant-numeric: tabular-nums; }
.ctl-seg button + button { border-left: 1px solid var(--line); }
.ctl-seg button.on { background: var(--accent); color: var(--bg); }
.ctl-seg button:hover:not(.on):not(:disabled) { color: var(--ink); }
.ctl-seg button:disabled { opacity: .4; cursor: default; }
.ctl-reset { background: none; border: 0; padding: 2px 4px; font-size: 11px; color: var(--accent); cursor: pointer; }
.ctl-reset:hover:not(:disabled) { text-decoration: underline; }
.ctl-reset:disabled { color: var(--dim); opacity: .5; cursor: default; }
.ctl-reset.on { background: var(--accent); color: var(--bg); border-radius: 3px; }

/* state table */
.note-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 7px 10px; border-radius: 8px; background: #232833; border-left: 4px solid var(--dim); margin-bottom: 10px; }
.note-line.tier-correct { border-left-color: var(--correct); }
.note-line.tier-flipped { border-left-color: var(--flipped); }
.note-line.tier-wrong { border-left-color: var(--wrong); }
.note-big { font-size: 20px; font-weight: 700; }
.note-meta, .note-exp { color: var(--dim); font-size: 12px; }
.note-meta { font-variant-numeric: tabular-nums; }
.note-tier { font-size: 12px; }
.field { margin-bottom: 14px; }
.field-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--dim); margin-bottom: 6px; }
.surface { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.surf-cell { text-align: center; padding: 5px 1px; border-radius: 4px; background: #232833; border: 1px solid var(--line); }
.surf-cell.altered { background: #2c2438; border-color: #4a3d63; }
/* surface cell the keep-alive / sounding overlay moved off the bare frame */
.surf-cell.overlaid { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.surf-spell { display: block; font-size: 12px; line-height: 1.2; font-weight: 600; }
.sounding { display: flex; gap: 6px; flex-wrap: wrap; }
.chord-line { font-size: 13px; line-height: 1.4; }
.sound-chip { padding: 3px 9px; border-radius: 12px; background: #232833; border: 1px solid var(--line); font-size: 13px; }
.sound-chip.current { background: var(--tonic); border-color: var(--accent); }

/* scoring table — wrapped so a tight column scrolls the table, never the page. Fixed column widths and a
   reserved row block keep the geometry identical from onset to onset instead of reflowing per content. */
#scoring .score-scroll { overflow-x: auto; margin-top: 6px; }
.score-table { table-layout: fixed; border-collapse: collapse; width: 100%; min-width: 348px; font-size: 12.5px; }
.score-table .col-cand { width: 56px; }
.score-table .col-total { width: 74px; }
.score-table .col-slot { width: 23px; }
.score-table .col-delta { width: 30px; }
.score-table th, .score-table td { height: 22px; padding: 2px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; }
.score-table th { height: 19px; font-size: 11px; color: var(--dim); font-weight: 600; text-align: left; }
.score-table td.c, .score-table th.c { text-align: center; font-variant-numeric: tabular-nums; }
.score-table tr.winner { background: rgba(110,168,254,.10); }
.score-table tr.winner td { font-weight: 600; }
.score-table tr.filler td { border-bottom-color: transparent; }
.score-table td.total { font-variant-numeric: tabular-nums; }
.score-table td.total b { font-size: 14px; }
/* the winner caret keeps its slot on every row, so candidate names never shift sideways */
.score-table .pick { display: inline-block; width: 13px; color: var(--accent); }
.score-table .pick.blank { visibility: hidden; }
.score-table .pos { color: var(--correct); }
.score-table .neg { color: var(--wrong); }
.score-table .zero, .score-table .dim { color: var(--dim); }
/* two lines' worth of room: short and long decision notes occupy the same box */
.decision-note { margin-top: 8px; min-height: 34px; font-size: 12.5px; color: var(--ink); background: #232833; border-left: 3px solid var(--accent); border-radius: 6px; padding: 6px 10px; line-height: 1.4; }

footer { color: var(--dim); font-size: 11px; padding: 4px 16px 7px; line-height: 1.4; flex: 0 0 auto; }
footer code, footer b { color: var(--ink); }

/* "copied" flash for the clipboard shortcut — brief, corner-anchored, never in the way */
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  padding: 7px 14px; border-radius: 8px; font-size: 12px; letter-spacing: .3px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--accent);
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}
.toast.show { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* --- Help / tutorial -------------------------------------------------------------------------- */
/* The `? help` button in the toolbar, styled like the other toolbar controls. */
.help-open { background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 9px; font-size: 12px; cursor: pointer; }
.help-open:hover { border-color: var(--accent); color: var(--accent); }

/* The small `i` pinned to a panel's top-right corner. Panels are made position:relative in JS. */
.help-i { position: absolute; top: 6px; right: 6px; z-index: 5; width: 18px; height: 18px; padding: 0;
  border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--dim);
  font-size: 11px; font-style: italic; font-weight: 700; line-height: 1; cursor: pointer; opacity: .65; }
.help-i:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
/* The expand button sits just left of the `i`, in the same place on every card (modal.ts). */
.panel-expand { position: absolute; top: 6px; right: 28px; z-index: 5; width: 18px; height: 18px; padding: 0;
  border: 1px solid var(--line); border-radius: 4px; background: var(--panel); color: var(--dim);
  font-size: 11px; line-height: 1; cursor: pointer; opacity: .65; }
.panel-expand::before { content: '⤢'; }
.panel-modal > .panel-expand::before { content: '✕'; }
.panel-expand:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }

/* The overlay: a dim backdrop and a centred dialog with a page list on the left and the page on the right. */
#help-overlay { position: fixed; inset: 0; z-index: 1000; }
#help-overlay[hidden] { display: none; }
.help-backdrop { position: absolute; inset: 0; background: rgba(6, 8, 12, .66); }
.help-dialog { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(880px, 92vw); height: min(660px, 88vh); display: grid; grid-template-columns: 180px 1fr;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.help-nav { border-right: 1px solid var(--line); padding: 12px 8px; overflow-y: auto; background: var(--bg); }
.help-nav button { display: block; width: 100%; text-align: left; background: transparent; color: var(--dim);
  border: 0; border-radius: 6px; padding: 7px 10px; font-size: 13px; cursor: pointer; }
.help-nav button:hover { color: var(--ink); background: var(--panel); }
.help-nav button.active { color: var(--ink); background: var(--tonic); }
.help-content { padding: 22px 26px; overflow-y: auto; color: var(--ink); line-height: 1.55; font-size: 13.5px; }
.help-content h2 { margin: 0 0 14px; font-size: 19px; letter-spacing: .2px; }
.help-content p { margin: 0 0 11px; }
.help-content ul, .help-content ol { margin: 0 0 12px; padding-left: 20px; }
.help-content li { margin-bottom: 6px; }
.help-content code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; font-size: 12px; }
.help-content b { color: #fff; }
.help-eq { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 17px; text-align: center;
  color: var(--accent); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; margin: 4px 0 14px; letter-spacing: 1px; }
/* Inline tier chips reused from the legend. */
.help-content .k { font-weight: 700; padding: 0 4px; border-radius: 3px; }
.help-content .k.correct { color: var(--correct); }
.help-content .k.flipped { color: var(--flipped); }
.help-content .k.wrong { color: var(--wrong); }
.help-close { position: absolute; top: 8px; right: 10px; background: transparent; border: 0; color: var(--dim);
  font-size: 26px; line-height: 1; cursor: pointer; padding: 2px 6px; }
.help-close:hover { color: var(--ink); }
@media (max-width: 720px) {
  .help-dialog { grid-template-columns: 1fr; height: 90vh; width: 94vw; }
  .help-nav { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .help-nav button { white-space: nowrap; width: auto; }
}
/* The transport `i` sits inline at the end of the control row; override the #transport button sizing. */
#transport button.help-i { position: static; width: 18px; height: 18px; padding: 0; font-size: 11px;
  margin-left: 2px; }
.help-content .help-quote { margin: 0 0 12px; padding: 10px 14px; border-left: 3px solid var(--accent);
  background: var(--bg); border-radius: 0 6px 6px 0; }
.help-content a, .help-content a code { color: var(--accent); text-decoration: underline; }

/* Import loading wheel: a centred overlay shown while a file is read/unzipped/parsed. */
#import-overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(1.5px); }
#import-overlay[hidden] { display: none; }
#import-overlay .import-spinner { width: 46px; height: 46px; border: 4px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
#import-overlay .import-msg { color: var(--dim); font-size: 13px; letter-spacing: .3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Help: computer-keyboard note map. Key width = 1/12.75 of the row, so it fits any dialog width. */
.kb-map { margin: 4px 0 14px; padding: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 3px; user-select: none; }
.kb-row { display: flex; gap: 3px; padding-left: calc(var(--kb-offset) * (100% / 12.75)); }
.kb-key { flex: 0 0 calc(100% / 12.75 - 3px); aspect-ratio: 1 / 1.05; box-sizing: border-box; border-radius: 4px; border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; font-size: clamp(8px, 1.4vw, 11px); }
.kb-key i { font-style: normal; font-size: .82em; opacity: .6; }
.help-content .kb-key b { font-weight: 600; text-align: center; color: inherit; }
.kb-white { background: #e9ebef; color: #3a3e45; border-color: #c4c8d0; }
.kb-white i { opacity: .75; }
.kb-black { background: #07080a; color: var(--ink); border-color: #3a404b; }
.kb-black b { font-size: .86em; font-weight: 500; }
.kb-off { color: var(--dim); opacity: .45; }
.kb-key.kb-down { outline: 2px solid var(--accent); outline-offset: -1px; }
.kb-white.kb-down { background: #c9d6ee; }
.kb-black.kb-down { background: #26324a; }

/* Metronome (live takes) */
#metro-bpm { width: 46px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 5px; padding: 2px 4px; font-size: 12px; }
#metro-meter { background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 5px; font-size: 12px; }
#metro-bpm:disabled, #metro-meter:disabled { opacity: .6; }
.metro-beat { min-width: 64px; font-variant-numeric: tabular-nums; color: var(--ink); }
.metro-beat.pulse { animation: metro-pulse .18s ease-out; }
.metro-beat.downbeat { color: var(--accent); }
#transport button#metro-toggle.recording { border-color: #e06c75; color: #e06c75; }
@keyframes metro-pulse { from { opacity: .35; } to { opacity: 1; } }

/* In the bars, the hidden attribute wins over the button display rules. */
#toolbar [hidden], #transport [hidden] { display: none !important; }
/* Clear the live take: a muted red, brighter on hover. */
#transport button#take-clear { color: #d98a8f; border-color: #6e3a3f; background: color-mix(in srgb, #e06c75 10%, var(--panel)); }
#transport button#take-clear:hover { color: #f0a0a5; border-color: #b0545b; }

/* Help: shortcut table */
.help-content .help-keys { border-collapse: collapse; margin: 0 0 14px; font-size: 13px; }
.help-content .help-keys td { padding: 4px 14px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-content .help-keys td:first-child { white-space: nowrap; color: var(--ink); }
#transport .ctl-val { cursor: pointer; }   /* click resets the roll scale to its default */

/* --- LOCAL-ONLY speller comparison (viz/src/compare.ts); hidden unless compare data was synced --- */
#compare { width: 130px; }   /* narrower than the longest names; they truncate, the open menu shows them whole */
#moments { width: 120px; }
#status .cmp { color: var(--compare); }
#moment-note { display: flex; align-items: baseline; gap: 10px; margin: 4px 16px 0; padding: 5px 10px; font-size: 12.5px;
  border-left: 3px solid var(--compare); border-radius: 4px; background: color-mix(in srgb, var(--compare) 10%, var(--panel)); }
#moment-note[hidden] { display: none; }
#moment-note b { color: var(--compare); margin-right: 4px; }
#moment-note #moment-text { flex: 1 1 auto; }
#moment-note button { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 15px; line-height: 1; }
#moment-note button:hover { color: var(--ink); }
.cmp-block { margin: -2px 0 10px; padding: 6px 8px; border: 1px solid color-mix(in srgb, var(--compare) 45%, var(--line)); border-radius: 6px; font-size: 12px; }
.cmp-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cmp-name { color: var(--compare); font-weight: 700; }
.cmp-sp { color: var(--compare); font-size: 18px; font-weight: 700; }
.cmp-tier { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; padding: 0 5px; border-radius: 3px; border: 1px solid currentColor; }
.cmp-tier.correct { color: var(--correct); } .cmp-tier.flipped { color: var(--flipped); } .cmp-tier.wrong { color: var(--wrong); } .cmp-tier.unread { color: var(--dim); }
.cmp-sub { margin-top: 5px; font-size: 10.5px; }
.cmp-chord { border-collapse: collapse; margin: 2px 0 4px; font-size: 13px; }
.cmp-chord th { text-align: left; font-weight: 500; color: var(--dim); padding: 1px 10px 1px 0; font-size: 11px; white-space: nowrap; }
.cmp-chord th.cmp-name { color: var(--compare); font-weight: 700; }
.cmp-chord td { padding: 1px 7px; text-align: center; }
.cmp-diff { color: var(--compare); font-weight: 700; }
.cmp-bad { text-decoration: underline wavy var(--wrong); text-underline-offset: 3px; }
.cmp-sum { font-size: 11px; line-height: 1.4; }

/* --- Piano keyboard strip (panels/keyboard.ts): the sounding notes lit on a compact full keyboard (A0..C8),
   no labels. Look from the tonnetz app's read-only keyboard: dark rounded case, small gradient keys, lit keys
   filled with their chord's 3D-lattice shade and glowing; notes outside the chord grey; wrong notes framed
   red. Off by default (the "piano" toggle). */
#keyboard { flex: 0 0 auto; padding: 10px 16px 0; position: relative; }   /* between #music and #panels */
#keyboard[hidden] { display: none; }
/* never wider than at a 1080 px screen (1080 − 2×16 gutter − 2×5 case = 1038 px of keys, ~20 px per white): the
   range is already the whole piano, so a wider screen centres the keyboard instead of growing the keys */
.pk-keys { max-width: 1038px; margin: 0 auto; }
.pk-keys { position: relative; height: 56px; background: #3a3a3a; border: 5px solid #3a3a3a; border-radius: 8px; box-sizing: content-box; box-shadow: 0 2px 8px rgba(0,0,0,.25); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.pk-key { position: absolute; top: 0; cursor: pointer; transition: background .15s ease, box-shadow .15s ease; box-sizing: border-box; }
.pk-white { bottom: 0; background: linear-gradient(145deg, #ffffff, #f7fafc); border: 1px solid #cbd5e0; border-radius: 0 0 4px 4px; z-index: 1; }
.pk-black { height: 58%; background: linear-gradient(145deg, #2d3748, #1a202c); border: 1px solid #1a202c; border-radius: 0 0 3px 3px; transform: translateX(-50%); z-index: 2; }
.pk-white:hover { background: linear-gradient(145deg, #edf2f7, #e2e8f0); }
.pk-black:hover { background: linear-gradient(145deg, #4a5568, #2d3748); }
.pk-key.pk-on { background: var(--pk-bg, var(--pk-fill)); border-color: color-mix(in srgb, var(--pk-fill) 70%, #000); box-shadow: 0 0 8px color-mix(in srgb, var(--pk-fill) 60%, transparent); }
.pk-black.pk-on { z-index: 3; }   /* lit whites stay under the blacks */
/* held from an earlier onset: the same colour, paler, no glow */
.pk-key.pk-on.pk-held { background: color-mix(in srgb, var(--pk-fill) 40%, #f1f2f5); box-shadow: none; }
.pk-black.pk-on.pk-held { background: color-mix(in srgb, var(--pk-fill) 45%, #2d3748); }
.pk-key.pk-on.pk-nct { box-shadow: none; }
.pk-key.pk-cur { box-shadow: inset 0 0 0 2px #0b0d10, 0 0 10px var(--pk-fill); }
/* wrong (the tier the fill no longer carries): a red inner frame, drawn over the current-note ring */
.pk-key.pk-wrong::before { content: ''; position: absolute; inset: 2px; border: 3px solid var(--wrong); border-radius: 2px; pointer-events: none; }
.pk-key.pk-cur.pk-wrong { box-shadow: 0 0 10px var(--pk-fill); }
/* LOCAL compare: the other speller spelled this sounding note differently (tooltip names both) */
.pk-key.pk-diff::after { content: ''; position: absolute; left: 15%; right: 15%; bottom: 3px; height: 4px; border-radius: 2px; background: var(--compare); box-shadow: 0 0 0 1px #0b0d10; }
.pk-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 720px) {
  #keyboard { overflow-x: auto; }
  .pk-keys { min-width: 640px; }
}

/* the logo links to the landing page; keep it looking like the title */
#toolbar a.home { color: inherit; text-decoration: none; }
#toolbar a.home:hover { text-decoration: underline; }
