/* Page Turner: a music stand. A slim bar on top; the score fills everything below it; panels slide over the side.
   Warm paper and ink, one brass accent; every colour is a token, redefined for dark mode. */
:root {
  --stand: #e9e6e0;         /* behind the pages */
  --rail: #fbfaf7;          /* the top bar */
  --surface: #ffffff;       /* panels and buttons */
  --well: #f1eee8;          /* quiet fills inside panels */
  --well-dark: #dfdad1;
  --ink: #1d1b18;
  --muted: #6b665e;
  --line: #ddd8cf;
  --line-strong: #c9c2b6;
  --brass: #8a6a1f;
  --brass-strong: #6f5413;
  --brass-wash: #f4ead2;
  --ok: #2f6b45;
  --rec: #b3261e;
  --chart-line: #8f6400; /* checked with the dataviz palette validator against the panel colour */
  --page-shadow: 0 1px 2px rgba(40, 30, 10, .12), 0 12px 32px rgba(40, 30, 10, .14);
  --panel-shadow: 0 2px 6px rgba(40, 30, 10, .08), 0 18px 48px rgba(40, 30, 10, .18);
  --radius: 14px;
  --font-ui: "Atkinson Hyperlegible", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-key: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --stand: #111214; --rail: #1b1c20; --surface: #24252a; --well: #2b2c32; --well-dark: #18191c;
    --ink: #ecebe7; --muted: #a29d94; --line: #34353b; --line-strong: #474850;
    --brass: #d8b45f; --brass-strong: #e7c677; --brass-wash: #3a3021; --ok: #7cc495; --rec: #f2b8b5; --chart-line: #b8892a;
    --page-shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px rgba(0, 0, 0, .5);
    --panel-shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 18px 48px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --stand: #111214; --rail: #1b1c20; --surface: #24252a; --well: #2b2c32; --well-dark: #18191c;
    --ink: #ecebe7; --muted: #a29d94; --line: #34353b; --line-strong: #474850;
    --brass: #d8b45f; --brass-strong: #e7c677; --brass-wash: #3a3021; --ok: #7cc495; --rec: #f2b8b5; --chart-line: #b8892a;
    --page-shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 32px rgba(0, 0, 0, .5);
    --panel-shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 18px 48px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--stand); color: var(--ink); font-family: var(--font-ui); font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; overflow: hidden; }
.app { height: 100%; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 10px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  font-weight: 700; font-size: 15px; cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background .15s, border-color .15s, color .15s, transform .08s;
}
.btn:hover { border-color: var(--line-strong); }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .piece-btn:focus-visible, .lib-tab:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn.icon { width: 40px; padding: 0; }
.btn.flat { background: transparent; border-color: transparent; }
.btn.flat:hover { background: var(--well); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn.small.icon { width: 36px; padding: 0; }
.btn.small .i { width: 18px; height: 18px; }
.btn.primary { background: var(--ink); color: var(--rail); border-color: var(--ink); }
.btn.quiet { color: var(--muted); }
.btn.wide { width: 100%; }
.btn[aria-pressed="true"]:not(.follow) { background: var(--brass-wash); border-color: var(--brass); color: var(--brass-strong); }
.btn[data-armed="1"] { border-color: var(--rec); color: var(--rec); }

/* ---------- The top bar ---------- */
.rail {
  position: relative; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: max(8px, env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 8px max(14px, env(safe-area-inset-left, 0px));
  background: var(--rail); border-bottom: 1px solid var(--line);
}
.ident { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 0; overflow: hidden; }
.piece-btn {
  display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%;
  padding: 4px 12px 4px 8px; min-height: 44px; border-radius: 12px;
  background: transparent; border: 1px solid transparent; cursor: pointer; text-align: left;
}
.piece-btn:hover { background: var(--well); }
.piece-btn .i { width: 22px; height: 22px; color: var(--brass); }
.piece-text { display: grid; min-width: 0; line-height: 1.15; }
.mark { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.tag { color: var(--brass); margin-left: 4px; }
.file { font-family: var(--font-display); font-weight: 600; font-size: 18px; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.counter {
  display: flex; align-items: center; gap: 2px; padding: 2px;
  background: var(--well); border-radius: 12px; flex: none;
}
.counter output { min-width: 76px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.controls { display: flex; align-items: center; gap: 6px; flex: 1 1 0; justify-content: flex-end; }
.btn.tool { padding: 0 12px; }
.btn.follow { background: var(--ink); color: var(--rail); border-color: var(--ink); padding: 0 18px; min-width: 104px; border-radius: 999px; }
.btn.follow[aria-pressed="true"] { background: var(--brass); border-color: var(--brass); color: #1d1b18; }
.btn.follow[aria-pressed="true"] .i { animation: listen 1.4s ease-in-out infinite; }
.btn.follow[data-ready="false"] { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
@keyframes listen { 50% { transform: scale(1.18); } }
.setlist-chip { display: inline-flex; align-items: center; gap: 2px; min-width: 0; font-size: 13px; font-weight: 700; color: var(--brass-strong); background: var(--brass-wash); border-radius: 999px; padding: 3px 3px 3px 12px; white-space: nowrap; }
#setlistText { overflow: hidden; text-overflow: ellipsis; }
.chip-x { flex: none; display: grid; place-items: center; border: 0; background: transparent; color: inherit; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; }
.chip-x .i { width: 14px; height: 14px; }
body.in-setlist .piece-btn .mark { display: none; }

/* iPad in portrait: the tools' names go under their icons, so the piece's name keeps its room */
@media (max-width: 1060px) {
  .btn.tool { flex-direction: column; gap: 1px; min-height: 48px; padding: 3px 8px 2px; min-width: 60px; border-color: transparent; background: transparent; }
  .btn.tool:hover { background: var(--well); }
  .btn.tool .lbl { font-size: 11px; line-height: 1.1; }
  .btn.tool[aria-pressed="true"], .btn.tool[aria-expanded="true"] { background: var(--brass-wash); border-color: var(--brass); color: var(--brass-strong); }
  .controls { gap: 2px; }
  .btn.follow { min-width: 96px; }
}
/* narrow screens: icons only for the tools */
@media (max-width: 620px) {
  .btn.tool .lbl { display: none; }
  .btn.tool { min-width: 42px; padding: 0; }
}
@media (max-width: 620px) {
  .rail { flex-wrap: wrap; }
  .ident { flex-basis: 100%; }
  .controls { flex: 1 1 auto; }
  .btn.follow { min-width: 0; padding: 0 14px; }
}

/* ---------- The music ---------- */
.progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: transparent; z-index: 2; }
.progress i { display: block; height: 100%; width: 0; background: var(--brass); transition: width .2s linear; border-radius: 0 2px 2px 0; }
.progress[data-unsure="true"] i { background: var(--muted); }
.stand {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; outline: none;
}
.sheet { position: relative; display: flex; align-items: center; justify-content: center; }
.sheet.two-up { gap: 14px; }
.page { position: relative; flex: none; touch-action: none; -webkit-touch-callout: none; }
.page > canvas:first-child { display: block; background: #fff; box-shadow: var(--page-shadow); border-radius: 2px; }
.page canvas.marks { position: absolute; inset: 0; pointer-events: none; }
.half-stack { display: flex; flex-direction: column; box-shadow: var(--page-shadow); }
.half-stack .half { overflow: hidden; position: relative; }
.half-stack .half + .half { border-top: 2px dashed var(--brass); }
.half-stack canvas { box-shadow: none !important; }
body.marking .page { cursor: crosshair; }
body.marking .page > canvas:first-child { box-shadow: 0 0 0 3px var(--brass), var(--page-shadow); }

.measure-mark {
  position: absolute; pointer-events: none; z-index: 2;
  background: rgba(216, 168, 60, .2); border: 2px solid rgba(160, 118, 30, .55); border-radius: 6px;
  transition: left .12s ease-out, top .12s ease-out, width .12s ease-out; mix-blend-mode: multiply;
}
.overlay { position: absolute; inset: 0; pointer-events: none; }
.loop-mark { position: absolute; border: 2px dashed var(--brass); border-radius: 5px; background: rgba(216, 168, 60, .08); }
.heat-mark { position: absolute; border-radius: 4px; background: rgb(200 140 20 / var(--heat)); mix-blend-mode: multiply; }
.heat-mark::after { content: attr(data-count); position: absolute; top: 2px; right: 4px; font: 700 12px/1 var(--font-ui); color: #5c4300; }
.heat-mark[data-hesitated]::before { content: ""; position: absolute; top: 4px; left: 4px; width: 8px; height: 8px; border-radius: 50%; background: #b3261e; box-shadow: 0 0 0 2px #fff; }
.flash-mark { position: absolute; border-radius: 5px; outline: 3px solid var(--brass); animation: flash 1.6s ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; color: var(--muted); pointer-events: none; }
.status[data-kind="error"] { color: var(--ink); }
.status span { max-width: 36ch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--panel-shadow); }
.toast {
  position: absolute; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 9;
  max-width: min(560px, calc(100% - 32px)); text-align: center;
  background: var(--ink); color: var(--rail); font-weight: 700; font-size: 15px;
  padding: 10px 18px; border-radius: 999px; pointer-events: none; box-shadow: var(--panel-shadow);
  animation: rise .18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 6px); } }

/* bars floating over the music: what's happening, replay controls, marking tools */
.modebar {
  position: absolute; z-index: 5; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 32px);
  padding: 6px 8px 6px 14px; min-height: 44px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--panel-shadow);
  font-size: 15px; font-weight: 700;
}
.modebar:not(:has(#teachDone:not([hidden]))) { padding-right: 16px; }
#modeText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modebar .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brass); flex: none; animation: pulse 1.4s ease-in-out infinite; }
.modebar[data-mode="teach"] .dot { background: var(--rec); }
@keyframes pulse { 50% { opacity: .35; } }
.floatbar {
  position: absolute; z-index: 6; left: 50%; top: 12px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100% - 24px); padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--panel-shadow);
}
.replaybar { width: min(660px, calc(100% - 32px)); }
.replaybar input[type=range] { flex: 1 1 160px; min-width: 120px; accent-color: var(--brass); }
.rp-time { font-family: var(--font-key); font-size: 13px; color: var(--muted); min-width: 92px; text-align: center; }
.tool-group { display: flex; gap: 6px; align-items: center; }
.unlock {
  position: absolute; z-index: 8; top: 12px; right: 14px;
  display: flex; align-items: center; gap: 6px;
  font: 700 14px var(--font-ui); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; min-height: 42px; box-shadow: var(--panel-shadow);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.unlock.holding { background: var(--brass-wash); border-color: var(--brass); transition: background .9s; }
body.locked .rail .controls, body.locked .rail .counter button, body.locked .piece-btn, body.locked .chip-x { visibility: hidden; }

/* ---------- View menu ---------- */
.view-wrap { position: relative; }
.view-menu {
  position: absolute; z-index: 20; right: 0; top: calc(100% + 8px); width: 320px;
  display: grid; gap: 12px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--panel-shadow);
  animation: drop .14s ease-out;
}
@keyframes drop { from { opacity: 0; transform: translateY(-4px); } }
.menu-title { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.switch span { display: grid; gap: 2px; }
.switch small { color: var(--muted); font-size: 13px; }
.switch input { appearance: none; -webkit-appearance: none; flex: none; margin: 2px 0 0; width: 42px; height: 26px; border-radius: 999px; background: var(--well-dark); position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked { background: var(--brass); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.view-menu .note { margin: -4px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- Panels ---------- */
.panel {
  position: fixed; z-index: 12;
  display: grid; gap: 14px; align-content: start;
  max-height: calc(100% - 96px); overflow: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--panel-shadow);
  padding: 16px 18px 18px;
  animation: slide .18s ease-out;
}
@keyframes slide { from { opacity: 0; transform: translateY(8px); } }
.panel.side {
  right: calc(14px + env(safe-area-inset-right, 0px)); top: 76px;
  width: min(390px, calc(100vw - 28px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.panel-head::before { content: ""; position: absolute; left: 50%; top: 6px; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line); }
.panel h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 22px; line-height: 1.15; overflow-wrap: anywhere; }
.panel h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.eyebrow { margin: 0 0 2px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brass); }
.panel p { margin: 0; }
.note { color: var(--muted); font-size: 14px; }
.group { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lesson-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lesson { font-weight: 700; font-size: 15px; }
.seen { font-size: 13px; color: var(--muted); }
.seen span { font-family: var(--font-key); font-size: 12px; }
.offline-note { font-size: 13px; color: var(--ok); }
.score-opts summary { cursor: pointer; font-weight: 700; font-size: 15px; list-style-position: inside; }
.scrim { position: fixed; inset: 0; z-index: 11; background: rgba(20, 16, 8, .28); animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }

/* sheet music options */
.score-opts { display: grid; gap: 8px; background: var(--well); border-radius: 12px; padding: 10px 12px; }
.score-opts[open] { gap: 8px; }
.score-opts > *:not(summary) { margin-top: 8px; }
.score-opts fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: 6px; }
.score-opts legend, .score-opts .field { font-size: 14px; font-weight: 700; padding: 0; }
.score-opts .parts { display: grid; gap: 4px; max-height: 240px; overflow: auto; font-size: 15px; }
.score-opts .parts label { display: flex; align-items: flex-start; gap: 8px; min-height: 32px; padding-top: 4px; line-height: 1.3; }
.score-opts .parts input, .heat-toggle input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--brass); }
.score-opts input[type=text], .lib-search, .lib-setname {
  font: inherit; font-size: 16px; /* 16px keeps Safari from zooming in */
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; max-width: 100%;
}
.score-opts input[type=text]:focus-visible, .lib-search:focus-visible, .lib-setname:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

/* what the microphone hears: one octave of note names, laid out like piano keys */
.ear-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ear .heard { font-size: 14px; }
.ear .heard .label { color: var(--muted); }
.ear .heard b { font-family: var(--font-key); font-weight: 500; font-size: 14px; }
.keys { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; }
.key-col { display: grid; gap: 4px; justify-items: center; }
.key-col .bar { width: 100%; height: 48px; background: var(--well); border-radius: 5px; overflow: hidden; display: flex; align-items: flex-end; }
.key-col.black .bar { background: var(--well-dark); }
.key-col .bar i { display: block; width: 100%; height: 100%; background: var(--brass); transform-origin: bottom; transform: scaleY(0); transition: transform .08s linear; }
.key-col .name { font-size: 11px; color: var(--muted); font-weight: 700; }
.key-col.on .name { color: var(--brass-strong); }
.level { height: 4px; background: var(--well); border-radius: 2px; overflow: hidden; }
.level i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .1s linear; }

/* ---------- Practice report ---------- */
.report-head h2 { font-size: 20px; }
.report-buttons { display: flex; gap: 6px; align-items: center; }
.report-sum { font-weight: 700; font-size: 15px; }
.report h3 { margin-top: 4px; }
.report-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 15px; }
.report-list li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.report-list li.notes-item { flex-wrap: nowrap; }
.report-list .notes-what { flex: 1; min-width: 0; }
.report-loop { font-family: var(--font-key); font-size: 13px; }
.bar-link { font: inherit; font-weight: 700; color: var(--ink); background: var(--well); border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; min-height: 34px; cursor: pointer; }
.bar-link:disabled { cursor: default; opacity: .6; }
.listen-btn { font: inherit; font-size: 12px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.listen-btn[hidden] { display: none; }
.tempo-chart { position: relative; }
.tempo-chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.tempo-chart .grid { stroke: var(--line); stroke-width: 1; }
.tempo-chart .axis { fill: var(--muted); font: 11px var(--font-ui); }
.tempo-chart .marked { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.tempo-chart .tempo-line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.tempo-chart .tempo-dot { fill: var(--chart-line); stroke: var(--surface); stroke-width: 2; }
.tempo-chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart-tip { position: absolute; top: 0; transform: translate(-50%, -100%); background: var(--ink); color: var(--rail); font-size: 13px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.tempo-chart details { font-size: 14px; margin-top: 4px; }
.tempo-chart table { border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.tempo-chart td, .tempo-chart th { padding: 2px 10px 2px 0; text-align: left; }
.heat-toggle { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--muted); }

/* ---------- Library ---------- */
.panel.library {
  z-index: 13; left: 50%; top: 72px; transform: translateX(-50%);
  width: min(760px, calc(100vw - 28px)); max-height: calc(100% - 96px);
  animation: none;
}
.lib-head { cursor: default; }
.lib-head::before { display: none; }
.lib-buttons { display: flex; gap: 8px; align-items: center; }
.segmented { display: inline-flex; padding: 3px; gap: 3px; background: var(--well); border-radius: 11px; justify-self: start; }
.lib-tab { border: 0; background: transparent; padding: 7px 16px; border-radius: 8px; font-weight: 700; font-size: 14px; color: var(--muted); cursor: pointer; }
.lib-tab[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.lib-body { display: grid; gap: 10px; }
.lib-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lib-setname { flex: 1 1 200px; width: auto; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.lib-piece {
  display: grid; grid-template-columns: 60px 1fr; gap: 6px 12px; padding: 10px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .08s;
}
.lib-piece:hover { border-color: var(--line-strong); box-shadow: 0 4px 14px rgba(40, 30, 10, .08); }
.lib-piece:active { transform: scale(.99); }
.lib-piece:focus-visible { outline: 2px solid var(--brass); }
.lib-thumb { grid-row: span 2; width: 60px; height: 78px; background: #fff; border-radius: 4px; overflow: hidden; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.lib-info { display: grid; gap: 2px; min-width: 0; align-content: start; }
.lib-name { font-weight: 700; overflow-wrap: anywhere; }
.lib-piece .lib-name { font-family: var(--font-display); font-weight: 600; font-size: 17px; line-height: 1.2; }
.lib-meta { font-size: 13px; color: var(--muted); }
.lib-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.lib-piece .lib-actions .btn { min-height: 30px; padding: 0 10px; font-size: 13px; color: var(--muted); background: transparent; }
.lib-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lib-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.lib-order { list-style: decimal inside; }
.lib-delete { justify-self: start; color: var(--rec); }

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

.actions:not(:has(> :not([hidden]):not(input))) { display: none; }

/* ---------- Settings, help, the welcome tour ---------- */
.group.first { border-top: 0; padding-top: 0; }
.range-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); font-weight: 700; }
.range-row input { flex: 1; accent-color: var(--brass); }
.field b { color: var(--brass-strong); }
.segmented button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-weight: 700; font-size: 14px; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
a.btn { text-decoration: none; }
.menu-links { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.menu-links .btn { flex: 1; }
.footer-links { padding-top: 12px; border-top: 1px solid var(--line); }
.help details { border-top: 1px solid var(--line); padding: 10px 0 2px; }
.help summary { cursor: pointer; font-weight: 700; font-size: 16px; padding: 2px 0 6px; }
.help ol, .help ul { margin: 4px 0 8px; padding-left: 20px; display: grid; gap: 6px; font-size: 15px; }
.help p { margin: 4px 0 8px; font-size: 15px; }
.tour { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(20, 16, 8, .45); animation: fade .2s ease-out; }
.tour-card {
  width: min(480px, 100%); display: grid; gap: 16px; justify-items: center; text-align: center;
  background: var(--surface); border-radius: 24px; padding: 32px 28px 20px; box-shadow: var(--panel-shadow);
}
.tour-step { display: grid; gap: 12px; justify-items: center; animation: slide .2s ease-out; }
.tour-step h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 26px; line-height: 1.15; }
.tour-step p { margin: 0; font-size: 16px; line-height: 1.5; max-width: 38ch; }
.tour-icon { display: grid; place-items: center; width: 76px; height: 76px; border-radius: 50%; background: var(--brass-wash); color: var(--brass-strong); }
.tour-icon .i { width: 36px; height: 36px; stroke-width: 1.6; }
.tour-dots { display: flex; gap: 8px; }
.tour-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); transition: width .2s, background .2s; }
.tour-dots i.on { width: 22px; border-radius: 4px; background: var(--brass); }
.tour-nav { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.tour-move { display: flex; gap: 8px; margin-left: auto; }

/* ---------- Go to, metronome, journal ---------- */
.counter { position: relative; }
#pageNum { cursor: pointer; border-radius: 8px; padding: 6px 4px; }
#pageNum:hover { background: var(--surface); }
#pageNum:focus-visible { outline: 2px solid var(--brass); }
.goto-menu {
  position: absolute; z-index: 20; left: 50%; top: calc(100% + 8px); transform: translateX(-50%); width: 280px;
  display: grid; gap: 10px; padding: 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--panel-shadow);
}
.goto-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; margin: 0; font-weight: 700; font-size: 15px; }
.goto-row input, .ladder-opts input { font: inherit; font-size: 16px; color: var(--ink); background: var(--well); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; min-width: 0; }
.bookmarks { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 200px; overflow: auto; }
.bookmarks li { display: flex; align-items: center; gap: 6px; }
.bookmarks .bm-go { flex: 1; justify-content: flex-start; }
.bookmarks .note { padding: 2px 0; }

.mini-check { display: flex; gap: 6px; align-items: center; font-size: 14px; font-weight: 700; }
.mini-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brass); }
.ladder-opts { display: flex; gap: 6px; align-items: center; font-size: 14px; font-weight: 700; }
.ladder-opts input { width: 56px; }
.tempo-chart .day-bar { fill: var(--chart-line); }
.journal-sessions li { font-size: 14px; }
.sheet.dark-pages .page { filter: invert(.92) hue-rotate(180deg); }


.note-mark { position: absolute; border-radius: 4px; box-shadow: inset 0 0 0 2px rgba(179, 38, 30, .65); }
.note-mark::after { content: attr(data-count); position: absolute; bottom: 2px; right: 4px; font: 700 12px/1 var(--font-ui); color: #fff; background: #b3261e; border-radius: 999px; padding: 2px 6px; }

/* ---------- Test 16: the Practice menu ---------- */
.btn.tool { position: relative; }
.tool-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--brass); box-shadow: 0 0 0 2px var(--rail); }
.practice-menu { width: 348px; gap: 10px; }
.menu-list { display: grid; gap: 2px; margin: 0 -8px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  padding: 9px 10px; border: 0; border-radius: 11px; background: transparent; color: var(--ink); font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-item:hover { background: var(--well); }
.menu-item:active { background: var(--well-dark); }
.menu-item:disabled { opacity: .4; cursor: default; background: transparent; }
.menu-item .i { color: var(--brass); width: 22px; height: 22px; }
.menu-item span { display: grid; gap: 1px; min-width: 0; }
.menu-item b { font-size: 15px; }
.menu-item small { color: var(--muted); font-size: 13px; }
.menu-item[aria-pressed="true"] { background: var(--brass-wash); }
.menu-item[aria-pressed="true"] b { color: var(--brass-strong); }
.menu-item:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; }
.hands-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hands-label { font-weight: 700; font-size: 15px; }
.segmented button:disabled { opacity: .45; cursor: default; }
.view-menu > .menu-title:not(:first-child) { padding-top: 10px; border-top: 1px solid var(--line); }

/* floating bars that were dragged somewhere keep their place */
.floatbar[style*="left"] { transform: none; }

/* ---------- The Mark toolbar ---------- */
.markbar { flex-direction: column; align-items: stretch; gap: 8px; width: min(760px, calc(100% - 24px)); padding: 8px; }
.mark-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.mark-row.options { justify-content: flex-start; padding-top: 8px; border-top: 1px solid var(--line); min-height: 44px; }
.tool-btn { flex-direction: column; gap: 2px; min-height: 50px; min-width: 62px; padding: 4px 8px; font-size: 12px; }
.tool-btn .i { width: 20px; height: 20px; }
.tool-btn .tl { font-size: 12px; font-weight: 700; }
.swatch { position: relative; display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border-radius: 50%; border: 2px solid transparent; background: transparent; cursor: pointer; }
.swatch i { display: block; width: 24px; height: 24px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.swatch[aria-pressed="true"], .swatch.wheel[data-on="true"] { border-color: var(--ink); }
.swatch.wheel i { background: conic-gradient(#e53935, #fdd835, #43a047, #1e88e5, #8e24aa, #e53935); }
.swatch.wheel i[style*="background:"]:not([style="background: ;"]) { box-shadow: inset 0 0 0 3px #fff, 0 0 0 1px rgba(0, 0, 0, .2); }
.swatch.wheel input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.digits .btn { width: 36px; padding: 0; }
.stamps { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; gap: 4px; padding-bottom: 2px; scrollbar-width: thin; }
.stamp-btn { flex: none; display: grid; place-items: center; width: 46px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; }
.stamp-btn canvas { width: 36px; height: 24px; }
.stamp-btn[aria-pressed="true"] { border-color: var(--brass); background: var(--brass-wash); }
.size-wrap { flex: 1 1 160px; min-width: 140px; gap: 10px; }
.size-wrap input { flex: 1; accent-color: var(--brass); }
.size-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 1px rgba(0, 0, 0, .1); }
.mark-row.options .tool-group + .tool-group:not([hidden]) { padding-left: 8px; border-left: 1px solid var(--line); }
.mark-hint { margin: 0; }
.note-input {
  position: absolute; z-index: 7; width: 260px; display: grid; gap: 8px; padding: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--panel-shadow);
}
.note-input textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--well); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; resize: vertical; min-height: 56px; }
.note-input .actions { justify-content: flex-end; }
@media (max-width: 700px) { .tool-btn .tl { display: none; } .tool-btn { min-width: 44px; min-height: 44px; } }

/* ---------- The metronome ---------- */
.metrobar {
  top: auto; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  flex-direction: column; align-items: stretch; gap: 10px; width: min(440px, calc(100% - 24px)); padding: 12px 14px 14px;
}
.metro-top { display: flex; align-items: center; justify-content: space-between; cursor: grab; touch-action: none; min-height: 32px; }
.beats { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.beats i { width: 14px; height: 14px; border-radius: 50%; background: var(--well-dark); transition: background .05s, transform .05s; }
.beats i[data-level="0"] { width: 18px; height: 18px; }
.beats i[data-level="1"] { width: 16px; height: 16px; }
.beats i.on { background: var(--brass); transform: scale(1.15); }
.beats i[data-level="0"].on { background: var(--rec); }
.metro-main { display: flex; align-items: center; gap: 10px; }
.metro-main .btn.icon { font-size: 22px; font-weight: 700; width: 44px; min-height: 44px; border-radius: 50%; }
.metro-bpm { flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.metro-unit { font-size: 20px; color: var(--muted); }
#metroTempo {
  width: 3.2ch; font: 600 40px/1 var(--font-display); text-align: center; color: var(--ink); font-variant-numeric: tabular-nums;
  background: transparent; border: 0; border-bottom: 2px dashed var(--line-strong); border-radius: 0; padding: 2px 0;
}
#metroTempo:focus { outline: none; border-bottom-color: var(--brass); background: var(--brass-wash); }
.metro-go { min-width: 92px; border-radius: 999px; }
.metro-go[aria-pressed="true"] { background: var(--brass); border-color: var(--brass); color: #1d1b18; }
.metro-slider { width: 100%; accent-color: var(--brass); }
.metro-name { text-align: center; font-family: var(--font-display); font-size: 15px; color: var(--muted); margin-top: -6px; }
.metro-opts { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; padding-top: 10px; border-top: 1px solid var(--line); }
.metro-field { display: grid; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.meter { display: flex; align-items: center; gap: 4px; color: var(--ink); font-size: 16px; }
.meter select, .metrobar select { font: inherit; font-size: 16px; font-weight: 700; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 6px 8px; text-transform: none; }
.metro-field .segmented button { padding: 6px 12px; text-transform: none; letter-spacing: 0; }
.metro-ladder { display: grid; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.ladder-opts { flex-wrap: wrap; }

/* ---------- Hear the music ---------- */
.hearbar { top: auto; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); width: min(600px, calc(100% - 32px)); }
.hear-what { font-weight: 700; font-size: 14px; }
.hear-speed { display: flex; align-items: center; gap: 8px; flex: 1 1 200px; font-size: 14px; font-weight: 700; color: var(--muted); }
.hear-speed input { flex: 1; accent-color: var(--brass); }
.hear-speed output { min-width: 42px; font-variant-numeric: tabular-nums; color: var(--ink); }

/* ---------- Trouble spots ---------- */
.trouble-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.trouble-list li { display: flex; align-items: stretch; gap: 10px; }
.trouble-rank { flex: none; display: grid; place-items: center; width: 30px; border-radius: 9px; background: var(--brass-wash); color: var(--brass-strong); font-weight: 700; }
.trouble-go { flex: 1; display: grid; gap: 2px; text-align: left; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.trouble-go:hover { border-color: var(--brass); }
.trouble-go b { font-size: 16px; }
.trouble-go span { font-size: 13px; color: var(--muted); }
.skip-btn { flex: none; font: inherit; font-size: 12px; font-weight: 700; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; min-height: 30px; cursor: pointer; }
.skip-btn:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- Edit pages ---------- */
.pages-panel { width: min(900px, calc(100vw - 28px)); }
.pe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pe-page { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.pe-page[data-removed="1"] { opacity: .5; background: var(--well); border-style: dashed; }
.pe-thumb { aspect-ratio: 3 / 4; display: grid; place-items: center; overflow: hidden; background: #fff; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.pe-thumb img { max-width: 100%; max-height: 100%; transition: transform .2s; }
.pe-label { display: grid; font-size: 14px; }
.pe-from { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pe-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.pe-btns .btn { min-width: 32px; padding: 0 8px; min-height: 32px; }
.pe-actions { justify-content: flex-end; position: sticky; bottom: -18px; background: var(--surface); padding: 10px 0 2px; }

/* ---------- Pinch to zoom ---------- */
.sheet { transform-origin: center center; will-change: transform; }
.sheet.zoomed { z-index: 0; }
.stand { overflow: hidden; }
.zoom-chip {
  position: absolute; z-index: 5; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--panel-shadow); font-weight: 700; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.zoom-chip .btn { border-radius: 999px; }

/* ---------- Kept takes ---------- */
.takes-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.takes-list li { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.take-info { display: grid; gap: 2px; }
.take-info span { font-size: 13px; color: var(--muted); }
.rp-title { font-weight: 700; font-size: 14px; max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* the App Store app (see native/) and the website each have a few instructions of their own */
.native .web-only, :root:not(.native) .app-only { display: none !important; }

/* ---------- 0.5.3: the history tabs, the stamps that scroll sideways, the microphone check in Help ---------- */
.history-tabs { justify-self: stretch; display: flex; }
.history-tabs button { flex: 1; }
.history-tab { display: grid; gap: 10px; }
.menu-split { padding-top: 8px; border-top: 1px solid var(--line); margin-top: 2px; }
.mark-row.options .stamps {
  flex: 1 1 100%; min-width: 0; max-width: 100%; overflow-x: auto; overflow-y: hidden; touch-action: pan-x;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; scroll-snap-type: x proximity; padding: 2px 2px 6px;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.mark-row.options .stamps:not([hidden]) { border-left: 0; padding-left: 2px; }
.stamp-btn { scroll-snap-align: start; width: 54px; }
.stamp-btn canvas { width: 46px; height: 24px; }
.help .ear { display: grid; gap: 8px; margin: 6px 0 8px; }
.help .ear-head { display: flex; align-items: center; justify-content: space-between; }
.markbar { flex-wrap: nowrap; } /* one column: each row is as wide as the toolbar, so the stamps scroll inside it */
.markbar .mark-row { min-width: 0; }
.stamp-btn { width: 66px; height: 42px; }
.stamp-btn canvas { width: 60px; height: 31px; }

/* ---------- 1.0 polish: Beta label, licenses ---------- */
.notes-head { display: flex; align-items: center; gap: 8px; }
.beta { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--brass-strong); background: var(--brass-wash); border: 1px solid var(--brass); border-radius: 999px; padding: 1px 8px; }
.licenses summary { cursor: pointer; font-weight: 700; font-size: 15px; }
.licenses ul { margin: 8px 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; }
.licenses a { color: var(--brass-strong); overflow-wrap: anywhere; }

.lib-piece { grid-template-columns: 1fr; }
.lib-open { display: grid; grid-template-columns: 60px 1fr; gap: 6px 12px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 10px; }
.lib-open:focus-visible { outline: 2px solid var(--brass); outline-offset: 3px; }
.lib-open .lib-thumb { grid-row: auto; }
.lib-piece .lib-actions { padding-left: 72px; }

/* Read the music for me: the permission card, and the reading's progress (Piece panel and library) */
.tour[hidden] { display: none; }
.read-ask { text-align: left; justify-items: stretch; }
.read-ask h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 24px; line-height: 1.15; }
.read-ask p { margin: 0; font-size: 16px; line-height: 1.5; }
.read-ask .note { font-size: 14px; }
.read-ask .actions { justify-content: flex-end; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--brass); }
.reading { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; background: var(--brass-wash); }
.reading p { flex: 1 1 160px; font-size: 14px; font-weight: 700; color: var(--brass-strong); }
.reading-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brass); animation: listen 1.4s ease-in-out infinite; }
.reading.failed { background: var(--surface-2, rgba(198, 40, 40, .08)); }
.reading.failed p { color: var(--ink); font-weight: 400; }
.reading.failed .reading-dot { display: none; }
.lib-reading { display: block; font-size: 13px; font-weight: 700; color: var(--brass-strong); }
.lib-reading.failed { color: var(--muted); font-weight: 400; }
