:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #cde2fb;
  --good: #0ca30c;
  --critical: #d03b3b;
  --flat: #3987e5;
  --sharp: #e66767;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary); }
body { min-height: 100vh; }
a { color: var(--accent-ink); }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(13,13,13,.92); backdrop-filter: blur(8px); z-index: 5; }
.brand { font-weight: 700; font-size: 18px; text-decoration: none; color: var(--text-primary); letter-spacing: .2px; }
.logo { color: var(--accent); }
nav a { margin-left: 18px; text-decoration: none; color: var(--text-secondary); font-weight: 500; }
nav a.active { color: var(--text-primary); border-bottom: 2px solid var(--accent); padding-bottom: 3px; }

main { max-width: 980px; margin: 0 auto; padding: 24px 20px 64px; }
.hero h1 { font-size: clamp(30px, 5vw, 46px); margin: 18px 0 8px; }
.sub { color: var(--text-secondary); max-width: 640px; line-height: 1.5; margin: 0 0 18px; }
.label { font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 30px 0 12px; font-weight: 600; }
.fine { color: var(--muted); font-size: 13px; line-height: 1.45; }
.center { text-align: center; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }

.inst-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.inst { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 10px; cursor: pointer; text-align: center; color: var(--text-primary); font: inherit; transition: border-color .15s, transform .1s; }
.inst:hover { border-color: rgba(255,255,255,.25); }
.inst:active { transform: scale(.98); }
.inst .ic { font-size: 28px; display: block; margin-bottom: 6px; }
.inst .nm { font-weight: 600; font-size: 14px; }
.inst .rg { color: var(--muted); font-size: 12px; margin-top: 2px; }
.inst.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: #17243a; }

.opts { display: grid; gap: 10px; }
.opt { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.opt > span { width: 130px; color: var(--text-secondary); font-size: 14px; }
.seg { display: inline-flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg button { background: none; border: 0; color: var(--text-secondary); font: inherit; font-size: 14px; padding: 7px 12px; border-radius: 7px; cursor: pointer; }
.seg button.sel { background: var(--surface-2); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border) inset; font-weight: 600; }

.btn { display: inline-flex; align-items: center; gap: 6px; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; border: 1px solid var(--border); text-decoration: none; color: var(--text-primary); background: var(--surface-1); }
.btn:hover { border-color: rgba(255,255,255,.25); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.big { font-size: 18px; padding: 14px 26px; }
.btn.danger { color: #f19a9a; }
.btn small { color: var(--muted); font-weight: 400; }

.miccheck { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.miccheck .fine { flex-basis: 100%; margin: 0; }
.mic-live { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 200px; }
.meter { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
#mic-level { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .05s; }
.mic-note { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; min-width: 110px; text-align: right; }

.start-row { display: flex; align-items: center; gap: 18px; margin-top: 28px; flex-wrap: wrap; }
.best-line { color: var(--text-secondary); font-size: 14px; }

/* play */
.play-head { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; text-align: center; }
.play-head b { font-size: 22px; display: block; font-variant-numeric: tabular-nums; }
.k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.timer { height: 4px; background: var(--surface-2); border-radius: 2px; margin: 14px 0 6px; overflow: hidden; }
#p-timer { height: 100%; width: 100%; background: var(--text-secondary); }
.stage { position: relative; width: min(340px, 80vw); aspect-ratio: 1; margin: 18px auto 8px; }
.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { fill: var(--surface-1); stroke: var(--surface-2); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--good); stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray .06s linear; }
.stage-inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.status { color: var(--text-secondary); font-size: 15px; letter-spacing: .5px; }
.target { font-size: 80px; font-weight: 800; line-height: 1; }
.stage.listening .target { color: var(--text-primary); }
.stage.playing .ring-bg { stroke: #24476f; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { stroke: var(--accent); } }
.stage.hit .ring-bg { stroke: var(--good); }
.stage.miss .ring-bg { stroke: var(--critical); }
.you { font-size: 18px; font-variant-numeric: tabular-nums; }
.you b { font-size: 22px; }
.cents { color: var(--muted); font-size: 14px; }
.tuner { position: relative; height: 22px; max-width: 360px; margin: 6px auto 0; background: linear-gradient(90deg, transparent, var(--surface-2) 30%, var(--surface-2) 70%, transparent); border-radius: 11px; }
.tuner-mid { position: absolute; left: 50%; top: 2px; bottom: 2px; width: 2px; background: var(--axis); }
.needle { position: absolute; top: 3px; width: 4px; height: 16px; border-radius: 2px; background: var(--text-primary); left: 50%; transform: translateX(-50%); transition: left .06s linear; opacity: 0; }
.feedback { min-height: 30px; text-align: center; font-size: 17px; margin: 10px 0; }
.feedback .ok { color: #5fd35f; font-weight: 700; }
.feedback .bad { color: #f19a9a; font-weight: 700; }
.play-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* results */
.results { max-width: 640px; margin: 20px auto; text-align: center; padding: 28px; }
.badge { display: inline-block; background: #3a2c00; color: #fab219; border-radius: 20px; padding: 6px 14px; font-weight: 700; margin-bottom: 8px; }
.r-score span { font-size: 72px; font-weight: 800; display: block; line-height: 1.1; }
.r-score small { color: var(--muted); }
.r-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 22px 0 8px; }
.r-tiles b { font-size: 22px; display: block; }
.r-tiles span { color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { padding: 5px 10px; border-radius: 8px; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); }
.chip.ok::before { content: "✓ "; color: #5fd35f; }
.chip.bad::before { content: "✕ "; color: #f19a9a; }
.r-actions { display: flex; gap: 10px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }

/* stats */
.stats-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.stats-head h1 { margin: 8px 0 0; font-size: 30px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; }
.filters label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
select { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .v { font-size: 28px; font-weight: 700; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; margin-bottom: 14px; }
#stats-body > .card { margin-bottom: 14px; }
.card h3 { margin: 0 0 2px; font-size: 16px; }
.cap { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .ink { fill: var(--text-secondary); }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.hit { cursor: default; }
.empty { text-align: center; color: var(--text-secondary); padding: 40px; }
.none { color: var(--muted); font-size: 14px; padding: 8px 0; }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 48px 1fr 46px; align-items: center; gap: 10px; font-size: 14px; }
.bar-row .n { font-weight: 700; }
.bar-row .track { height: 14px; background: var(--surface-2); border-radius: 4px; position: relative; }
.bar-row .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.bar-row .sub2 { grid-column: 2 / 4; color: var(--muted); font-size: 12px; margin-top: -4px; }

.seq-legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin-top: 10px; }
.seq-legend .ramp { width: 160px; height: 10px; border-radius: 3px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--axis); }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 12px; }
.data-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

.tooltip { position: fixed; pointer-events: none; background: #2a2a28; color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.45; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 240px; }
.tooltip b { font-weight: 700; }
.tooltip .m { color: var(--text-secondary); }

@media (max-width: 600px) {
  .opt > span { width: 100%; }
  .play-head b { font-size: 18px; }
  .target { font-size: 64px; }
  .r-tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (forced-colors: active) {
  .bar-row .fill { background: CanvasText; }
}
#s-heat { overflow-x: auto; } #s-heat svg { min-width: 420px; }
