:root {
  --bg: #0e1726;
  --bg2: #14223a;
  --panel: #16263f;
  --panel2: #1d3454;
  --ink: #f4f7fb;        /* notes / clef on the staff card */
  --staff: #51627e;
  --muted: #93a4be;
  --accent: #f4b740;     /* brass */
  --accent2: #ffd479;
  --ok: #36d399;
  --bad: #f76d6d;
  --line: #26405f;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #1b2d4d 0%, var(--bg) 60%);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
  min-height: 100%;
}

/* ---------- header ---------- */
.app-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(10,18,32,.6);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; letter-spacing: .2px; font-size: 18px; white-space: nowrap; }
.brand-ic { filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.tabs { display: flex; gap: 6px; margin: 0 auto; background: var(--bg2); padding: 4px; border-radius: 999px; border: 1px solid var(--line); }
.tab {
  appearance: none; border: 0; cursor: pointer;
  background: transparent; color: var(--muted);
  font-weight: 700; font-size: 14px; padding: 7px 16px; border-radius: 999px;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--accent); color: #2a1c00; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  appearance: none; cursor: pointer; border: 0;
  background: var(--accent); color: #2a1c00; font-weight: 700;
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.icon-btn {
  appearance: none; cursor: pointer; border: 1px solid var(--line);
  background: var(--bg2); color: var(--ink); width: 38px; height: 38px;
  border-radius: 10px; font-size: 17px; line-height: 1; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--panel2); }

/* ---------- main / panels ---------- */
.app-main {
  width: 100%; max-width: 760px; margin: 0 auto; padding: 18px 16px 28px;
  flex: 1; display: flex; flex-direction: column;
}
.panel { display: none; }
.panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.staff-wrap {
  background: linear-gradient(180deg, #fbfdff, #eef3fa);
  border: 1px solid #c8d4e6; border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 8px; overflow: hidden;
}
.staff { width: 100%; }
.staff-svg { display: block; width: 100%; height: auto; }

/* staff drawing colours (override the light card's ink) */
.staff-svg { --ink: #15233c; }
.staff-line, .ledger-line { stroke: #2c3c57; stroke-width: 1.5; }
.ledger-line { stroke-width: 2; }
.notehead { fill: var(--ink); }
.stem { stroke: var(--ink); }
.accidental { fill: var(--ink); font-family: Georgia, "Times New Roman", serif; }
.clef path { fill: var(--ink); }
.clef-bg { fill: #f4f8fd; }

.note-name {
  text-align: center; font-weight: 800; letter-spacing: .5px;
  font-size: clamp(34px, 9vw, 56px); margin: 14px 0 4px;
  color: var(--accent2);
}
.note-name.ok { color: var(--ok); }
.note-name.bad { color: var(--bad); }

.feedback { text-align: center; min-height: 24px; font-size: 16px; color: var(--muted); }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.feedback strong { color: inherit; }

.row { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }
.row.end { justify-content: flex-end; }
.score { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 12px auto 0; max-width: 46ch; }

/* ---------- scroll mode ---------- */
.scroll-wrap { padding: 0; }
.scroll-svg { width: auto; max-width: 100%; height: auto; }
.scroll-notes { will-change: transform; }
.playhead { stroke: var(--accent); stroke-width: 2.5; opacity: .85; }
.scroll-notes .note .notehead,
.scroll-notes .note .stem,
.scroll-notes .note .accidental { transition: fill .15s, stroke .15s, opacity .15s; }
.scroll-notes .note.done .notehead { fill: var(--ok); }
.scroll-notes .note.done .stem { stroke: var(--ok); }
.scroll-notes .note.done .accidental { fill: var(--ok); }
.scroll-notes .note.done { opacity: .45; }
.scroll-notes .note.active .notehead { fill: var(--accent); }
.scroll-notes .note.active .stem { stroke: var(--accent); }
.scroll-notes .note.active .accidental { fill: var(--accent); }
.scroll-notes .note.active.wrong .notehead { fill: var(--bad); }
.scroll-notes .note.active.wrong .stem { stroke: var(--bad); }
.scroll-notes .note.active.wrong .accidental { fill: var(--bad); }
.scroll-notes .note.shake { animation: shake .34s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.stats { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 14px; min-width: 78px; text-align: center;
}
.stat-val { display: block; font-size: 22px; font-weight: 800; color: var(--accent2); font-variant-numeric: tabular-nums; }
.stat-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

/* ---------- valve bar ---------- */
.valvebar { display: flex; justify-content: center; gap: 16px; margin-top: 22px; }
.valve {
  width: 70px; height: 88px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: transform .08s, box-shadow .12s, border-color .12s, background .12s;
}
.valve .vnum { font-size: 28px; font-weight: 800; color: var(--ink); }
.valve .vkey {
  font-size: 12px; color: var(--muted); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; font-weight: 700;
}
.valve.held { background: var(--accent); border-color: var(--accent2); transform: translateY(2px); box-shadow: 0 6px 16px rgba(244,183,64,.4); }
.valve.held .vnum { color: #2a1c00; }
.valve.held .vkey { color: #2a1c00; background: rgba(255,255,255,.5); border-color: transparent; }
.valve.req { box-shadow: 0 0 0 3px var(--ok) inset; border-color: var(--ok); }

/* ---------- settings modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; display: none;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(4,9,18,.6); backdrop-filter: blur(4px);
}
.modal.open { display: flex; }
.modal-card {
  width: 100%; max-width: 460px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  padding: 18px; max-height: 90vh; overflow: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { font-size: 20px; margin: 0; }
.setting { padding: 14px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting-label { font-weight: 700; margin-bottom: 10px; display: block; }
.binds { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bind { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.bind-name { color: var(--muted); font-size: 13px; }
.rebind {
  min-width: 64px; cursor: pointer; font-weight: 800;
  background: var(--bg2); color: var(--ink); border: 1px solid var(--accent);
  border-radius: 8px; padding: 6px 10px;
}
.rebind.listening { background: var(--accent); color: #2a1c00; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
input[type=range] { width: 100%; accent-color: var(--accent); }
.range-row { display: flex; gap: 14px; flex-wrap: wrap; }
.range-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); flex: 1; }
select {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; font-size: 15px;
}

@media (max-width: 560px) {
  .brand { font-size: 16px; }
  .app-header { flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; justify-content: center; margin: 4px 0 0; }
  .valve { width: 62px; height: 80px; }
  .binds { grid-template-columns: 1fr; }
}
