:root {
  --bg: #14110f;
  --panel: #1e1a17;
  --panel-2: #26211d;
  --line: #3a322b;
  --text: #f1e9df;
  --muted: #a89a8b;
  --brass: #e0a93b;
  --brass-2: #f5c96a;
  --target: #e0a93b;
  --tone: #5fb3a1;
  --scale: #5b524a;
  --good: #6cc68a;
  --warn: #e7b04c;
  --bad: #e06a5a;
  --staff: #cfc3b5;
  --demo: #6ea8ff;   /* the demo sax */
  --call: #c18cff;   /* the trumpet call */
  --radius: 14px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f1ea;
    --panel: #fffdf9;
    --panel-2: #f3ece2;
    --line: #e2d7c8;
    --text: #2a2119;
    --muted: #7a6c5c;
    --brass: #b87d0f;
    --brass-2: #9a6608;
    --target: #c98a12;
    --tone: #2f8f7c;
    --scale: #d8cdbf;
    --staff: #3d3228;
    --demo: #2f6fd6;
    --call: #8a4fd6;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

button, select, input { font: inherit; color: inherit; }

select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}

button { cursor: pointer; }

.label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint { color: var(--muted); font-size: 13px; }

.ghost {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
}
.ghost:hover { border-color: var(--brass); }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--brass);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--brass-2), var(--brass));
  color: #1b1307;
  font-size: 22px;
}
h1 { margin: 0; font-size: 18px; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }

.top-controls { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field > span { white-space: nowrap; }

.log { font-size: 13px; color: var(--muted); display: flex; gap: 12px; padding-bottom: 6px; }
.log b { color: var(--text); }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: calc(100vh - 69px);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  background: var(--panel);
}
.sidebar h2 { margin: 0 8px 10px; font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

.lessons { list-style: none; margin: 0; padding: 0; counter-reset: lesson; }
.lessons .level {
  font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em;
  margin: 14px 8px 4px;
}
.lessons button {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px;
}
.lessons button:hover { background: var(--panel-2); }
.lessons button.active { background: var(--panel-2); border-color: var(--brass); }
.lessons .num {
  flex: none;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.lessons .done .num { background: var(--good); border-color: var(--good); color: #10240f; }

.lesson-free {
  margin-top: 14px; width: 100%;
  background: none; border: 1px dashed var(--line); border-radius: 10px; padding: 8px;
  color: var(--muted);
}
.lesson-free.active { border-color: var(--brass); color: var(--text); }

.main { padding: 18px 24px 40px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

/* ---------- lesson card ---------- */

.lesson h2 { margin: 2px 0 4px; font-size: 20px; }
.lesson .goal { margin: 0 0 10px; color: var(--muted); }
.lesson ol { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.lesson li.cur { color: var(--brass-2); }
.lesson .tip {
  margin-top: 10px; padding: 8px 12px; border-radius: 10px;
  background: var(--panel-2); font-size: 14px;
}
.lesson-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- transport ---------- */

.transport { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 18px; }

.play {
  display: flex; align-items: center; gap: 8px;
  background: var(--brass);
  color: #1b1307;
  border: 0;
  border-radius: 999px;
  padding: 10px 22px;
  font-weight: 600;
  font-size: 16px;
}
.play:hover { background: var(--brass-2); }
.play.on { background: var(--bad); color: #fff; }

.tempo input { width: 160px; accent-color: var(--brass); }
.vol input { width: 90px; accent-color: var(--brass); }
.toggles { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.chk { display: flex; align-items: center; gap: 6px; }
.chk input { accent-color: var(--brass); }

.mixer { display: flex; gap: 6px; align-items: flex-end; margin-left: auto; }
.mute {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.mute[aria-pressed="true"] { border-color: var(--text); }
.mute[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(320px, 1.6fr) minmax(240px, 1fr);
  gap: 16px;
}

.now-head, .scale-head, .mic-head, .chart-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.chart-head { justify-content: flex-start; }
.scale-head h3, .chart-head h3 { margin: 2px 0 0; font-size: 16px; }
.chart-head h3 { margin: 0; }

.chord-now {
  font-size: 64px; font-weight: 700; line-height: 1.1; margin-top: 10px;
  color: var(--brass-2);
  font-variant-numeric: tabular-nums;
}
.chord-concert { color: var(--muted); font-size: 13px; min-height: 18px; }
.beats { display: flex; gap: 8px; margin: 14px 0; }
.beats i {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line);
}
.beats i.on { background: var(--brass); border-color: var(--brass); }
.beats.count i.on { background: var(--text); border-color: var(--text); }
.next { color: var(--muted); }
.next strong { color: var(--text); font-size: 20px; margin-left: 4px; }
.bar-count { color: var(--muted); font-size: 13px; }

.phrase {
  font-size: 12px; font-weight: 700; letter-spacing: 0.1em;
  padding: 3px 10px; border-radius: 999px;
}
.phrase.listen { background: var(--call); color: #1a0b2e; }
.phrase.play { background: var(--text); color: var(--bg); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }
.lick { margin-top: 10px; font-size: 14px; }
.lick span { margin-left: 8px; font-weight: 600; }

/* ---------- scale ---------- */

.staff { width: 100%; height: auto; margin: 8px 0 4px; display: block; }
.staff .line { stroke: var(--staff); stroke-width: 1; opacity: 0.7; }
.staff .clef { fill: var(--staff); }
.staff .head { fill: var(--scale); stroke: var(--staff); stroke-width: 1; }
.staff .head.tone { fill: var(--tone); stroke: var(--tone); }
.staff .head.target { fill: var(--target); stroke: var(--target); }
.staff .head.heard { stroke: var(--text); stroke-width: 3; }
.staff .acc { fill: var(--staff); font-size: 20px; }
.staff .deg { fill: var(--muted); font-size: 12px; text-anchor: middle; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; flex-direction: column; align-items: center;
  min-width: 54px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  transition: transform 0.08s;
}
.chip b { font-size: 20px; }
.chip small { color: var(--muted); font-size: 12px; }
.chip.tone { border-color: var(--tone); box-shadow: inset 0 -3px 0 var(--tone); }
.chip.target { border-color: var(--target); background: color-mix(in srgb, var(--target) 22%, var(--panel-2)); box-shadow: inset 0 -3px 0 var(--target); }
.chip.heard { transform: scale(1.1); outline: 2px solid var(--text); }
.chip:hover { border-color: var(--brass-2); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); align-items: center; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.target { background: var(--target); }
.sw.tone { background: var(--tone); }
.sw.scale { background: var(--scale); border: 1px solid var(--staff); }
.legend .hint { margin-left: auto; }

/* ---------- mic ---------- */

.mic-note { display: flex; align-items: center; gap: 14px; margin: 12px 0 8px; }
.detected {
  font-size: 52px; font-weight: 700; min-width: 90px; line-height: 1;
}
.detected.target { color: var(--target); }
.detected.tone { color: var(--tone); }
.detected.scale { color: var(--text); }
.detected.out { color: var(--bad); }
.detected-info { color: var(--muted); font-size: 13px; }

.cents { position: relative; height: 10px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); }
.cents-center { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--muted); }
.cents-needle {
  position: absolute; top: -4px; width: 6px; height: 16px; border-radius: 3px; left: calc(50% - 3px);
  background: var(--good); transition: left 0.08s linear; opacity: 0;
}
.cents-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }

.stats { display: grid; gap: 6px; margin-top: 14px; }
.stat { display: grid; grid-template-columns: 86px 1fr 38px; align-items: center; gap: 8px; font-size: 13px; }
.stat em { font-style: normal; text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.meter b { display: block; height: 100%; width: 0; transition: width 0.3s; }
#st-target { background: var(--target); }
#st-tone { background: var(--tone); }
#st-scale { background: var(--muted); }
#st-out { background: var(--bad); }
.mic-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- chart ---------- */

.chart-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.bar {
  display: flex; gap: 8px; align-items: center;
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 18px; font-weight: 600;
  position: relative;
}
.bar .n { position: absolute; top: 4px; right: 8px; font-size: 10px; color: var(--muted); font-weight: 400; }
.bar .repeat { color: var(--muted); font-weight: 400; }
.bar.cur { border-color: var(--brass); background: color-mix(in srgb, var(--brass) 18%, var(--panel-2)); }

/* ---------- responsive ---------- */

@media (max-width: 1200px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid .scale { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  .chart-grid { grid-template-columns: repeat(2, 1fr); }
  .mixer { margin-left: 0; }
}

/* ---------- fingerings ---------- */

.fingerings-card .chart-head { flex-wrap: wrap; }
.fing-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: 12px; }
.fing-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.fing-legend .sw.on { background: var(--brass); }
.fingerings { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.fing {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 104px;
  padding: 8px 4px 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.fing:hover { border-color: var(--brass-2); }
.fing b { font-size: 15px; }
.fing small { color: var(--muted); font-size: 12px; }
.fing.tone { box-shadow: inset 0 -3px 0 var(--tone); }
.fing.target { box-shadow: inset 0 -3px 0 var(--target); }
.fing.heard { outline: 2px solid var(--text); }
.fing-svg { width: 78px; height: auto; display: block; }
.fing-svg .key { fill: transparent; stroke: var(--staff); stroke-width: 1.2; }
.fing-svg .key.on { fill: var(--brass); stroke: var(--brass); }
.fing-svg .fing-sep { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 2; }
.fing-svg .fing-na { fill: var(--muted); font-size: 9px; }
.detected-fing { flex: none; }
.detected-fing:empty { display: none; }
.detected-fing .fing-svg { width: 56px; }

/* ---------- lesson demo ---------- */

.demo-btn {
  background: var(--demo);
  color: #081a33;
  border: 0;
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 600;
}
.demo-btn:hover { filter: brightness(1.1); }
.demo-now {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--demo);
  background: color-mix(in srgb, var(--demo) 10%, var(--panel));
}
.demo-body { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.demo-fing .fing-svg { width: 60px; }
.demo-fing:empty { display: none; }
.demo-note { font-size: 40px; font-weight: 700; line-height: 1; color: var(--demo); transition: opacity 0.1s; }
.demo-note sup { font-size: 0.4em; }
.demo-note.rest { opacity: 0.35; }
.demo-kind { font-size: 13px; margin-top: 4px; }
.demo-now .hint { margin: 8px 0 0; font-size: 12px; }
.chip.demo { background: color-mix(in srgb, var(--demo) 40%, var(--panel-2)); outline: 2px solid var(--demo); transform: scale(1.1); }
.fing.demo { outline: 3px solid var(--demo); }
.staff .head.demo { stroke: var(--demo); stroke-width: 4; }
.chip.call { background: color-mix(in srgb, var(--call) 40%, var(--panel-2)); outline: 2px solid var(--call); transform: scale(1.1); }
.fing.call { outline: 3px solid var(--call); }
.staff .head.call { stroke: var(--call); stroke-width: 4; }

/* ---------- call & response ---------- */

.phrase { white-space: nowrap; }
.cr {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.cr-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.cr-who { font-weight: 600; font-size: 14px; }
.cr-hide { font-size: 12px; color: var(--muted); }
.cr .demo-body { min-height: 64px; }
.cr .demo-note.who-call { color: var(--call); }
.cr .demo-note.who-demo { color: var(--demo); }
.cr-phrase { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.cr-chip {
  min-width: 30px;
  padding: 3px 7px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}
.cr-chip.pending { color: var(--muted); border-style: dashed; }
.cr-chip.cur.call { border-color: var(--call); background: color-mix(in srgb, var(--call) 30%, var(--panel)); }
.cr-chip.cur.demo { border-color: var(--demo); background: color-mix(in srgb, var(--demo) 30%, var(--panel)); }
.cr-chip.hit { border-color: var(--good); background: color-mix(in srgb, var(--good) 30%, var(--panel)); }
.cr-status { margin-top: 8px; font-size: 13px; color: var(--muted); }
.cr-status.done { color: var(--good); font-weight: 600; }
.chip.passing, .fing.passing { border-style: dashed; }
.chip.passing.demo, .fing.passing.demo { border-color: var(--demo); }
.chip.passing.call, .fing.passing.call { border-color: var(--call); }
.chip.passing small, .fing.passing small { color: var(--muted); }
.chip, .fing { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.chip.pressed, .fing.pressed { border-color: var(--brass-2); background: color-mix(in srgb, var(--brass) 25%, var(--panel-2)); }
.sw.demo { background: var(--demo); }
.sw.call { background: var(--call); }
.sw.you { background: transparent; border: 2px solid var(--text); }
.legend-who { display: inline-flex; align-items: center; gap: 4px; }
.legend-who .sw + .sw, .legend-who .sw:not(:first-child) { margin-left: 8px; }
/* the mic's "you" highlight: a plain outline, never a fill colour */
.chip.heard { outline: 2px solid var(--text); }
.phrase.demo { background: var(--demo); color: #081a33; }

/* ---------- new scale cards ---------- */

.new-scales { margin-top: 14px; }
.ns-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; margin-top: 6px; }
.ns-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--panel-2); }
.ns-title { font-weight: 700; font-size: 17px; }
.ns-card p { margin: 6px 0; font-size: 14px; }
.ns-rule { font-weight: 600; }
.ns-rel, .ns-sound { color: var(--muted); }
.ns-rel b { color: var(--text); }
.ns-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.ns-lab { width: 100%; font-size: 12px; color: var(--muted); }
.ns-chip { display: inline-flex; flex-direction: column; align-items: center; min-width: 30px; padding: 2px 4px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); }
.ns-chip b { font-size: 14px; }
.ns-chip small { font-size: 10px; color: var(--muted); }
.ns-chip.changed { border-color: var(--text); outline: 1px solid var(--text); background: var(--panel); }
.ns-chip.dropped { opacity: 0.35; text-decoration: line-through; }
.ns-play { margin-top: 4px; }
