/* Piano Practice Coach — a fine printed edition, on an iPad.
   Paper and ink; one oxblood accent; gold hairlines; Cormorant Garamond for display, EB Garamond for reading and UI.
   Dark mode is a candlelit room: umber walls, parchment text, and the score kept on a dimmed paper sheet. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --paper: #f3ecdf;
  --paper-raised: #f8f3ea;
  --paper-sunk: #ebe2d1;
  --sheet: #fbf7ef;
  --ink: #1e1915;
  --ink-2: #4b4036;
  --ink-3: #6b5d4f;
  --accent: #7b1e24;          /* oxblood: text and marks */
  --accent-fill: #7b1e24;     /* oxblood: filled buttons */
  --accent-press: #5e1519;
  --on-accent: #fbf4e8;
  --accent-wash: rgb(123 30 36 / 0.07);
  --gold: #a88a52;            /* hairlines only, never text */
  --gold-soft: rgb(168 138 82 / 0.42);
  --hair: rgb(75 64 54 / 0.18);
  --focus: #7b1e24;
  --selection: rgb(123 30 36 / 0.16);
  --shadow-sheet: 0 1px 1px rgb(70 48 22 / 0.06), 0 12px 32px -18px rgb(70 48 22 / 0.35);
  --shadow-panel: 0 -1px 0 var(--gold-soft), 0 -18px 40px -28px rgb(70 48 22 / 0.45);

  /* Marks on the score (always drawn on the light sheet, so these stay the same in dark mode) */
  --score-ink: #1e1915;
  --mark-wrong: #8f1d24;
  --mark-check: #b8780f;
  --mark-dyn: #855d1c;
  --mark-pedal: #3f566a;
  --mark-slur: #6a4470;
  --mark-lh: #2f6a5d;
  --mark-ok: #5d8a4c;
  --range-wash: rgb(168 138 82 / 0.13);
  --pc-outline: 26;           /* notehead outline for "missed", in score SVG units (Verovio units are ~10x px) */

  --font-display: "Cormorant Garamond", "Cormorant", "EB Garamond", Garamond, "Times New Roman", serif;
  --font-text: "EB Garamond", Garamond, "Iowan Old Style", "Palatino", "Times New Roman", serif;

  --gutter: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  --drawer-w: min(420px, 38vw);
  --sheet-h: 56dvh;
  --peek: 76px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --radius: 3px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #15110d;
    --paper-raised: #1e1812;
    --paper-sunk: #0f0c09;
    --sheet: #d9ccb2;
    --ink: #eee2ca;
    --ink-2: #cdbd9f;
    --ink-3: #a39278;
    --accent: #df8a7b;
    --accent-fill: #8e2a2b;
    --accent-press: #a3393a;
    --on-accent: #f8ead4;
    --accent-wash: rgb(223 138 123 / 0.09);
    --gold: #b1924f;
    --gold-soft: rgb(177 146 79 / 0.38);
    --hair: rgb(238 226 202 / 0.13);
    --focus: #e3a089;
    --selection: rgb(223 138 123 / 0.24);
    --shadow-sheet: 0 0 0 1px rgb(0 0 0 / 0.35), 0 18px 48px -18px rgb(0 0 0 / 0.75);
    --shadow-panel: 0 -1px 0 var(--gold-soft), 0 -20px 44px -24px rgb(0 0 0 / 0.8);
    --range-wash: rgb(133 93 28 / 0.16);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #15110d;
  --paper-raised: #1e1812;
  --paper-sunk: #0f0c09;
  --sheet: #d9ccb2;
  --ink: #eee2ca;
  --ink-2: #cdbd9f;
  --ink-3: #a39278;
  --accent: #df8a7b;
  --accent-fill: #8e2a2b;
  --accent-press: #a3393a;
  --on-accent: #f8ead4;
  --accent-wash: rgb(223 138 123 / 0.09);
  --gold: #b1924f;
  --gold-soft: rgb(177 146 79 / 0.38);
  --hair: rgb(238 226 202 / 0.13);
  --focus: #e3a089;
  --selection: rgb(223 138 123 / 0.24);
  --shadow-sheet: 0 0 0 1px rgb(0 0 0 / 0.35), 0 18px 48px -18px rgb(0 0 0 / 0.75);
  --shadow-panel: 0 -1px 0 var(--gold-soft), 0 -20px 44px -24px rgb(0 0 0 / 0.8);
  --range-wash: rgb(133 93 28 / 0.16);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 1.125rem;
  line-height: 1.5;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a, label, input, [role="button"] { touch-action: manipulation; }
::selection { background: var(--selection); color: inherit; }
input { caret-color: var(--accent); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
* { scrollbar-width: thin; scrollbar-color: var(--gold-soft) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--gold-soft); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
.icon { width: 22px; height: 22px; flex: none; }
.quiet { color: var(--ink-3); font-size: 1rem; }
.smallcaps {
  font-variant-caps: all-small-caps; letter-spacing: 0.07em;
}

/* Engraved rules: a thin gold hairline, a double rule, and a rule with a centered ornament */
.rule { height: 0; border-top: 1px solid var(--gold-soft); }
.rule-double { height: 4px; border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold-soft); }
.rule-orn { display: flex; align-items: center; gap: 10px; color: var(--gold); }
.rule-orn span { flex: 1; border-top: 1px solid var(--gold-soft); }
.rule-orn svg { width: 40px; height: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--hair); border-radius: var(--radius);
  background: transparent; color: var(--ink);
  font-size: 1.0625rem; font-weight: 500; letter-spacing: 0.01em;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), color 160ms var(--ease-out), transform 120ms var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: default; transform: none; }
.btn-primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
.btn-primary:active { background: var(--accent-press); border-color: var(--accent-press); }
.btn-secondary { border-color: var(--gold); background: var(--paper-raised); }
.btn-secondary:active { background: var(--paper-sunk); }
.btn-quiet { border-color: transparent; padding: 0 10px; color: var(--ink-2); }
.btn-quiet:active { background: var(--accent-wash); }
.btn-large { min-height: 52px; padding: 0 28px; font-size: 1.1875rem; }
.btn-icon {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); cursor: pointer;
}
.btn-icon:active { background: var(--accent-wash); }
@media (hover: hover) {
  .btn-secondary:hover { background: var(--paper-sunk); }
  .btn-quiet:hover, .btn-icon:hover { color: var(--accent); }
  .btn-primary:hover { background: var(--accent-press); border-color: var(--accent-press); }
}

/* ---------- 1. Home ---------- */
.view-home {
  max-width: 1120px; margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) var(--gutter-r) max(24px, env(safe-area-inset-bottom)) var(--gutter);
}
.masthead { padding-inline: 8px; }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.app-title {
  font-family: var(--font-display); font-weight: 600; font-size: clamp(2.25rem, 4.6vw, 3.25rem);
  line-height: 1.05; letter-spacing: -0.01em;
}
.tagline { font-style: italic; color: var(--ink-2); font-size: 1.25rem; margin: 6px 0 18px; }
.theme-toggle { gap: 6px; font-size: 1rem; }
.theme-toggle .icon { width: 20px; height: 20px; }

.home-grid {
  display: grid; gap: 40px; margin-top: 36px; align-items: start;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1000px) {
  .home-grid { grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr); gap: 56px; }
}

/* Frontispiece: the featured piece set like a title page inside a double gold frame */
.frontispiece { background: var(--paper-raised); border: 1px solid var(--gold); padding: 7px; box-shadow: var(--shadow-sheet); }
.frontispiece-frame {
  border: 1px solid var(--gold-soft);
  padding: clamp(32px, 5vw, 56px) clamp(20px, 4vw, 48px) clamp(28px, 4vw, 40px);
  text-align: center; display: flex; flex-direction: column; align-items: center;
}
.fp-composer { font-variant-caps: all-small-caps; letter-spacing: 0.16em; font-size: 1.25rem; color: var(--ink-2); }
.fp-title {
  font-family: var(--font-display); font-weight: 600; font-size: clamp(2.125rem, 4.4vw, 3rem);
  line-height: 1.08; margin-top: 18px; text-wrap: balance;
}
.fp-no { white-space: nowrap; }
.fp-key { display: block; font-size: clamp(1.25rem, 2.6vw, 1.75rem); font-weight: 500; color: var(--ink-2); margin-top: 2px; }
.fp-nick {
  font-family: var(--font-display); font-style: italic; font-weight: 500; color: var(--accent);
  font-size: clamp(2rem, 4.2vw, 2.75rem); line-height: 1.1; margin-top: 4px;
}
.fp-opus { font-variant-caps: all-small-caps; letter-spacing: 0.12em; font-size: 1.1875rem; color: var(--ink-2); margin-top: 10px; }
.frontispiece .rule-orn { width: min(320px, 80%); margin: 26px 0 18px; }
.fp-mvt { font-style: italic; font-size: 1.375rem; }
.frontispiece .btn-large { margin-top: 30px; }
.fp-note { margin-top: 14px; font-size: 0.9375rem; color: var(--ink-3); max-width: 34ch; }

.home-side { display: flex; flex-direction: column; gap: 36px; padding-top: 4px; }
.section-h {
  font-family: var(--font-display); font-weight: 600; font-size: 1.75rem; line-height: 1.15;
  padding-bottom: 8px; margin-bottom: 14px; border-bottom: 1px solid var(--gold-soft);
}
.home-section > .quiet { margin-top: 10px; }

.search { position: relative; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search-input {
  width: 100%; min-height: 52px; padding: 0 16px 0 46px;
  font-size: 1.125rem; /* never below 16px, so iOS does not zoom */
  background: var(--paper-raised); color: var(--ink);
  border: 1px solid var(--gold-soft); border-radius: var(--radius);
  -webkit-appearance: none; appearance: none;
  transition: border-color 160ms var(--ease-out);
}
.search-input::placeholder { color: var(--ink-3); opacity: 1; font-style: italic; }
.search-input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-status { margin-top: 10px; min-height: 0; }
.search-status:empty { display: none; }

/* Index-style list rows: composer in small caps, title, movement in italic */
.index-list { margin-top: 6px; }
.index-list li + li { border-top: 1px solid var(--hair); }
.index-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
  width: 100%; min-height: 60px; padding: 10px 6px; text-align: left;
  background: transparent; border: 0; cursor: pointer; border-radius: var(--radius);
}
.index-row:active { background: var(--accent-wash); }
@media (hover: hover) { .index-row:hover .ir-title { color: var(--accent); } }
.ir-composer { display: block; font-variant-caps: all-small-caps; letter-spacing: 0.1em; color: var(--ink-3); font-size: 1rem; line-height: 1.2; }
.ir-title { display: block; font-size: 1.125rem; line-height: 1.3; transition: color 160ms var(--ease-out); }
.ir-sub { display: block; font-style: italic; color: var(--ink-2); font-size: 1rem; line-height: 1.3; }
.ir-meta { color: var(--ink-3); font-size: 0.9375rem; white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }

.upload-btn { cursor: pointer; }
.inline-error { margin-top: 10px; color: var(--accent); font-size: 1rem; }

.colophon { margin-top: 56px; text-align: center; color: var(--ink-3); font-size: 0.9375rem; font-style: italic; }
.colophon .rule { width: 120px; margin: 0 auto 14px; }

/* ---------- 2. Practice view ---------- */
.view-practice {
  position: fixed; inset: 0; height: 100dvh;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--paper);
}
body:not([data-screen="home"]) .view-home { display: none; }
body[data-screen="home"] .view-practice { display: none !important; }

.toolbar {
  padding: max(10px, env(safe-area-inset-top)) var(--gutter-r) 0 var(--gutter);
  background: var(--paper);
  border-bottom: 1px solid var(--gold);
  box-shadow: 0 3px 0 -2px var(--gold-soft); /* second engraved hairline under the bar */
  position: relative; z-index: 3;
}
.tb-row { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; }
.tb-top { min-height: 64px; }
.back-btn { margin-left: -8px; gap: 2px; padding-right: 12px; }
.piece-heading { flex: 1 1 200px; min-width: 0; }
.piece-title {
  font-family: var(--font-display); font-weight: 600; font-size: 1.625rem; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.piece-sub { color: var(--ink-2); font-style: italic; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.transport { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.rec-readout { display: flex; align-items: center; gap: 10px; opacity: 0.35; transition: opacity 200ms var(--ease-out); }
body[data-screen="recording"] .rec-readout { opacity: 1; }
.meter {
  width: 76px; height: 8px; border: 1px solid var(--gold); border-radius: 1px; overflow: hidden; background: var(--paper-sunk);
}
.meter-fill {
  display: block; height: 100%; width: 100%; background: var(--accent-fill);
  transform-origin: left center; transform: scaleX(0); transition: transform 70ms linear;
}
.rec-timer { min-width: 3.4ch; font-variant-numeric: lining-nums tabular-nums; font-size: 1.125rem; color: var(--ink-2); }
.btn-record {
  min-height: 56px; padding: 0 24px 0 18px; gap: 10px; font-size: 1.1875rem;
  background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent);
}
.btn-record:active { background: var(--accent-press); }
.rec-dot { width: 16px; height: 16px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgb(255 255 255 / 0.18); }
body[data-screen="recording"] .btn-record,
body[data-screen="recording"] .btn-record:disabled { opacity: 1; background: var(--accent-wash); color: var(--accent); border-color: var(--accent); }
body[data-screen="recording"] .rec-dot { background: var(--accent); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.35; } }
.btn-stop { min-height: 56px; padding: 0 20px 0 16px; gap: 10px; font-size: 1.1875rem; border-color: var(--ink-3); }
body[data-screen="recording"] .btn-stop { border-color: var(--ink); background: var(--paper-raised); }
.stop-square { width: 14px; height: 14px; background: currentColor; border-radius: 1px; }
.show-review { display: none !important; }

.tb-range, .tb-analyzing { min-height: 60px; padding: 6px 0 10px; }
body[data-screen="analyzing"] .tb-range { display: none; }
body:not([data-screen="analyzing"]) .tb-analyzing { display: none; }
body[data-screen="recording"] .tb-range, body[data-screen="loading"] .tb-range { opacity: 0.5; pointer-events: none; }

.stepper { display: flex; align-items: center; gap: 0; }
.stepper-label { font-variant-caps: all-small-caps; letter-spacing: 0.08em; color: var(--ink-2); margin-right: 10px; font-size: 1.0625rem; }
.step-btn {
  width: 44px; height: 44px; border: 1px solid var(--gold-soft); background: var(--paper-raised);
  font-size: 1.375rem; line-height: 1; color: var(--ink-2); cursor: pointer;
}
.step-btn:first-of-type { border-radius: var(--radius) 0 0 var(--radius); }
.step-btn:last-of-type { border-radius: 0 var(--radius) var(--radius) 0; }
.step-btn:active { background: var(--paper-sunk); }
.step-input {
  width: 64px; height: 44px; text-align: center; font-size: 1.1875rem; /* >= 16px */
  font-variant-numeric: lining-nums tabular-nums;
  border: 1px solid var(--gold-soft); border-left: 0; border-right: 0; border-radius: 0;
  background: var(--paper); color: var(--ink); -webkit-appearance: none; appearance: none;
}
.step-input:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 0; }
.range-hint { flex: 1 1 220px; color: var(--ink-3); font-style: italic; font-size: 1rem; }
.range-hint.is-armed { color: var(--accent); }

.tb-analyzing { gap: 18px; flex-wrap: nowrap; }
.analyzing-text { min-width: 0; flex: none; }
.analyzing-title { font-family: var(--font-display); font-weight: 600; font-size: 1.375rem; line-height: 1.1; }
.analyzing-title .pct { font-family: var(--font-text); font-weight: 400; font-size: 1.0625rem; color: var(--ink-2); font-variant-numeric: lining-nums tabular-nums; }
.analyzing-step { color: var(--ink-3); font-style: italic; font-size: 1rem; }
.progress-rule { position: relative; flex: 1; height: 5px; border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold-soft); }
.progress-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: var(--accent-fill);
  transform-origin: left center; transform: scaleX(0); transition: transform 240ms var(--ease-out);
}

/* Notices: an erratum slip pinned under the toolbar */
.notice {
  margin: 12px var(--gutter-r) 0 var(--gutter); padding: 16px 18px;
  background: var(--paper-raised); border: 1px solid var(--accent); outline: 1px solid var(--gold-soft); outline-offset: 3px;
  display: grid; gap: 6px; max-width: 760px; position: relative; z-index: 2;
}
.notice-title { font-family: var(--font-display); font-weight: 600; font-size: 1.375rem; color: var(--accent); line-height: 1.2; }
.notice-body { color: var(--ink); font-size: 1.0625rem; max-width: 68ch; }
.notice-body ol { margin: 6px 0 0; padding-left: 1.4em; }
.notice-body li + li { margin-top: 2px; }
.notice-detail { color: var(--ink-3); font-size: 0.9375rem; font-style: italic; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.practice-body { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; }
.score-scroll {
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 20px var(--gutter-r) max(28px, env(safe-area-inset-bottom)) var(--gutter);
  scroll-padding: 24px;
}
.score-sheet {
  position: relative; max-width: 1180px; margin: 0 auto; min-height: 60%;
  background: var(--sheet); color: var(--score-ink);
  box-shadow: var(--shadow-sheet);
  padding: clamp(14px, 2.4vw, 32px) clamp(8px, 2vw, 28px);
}
.pc-score { min-height: 200px; touch-action: manipulation; }
.pc-score svg { display: block; width: 100%; height: auto; color: var(--score-ink); }
.score-status {
  display: grid; place-items: center; text-align: center; min-height: 50dvh; padding: 24px;
  font-family: var(--font-display); font-style: italic; font-size: 1.5rem; color: #6b5d4f;
}
.score-status .rule-orn { width: 160px; margin: 0 auto 14px; color: #a88a52; }

/* ---------- Score marks (classes added by score.js highlight) ---------- */
/* Selected bar range: score.js highlightBars draws rect.score-bar-selected; the stub uses .pc-range */
.pc-score .score-bar-selected { fill: var(--range-wash); fill-opacity: 1; }
.pc-score .pc-range > .hit, .pc-score .pc-range > rect:first-child { fill: var(--range-wash); }
/* Lowest priority first, so note errors win where classes overlap */
.pc-score .pc-ok, .pc-score .pc-ok * { fill: var(--mark-ok); stroke: var(--mark-ok); color: var(--mark-ok); }
.pc-score .pc-lh, .pc-score .pc-lh * { fill: var(--mark-lh); stroke: var(--mark-lh); color: var(--mark-lh); }
.pc-score .pc-slur, .pc-score .pc-slur * { fill: var(--mark-slur); stroke: var(--mark-slur); color: var(--mark-slur); }
.pc-score .pc-pedal, .pc-score .pc-pedal * { fill: var(--mark-pedal); stroke: var(--mark-pedal); color: var(--mark-pedal); }
.pc-score .pc-dyn, .pc-score .pc-dyn * { fill: var(--mark-dyn); stroke: var(--mark-dyn); color: var(--mark-dyn); }
.pc-score .pc-check, .pc-score .pc-check * { fill: var(--mark-check); stroke: var(--mark-check); color: var(--mark-check); }
.pc-score .pc-wrong, .pc-score .pc-wrong * { fill: var(--mark-wrong); stroke: var(--mark-wrong); color: var(--mark-wrong); }
.pc-score .pc-missed, .pc-score .pc-missed *, .pc-score .pc-missed .stem, .pc-score .pc-missed .stem * { fill: var(--mark-wrong); stroke: var(--mark-wrong); color: var(--mark-wrong); }
.pc-score .pc-missed .notehead, .pc-score .pc-missed .notehead *, .pc-score .pc-missed > use {
  fill: var(--sheet); stroke: var(--mark-wrong); stroke-width: var(--pc-outline);
}
/* The issue the player tapped: a heavier outline and a soft halo */
.pc-score .pc-focus .notehead, .pc-score .pc-focus .notehead *, .pc-score .pc-focus > use {
  stroke-width: calc(var(--pc-outline) * 1.5);
}
.pc-score .pc-focus { filter: drop-shadow(0 0 2.5px rgb(143 29 36 / 0.55)); }

/* ---------- 3. Review panel ---------- */
.review {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--paper-raised); color: var(--ink);
  z-index: 4;
}
body:not([data-screen="review"]) .review { display: none; }

.review-head {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 12px 10px 10px 22px; border-bottom: 1px solid var(--gold-soft); position: relative;
}
.sheet-grip { display: none; }
.review-h { font-family: var(--font-display); font-weight: 600; font-size: 1.75rem; line-height: 1.1; }
.review-bars { color: var(--ink-2); font-style: italic; font-size: 1rem; }
.review-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 18px 22px max(28px, env(safe-area-inset-bottom)); }

.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold-soft); }
.sum-item { padding: 12px 6px 10px; text-align: center; }
.sum-item + .sum-item { border-left: 1px solid var(--hair); }
.sum-item dt { font-variant-caps: all-small-caps; letter-spacing: 0.08em; color: var(--ink-2); font-size: 0.9375rem; line-height: 1.2; }
.sum-item dd {
  font-family: var(--font-display); font-weight: 600; font-size: 2.125rem; line-height: 1.1; margin-top: 2px;
  font-variant-numeric: lining-nums tabular-nums; display: flex; align-items: baseline; justify-content: center; gap: 2px;
}
.sum-item dd small { font-size: 0.55em; font-weight: 500; color: var(--ink-2); }
.sum-item dd .crotchet { width: 11px; height: 20px; align-self: center; margin-right: 3px; }
.sum-item dd .none { font-family: var(--font-text); font-weight: 400; font-style: italic; font-size: 1rem; color: var(--ink-3); }
.honest { margin-top: 12px; font-style: italic; color: var(--ink-3); font-size: 0.9375rem; line-height: 1.45; }

.take { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; margin-top: 18px; }
.take-play { border: 1px solid var(--gold); background: var(--paper); color: var(--accent); }
.take-play .icon-pause { display: none; }
.take.is-playing .icon-pause { display: block; }
.take.is-playing .icon-play { display: none; }
.take-track { display: grid; gap: 0; min-width: 0; }
.take-label { font-variant-caps: all-small-caps; letter-spacing: 0.08em; color: var(--ink-2); font-size: 0.9375rem; line-height: 1.1; }
.take-time { font-variant-numeric: lining-nums tabular-nums; color: var(--ink-2); font-size: 0.9375rem; white-space: nowrap; }
.take-seek { -webkit-appearance: none; appearance: none; width: 100%; height: 44px; background: transparent; margin: 0; }
.take-seek::-webkit-slider-runnable-track { height: 3px; background: linear-gradient(var(--accent-fill), var(--accent-fill)) 0 / var(--p, 0%) 100% no-repeat, var(--gold-soft); border-radius: 2px; }
.take-seek::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7.5px; border-radius: 50%; background: var(--paper); border: 1px solid var(--accent); }
.take-seek::-moz-range-track { height: 3px; background: var(--gold-soft); }
.take-seek::-moz-range-progress { height: 3px; background: var(--accent-fill); }
.take-seek::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--paper); border: 1px solid var(--accent); }

.review-actions { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 1rem; color: var(--ink-2); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 42px; height: 24px; border-radius: 12px; border: 1px solid var(--gold); background: var(--paper); position: relative; transition: background-color 180ms var(--ease-out); }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink-3); transition: transform 200ms var(--ease-out), background-color 180ms var(--ease-out); }
.switch input:checked + .switch-track { background: color-mix(in srgb, var(--mark-ok) 22%, var(--paper)); border-color: var(--mark-ok); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: var(--mark-ok); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--gold-soft); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--hair); border-radius: 22px; background: transparent; color: var(--ink-3);
  font-size: 1rem; cursor: pointer; transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), color 160ms var(--ease-out);
}
.chip .n { font-variant-numeric: lining-nums tabular-nums; font-size: 0.9375rem; }
.chip[aria-pressed="true"] { border-color: var(--gold); background: var(--paper); color: var(--ink); }
.chip[aria-pressed="true"] .n { color: var(--accent); }
.chip:active { transform: translateY(1px); }

.issue-groups { margin-top: 8px; }
.group { margin-top: 22px; }
.group-h { display: flex; align-items: baseline; gap: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--gold-soft); }
.group-h h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.375rem; line-height: 1.2; margin: 0; }
.group-h .it { font-style: italic; color: var(--ink-3); font-size: 1rem; }
.group-h .count { margin-left: auto; color: var(--ink-3); font-size: 0.9375rem; font-variant-numeric: lining-nums tabular-nums; }
.group-empty { padding: 10px 0 0; color: var(--ink-3); font-style: italic; font-size: 1rem; }
.issue-list li + li { border-top: 1px solid var(--hair); }
.issue {
  display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 2px 12px; align-items: start;
  width: 100%; padding: 12px 8px 12px 4px; text-align: left; background: transparent; border: 0; cursor: pointer;
  border-radius: var(--radius); transition: background-color 160ms var(--ease-out);
}
.issue:active { background: var(--accent-wash); }
.issue[aria-current="true"] { background: var(--accent-wash); }
.issue[aria-current="true"] .issue-title { color: var(--accent); }
.issue .glyph { width: 28px; height: 28px; grid-row: span 2; margin-top: 1px; color: var(--ink-2); }
.issue-top { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.issue-bar { font-variant-caps: all-small-caps; letter-spacing: 0.08em; color: var(--ink-3); font-size: 0.9375rem; white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }
.issue-title { font-weight: 600; font-size: 1.0625rem; line-height: 1.3; transition: color 160ms var(--ease-out); }
.issue-detail { grid-column: 2; color: var(--ink-2); font-size: 1rem; line-height: 1.45; }
.k-wrong .glyph, .k-missed .glyph, .k-extra .glyph { color: var(--accent); }
.k-check .glyph { color: var(--mark-check); }
.k-dynamics .glyph { color: color-mix(in srgb, var(--mark-dyn) 80%, var(--ink)); }
.k-pedal .glyph { color: color-mix(in srgb, var(--mark-pedal) 80%, var(--ink)); }
.k-slur .glyph, .k-detached .glyph { color: color-mix(in srgb, var(--mark-slur) 80%, var(--ink)); }
.k-uneven-lh-timing .glyph, .k-uneven-lh-volume .glyph { color: color-mix(in srgb, var(--mark-lh) 80%, var(--ink)); }
:root[data-theme="dark"] .issue .glyph { filter: brightness(1.7) saturate(0.8); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .issue .glyph { filter: brightness(1.7) saturate(0.8); } }
.k-wrong .glyph, .k-missed .glyph, .k-extra .glyph { filter: none !important; }
/* "Practice these first": the top few issues, above everything else */
.top-issues { margin: 0 0 18px; padding: 12px 14px 4px; border: 1px solid var(--gold); border-radius: var(--radius); background: var(--paper); }
.top-h { font-family: var(--font-display); font-weight: 600; font-size: 1.375rem; line-height: 1.2; margin: 0 0 2px; }
.top-list .issue { padding-left: 0; }
.sum-extra { margin-top: 10px; color: var(--ink-2); font-size: 0.9375rem; line-height: 1.45; }
.sum-extra span { display: block; }
/* Quiet "Use an audio file instead" link in the range row */
.file-link { flex: none; display: inline-flex; align-items: center; min-height: 44px; margin-left: auto; padding: 0 4px; color: var(--ink-3); font-size: 0.875rem; font-style: italic; text-decoration: underline; text-decoration-color: var(--hair); text-underline-offset: 3px; cursor: pointer; }
.file-link:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
body:not([data-screen="ready"]):not([data-screen="review"]) .file-link { visibility: hidden; }
/* Portrait iPad: let the hint wrap beside the link instead of pushing the link onto its own line */
@media (max-width: 1000px) { .tb-range .range-hint { flex: 1 1 0; min-width: 150px; } }
.bravo { margin-top: 24px; text-align: center; }
.bravo p:first-child { font-family: var(--font-display); font-style: italic; font-size: 2rem; color: var(--accent); }
.bravo p + p { color: var(--ink-2); }

/* ---------- Review placement: side drawer (landscape) / bottom sheet (portrait) ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  body[data-screen="review"]:not([data-sheet="collapsed"]) .practice-body { grid-template-columns: minmax(0, 1fr) var(--drawer-w); }
  .review { border-left: 1px solid var(--gold); box-shadow: -3px 0 0 -2px var(--gold-soft); }
  body[data-screen="review"]:not([data-sheet="collapsed"]) .review { animation: drawer-in 340ms var(--ease-out); }
  body[data-sheet="collapsed"] .review { display: none; }
  body[data-screen="review"][data-sheet="collapsed"] .show-review { display: inline-flex !important; }
  .review .icon-chev { display: none; }
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }

@media not ((min-aspect-ratio: 1/1) and (min-width: 700px)) {
  .review {
    position: absolute; left: 0; right: 0; bottom: 0; height: var(--sheet-h);
    border-top: 1px solid var(--gold); box-shadow: var(--shadow-panel);
    border-radius: 10px 10px 0 0;
    transform: translateY(0); transition: transform 360ms var(--ease-out);
  }
  body[data-screen="review"] .review { animation: sheet-in 380ms var(--ease-out); }
  body[data-sheet="collapsed"] .review { transform: translateY(calc(100% - var(--peek) - env(safe-area-inset-bottom))); }
  .review-head { padding-top: 18px; cursor: default; }
  .sheet-grip {
    display: grid; align-content: start; padding-top: 8px; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 120px; height: 44px; border: 0; background: transparent; cursor: pointer; padding: 0;
  }
  .grip-bar { display: block; width: 40px; height: 4px; margin: 0 auto; border-radius: 2px; background: var(--gold-soft); }
  .review .icon-close { display: none; }
  .review .icon-chev { transition: transform 260ms var(--ease-out); }
  body[data-sheet="collapsed"] .review .icon-chev { transform: rotate(180deg); }
  body[data-screen="review"]:not([data-sheet="collapsed"]) .score-scroll { padding-bottom: calc(var(--sheet-h) + 24px); scroll-padding-bottom: calc(var(--sheet-h) + 16px); }
  body[data-screen="review"][data-sheet="collapsed"] .score-scroll { padding-bottom: calc(var(--peek) + 24px); scroll-padding-bottom: calc(var(--peek) + 16px); }
}
@keyframes sheet-in { from { transform: translateY(100%); } }

/* ---------- Narrow (phone) ---------- */
@media (max-width: 600px) {
  .tb-top { gap: 8px; }
  .piece-heading { flex-basis: calc(100% - 120px); order: 0; }
  .transport { width: 100%; justify-content: flex-end; order: 2; }
  .rec-readout { margin-right: auto; }
  .stepper-label { margin-right: 6px; }
  .step-input { width: 52px; }
  .summary .sum-item dd { font-size: 1.75rem; }
  :root { --sheet-h: 62dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  body[data-screen="recording"] .rec-dot { animation: none; }
}

/* No empty paper sheet when the score failed to load */
.score-sheet:has(> #score:empty):has(> .score-status[hidden]) { display: none; }
