:root {
  --page: #110f26;
  --ink: #16132f;
  --panel: #1d1a3a;
  --panel-2: #262250;
  --line: rgba(214, 208, 255, 0.12);
  --text: #f4f2ff;
  --muted: #b3acd9;
  --gold: #ffc83d;
  --voice: #5ad8ea;
  --coral: #ff6f6f;
  --wipe: #ff8fd1;
  /* validated chart steps (dark surface) */
  --c-hit: #c2870f;
  --c-part: #7f72d1;
  --c-miss: #df5658;
  --c-voice: #25a4b6;
  --r-s: 6px;
  --r-m: 12px;
  --ui: "Zen Kaku Gothic New", system-ui, -apple-system, "Segoe UI", sans-serif;
  --round: "M PLUS Rounded 1c", "Zen Kaku Gothic New", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--text); font: 15px/1.5 var(--ui); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--voice); outline-offset: 2px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- buttons & fields ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: var(--r-s); padding: 8px 14px; cursor: pointer;
  background: var(--text); color: var(--ink); font-weight: 700; white-space: nowrap;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.ghost, .btn.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; }
button.ghost:hover:not(:disabled), .btn.ghost:hover { box-shadow: inset 0 0 0 1px var(--muted); }
button.small, .btn.small { padding: 5px 10px; font-size: 13px; }
input[type="text"], select {
  background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-s); padding: 8px 10px; min-width: 0;
}
input[type="range"] { accent-color: var(--voice); min-width: 0; }
input[type="checkbox"] { accent-color: var(--voice); width: 16px; height: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.field { display: grid; grid-template-columns: 9.5em 1fr 4.5em; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; }
.field output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; text-align: right; }
.field input[type="file"] { grid-column: 2 / 4; font-size: 13px; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 14px; }

/* ---------- top bar ---------- */
.top {
  height: 56px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--page);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font: 800 20px/1 var(--round); letter-spacing: 0.01em; color: var(--text); text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 50%; }
.now { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: baseline; overflow: hidden; white-space: nowrap; }
.now #songTitle { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel); font-size: 13px; white-space: nowrap; }
.chip-x { background: none; color: var(--muted); padding: 0 2px; font-size: 16px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 380px 1fr; height: calc(100vh - 56px); height: calc(100dvh - 56px); }
body.setup-hidden .layout { grid-template-columns: 1fr; }
body.setup-hidden .setup { display: none; }
.setup { overflow-y: auto; border-right: 1px solid var(--line); padding: 8px 18px 40px; background: var(--page); }
.step { padding: 16px 0 18px; border-bottom: 1px solid var(--line); }
.step.quiet { border-bottom: 0; }
.step h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font: 700 16px/1.3 var(--ui); }
.num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--panel-2); font: 800 13px/1 var(--round); }

.results { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; max-height: 260px; overflow-y: auto; }
.results button {
  width: 100%; display: grid; grid-template-columns: 1fr auto; text-align: left; gap: 2px 10px;
  background: transparent; color: var(--text); font-weight: 500; padding: 8px 10px; border-radius: var(--r-s);
}
.results button:hover, .results button[aria-current="true"] { background: var(--panel); }
.results .r-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .r-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .r-dur { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; }
.results .r-tag { font-size: 12px; text-align: right; color: var(--voice); }
.results .r-tag.plain { color: var(--muted); }

.tabs { display: flex; gap: 4px; background: var(--ink); padding: 4px; border-radius: var(--r-s); }
.tabs button { flex: 1; background: transparent; color: var(--muted); font-weight: 500; padding: 6px; }
.tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--text); font-weight: 700; }
.pane { margin-top: 12px; }
.drop {
  display: grid; gap: 4px; padding: 18px 16px; border: 1.5px dashed rgba(214, 208, 255, 0.3); border-radius: var(--r-m);
  cursor: pointer; text-align: center; transition: border-color 0.15s, background 0.15s;
}
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop:focus-within, .drop.over { border-color: var(--voice); background: rgba(90, 216, 234, 0.06); }
.drop .muted { font-size: 13px; }
details.sub { margin-top: 12px; font-size: 14px; }
details.sub summary { cursor: pointer; color: var(--muted); }
.progress { margin-top: 10px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.progress .bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--ink); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--voice); transition: width 0.2s; }
.progress .hint { margin: 0; }
.meter { margin-top: 10px; height: 6px; border-radius: 3px; background: var(--ink); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--voice); }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--ink); }
.stage-top { display: flex; gap: 12px; padding: 12px 16px 8px; align-items: stretch; }
.hud { flex: 1; display: flex; align-items: center; gap: 22px; flex-wrap: wrap; min-width: 0; }
.hud-score { display: flex; flex-direction: column; line-height: 1; }
.hud-score span { font: 800 34px/1 var(--round); font-variant-numeric: tabular-nums; }
.hud-score small, .hud-note small { color: var(--muted); font-size: 12px; }
.hud-note { display: flex; gap: 18px; }
.hud-note div { display: flex; flex-direction: column; }
.hud-note b { font: 800 22px/1.1 var(--round); min-width: 3.2ch; }
.hud-note #hudYou.hit { color: var(--gold); }
.hud-note #hudYou.miss { color: var(--coral); }
.gauge { width: 180px; }
.gauge-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.gauge-track { position: relative; height: 12px; border-radius: 6px; background: var(--panel); }
.gauge-zone { position: absolute; left: 37.5%; width: 25%; top: 0; bottom: 0; background: rgba(255, 200, 61, 0.25); border-radius: 6px; }
.gauge-needle { position: absolute; top: -3px; width: 4px; height: 18px; margin-left: -2px; left: 50%; border-radius: 2px; background: var(--muted); transition: left 0.06s linear; }
.gauge-needle.hit { background: var(--gold); }
.gauge-needle.miss { background: var(--coral); }
.hud-timing { font: 800 16px/1 var(--round); min-width: 9em; opacity: 0; transition: opacity 0.2s; }
.hud-timing.show { opacity: 1; }
.hud-timing.on { color: var(--gold); }
.hud-timing.off { color: var(--coral); }
.embed { position: relative; width: 320px; flex: none; }
.embed-box { width: 100%; aspect-ratio: 16 / 9; border-radius: var(--r-s); overflow: hidden; background: #000; }
.embed-box iframe { width: 100%; height: 100%; border: 0; display: block; }
.embed.spotify .embed-box { aspect-ratio: auto; height: 152px; background: transparent; }
.embed.collapsed .embed-box { height: 0; aspect-ratio: auto; overflow: hidden; }
.embed-toggle { position: absolute; right: 6px; bottom: -30px; }
.embed.collapsed .embed-toggle { position: static; }

.highway-wrap { position: relative; flex: 1; min-height: 220px; margin: 0 16px; border-radius: var(--r-m); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
#highway { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 20px; pointer-events: none; }
.empty p { margin: 4px 0; }

/* Two-line karaoke lyrics: first line left, second line right, wipe fills in pink. */
.lyrics { position: relative; padding: 14px 28px 6px; min-height: 132px; display: grid; gap: 6px; }
.lyr { display: flex; align-items: center; gap: 10px; min-height: 52px; white-space: nowrap; overflow: hidden; }
.lyr.slot1 { justify-content: flex-end; }
.lyr .txt { position: relative; font: 800 34px/1.25 var(--round); letter-spacing: 0.01em; }
.lyr .base { color: #fff; -webkit-text-stroke: 5px #120f2a; paint-order: stroke fill; }
.lyr .fill { position: absolute; inset: 0; color: var(--wipe); -webkit-text-stroke: 5px #120f2a; paint-order: stroke fill; clip-path: inset(-10px calc(100% - var(--p, 0%)) -10px -10px); }
.lyr.done .txt { opacity: 0.45; }
.lyr.next .txt { opacity: 0.8; }
.lyr .count { display: inline-flex; gap: 5px; }
.lyr .count i { width: 10px; height: 10px; border-radius: 50%; background: var(--wipe); }
.plain { max-height: 160px; overflow-y: auto; white-space: pre-line; color: var(--muted); font-size: 16px; }

.timeline-wrap { display: flex; align-items: center; gap: 10px; padding: 6px 16px; }
#timeline { flex: 1; height: 30px; cursor: pointer; display: block; min-width: 0; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 3em; }
.time:last-child { text-align: right; }

.controls { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px; padding: 6px 16px 16px; align-items: center; }
.transport { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.transport .round { width: 42px; height: 42px; border-radius: 50%; padding: 0; font-variant-numeric: tabular-nums; }
.transport .play { height: 46px; min-width: 104px; border-radius: 23px; background: var(--gold); color: var(--ink); font: 800 16px/1 var(--round); }
.transport .active { box-shadow: inset 0 0 0 1.5px var(--voice); color: var(--voice); }
.mixer { display: grid; grid-template-columns: auto 120px auto 120px; gap: 6px 10px; align-items: center; font-size: 14px; }
.mixer-note { grid-column: 1 / -1; margin: 0; }
.switch { display: flex; gap: 8px; align-items: center; cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); max-width: min(560px, calc(100vw - 32px));
  background: var(--text); color: var(--ink); padding: 10px 16px; border-radius: var(--r-s); font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--coral); }

/* ---------- report ---------- */
.report { position: fixed; inset: 0; overflow-y: auto; background: var(--page); z-index: 40; }
.rep { max-width: 1120px; margin: 0 auto; padding: 24px 24px 80px; }
.rep-head { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.rep-head h1 { margin: 0; font: 700 18px/1.3 var(--ui); color: var(--muted); }
.rep-score { font: 800 clamp(64px, 11vw, 120px)/0.95 var(--round); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin: 6px 0 4px; }
.rep-score small { font-size: 0.32em; letter-spacing: 0; margin-left: 6px; color: var(--muted); }
.rep-delta { color: var(--muted); font-size: 14px; }
.rep-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.radar { width: 300px; height: 280px; }
.radar text { fill: var(--text); font: 500 12px var(--ui); }
.radar .v { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.rep-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0; margin: 20px 0 8px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.rep-grid div { padding: 12px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.rep-grid dt { color: var(--muted); font-size: 13px; }
.rep-grid dd { margin: 2px 0 0; font: 800 22px/1.2 var(--round); font-variant-numeric: tabular-nums; }
.rep-grid dd small { font: 500 13px var(--ui); color: var(--muted); margin-left: 4px; }
.rep h2 { font: 700 20px/1.3 var(--ui); margin: 36px 0 6px; }
.rep h2 + .hint { margin-top: 0; margin-bottom: 12px; }
.recs { list-style: none; counter-reset: rec; padding: 0; margin: 12px 0 0; display: grid; gap: 14px; }
.recs li { counter-increment: rec; display: grid; grid-template-columns: 34px 1fr; gap: 2px 12px; }
.recs li::before { content: counter(rec); grid-row: span 3; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--panel-2); font: 800 14px/1 var(--round); }
.recs b { font-size: 16px; }
.recs p { margin: 0; color: var(--muted); }
.recs .drill { color: var(--text); }
.recs .drill::before { content: "Try: "; color: var(--voice); font-weight: 700; }
.strengths { margin: 10px 0 0; padding-left: 20px; }
.overview-scroll { overflow-x: auto; border-radius: var(--r-m); box-shadow: inset 0 0 0 1px var(--line); background: var(--ink); position: relative; }
.overview-scroll canvas { display: block; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 8px; border-radius: 4px; display: inline-block; }
.legend i.line { height: 2px; border-radius: 1px; }
.tip { position: fixed; pointer-events: none; background: var(--text); color: var(--ink); padding: 6px 10px; border-radius: var(--r-s); font-size: 13px; max-width: 280px; z-index: 60; }
.charts2 { display: grid; grid-template-columns: 3fr 2fr; gap: 28px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart svg text { fill: var(--muted); font: 11px var(--ui); }
.chart .bar-hit { cursor: default; }
.lines-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
.lines-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.lines-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lines-table td.lyric { font-weight: 700; }
.lines-table td.tnum { font-variant-numeric: tabular-nums; white-space: nowrap; }
.listen { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.history { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 8px 22px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.history b { color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  body.setup-hidden .layout { grid-template-columns: 1fr; }
  .setup { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; }
  .stage { min-height: calc(100dvh - 56px); }
  .highway-wrap { min-height: 38vh; }
  .stage-top { flex-direction: column-reverse; }
  .embed { width: 100%; }
  .embed-toggle { position: static; margin-top: 6px; }
  .lyr .txt { font-size: 24px; }
  .lyrics { padding: 10px 16px 4px; min-height: 100px; }
  .lyr { min-height: 38px; }
  .gauge { width: 140px; }
  .mixer { grid-template-columns: auto 1fr; width: 100%; }
  .rep-head { grid-template-columns: 1fr; }
  .charts2 { grid-template-columns: 1fr; }
  .top .chips { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
