/* Layout: a practice stand. Top bar with the piece picker, a title block like the printed page,
   settings, the bars grouped in the book's printed lines, and a keyboard dock stuck to the bottom. */
:root {
  --paper: #F3F5F1;
  --surface: #FFFFFF;
  --ink: #1B1F23;
  --muted: #5D6670;
  --line: #D7DBD4;
  --rh: #2B6A4F;
  --rh-soft: #E2EFE8;
  --lh: #3D5B8C;
  --lh-soft: #E3E9F4;
  --range: #EEF3EC;
  --warn: #B4531B;
  --warn-soft: #FBEEE4;
  --key-white: #FBFBF8;
  --key-black: #1B1F23;
  --key-edge: #BFC4BC;
  --key-label: #6B716C;
  --on-accent: #FFFFFF;
  --shadow: 0 1px 0 rgba(27, 31, 35, .06), 0 6px 18px rgba(27, 31, 35, .06);
  --display: "Bodoni Moda", "Didot", "Bodoni 72", Georgia, serif;
  --ui: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111413; --surface: #191D1C; --ink: #E7EAE5; --muted: #9AA39F; --line: #2B312F;
    --rh: #74C59D; --rh-soft: #1E3329; --lh: #93AEDB; --lh-soft: #1F2939; --range: #17201C;
    --warn: #E59A63; --warn-soft: #2E2016;
    --key-white: #D9DCD6; --key-black: #0A0C0B; --key-edge: #8A908B; --key-label: #4A504C; --on-accent: #0F1412;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #111413; --surface: #191D1C; --ink: #E7EAE5; --muted: #9AA39F; --line: #2B312F;
  --rh: #74C59D; --rh-soft: #1E3329; --lh: #93AEDB; --lh-soft: #1F2939; --range: #17201C;
  --warn: #E59A63; --warn-soft: #2E2016;
  --key-white: #D9DCD6; --key-black: #0A0C0B; --key-edge: #8A908B; --key-label: #4A504C; --on-accent: #0F1412;
  --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--ui); font-size: 15px; line-height: 1.5; }
code { font-family: var(--mono); font-size: .92em; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding-inline: 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); padding-bottom: 10px; }
.topbar-inner { max-width: 1040px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.brand { font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .01em; }
.picker { display: flex; align-items: center; gap: 8px; min-width: 0; }
.picker span { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.picker select { max-width: min(70vw, 360px); }

.wrap { max-width: 1040px; margin: 0 auto; padding-inline: 16px; padding-block: 28px 24px; display: grid; gap: 28px; }
.player { display: grid; gap: 28px; }

/* Panels for loading and problems */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel p { margin: 6px 0 0; max-width: 65ch; }
.problems { border-color: var(--warn); background: var(--warn-soft); }
.problems strong { color: var(--warn); }
.problems ul { margin: 8px 0 0; padding-left: 20px; font-family: var(--mono); font-size: 13px; display: grid; gap: 2px; }

/* Title block */
header { display: grid; gap: 6px; text-align: center; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { font-family: var(--display); font-weight: 700; font-size: clamp(34px, 7vw, 54px); line-height: 1.05; margin: 0; letter-spacing: .01em; text-wrap: balance; }
.tempo-mark { font-family: var(--display); font-style: italic; font-size: 20px; }
.tempo-mark:empty { display: none; }
.meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Settings */
.settings { display: grid; gap: 18px; grid-template-columns: 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
@media (min-width: 760px) { .settings { grid-template-columns: 1fr 1fr; column-gap: 32px; } }
.field { display: grid; gap: 8px; min-width: 0; align-content: start; }
.label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.label output { font-family: var(--display); font-size: 18px; letter-spacing: 0; text-transform: none; color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--rh); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.toggle { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--rh); margin: 0; }
select { font: inherit; font-size: 14px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.chip:focus-visible, .bar:focus-visible, .play:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--rh); outline-offset: 2px; }

/* Score */
.score { display: grid; gap: 22px; }
.system { display: grid; gap: 8px; }
.system-label { font-size: 12px; color: var(--muted); letter-spacing: .04em; display: flex; gap: 10px; align-items: center; }
.system-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
/* Each bar asks for the width its notes need (flex-basis, set in app.js) and rows share out the rest, like a justified line of music. */
.bars { display: flex; flex-wrap: wrap; gap: 8px; }
.bar { flex: 1 1 104px; max-width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; display: grid; gap: 4px; padding: 8px 9px 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); min-width: 0; scroll-margin-bottom: 200px; scroll-margin-top: 16px; transition: border-color .15s, background-color .15s; }
.bar.in-range { background: var(--range); }
.bar.out-range { opacity: .55; }
.bar.bad { border-color: var(--warn); border-style: dashed; }
.bar.now { border-color: var(--rh); box-shadow: 0 0 0 1px var(--rh); }
.bar-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.time-change { margin-left: 6px; padding: 0 5px; border-radius: 4px; background: var(--rh-soft); color: var(--rh); font-weight: 600; }
.dyn { font-family: var(--display); font-style: italic; font-weight: 700; font-size: 15px; color: var(--ink); }
.rh { position: relative; height: 40px; }
.n { position: absolute; font-size: 12px; font-weight: 600; line-height: 1; color: var(--ink); white-space: nowrap; padding: 3px 2px; border-radius: 4px; transition: background-color .08s; }
.n sup { font-size: 9px; font-weight: 500; color: var(--muted); margin-left: 1px; }
.n.rest { color: var(--muted); font-weight: 400; }
.n.tied { opacity: .5; }
.n.on { background: var(--rh); color: var(--on-accent); opacity: 1; }
.n.on sup { color: var(--on-accent); }
.lh { font-size: 11px; color: var(--lh); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 16px; }

/* Sheet music: one SVG per printed line. A line wider than the screen scrolls sideways.
   Tap targets sit over the bars; they tint the bar that's playing and veil the bars outside the range. */
.score-head { display: flex; justify-content: flex-end; margin-bottom: -14px; }
.sheet-line { overflow-x: auto; overscroll-behavior-x: contain; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 0; scrollbar-width: thin; }
.sheet .system { scroll-margin-bottom: 200px; scroll-margin-top: 16px; }
.sheet-inner { position: relative; width: max-content; min-width: 100%; }
.sheet-inner svg { display: block; color: var(--ink); fill: currentColor; stroke: currentColor; }
.sheet-inner svg [fill]:not([fill="none"]) { fill: currentColor; }
.sheet-inner svg [stroke]:not([stroke="none"]) { stroke: currentColor; }
.sheet-inner svg .on { color: var(--rh); }
.sheet-inner svg .on.hand-l { color: var(--lh); }
.sheet-error { margin: 0; padding: 16px; font-size: 13px; color: var(--warn); }
.bar-hit { position: absolute; top: 0; bottom: 0; padding: 0; border: 0; border-radius: 8px; background: transparent; font: inherit; cursor: pointer; transition: background-color .15s; }
.bar-hit .num { position: absolute; top: 2px; left: 5px; font-size: 10px; line-height: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-hit.in-range { background: color-mix(in srgb, var(--rh) 6%, transparent); }
.bar-hit.out-range { background: color-mix(in srgb, var(--surface) 50%, transparent); }
.bar-hit.bad { outline: 1.5px dashed var(--warn); outline-offset: -2px; }
.bar-hit.now { background: color-mix(in srgb, var(--rh) 11%, transparent); box-shadow: inset 0 0 0 1.5px var(--rh); }
.bar-hit:focus-visible { outline: 2px solid var(--rh); outline-offset: -2px; }

.footnote { font-size: 13px; color: var(--muted); max-width: 65ch; margin: 0; display: grid; gap: 6px; }
.footnote p { margin: 0; }

/* Dock */
.dock { position: sticky; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(0, 0, 0, .06); padding-inline: 16px; padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
.dock-inner { max-width: 1040px; margin: 0 auto; display: grid; gap: 10px; }
.transport { display: flex; align-items: center; gap: 14px; }
.play { flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--rh); color: var(--on-accent); display: grid; place-items: center; cursor: pointer; }
.play svg { width: 22px; height: 22px; fill: currentColor; }
.status { display: grid; gap: 2px; min-width: 0; flex: 1; }
.status strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.status span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.beats { display: flex; gap: 6px; }
.beat { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--muted); }
.beat.on { background: var(--rh); border-color: var(--rh); }
.sound-load { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 12px; color: var(--muted); }
.sound-load span { text-wrap: pretty; }
.sound-load .chip { padding: 2px 10px; font-size: 12px; }
.meter { flex-basis: 100%; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--rh); transition: width .2s; }

.kb { position: relative; height: 74px; user-select: none; -webkit-user-select: none; }
.wk, .bk { position: absolute; top: 0; display: flex; align-items: flex-end; justify-content: center; font-size: 10px; font-weight: 700; padding-bottom: 4px; transition: background-color .06s; overflow: hidden; }
.kb.dense .wk, .kb.dense .bk { font-size: 8px; }
.wk { height: 100%; background: var(--key-white); border: 1px solid var(--key-edge); border-radius: 0 0 4px 4px; color: var(--key-label); }
.bk { height: 60%; background: var(--key-black); border-radius: 0 0 3px 3px; z-index: 2; color: #fff; }
.wk.r, .bk.r { background: var(--rh); color: var(--on-accent); }
.wk.l, .bk.l { background: var(--lh); color: var(--on-accent); }
.wk.ghost-r { background: var(--rh-soft); color: var(--rh); }
.wk.ghost-l { background: var(--lh-soft); color: var(--lh); }
.bk.ghost-r { background: var(--rh); opacity: .45; }
.bk.ghost-l { background: var(--lh); opacity: .45; }
.kb-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--muted); }
.kb-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
