/* Layout: a practice stand. Top bar with the piece picker, a title block like the printed page,
   the bars grouped in the book's printed lines, and a dock stuck to the bottom with play, the practice controls
   and the keyboard. The rest of the settings are in a sheet the dock opens. */
: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);
  --lift: 0 2px 6px rgba(27, 31, 35, .08), 0 18px 40px rgba(27, 31, 35, .14);
  --track: #C5CAC2;
  --knob: #FFFFFF;
  --scrim: rgba(27, 31, 35, .32);
  --scrim-soft: rgba(27, 31, 35, .1);
  --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);
    --lift: 0 2px 6px rgba(0, 0, 0, .4), 0 18px 40px rgba(0, 0, 0, .5);
    --track: #3A423F; --knob: #E7EAE5; --scrim: rgba(0, 0, 0, .5); --scrim-soft: 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);
  --lift: 0 2px 6px rgba(0, 0, 0, .4), 0 18px 40px rgba(0, 0, 0, .5);
  --track: #3A423F; --knob: #E7EAE5; --scrim: rgba(0, 0, 0, .5); --scrim-soft: rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
/* At least as tall as the screen, so the dock sits at the bottom even when a short piece doesn't fill it. */
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; 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 { width: 100%; 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; }

/* Controls, shared by the dock, its trays and the settings sheet */
.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); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.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); }
select { font: inherit; font-size: 14px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--rh); outline-offset: 2px; }
.stepper button:focus-visible, .seg button:focus-visible { outline-offset: -2px; }
/* A switch: a checkbox drawn as a sliding knob. */
.switch { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 40px; height: 24px; margin: 0; border-radius: 999px; background: var(--track); cursor: pointer; transition: background-color .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--knob); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
.switch:checked { background: var(--rh); }
.switch:checked::after { transform: translateX(16px); }
.switch:disabled { opacity: .55; cursor: default; }
/* A segmented control: one of a few buttons pressed. */
.seg { flex: none; display: flex; height: 36px; padding: 2px; gap: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); }
.seg button { font: inherit; font-size: 13px; color: var(--ink); border: 0; border-radius: 999px; background: transparent; padding: 0 12px; white-space: nowrap; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg button:disabled { color: var(--muted); cursor: default; }
.seg.small { height: 32px; }
.seg.small button { padding: 0 10px; font-size: 12.5px; }
.icon-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; min-width: 36px; padding: 0; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; }
.icon-btn svg { width: 20px; height: 20px; flex: none; }
.icon-btn[aria-pressed="true"] { background: var(--rh-soft); border-color: var(--rh); color: var(--rh); }

/* 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: 240px; 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, or one for the whole piece when the printed lines don't fit. That one scrolls sideways.
   Tap targets sit over the bars; they tint the bar that's playing and veil the bars outside the range. */
.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; }
.system { scroll-margin-bottom: 240px; scroll-margin-top: 16px; }
/* Black on white: the sheet music keeps the light colours in dark mode, like the printed page. Its switch in Settings only shows in dark mode. */
.score.paper .sheet-line {
  --surface: #FFFFFF; --ink: #1B1F23; --muted: #5D6670; --line: #D7DBD4; --rh: #2B6A4F; --lh: #3D5B8C; --warn: #B4531B;
  color-scheme: light;
}
.set.paper-toggle { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .paper-toggle { display: flex; } }
:root[data-theme="dark"] .paper-toggle { display: flex; }
.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; margin-top: auto; 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; }
/* Two rows on a narrow screen: play, where you are, the beat, metronome and settings; then tempo, hands and bars.
   One row from 960px, and on a phone on its side, where the keyboard gets shorter to leave room for the music. */
.controls { display: grid; align-items: center; gap: 8px 10px; grid-template-columns: auto minmax(0, 1fr) auto auto auto; grid-template-areas: "play status beats metro gear" "practice practice practice practice practice"; }
@media (min-width: 960px), (max-height: 500px) and (min-width: 600px) {
  .controls { column-gap: 14px; grid-template-columns: auto minmax(0, 1fr) auto auto auto auto; grid-template-areas: "play status practice beats metro gear"; }
}
.play { grid-area: 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 { grid-area: status; display: grid; gap: 2px; min-width: 0; }
.status strong { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.beats { grid-area: 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); }
@media (max-width: 479px) { .beats { gap: 4px; } .beat { width: 10px; height: 10px; } }
#metro { grid-area: metro; }
.gear { grid-area: gear; }
.gear span { display: none; }
@media (min-width: 480px) { .gear { padding: 0 13px 0 10px; } .gear span { display: inline; } }
@media (max-height: 500px) and (max-width: 959px) { .gear { padding: 0; } .gear span { display: none; } }

.practice { grid-area: practice; display: flex; gap: 8px; align-items: center; min-width: 0; }
.stepper { flex: none; display: flex; height: 36px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); }
.stepper button { font: inherit; color: var(--ink); border: 0; background: transparent; padding: 0; cursor: pointer; }
.stepper .step { width: 32px; font-size: 19px; line-height: 1; border-radius: 999px; }
.stepper .step:disabled { color: var(--muted); opacity: .5; cursor: default; }
.stepper .tempo-btn { display: flex; align-items: center; justify-content: center; gap: 3px; min-width: 58px; padding: 0 6px; border-inline: 1px solid var(--line); font-family: var(--display); font-size: 17px; font-variant-numeric: tabular-nums; }
.stepper .tempo-btn b { font-weight: 500; }
/* Two switches, filled in the colours the keys light up in while the app plays that hand. L and R on a phone. */
.hands [data-h="L"] { color: var(--lh); font-weight: 600; }
.hands [data-h="R"] { color: var(--rh); font-weight: 600; }
.hands [data-h="L"][aria-pressed="true"] { background: var(--lh); color: var(--on-accent); }
.hands [data-h="R"][aria-pressed="true"] { background: var(--rh); color: var(--on-accent); }
.hands .short { display: none; }
@media (max-width: 479px) { .hands button { padding: 0 10px; } .hands .long { display: none; } .hands .short { display: inline; } }
.bars-btn { flex: 0 1 auto; min-width: 0; height: 36px; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 0 10px 0 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; overflow: hidden; }
.bars-btn > svg { width: 14px; height: 14px; flex: none; color: var(--muted); }
#barsLabel { display: flex; align-items: center; gap: 5px; min-width: 0; }
#barsLabel .nm { min-width: 2.2em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#barsLabel .rg { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
#barsLabel svg { width: 14px; height: 14px; flex: none; color: var(--rh); }
@media (max-width: 479px) {
  .practice { gap: 6px; }
  .stepper .step { width: 30px; }
  .stepper .tempo-btn { min-width: 52px; }
  .bars-btn { flex: 1 1 0; padding: 0 10px; }
  .bars-btn > svg { display: none; }
}
.stepper .tempo-btn[aria-expanded="true"], .bars-btn[aria-expanded="true"] { background: var(--rh-soft); color: var(--rh); }

/* A tray rises from the dock: full width on a phone, over its button (placed by app.js) on a wider screen. */
.tray { position: absolute; z-index: 3; bottom: calc(100% + 8px); left: 16px; right: 16px; display: grid; gap: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--lift); }
@media (min-width: 480px) { .tray { right: auto; width: 360px; } }
.range-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.range-row label + select { margin-right: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.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; }
@media (max-height: 500px) and (min-width: 600px) { .kb { height: 52px; } }
.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; }
/* Settings: a sheet from the bottom on a phone, a panel on the right from 480px, so the score stays in view. */
.prefs { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 85vh; max-height: 85dvh; background: var(--surface); color: var(--ink); border-radius: 18px 18px 0 0; box-shadow: var(--lift); overscroll-behavior: contain; }
.prefs::backdrop { background: var(--scrim); }
.prefs[open] { animation: prefs-up .18s ease-out; }
.prefs-body { min-height: 100%; padding: 6px 20px calc(24px + env(safe-area-inset-bottom, 0px)); }
.prefs-body::before { content: ""; display: block; width: 36px; height: 4px; margin: 4px auto 6px; border-radius: 2px; background: var(--line); }
@media (min-width: 480px) {
  .prefs { margin: 0 0 0 auto; width: 380px; height: 100%; max-height: 100%; border-radius: 0; border-left: 1px solid var(--line); }
  .prefs::backdrop { background: var(--scrim-soft); }
  .prefs[open] { animation-name: prefs-in; }
  .prefs-body { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
  .prefs-body::before { display: none; }
}
@keyframes prefs-up { from { transform: translateY(24px); opacity: 0; } }
@keyframes prefs-in { from { transform: translateX(24px); opacity: 0; } }
.prefs-head { display: flex; align-items: center; justify-content: space-between; padding-block: 4px 6px; }
.prefs-head h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 24px; }
.group { padding-top: 14px; }
.group h3 { margin: 0; padding-bottom: 4px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.set { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-block: 11px; border-bottom: 1px solid var(--line); font-size: 14px; }
label.set { cursor: pointer; }
label.set:has(input:disabled) { cursor: default; }
.set > span { display: grid; gap: 1px; min-width: 0; }
.set b { font-weight: 600; }
.set small { font-size: 12px; line-height: 1.4; color: var(--muted); }
.set.col { display: grid; gap: 10px; border-bottom: 0; }
.set .hint { font-size: 12px; line-height: 1.4; }
.pair { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pair output { font-family: var(--display); font-size: 18px; font-variant-numeric: tabular-nums; }
.calib { display: flex; align-items: center; gap: 12px; }
.calib .dot { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--muted); }
.calib .dot.on { background: var(--rh); border-color: var(--rh); }

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