:root {
  --bg: #f6f1e9; --surface: #fffaf3; --surface-2: #efe6d8; --line: #ddd0bd; --text: #231d16; --muted: #6f6253;
  --accent: #d8612a; --accent-ink: #fff; --green: #3f7d5a; --cell: #e6dccd; --cell-on: #2b241c;
  --perfect: #2f9e6a; --good: #2b7fc4; --okay: #c48a12; --off: #c9473b;
  --radius: 12px; --shadow: 0 1px 2px rgba(40, 28, 14, .06), 0 4px 14px rgba(40, 28, 14, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f; --surface: #201b16; --surface-2: #2a241d; --line: #3a3229; --text: #f2e9dc; --muted: #a8998a;
    --accent: #e8743b; --accent-ink: #1a120b; --green: #6bb48b; --cell: #2f2821; --cell-on: #f2e9dc;
    --perfect: #46c288; --good: #5aa9ec; --okay: #e5b23c; --off: #ef6a5c; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16130f; --surface: #201b16; --surface-2: #2a241d; --line: #3a3229; --text: #f2e9dc; --muted: #a8998a;
  --accent: #e8743b; --accent-ink: #1a120b; --green: #6bb48b; --cell: #2f2821; --cell-on: #f2e9dc;
  --perfect: #46c288; --good: #5aa9ec; --okay: #e5b23c; --off: #ef6a5c; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
button, select, input { font: inherit; color: inherit; }
kbd { font: 600 .72em ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; margin-left: .35em; background: var(--surface); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.brand em { font-style: normal; color: var(--accent); font-weight: 600; }
.mark { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 50% 38%, var(--bg) 0 32%, transparent 33%), var(--accent); }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.tab { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
#midi-btn { margin-left: auto; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.foot { max-width: 1200px; margin: 0 auto; padding: 8px 16px 32px; }

/* ---- generic ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; cursor: pointer; font-weight: 600; min-height: 40px; touch-action: manipulation; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: .85rem; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.15rem; padding: 12px 26px; min-height: 56px; }
.btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.field.inline { flex-direction: row; align-items: center; gap: 6px; margin: 0; }
.field select, .field input[type="text"] { color: var(--text); font-weight: 500; font-size: 1rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 40px; }
.field.inline select { width: auto; }
.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; margin: 6px 0; cursor: pointer; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
.inline-out { display: flex; align-items: center; gap: 8px; color: var(--text); }
.inline-out output { min-width: 5.5em; font-variant-numeric: tabular-nums; font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }

/* ---- learn ---- */
#learn:not([hidden]) { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 24px; align-items: start; }
#lesson-nav { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; padding-right: 4px; }
.nav-group { border-bottom: 1px solid var(--line); padding: 6px 0; }
.nav-group summary { cursor: pointer; font-weight: 700; padding: 6px 4px; list-style-position: outside; }
.nav-blurb { margin: 0 4px 6px; font-size: .8rem; color: var(--muted); }
.nav-list { list-style: none; margin: 0; padding: 0 0 6px; }
.nav-item { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.current { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.nav-sub { color: var(--muted); font-size: .78rem; white-space: nowrap; }
#lesson-view { min-width: 0; max-width: 820px; }
.lesson-head h2 { margin: 0 0 4px; font-size: 1.8rem; line-height: 1.2; }
.eyebrow { margin: 0; color: var(--accent); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.lede { color: var(--muted); margin-top: 0; font-size: 1.05rem; }
.prose { max-width: 68ch; }
.task { border-left: 3px solid var(--green); padding: 8px 12px; background: var(--surface); border-radius: 0 8px 8px 0; margin: 12px 0; }
.next-row { margin: 28px 0; }

.drum-card { margin: 18px 0; }
.drum-card h3 { margin: 0 0 2px; font-size: 1.05rem; }
.caption { margin: 0 0 10px; color: var(--muted); font-size: .9rem; }
.grid-wrap { position: relative; margin: 10px 0 12px; overflow-x: auto; }
.grid { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.grid-row { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 8px; }
.grid-row .lbl { font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap; display: flex; align-items: center; justify-content: space-between; }
.grid-row.target .lbl { color: var(--accent); }
.cells { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 3px; }
.cell { aspect-ratio: 1 / 1; max-height: 34px; border-radius: 5px; background: var(--cell); position: relative; }
.cell.beat { box-shadow: inset 2px 0 0 var(--line); }
.cell.on { background: color-mix(in srgb, var(--cell-on) calc(var(--vel, 1) * 100%), var(--cell)); }
.grid-row.target .cell.on { background: color-mix(in srgb, var(--accent) calc(40% + var(--vel, 1) * 60%), var(--cell)); }
.cell[data-grade]::after { content: ""; position: absolute; inset: -2px; border-radius: 6px; border: 3px solid var(--g); }
.cell[data-grade="perfect"] { --g: var(--perfect); } .cell[data-grade="good"] { --g: var(--good); }
.cell[data-grade="okay"] { --g: var(--okay); } .cell[data-grade="off"], .cell[data-grade="missed"] { --g: var(--off); }
.cell[data-grade="missed"]::after { border-style: dashed; }
.counts .count { text-align: center; font-size: .65rem; color: var(--muted); }
.counts .count.beat { color: var(--text); font-weight: 700; }
.playhead { position: absolute; top: -3px; bottom: 14px; left: calc(92px + (100% - 92px) * var(--x, 0)); width: 3px; margin-left: -1px; border-radius: 2px; background: var(--accent); pointer-events: none; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.tempo { display: flex; align-items: center; gap: 6px; }
.tempo-val { min-width: 5.2em; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.status { display: flex; align-items: baseline; gap: 16px; min-height: 2.2em; margin-top: 10px; flex-wrap: wrap; }
.phase { font-weight: 800; font-size: 1.25rem; }
.phase[data-phase="yours"] { color: var(--accent); }
.feedback { font-variant-numeric: tabular-nums; font-weight: 700; }
.feedback[data-grade="perfect"] { color: var(--perfect); } .feedback[data-grade="good"] { color: var(--good); }
.feedback[data-grade="okay"] { color: var(--okay); } .feedback[data-grade="off"] { color: var(--off); }
.pads { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 12px; }
.pad { min-height: 96px; border-radius: 16px; border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); font-weight: 800; font-size: 1.1rem; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.pad.down { background: var(--accent); color: var(--accent-ink); transform: scale(.98); }
.results { margin-top: 14px; padding: 14px; border-radius: 10px; background: var(--surface-2); }
.score { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.score .big { font-size: 2.2rem; font-weight: 800; }
.tally { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin: 10px 0; text-align: center; font-size: .75rem; text-transform: uppercase; color: var(--muted); }
.tally b { display: block; font-size: 1.3rem; color: var(--text); }
.tally [data-grade="perfect"] b { color: var(--perfect); } .tally [data-grade="good"] b { color: var(--good); }
.tally [data-grade="okay"] b { color: var(--okay); } .tally [data-grade="off"] b, .tally [data-grade="missed"] b { color: var(--off); }
.card-foot { display: flex; justify-content: space-between; align-items: start; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.nudge summary { cursor: pointer; font-size: .85rem; color: var(--muted); }
.nudge { max-width: 360px; }
.quiz { margin: 18px 0; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.quiz-q { font-weight: 700; margin: 0 0 8px; }
.quiz-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-opt.right { background: var(--perfect); border-color: var(--perfect); color: #fff; }
.quiz-opt.wrong { background: var(--off); border-color: var(--off); color: #fff; }
.quiz-fb { margin: 8px 0 0; color: var(--muted); }

/* ---- jam ---- */
.jam-stage { margin-bottom: 16px; }
.stage-top { display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center; }
.now-section { font-weight: 700; font-size: 1.05rem; }
.now-chord { font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 800; line-height: 1.1; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stage-side { display: flex; flex-direction: column; align-items: end; gap: 10px; }
.beats { display: flex; gap: 6px; }
.beats i { width: 14px; height: 14px; border-radius: 50%; background: var(--cell); transition: background .05s; }
.beats i.on { background: var(--text); }
.beats i:first-child.on { background: var(--accent); }
.beats[data-fill] i:last-child { box-shadow: 0 0 0 2px var(--accent); }
.meter { width: 120px; height: 8px; border-radius: 4px; background: var(--cell); overflow: hidden; }
.meter span { display: block; height: 100%; width: calc(var(--e, 0) * 100%); background: linear-gradient(90deg, var(--green), var(--accent)); transition: width .4s; }
.form-strip { display: flex; gap: 3px; margin: 16px 0 12px; }
.chip { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .72rem; font-weight: 700; text-align: center; padding: 6px 2px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.chip.role-chorus, .chip.role-solo { background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); }
.chip.role-pre { background: color-mix(in srgb, var(--accent) 11%, var(--surface-2)); }
.chip.role-bridge, .chip.role-break { background: color-mix(in srgb, var(--green) 20%, var(--surface-2)); }
.chip.role-ending { flex: 0 0 auto; padding: 6px 10px; }
.chip.now { background: var(--text); color: var(--bg); }
.stage-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.jam-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.jam-controls h3 { margin: 0 0 12px; font-size: 1rem; }
.strip { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 10px; margin-bottom: 10px; font-size: .9rem; font-weight: 600; }
.mute[aria-pressed="true"] { background: var(--off); border-color: var(--off); color: #fff; }

@media (max-width: 900px) {
  .jam-grid { grid-template-columns: 1fr; }
  #learn:not([hidden]) { grid-template-columns: 1fr; gap: 12px; }
  #lesson-nav { position: static; max-height: 40vh; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 8px; background: var(--surface); }
}
@media (max-width: 560px) {
  .top { gap: 10px; padding: 8px 16px; flex-wrap: wrap; }
  .brand { font-size: .95rem; }
  #midi-btn { display: none; }
  .tabs { margin-left: auto; }
  .tab { padding: 6px 10px; }
  main { padding: 12px 16px; }
  .stage-top { grid-template-columns: 1fr auto; }
  .stage-top #jam-play { grid-column: 1 / -1; width: 100%; }
  .grid-row { grid-template-columns: 58px 1fr; gap: 4px; }
  .grid-row .lbl kbd { display: none; }
  .playhead { left: calc(62px + (100% - 62px) * var(--x, 0)); }
  .cells { gap: 2px; }
  .two { grid-template-columns: 1fr; gap: 0; }
  .tally { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lesson-head h2 { font-size: 1.45rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
