:root {
  --bg: #f7f4ee;
  --surface: #fffdf9;
  --ink: #1f2433;
  --muted: #6b6f7d;
  --line: #e4ded3;
  --brand: #2f3b69;
  --brand-ink: #ffffff;
  --accent: #f2b33d;
  --good: #2e8a57;
  --good-bg: #e3f3e9;
  --bad: #c2412d;
  --bad-bg: #fbe6e1;
  --warn: #b7791f;
  --warn-bg: #fdf1d8;
  --key-white: #ffffff;
  --key-black: #22252f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 36, 51, .06), 0 4px 14px rgba(31, 36, 51, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d;
    --surface: #1d2029;
    --ink: #eceef4;
    --muted: #9aa0b0;
    --line: #2d313d;
    --brand: #8ea2ff;
    --brand-ink: #10131c;
    --accent: #f2b33d;
    --good: #5fcf8f;
    --good-bg: #183327;
    --bad: #ff8a74;
    --bad-bg: #3a1f1a;
    --warn: #f0b85a;
    --warn-bg: #3a2e14;
    --key-white: #f4f2ee;
    --key-black: #0b0c10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: .4rem 0 .6rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .3rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error, .warn-text { color: var(--bad); }
.good-text { color: var(--good); }
code { background: var(--line); padding: 0 .3em; border-radius: 4px; font-size: .9em; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.6rem + env(safe-area-inset-top)) 16px .6rem;
  background: var(--brand); color: var(--brand-ink);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.topbar .btn.ghost { color: var(--brand-ink); border-color: transparent; background: rgba(255, 255, 255, .12); }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.tabbar:empty { display: none; }
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; font-size: .75rem; color: var(--muted); text-decoration: none; border-radius: 10px;
}
.tabbar a span { font-size: 1.3rem; line-height: 1; }
.tabbar a[aria-current] { color: var(--brand); font-weight: 600; background: var(--bg); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; box-shadow: var(--shadow);
}
.card.empty { text-align: center; color: var(--muted); }
.section-title { margin-top: 1.4rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .8rem 0; }
.actions.sticky { position: sticky; bottom: calc(70px + env(safe-area-inset-bottom)); background: var(--surface); padding: .5rem 0; }
.row { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: flex-end; }
.row.center { justify-content: center; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 200px; }
.back { text-decoration: none; color: var(--muted); }
.loading { color: var(--muted); padding: 2rem 0; text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3em;
  min-height: 44px; padding: .55rem 1.1rem;
  border: 1px solid var(--brand); border-radius: 999px;
  background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ghost.on { background: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 36px; padding: .3rem .85rem; font-size: .9rem; }
.btn.big { min-height: 54px; padding: .7rem 1.6rem; font-size: 1.1rem; }
.btn.icon { min-width: 44px; padding: .3rem .6rem; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: .35rem .9rem; font: inherit; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.badge { display: inline-block; font-size: .8rem; padding: 0 .5em; border-radius: 999px; background: var(--line); color: var(--ink); }

/* welcome */
.welcome { text-align: center; padding: 2rem 0; }
.welcome-keys { max-width: 320px; margin: 0 auto 1rem; }

/* lesson */
.lesson-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.lesson-head h2 a { color: inherit; text-decoration: none; }
.date { color: var(--muted); font-size: .85rem; margin: 0; }
.progress-ring {
  flex: none; min-width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  border: 4px solid var(--accent); color: var(--ink);
}
.teacher-notes { font-style: italic; color: var(--muted); }
.objectives { list-style: none; padding: 0; margin: .6rem 0 0; }
.objective { border-top: 1px solid var(--line); padding: .8rem 0; }
.objective:first-child { border-top: 0; }
.obj-main { display: flex; gap: .6rem; }
.obj-main .kind { font-size: 1.3rem; line-height: 1.4; }
.obj-text p { margin: 0; }
.obj-meta { color: var(--muted); font-size: .85rem; }
.objective.goal-met .obj-text p:first-child::after { content: " ✓"; color: var(--good); font-weight: 700; }
.obj-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .5rem; padding-left: 2rem; }
.marks { display: inline-flex; gap: 4px; flex-wrap: wrap; margin-right: auto; }
.mark {
  width: 22px; height: 22px; border-radius: 50%; border: 2px dashed var(--line);
  display: inline-grid; place-items: center; font-size: 13px; color: #7a5200;
}
.mark.on { border: 2px solid var(--accent); background: var(--accent); }
.mark-btns { display: inline-flex; gap: .3rem; }
.lesson-list, .log { list-style: none; padding: 0; margin: 0; }
.lesson-list a { display: flex; gap: .8rem; align-items: center; padding: .7rem .2rem; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.lesson-list .title, .log .title { flex: 1; }
.log li { display: flex; flex-wrap: wrap; gap: .2rem .8rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.log .date { min-width: 6.5rem; }
.photos { display: flex; gap: .5rem; overflow-x: auto; }
.photos img { max-height: 320px; border-radius: 10px; border: 1px solid var(--line); }

/* sections, scale grid, tallies */
.group-head { display: flex; align-items: flex-end; justify-content: space-between; gap: .5rem; border-bottom: 1px solid var(--line); margin: 1.1rem 0 .4rem; padding-bottom: .3rem; }
.group-head .group-name { border: 0; margin: 0; padding: 0; }
.group-name { margin: 1.1rem 0 .3rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: .2rem; }
.scale-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.scale-chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px;
  min-width: 0; min-height: 54px; padding: 6px 2px; line-height: 1.2;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit; cursor: pointer;
}
.scale-chip b { font-size: 1.05rem; display: block; width: 100%; text-align: center; white-space: nowrap; }
.scale-chip.wide { grid-column: span 2; }
.scale-chip.done { background: var(--warn-bg); border-color: var(--accent); }
.scale-chip[aria-expanded=true] { outline: 3px solid var(--brand); outline-offset: 1px; }
.scale-actions { grid-column: 1 / -1; margin: .2rem 0 .4rem; padding: .6rem .8rem; border: 1px solid var(--brand); border-radius: 12px; background: var(--bg); }
.tally { display: inline-flex; gap: 5px; font-weight: 700; color: var(--ink); letter-spacing: 1px; font-family: ui-monospace, monospace; }
.tally.empty { color: var(--line); }
.tally-group { position: relative; }
.tally-group.five::after { content: ""; position: absolute; left: -2px; right: -2px; top: 50%; border-top: 2px solid currentColor; transform: rotate(-20deg); }

/* forms */
.form label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; color: var(--muted); margin: .4rem 0; }
.form label.check { flex-direction: row; align-items: center; gap: .4rem; color: var(--ink); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; min-height: 44px; width: 100%;
}
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; }
input[type=range] { padding: 0; }
.row label { flex: 1 1 140px; }
fieldset.obj-edit { border: 1px solid var(--line); border-radius: 12px; margin: .8rem 0; padding: .6rem .9rem; }
fieldset.obj-edit legend { font-weight: 600; padding: 0 .3rem; }
details summary { cursor: pointer; color: var(--brand); margin: .3rem 0; }

/* practice */
.practice-title { font-size: 1.3rem; }
.strip {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 2px 10px; scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.note-chip {
  flex: none; min-width: 46px; padding: 6px 4px; border-radius: 10px; text-align: center;
  background: var(--surface); border: 2px solid var(--line); scroll-snap-align: center;
  transition: background .15s, border-color .15s;
}
.note-chip b { display: block; font-size: 1.15rem; }
.note-chip small { display: block; color: var(--muted); font-weight: 600; }
.note-chip small i { font-style: normal; color: var(--brand); margin-left: .4em; }
.note-chip.cross { border-style: dashed; border-color: var(--warn); }
.note-chip.current { border-color: var(--brand); border-style: solid; transform: translateY(-3px); box-shadow: 0 4px 0 var(--brand); }
.note-chip.ok { background: var(--good-bg); border-color: var(--good); border-style: solid; }
.note-chip.hes { background: var(--warn-bg); border-color: var(--warn); border-style: solid; }
.note-chip.err { background: var(--bad-bg); border-color: var(--bad); border-style: solid; }
.legend { margin-top: 0; }
#kb { margin: .4rem 0 .8rem; }
.keyboard { width: 100%; height: auto; display: block; max-height: 180px; }
.kb-white { fill: var(--key-white); stroke: #9a958c; stroke-width: 1; }
.kb-black { fill: var(--key-black); stroke: #000; }
.kb-white.on, .kb-white.hl { fill: #fff3d6; }
.kb-white.next { fill: #dfe6ff; }
.kb-white.cross { fill: #fde3c2; }
.kb-black.on, .kb-black.hl { fill: #6a5321; }
.kb-black.next { fill: #3d4fa3; }
.kb-black.cross { fill: #8a4b12; }
.kb-dot { fill: var(--accent); stroke: #7a5200; stroke-width: 1; }
.kb-dot.next { fill: #3d4fa3; stroke: #1c275c; }
.kb-dot.cross { fill: #e07b18; }
.kb-finger { font: 700 12px system-ui, sans-serif; text-anchor: middle; fill: #1f2433; }
.kb-dot.next + .kb-finger { fill: #fff; }
.kb-finger.on-black { fill: #fff; }
.kb-name { font: 600 10px system-ui, sans-serif; text-anchor: middle; fill: #6b6f7d; }
.kb-name.small { font-size: 9px; fill: var(--muted); }
.listen-panel { text-align: center; margin: 1rem 0 .5rem; }
.btn.listen { width: 100%; max-width: 360px; }
.btn.listen.on { background: var(--bad); border-color: var(--bad); }
.meter { height: 6px; max-width: 360px; margin: .6rem auto 0; background: var(--line); border-radius: 3px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--good); transition: width .06s linear; }
.hearing { min-height: 1.5em; font-weight: 600; }
.metro-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem; margin: .5rem 0 1rem; }
.tempo { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.bpm { min-width: 4.5em; text-align: center; }
.bpm b { font-size: 1.3rem; }
.beat { width: 16px; height: 16px; border-radius: 50%; background: var(--line); }
.beat.pulse { animation: pulse .18s ease-out; }
.beat.pulse.accent { background: var(--accent); }
@keyframes pulse { from { background: var(--brand); transform: scale(1.4); } to { transform: scale(1); } }
.result.clean { border-color: var(--good); background: var(--good-bg); }
.stats { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.stats b { font-size: 1.4rem; }
.feedback { padding-left: 1.1rem; margin: .5rem 0; }
.feedback li { margin: .25rem 0; }
.feedback li.good::marker { content: "✓  "; color: var(--good); }
.feedback li.fix::marker { content: "→  "; color: var(--bad); }
.feedback li.tip::marker { content: "•  "; color: var(--muted); }
.note-box textarea { margin: .4rem 0; }
.dots { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.dot.clean { background: var(--good); }
.dot.ok { background: var(--accent); }
.dot.bad { background: var(--bad); }
.dot.free { background: var(--brand); opacity: .6; }
.dots .muted { margin-left: .5rem; }
.spots { padding-left: 1.1rem; }

/* progress */
.bar { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; max-width: 340px; }
.day { aspect-ratio: 1; display: grid; place-items: center; border-radius: 8px; background: var(--bg); color: var(--muted); font-size: .8rem; border: 1px solid var(--line); }
.day.on { background: var(--accent); color: #3d2a00; font-weight: 700; border-color: var(--accent); }
.day.today { outline: 2px solid var(--brand); }

/* cheat sheets */
.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.sheet-link { display: block; padding: .7rem; border: 1px solid var(--line); border-radius: 10px; text-align: center; text-decoration: none; color: var(--ink); background: var(--bg); font-weight: 600; }
.fingers-line { display: flex; flex-wrap: wrap; gap: 6px; }
.fingers-line span { text-align: center; min-width: 34px; padding: 3px; border-radius: 8px; background: var(--bg); }
.fingers-line b { display: block; }
.fingers-line small { color: var(--brand); font-weight: 700; }
.tips { padding-left: 1.1rem; }
.hands { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; }
.hand { margin: 0; text-align: center; width: 150px; }
.hand svg { width: 100%; }
.palm { fill: var(--bg); stroke: var(--muted); stroke-width: 2; }
.finger { stroke: var(--muted); stroke-width: 16; stroke-linecap: round; opacity: .35; }
.tip { fill: var(--accent); }
.tip-num { font: 700 15px system-ui, sans-serif; text-anchor: middle; fill: #3d2a00; }

/* metronome */
.metronome { text-align: center; }
.big-bpm { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.big-bpm output { font-size: 3.4rem; font-weight: 800; min-width: 3ch; font-variant-numeric: tabular-nums; }
.beat-dots { display: flex; justify-content: center; gap: 10px; margin: 1rem 0; }
.beat-dots span { width: 22px; height: 22px; border-radius: 50%; background: var(--line); transition: background .05s; }
.beat-dots span.on { background: var(--brand); }
.beat-dots span:first-child.on { background: var(--accent); }
.big-note { font-size: 3rem; font-weight: 800; text-align: center; margin: .5rem 0; }

.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* NYSSMA mode */
.exam-step { font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .05em; font-size: .85rem; margin: 0; }
.exam-list { font-size: 1.35rem; font-weight: 700; padding-left: 1.6rem; }
.exam-list li { margin: .5rem 0; }
.exam-results { padding-left: 1.1rem; }
.exam-results > li { margin: .6rem 0; }
.peek { margin: .5rem 0; }

/* install */
.banner { display: flex; gap: .8rem; justify-content: space-between; align-items: flex-start; background: var(--warn-bg); border: 1px solid var(--accent); border-radius: 12px; padding: .7rem .9rem; margin: .8rem 0; text-align: left; }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; font-size: 1.1rem; cursor: pointer; padding: 0 .2rem; min-height: 0; }
.install-steps ol { padding-left: 1.3em; margin: 0 0 12px; }
.install-steps li { margin: 8px 0; }
.step-shot { display: block; width: 100%; max-width: 320px; height: auto; margin: .5rem 0; border-radius: 12px; border: 1px solid var(--line); }
.account { display: flex; gap: .4rem; align-items: center; }

/* scale run */
.run-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; margin: .5rem 0; }
.run-chip { text-align: center; padding: 4px 2px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); font-weight: 700; font-size: .9rem; white-space: nowrap; }
.run-chip.wide { grid-column: span 2; }
.run-chip.current { border: 2px solid var(--brand); }
.run-chip.clean { background: var(--good-bg); border-color: var(--good); }
.run-chip.ok { background: var(--warn-bg); border-color: var(--warn); }
.run-chip.bad { background: var(--bad-bg); border-color: var(--bad); }
.run-chip.skipped { opacity: .45; }
.run-now h2 { font-size: 1.5rem; margin: .2rem 0; }
