:root{
  --bg:#f7f8fb;
  --surface:#ffffff;
  --surface-2:#fbfcfe;
  --ink:#1c2230;
  --ink-soft:#5a6478;
  --muted:#9099ad;
  --line:#e6e9f0;
  --line-strong:#d2d8e3;
  --accent:#4a6cf7;
  --accent-soft:#eef2ff;
  --accent-deep:#2f4fd0;
  --warm:#e8743b;
  --warm-soft:#fff0e8;
  --good:#1aa97b;
  --good-soft:#e3f6ef;
  --shadow:0 1px 2px rgba(28,34,48,.04),0 6px 24px rgba(28,34,48,.06);
  --radius:16px;
  --mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}

*{box-sizing:border-box;}
html,body{margin:0;}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg);
  color:var(--ink);
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3{margin:0;font-weight:650;letter-spacing:-.01em;}
button{font:inherit;}

.page{max-width:1180px;margin:0 auto;padding:32px 24px 64px;}

/* Hero */
.hero{margin-bottom:28px;}
.brand{display:flex;align-items:center;gap:14px;}
.brand-mark{color:var(--accent);display:inline-flex;}
.brand-text h1{font-size:1.7rem;line-height:1.1;}
.brand-text p{margin:2px 0 0;color:var(--ink-soft);font-size:.95rem;}

/* App grid */
.app{display:grid;grid-template-columns:300px 1fr;gap:24px;align-items:start;}
@media(max-width:880px){.app{grid-template-columns:1fr;}}

/* Rail */
.rail{
  position:sticky;top:24px;
  background:var(--surface);border:1px solid var(--line);
  border-radius:var(--radius);padding:20px;box-shadow:var(--shadow);
}
.rail-head{display:flex;align-items:center;gap:12px;margin-bottom:16px;}
.rail-label{font-size:.72rem;font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--muted);}
.progress{flex:1;height:6px;background:var(--line);border-radius:99px;overflow:hidden;display:block;}
.progress span{display:block;height:100%;width:0;background:var(--accent);border-radius:99px;transition:width .4s cubic-bezier(.2,.8,.2,1);}
.steps{list-style:none;margin:0 0 16px;padding:0;display:flex;flex-direction:column;gap:2px;}
.step{
  display:flex;gap:12px;padding:12px 10px;border-radius:10px;cursor:pointer;
  border:1px solid transparent;transition:background .15s,border-color .15s;
}
.step:hover{background:var(--surface-2);}
.step.active{background:var(--accent-soft);border-color:#dbe3ff;}
.step.done .dot{background:var(--accent);color:#fff;}
.step .dot{
  flex:0 0 22px;height:22px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;
  font-size:.7rem;font-weight:700;background:var(--line);color:var(--muted);transition:.2s;
}
.step .dot svg{width:13px;height:13px;}
.step .body{flex:1;}
.step .body .t{font-size:.88rem;font-weight:600;color:var(--ink);}
.step .body .s{font-size:.78rem;color:var(--muted);margin-top:2px;}
.ghost-btn{
  width:100%;padding:9px;border:1px solid var(--line-strong);background:var(--surface-2);
  color:var(--ink-soft);border-radius:10px;cursor:pointer;transition:.15s;
}
.ghost-btn:hover{border-color:var(--accent);color:var(--accent);}

/* Cards */
.stage{display:flex;flex-direction:column;gap:20px;}
.card{
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
  padding:18px;box-shadow:var(--shadow);
}
.card-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px;flex-wrap:wrap;}
.card-head h2{font-size:1.02rem;}
.card-hint{font-size:.76rem;color:var(--muted);}

/* Piano */
.piano-card{padding-bottom:14px;}
.piano-scroll{overflow-x:auto;padding:6px 2px 10px;}
.piano{position:relative;height:150px;display:inline-block;user-select:none;}
.key{
  position:absolute;border:1px solid var(--line-strong);cursor:pointer;
  display:flex;align-items:flex-end;justify-content:center;padding-bottom:7px;
  font-size:.62rem;color:#7a8190;border-radius:0 0 7px 7px;transition:transform .05s,box-shadow .12s,background .12s;
  background:linear-gradient(#ffffff,#eef1f7);
}
.key.black{background:linear-gradient(#3a3f4d,#15171f);color:#aab2c4;border-color:#000;z-index:2;}
.key:hover{background:linear-gradient(#f4f6fb,#e3e7f1);}
.key.black:hover{background:linear-gradient(#454b5c,#1d2029);}
.key.sustained{box-shadow:inset 0 -4px 0 0 var(--accent);background:linear-gradient(#eef2ff,#dbe3ff);color:var(--accent-deep);}
.key.black.sustained{box-shadow:inset 0 -4px 0 0 var(--accent);background:linear-gradient(#3a4170,#1a1f3a);color:#cdd6ff;}
.key.flash{box-shadow:inset 0 -4px 0 0 var(--good);background:linear-gradient(#e3f6ef,#c7ecdd);}

.now-playing{
  display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:6px;min-height:30px;
  font-size:.84rem;
}
.np-label{font-size:.68rem;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);}
.np-empty{color:var(--muted);}
.chip{
  display:inline-flex;align-items:center;gap:6px;padding:4px 10px;border-radius:99px;
  background:var(--accent-soft);color:var(--accent-deep);font-weight:600;font-size:.8rem;border:1px solid #dbe3ff;
}
.chip .x{cursor:pointer;opacity:.55;display:inline-flex;}
.chip .x:hover{opacity:1;}
.chip .hz{font-family:var(--mono);font-weight:500;opacity:.7;font-size:.74rem;}

/* Timbre row */
.timbre-row{display:flex;gap:6px;}
.timbre-btn{
  display:inline-flex;align-items:center;gap:6px;padding:6px 11px;border-radius:9px;cursor:pointer;
  border:1px solid var(--line-strong);background:var(--surface-2);color:var(--ink-soft);
  font-size:.78rem;font-weight:550;transition:.15s;
}
.timbre-btn:hover{border-color:var(--accent);color:var(--accent);}
.timbre-btn.active{background:var(--accent);border-color:var(--accent);color:#fff;box-shadow:0 2px 8px rgba(74,108,247,.3);}
.timbre-btn svg{width:15px;height:15px;}

/* Canvases */
canvas{width:100%;display:block;background:#fcfdff;border:1px solid var(--line);border-radius:12px;}
#spectrum-canvas{height:300px;}
#wave-canvas{height:170px;}

/* Insight */
.insight{
  margin-top:14px;padding:14px 16px;border-radius:12px;font-size:.9rem;line-height:1.55;
  background:var(--surface-2);border:1px solid var(--line);color:var(--ink-soft);min-height:48px;
  display:flex;gap:11px;align-items:flex-start;transition:background .3s,border-color .3s;
}
.insight.empty{color:var(--muted);}
.insight .ic{flex:0 0 18px;margin-top:1px;color:var(--accent);}
.insight .ic svg{width:18px;height:18px;display:block;}
.insight .ic.warn{color:var(--warm);}
.insight .ic.good{color:var(--good);}
.insight.good{background:var(--good-soft);border-color:#bfe8d6;}
.insight.warn{background:var(--warm-soft);border-color:#f6d6c4;}
.insight b{color:var(--ink);}
.insight .pill{
  display:inline-block;padding:1px 7px;border-radius:6px;background:#fff;border:1px solid var(--line-strong);
  font-family:var(--mono);font-size:.78rem;color:var(--ink);
}

/* Footer */
footer{margin-top:40px;text-align:center;color:var(--muted);font-size:.8rem;}

/* ---------- course tabs ---------- */
.tabs{display:flex;gap:4px;margin:-20px -20px 16px;padding:6px;background:var(--surface-2);
  border-bottom:1px solid var(--line);}
.tab{
  flex:1;padding:9px 6px;border:none;background:transparent;cursor:pointer;border-radius:8px;
  font-size:.78rem;font-weight:600;color:var(--ink-soft);transition:.15s;text-align:center;
}
.tab:hover{background:rgba(74,108,247,.08);color:var(--accent);}
.tab.active{background:var(--accent);color:#fff;box-shadow:0 2px 8px rgba(74,108,247,.28);}

/* hide cards whose module isn't active */
.module-card{display:none;}
.module-card.active{display:block;}

/* stage-level insight (always visible, module-aware) */
.insight-stage{margin-bottom:4px;}

/* ---------- circle of fifths ---------- */
.cof-wrap{display:flex;gap:18px;align-items:center;flex-wrap:wrap;}
.cof{width:230px;height:230px;flex:0 0 230px;}
.cof .wedge{cursor:pointer;transition:filter .15s;}
.cof .wedge:hover{filter:brightness(1.08);}
.cof .wedge.sel{stroke:var(--accent);stroke-width:3;}
.cof .wedge-sharp{fill:#eef2ff;stroke:#dbe3ff;}
.cof .wedge-flat{fill:#fff0e8;stroke:#f6d6c4;}
.cof .wedge-nat{fill:#e3f6ef;stroke:#bfe8d6;}
.cof text{font-size:9px;font-weight:600;fill:var(--ink);pointer-events:none;text-anchor:middle;dominant-baseline:central;}
.cof .key-sig{font-size:7px;font-weight:500;fill:var(--muted);}
.cof .hub{fill:var(--surface);stroke:var(--line-strong);}

.scale-info{flex:1;min-width:160px;}
.scale-info h3{font-size:.95rem;margin:0 0 4px;}
.scale-info .key-line{font-size:.82rem;color:var(--ink-soft);margin-bottom:8px;}
.scale-info .pill{display:inline-block;padding:1px 7px;border-radius:6px;background:#fff;
  border:1px solid var(--line-strong);font-family:var(--mono);font-size:.78rem;color:var(--ink);margin:1px;}

.scale-controls{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-top:14px;flex-wrap:wrap;}
.scale-types{display:flex;gap:6px;flex-wrap:wrap;}
.scale-types button,.chord-qualities button,.chord-roots button{
  padding:6px 11px;border-radius:9px;cursor:pointer;border:1px solid var(--line-strong);
  background:var(--surface-2);color:var(--ink-soft);font-size:.78rem;font-weight:550;transition:.15s;
}
.scale-types button:hover,.chord-qualities button:hover,.chord-roots button:hover{border-color:var(--accent);color:var(--accent);}
.scale-types button.active,.chord-qualities button.active,.chord-roots button.active{
  background:var(--accent);border-color:var(--accent);color:#fff;
}
.play-btn{padding:8px 16px;border-radius:10px;cursor:pointer;border:none;
  background:var(--ink);color:#fff;font-weight:600;font-size:.84rem;transition:.15s;}
.play-btn:hover{background:var(--accent);}

/* ---------- chord builder ---------- */
.chord-controls{display:flex;flex-direction:column;gap:12px;margin-bottom:14px;}
.chord-roots{display:flex;gap:5px;flex-wrap:wrap;}
.chord-qualities{display:flex;gap:6px;flex-wrap:wrap;}
.chord-stack{display:flex;flex-direction:column-reverse;gap:8px;}
.chord-stack .stack-note{
  display:flex;align-items:center;gap:12px;padding:10px 14px;border-radius:10px;
  background:var(--surface-2);border:1px solid var(--line);transition:.2s;
}
.chord-stack .stack-note.root{border-color:var(--accent);background:var(--accent-soft);}
.chord-stack .stack-note .deg{
  flex:0 0 56px;font-size:.72rem;font-weight:700;letter-spacing:.04em;text-transform:uppercase;color:var(--muted);
}
.chord-stack .stack-note.root .deg{color:var(--accent-deep);}
.chord-stack .stack-note .nm{font-weight:650;font-size:.92rem;}
.chord-stack .stack-note .hz{font-family:var(--mono);font-size:.78rem;color:var(--muted);}
.chord-stack .stack-note .iv{margin-left:auto;font-size:.8rem;color:var(--ink-soft);font-weight:600;}
.chord-stack .stack-note .iv .pill{font-family:var(--mono);}

/* ---------- rail actions ---------- */
.rail-actions{display:flex;gap:8px;}
.rail-actions .ghost-btn{flex:1;}
.gear{flex:0 0 42px !important;font-size:1rem;line-height:1;padding:9px 0 !important;}

/* ---------- generator bar (core of practice) ---------- */
.genbar{
  display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;
  margin:-18px -18px 16px;padding:12px 18px;background:linear-gradient(135deg,#eef2ff,#f7f8fb);
  border-bottom:1px solid var(--line);border-radius:16px 16px 0 0;
}
.genbar-info{display:flex;align-items:center;gap:10px;}
.genbar-dot{width:10px;height:10px;border-radius:50%;background:var(--muted);flex:0 0 auto;transition:.2s;}
.genbar-dot.on{background:var(--good);box-shadow:0 0 0 4px rgba(26,169,123,.18);animation:pulse 1.4s infinite;}
.genbar-dot.busy{background:var(--accent);box-shadow:0 0 0 4px rgba(74,108,247,.18);animation:pulse .9s infinite;}
.genbar-dot.err{background:var(--warm);}
.genbar-title{font-weight:700;font-size:.9rem;color:var(--ink);}
.genbar-status{font-size:.78rem;color:var(--ink-soft);}
.genbar-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}
.genbar-cache{font-size:.74rem;color:var(--muted);font-family:var(--mono);}
.gen-generate{padding:8px 16px;font-size:.86rem;}
.gen-connect{width:auto !important;padding:8px 14px !important;font-size:.82rem !important;}

/* ---------- practice module ---------- */
.practice-head{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;margin-bottom:14px;}
.practice-stats{display:flex;gap:10px;}
.stat{display:flex;flex-direction:column;align-items:center;min-width:52px;padding:6px 10px;border-radius:10px;background:var(--surface-2);border:1px solid var(--line);}
.stat-n{font-size:1.25rem;font-weight:700;line-height:1;color:var(--ink);}
.stat-l{font-size:.62rem;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);margin-top:3px;}
.stat.bump .stat-n{color:var(--accent);transition:color .3s;}
.stat.bump-good .stat-n{color:var(--good);}
.practice-actions{display:flex;gap:6px;}
.icon-btn{
  width:38px;height:38px;border-radius:10px;cursor:pointer;border:1px solid var(--line-strong);
  background:var(--surface-2);color:var(--ink-soft);font-size:1rem;transition:.15s;display:inline-flex;align-items:center;justify-content:center;
}
.icon-btn:hover{border-color:var(--accent);color:var(--accent);}
.practice-prompt{padding:18px 18px 8px;border-radius:14px;background:var(--surface-2);border:1px solid var(--line);min-height:120px;}
.pr-kicker{font-size:.7rem;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--accent);}
.practice-prompt h2{font-size:1.4rem;margin:6px 0 4px;line-height:1.15;}
.pr-detail{margin:0;color:var(--ink-soft);font-size:.92rem;line-height:1.5;}
.pr-listen{display:flex;gap:8px;flex-wrap:wrap;margin-top:14px;}
.pr-listen .chip-choice{
  padding:7px 13px;border-radius:10px;cursor:pointer;border:1px solid var(--line-strong);
  background:#fff;color:var(--ink);font-size:.86rem;font-weight:600;transition:.12s;
}
.pr-listen .chip-choice:hover{border-color:var(--accent);}
.pr-listen .chip-choice.correct{background:var(--good);border-color:var(--good);color:#fff;}
.pr-listen .chip-choice.wrong{background:var(--warm);border-color:var(--warm);color:#fff;}
.pr-listen .replay-tag{padding:7px 13px;border-radius:10px;cursor:pointer;border:1px solid var(--line-strong);
  background:#fff;color:var(--accent);font-size:.84rem;font-weight:600;}
.pr-hintbox{margin-top:12px;padding:10px 13px;border-radius:10px;background:var(--accent-soft);
  border:1px solid #dbe3ff;color:var(--accent-deep);font-size:.84rem;display:none;}
.pr-hintbox.show{display:block;}
.pr-status{margin-top:12px;font-weight:600;font-size:.95rem;min-height:22px;}
.pr-status.correct{color:var(--good);}
.pr-status.wrong{color:var(--warm);}
.pr-status .pts{font-family:var(--mono);}
.practice-keyhint{margin:10px 2px 0;color:var(--muted);font-size:.74rem;}
.kbd{display:inline-block;padding:1px 6px;border-radius:5px;background:#fff;border:1px solid var(--line-strong);font-family:var(--mono);font-size:.72rem;color:var(--ink);}
.practice-genbar{margin-top:8px;font-size:.72rem;color:var(--muted);min-height:14px;}
.pr-gen{display:inline-flex;align-items:center;gap:6px;}
.pr-gen .dot{width:7px;height:7px;border-radius:50%;background:var(--muted);}
.pr-gen.on .dot{background:var(--good);animation:pulse 1.2s infinite;}
.pr-gen.err .dot{background:var(--warm);}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}

/* ---------- overlay / settings dialog ---------- */
.overlay{position:fixed;inset:0;background:rgba(28,34,48,.45);display:none;align-items:center;justify-content:center;z-index:100;padding:20px;}
.overlay.show{display:flex;animation:fade .15s;}
@keyframes fade{from{opacity:0}to{opacity:1}}
.dialog{background:var(--surface);border-radius:16px;padding:22px;max-width:460px;width:100%;box-shadow:0 20px 60px rgba(28,34,48,.3);max-height:90vh;overflow:auto;}
.dialog-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;}
.dialog-head h2{font-size:1.1rem;}
.dialog-intro{color:var(--ink-soft);font-size:.85rem;line-height:1.5;margin:0 0 14px;}
.dialog .row{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px;}
.dialog .row > span{font-size:.86rem;font-weight:600;color:var(--ink);flex:0 0 auto;}
.dialog .row input[type=text],.dialog .row input[type=password],.dialog .row input[type=number],.dialog .row select{
  flex:1;min-width:0;padding:8px 10px;border-radius:9px;border:1px solid var(--line-strong);background:var(--surface-2);font:inherit;font-size:.84rem;
}
.dialog .row input:focus,.dialog .row select:focus{outline:none;border-color:var(--accent);}
.dialog-actions{display:flex;gap:10px;justify-content:flex-end;margin-top:14px;}
.dialog-actions .ghost-btn{width:auto;padding:8px 16px;}
.set-msg{margin:10px 0 0;font-size:.8rem;min-height:16px;}
.set-msg.ok{color:var(--good);}
.set-msg.err{color:var(--warm);}

/* piano keys used as answer targets get a gentle highlight */
.key.target{box-shadow:inset 0 0 0 2px var(--warm);}
.key.target-hit{box-shadow:inset 0 -5px 0 0 var(--good);}

/* practice toast */
.pr-toast{
  position:fixed;left:50%;bottom:32px;transform:translateX(-50%) translateY(20px);
  background:var(--ink);color:#fff;padding:10px 18px;border-radius:99px;font-size:.86rem;font-weight:600;
  opacity:0;pointer-events:none;transition:.25s;z-index:200;box-shadow:0 8px 30px rgba(28,34,48,.3);
}
.pr-toast.show{opacity:1;transform:translateX(-50%) translateY(0);}