:root {
  --bg: #12141a;
  --card: #1c1f28;
  --line: #2c3040;
  --text: #e8eaf0;
  --muted: #8a90a3;
  --accent: #4f8cff;
  --good: #3ecf8e;
  --ok: #e8c65a;
  --bad: #ef6a6a;
  --key-white: #f2f3f5;
  --key-white-stroke: #999;
  --key-black: #23262f;
  --staff: #6d7386;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, select {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
}
button:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--accent); }
button:disabled, select:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary.running { background: var(--bad); border-color: var(--bad); }
.hidden { display: none !important; }

/* ---------- header bar ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.brand { background: none; border: none; font-weight: 500; letter-spacing: 0.04em; padding: 0.3rem 0.2rem; white-space: nowrap; }
.brand b { color: var(--ok); }
.drill-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.knobs { display: flex; gap: 0.4rem; flex-wrap: nowrap; min-width: 0; flex: 0 1 auto; overflow: hidden; }
.knobs > * { min-width: 0; flex: 0 1 auto; }
.knobs select { max-width: 15rem; }
.actions { margin-left: auto; display: flex; gap: 0.4rem; flex: none; }
.icon-btn { padding: 0.35rem 0.55rem; }
.drills-btn { white-space: nowrap; flex: none; }
body[data-state="menu"] .drills-btn,
body[data-state="menu"] .knobs,
body[data-state="menu"] .drill-title,
body[data-state="menu"] #startBtn,
body[data-state="menu"] #lessonBtn { display: none; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- the drill menu ---------- */
.menu {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 0.7rem;
  align-content: start;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}
.drill-card {
  display: flex;
  gap: 0.8rem;
  text-align: left;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  align-items: flex-start;
}
.dc-icon { font-size: 1.6rem; line-height: 1; }
.dc-body { display: flex; flex-direction: column; gap: 0.25rem; }
.dc-title { font-weight: 600; }
.dc-blurb { color: var(--muted); font-size: 0.86rem; line-height: 1.3; }
.dc-prog { color: var(--good); font-size: 0.78rem; }
body:not([data-state="menu"]) .menu { display: none; }
body[data-state="menu"] .stage { display: none; }

/* ---------- the stage ---------- */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 0.4rem 0.9rem 0;
}
.prompt { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; min-height: 2rem; }
.key-name { font-weight: 700; color: var(--ok); }
.intro { color: var(--text); }
.stats { color: var(--muted); font-variant-numeric: tabular-nums; }
.tools { margin-left: auto; display: flex; gap: 0.35rem; }
.tools button { padding: 0.25rem 0.55rem; font-size: 0.88rem; }
body:not([data-state="live"]) #hintBtn,
body:not([data-state="preview"]) #newBtn,
body[data-state="preview"] #mineBtn { display: none; }

.staff { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.staff-svg { width: 100%; height: 100%; display: block; }
.st-line { stroke: var(--staff); stroke-width: 1; }
.st-ledger { stroke: var(--staff); stroke-width: 1.2; }
.st-g { fill: var(--text); }
.st-g.bass { fill: var(--text); }
.st-g.example { fill: #9fb6e6; }
.st-g.done { fill: var(--text); }
.st-g.live { fill: var(--accent); }
.st-g.bad { fill: var(--bad); }
.st-ledger.bad { stroke: var(--bad); }
.st-g.stale { fill: var(--ok); }
.st-g.hint { fill: var(--good); opacity: 0.75; }
.st-g.cue { fill: var(--good); opacity: 0.55; }
.st-tie { fill: var(--text); }
.col-cur { fill: rgba(79, 140, 255, 0.13); stroke: rgba(79, 140, 255, 0.35); stroke-width: 1; }
.st-fig { fill: var(--text); font-size: 12.5px; font-weight: 600; text-anchor: middle; }
.st-label { fill: var(--accent); font-size: 9.5px; font-weight: 600; text-anchor: middle; }
.st-name { fill: var(--muted); font-size: 10.5px; text-anchor: middle; }
.st-deg { fill: none; stroke: var(--muted); stroke-width: 1; }
.st-degn { fill: var(--muted); font-size: 9.5px; text-anchor: middle; }
.st-arrow { fill: var(--muted); font-size: 10px; text-anchor: middle; }
body[data-state="score"] .staff { opacity: 0.25; }

.score-card {
  display: none;
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.5rem;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  max-width: 92%;
}
body[data-state="score"] .score-card { display: block; }
.score-head { font-size: 2rem; font-weight: 700; }
.score-line { color: var(--muted); margin: 0.4rem 0 0.9rem; }
.score-line b { color: var(--text); }
.score-btns { display: flex; gap: 0.6rem; justify-content: center; }

.fb-row { min-height: 3rem; padding: 0.2rem 0 0.3rem; flex: none; }
.feedback { font-weight: 600; min-height: 1.4em; }
.feedback.good { color: var(--good); }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.why { color: var(--muted); font-size: 0.85rem; min-height: 1.2em; }

/* ---------- keyboard ---------- */
.kb-wrap { flex: none; padding: 0 0.9rem 0.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.keyboard { width: 100%; height: 130px; display: block; touch-action: manipulation; }
.keyboard rect { cursor: pointer; }
.keyboard .white { fill: var(--key-white); stroke: var(--key-white-stroke); stroke-width: 1; }
.keyboard .black { fill: var(--key-black); stroke: #000; stroke-width: 1; }
.keyboard .held { fill: var(--accent); }
.keyboard .held-good { fill: var(--good); }
.keyboard .held-bad { fill: var(--bad); }
.keyboard .held-stale { fill: var(--ok); }
.keyboard .hint { fill: #9fe7c4; }
.keyboard .black.hint { fill: #2f9b6a; }
.keyboard .kb-c { fill: #888; font-size: 10px; text-anchor: middle; pointer-events: none; }
.midi-status { color: var(--muted); font-size: 0.75rem; padding-top: 0.2rem; }

/* ---------- panels ---------- */
.panel {
  display: none;
  position: fixed;
  z-index: 10;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.6);
}
.close { position: absolute; top: 0.5rem; right: 0.5rem; padding: 0.15rem 0.5rem; }
.lesson {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(40rem, 94vw);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 0.9rem 1.3rem 1rem;
  line-height: 1.45;
}
body.lesson-open .lesson { display: block; }
.lesson h2 { margin: 0.2rem 0 0.6rem; font-size: 1.2rem; }
.lesson p, .lesson li { color: #cfd3de; }
.lesson b { color: var(--text); }
.lesson ul, .lesson ol { padding-left: 1.2rem; }
.lesson table.roo { border-collapse: collapse; font-size: 0.8rem; margin: 0.4rem 0; width: 100%; }
.lesson table.roo th, .lesson table.roo td { border: 1px solid var(--line); padding: 0.2rem 0.3rem; text-align: center; white-space: nowrap; }
.lesson table.roo th { color: var(--ok); }
/* the floating sheets (⚙️ settings, 🔑 keys): centered like the lesson */
.opts, .key-sheet {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-height: 92dvh;
  overflow-y: auto;
}
.panel h3 { margin: 0 0 0.7rem; font-size: 1.15rem; }
.panel h3 .sub { color: var(--muted); font-weight: 400; font-size: 0.9rem; }
.opts { width: min(44rem, 94vw); padding: 1rem 1.3rem 0.9rem; }
body.opts-open .opts { display: block; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 0.4rem 1.6rem; }
.opts h4 { margin: 0.2rem 0 0.5rem; color: var(--ok); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.opts label { display: flex; gap: 0.5rem; margin: 0.55rem 0; font-size: 0.95rem; line-height: 1.3; }
.opts label.chk { align-items: flex-start; cursor: pointer; }
.opts label.chk input { margin-top: 0.2rem; flex: none; width: 1rem; height: 1rem; accent-color: var(--accent); }
.opts label.row { flex-direction: column; gap: 0.3rem; }
.opts label.row select { width: 100%; }
.hint-txt { color: var(--muted); font-size: 0.8rem; margin: 0.3rem 0 0; line-height: 1.35; }
.keys-help { color: var(--muted); font-size: 0.8rem; margin: 0.9rem 0 0; border-top: 1px solid var(--line); padding-top: 0.6rem; }

/* the keys knob: a mini circle of fifths + what's picked */
.keys-btn { display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.keys-btn svg { width: 1.3rem; height: 1.3rem; flex: none; }
#keysMini .wedge path { fill: #3a4154; }
#keysMini .wedge.on path { fill: var(--accent); }

.key-sheet { width: min(25rem, 94vw); padding: 0.9rem 1.1rem 1rem; text-align: center; }
body.keys-open .key-sheet { display: block; }
.key-sheet h3 { text-align: left; }
#keyWheel { width: min(20rem, 84vw, 64dvh); display: block; margin: 0 auto; user-select: none; }
#keyWheel .wedge { cursor: pointer; }
#keyWheel .wedge path { fill: #232734; transition: fill 0.12s; }
#keyWheel .wedge:hover path { fill: #2e3444; }
#keyWheel .wedge.on path { fill: var(--accent); }
#keyWheel text { text-anchor: middle; dominant-baseline: central; pointer-events: none; fill: var(--muted); }
#keyWheel .kw-maj { font-size: 13px; font-weight: 600; fill: var(--text); }
#keyWheel .kw-min { font-size: 8.5px; }
/* minor mode: the relative minor is the key you'll play */
#keyWheel.minor .kw-maj { font-size: 8.5px; font-weight: 400; fill: var(--muted); }
#keyWheel.minor .kw-min { font-size: 12px; font-weight: 600; fill: var(--text); }
#keyWheel .wedge.on text { fill: #fff !important; }
.key-all { cursor: pointer; }
.key-all circle { fill: #1a1e28; stroke: #363c4c; stroke-width: 1.5; }
.key-all:hover circle, .key-all.on circle { stroke: var(--accent); }
#keyWheel .key-all text { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; fill: var(--text); }
.key-presets { display: flex; gap: 0.4rem; justify-content: center; flex-wrap: wrap; margin-top: 0.7rem; }
/* 📈 gradual: unlocked keys glow green, the next unlock wears a dashed rim */
#keyWheel .wedge.unlocked path, #keysMini .wedge.unlocked path { fill: var(--good); }
#keyWheel .wedge.unlocked text { fill: #10131c !important; }
#keyWheel .wedge.next path { stroke: var(--good); stroke-width: 1.4; stroke-dasharray: 3 2.5; }
#keyWheel .kw-pips { font-size: 6.5px; letter-spacing: 0.6px; font-weight: 700; }
.key-grad { margin-top: 0.6rem; border-radius: 999px; font-size: 0.88rem; color: var(--muted); }
.key-grad.on { border-color: var(--good); color: var(--good); }
.grad-note { color: var(--muted); font-size: 0.78rem; line-height: 1.35; margin: 0.5rem 0 0; }
.key-presets button { font-size: 0.85rem; padding: 0.25rem 0.7rem; border-radius: 999px; }
.key-presets button.on { border-color: var(--accent); color: var(--accent); }

/* ---------- phone landscape: nothing scrolls ---------- */
@media (max-height: 430px) {
  .bar { padding: 0.3rem 0.5rem; gap: 0.35rem; }
  .brand { font-size: 0.85rem; }
  .drill-title { display: none; }
  button, select { padding: 0.22rem 0.45rem; font-size: 0.82rem; }
  .knobs select { max-width: 8.5rem; }
  .knobs { gap: 0.3rem; }
  /* in a drill the knobs need the room: ☰ is the way home */
  body:not([data-state="menu"]) .brand { display: none; }
  .drills-btn .lbl { display: none; }
  .keys-btn svg { width: 1.05rem; height: 1.05rem; }
  .key-sheet { display: none; padding: 0.5rem 0.8rem 0.6rem; width: min(30rem, 94vw); }
  body.keys-open .key-sheet { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr; align-items: center; column-gap: 0.8rem; }
  .key-sheet h3 { grid-column: 1 / -1; margin-bottom: 0.3rem; font-size: 1rem; }
  #keyWheel { width: min(15rem, 70dvh); }
  .key-presets { flex-direction: column; margin: 0; }
  .key-side { display: flex; flex-direction: column; }
  .grad-note { font-size: 0.72rem; }
  .opts { padding: 0.7rem 1rem 0.6rem; }
  .opts label { margin: 0.35rem 0; font-size: 0.85rem; }
  .keys-help { margin-top: 0.5rem; }
  .stage { padding: 0.15rem 0.5rem 0; }
  .prompt { min-height: 1.6rem; gap: 0.45rem; font-size: 0.85rem; flex-wrap: nowrap; }
  .intro { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .tools button { padding: 0.15rem 0.4rem; font-size: 0.78rem; }
  .fb-row { min-height: 2.3rem; font-size: 0.85rem; padding: 0; }
  .why { font-size: 0.75rem; }
  .keyboard { height: 66px; }
  .kb-wrap { padding: 0 0.5rem 0.2rem; }
  .midi-status { display: none; }
  .menu { padding: 0.5rem; gap: 0.45rem; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); }
  .drill-card { padding: 0.45rem 0.55rem; gap: 0.5rem; }
  .dc-icon { font-size: 1.2rem; }
  .dc-title { font-size: 0.88rem; }
  .dc-blurb { font-size: 0.74rem; }
  .dc-prog { font-size: 0.7rem; }
  body[data-state="menu"] .kb-wrap { display: none; }
}
@media (max-width: 760px), (max-height: 430px) {
  .tools .lbl { display: none; }
}
