:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --fg: #1f1b16;
  --muted: #7a7064;
  --line: #e4ddd2;
  --accent: #3d5afe;
  --accent-2: #e0702a;
  --good: #22a565;
  --warn: #e3a21a;
  --bad: #e0483e;
  --roll-bg: #fbfaf7;
  --roll-lane-dark: #f1ede6;
  --roll-grid: #ddd5c8;
  --roll-bar: #d8cfc2;
  --roll-other: rgba(122, 112, 100, 0.22);
  --roll-missed: #b9b0a4;
  --roll-sel: rgba(224, 112, 42, 0.08);
  --trace: #1f1b16;
  --s-pitch: #3d5afe;
  --s-timing: #8e5cc9;
  --s-words: #1f9e8f;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120f;
    --panel: #1d1a16;
    --fg: #f0ebe3;
    --muted: #9d9385;
    --line: #2f2a24;
    --accent: #7c8dff;
    --accent-2: #ff9a52;
    --good: #3ccf86;
    --warn: #f2bd3c;
    --bad: #ff6b5f;
    --roll-bg: #181613;
    --roll-lane-dark: #1f1c18;
    --roll-grid: #332d26;
    --roll-bar: #2d2822;
    --roll-other: rgba(200, 190, 175, 0.14);
    --roll-missed: #5a534a;
    --roll-sel: rgba(255, 154, 82, 0.08);
    --trace: #f0ebe3;
    --s-pitch: #7c8dff;
    --s-timing: #b48cf0;
    --s-words: #4cc9b7;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { font-size: 0.92em; }

.top {
  display: flex; align-items: center; gap: 20px; padding: 14px 20px;
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-family: Fraunces, Georgia, serif; font-weight: 700; font-size: 24px; margin: 0; letter-spacing: -0.01em; }
.tag { color: var(--muted); font-size: 13px; }
.song-info { flex: 1; min-width: 0; }
.song-title { font-family: Fraunces, Georgia, serif; font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.file-actions { display: flex; gap: 8px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  padding: 7px 13px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary.recording { background: var(--bad); border-color: var(--bad); }
.btn.big { padding: 9px 20px; font-size: 15px; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.controls {
  display: flex; align-items: center; gap: 22px; padding: 10px 20px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.group { display: flex; align-items: center; gap: 10px; }
.group.right { margin-left: auto; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.field.inline { margin-top: 6px; }
.field output { color: var(--fg); font-weight: 600; margin-left: 4px; }
.field select, .field input[type=range] { font: inherit; color: var(--fg); }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; font-size: 14px; color: var(--fg); max-width: 260px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--fg); cursor: pointer; }
input[type=range] { accent-color: var(--accent-2); width: 140px; }
input[type=checkbox] { accent-color: var(--accent-2); }
.hint { font-size: 11.5px; color: var(--muted); max-width: 300px; }

.meter { width: 90px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
#meterFill { height: 100%; width: 0; background: var(--good); transition: width 60ms linear; }

.panel { padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px 28px; }
.mixer-rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 24px; }
.mix-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.mix-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix-row input { width: 110px; }
.badge { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; background: var(--accent-2); color: #fff; border-radius: 4px; padding: 1px 5px; }

.stage { position: relative; flex: 1; min-height: 340px; }
#roll { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.stage-hint { position: absolute; left: 56px; bottom: 12px; pointer-events: none; opacity: 0.8; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.empty.drag .empty-card { border-color: var(--accent-2); }
.empty-card {
  background: var(--panel); border: 2px dashed var(--line); border-radius: 16px; padding: 28px 32px; max-width: 460px; text-align: center;
}
.empty-card h2 { font-family: Fraunces, Georgia, serif; margin: 0 0 8px; font-weight: 500; }
.empty-card p { color: var(--muted); margin: 0 0 18px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.live {
  position: absolute; top: 30px; right: 14px; background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; width: 200px;
  backdrop-filter: blur(6px);
}
.live-note { display: flex; flex-direction: column; }
.live-note span:last-child { font-family: Fraunces, Georgia, serif; font-size: 26px; font-weight: 700; line-height: 1.1; }
.lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.needle { grid-column: 1 / -1; position: relative; height: 10px; background: var(--line); border-radius: 5px; margin-top: 6px; }
.needle-zone { position: absolute; left: 40%; width: 20%; top: 0; bottom: 0; background: color-mix(in srgb, var(--good) 35%, transparent); border-radius: 5px; }
.needle-mark { position: absolute; top: -3px; width: 4px; height: 16px; border-radius: 2px; background: var(--fg); left: 50%; transform: translateX(-50%); transition: left 50ms linear; }
.live-cents { grid-column: 1 / -1; font-size: 12px; color: var(--muted); text-align: center; }

.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-family: Fraunces, Georgia, serif; font-size: 120px; font-weight: 700; color: var(--accent-2); opacity: 0.85;
}
.caption {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 64px; max-width: 70%;
  background: color-mix(in srgb, var(--fg) 82%, transparent); color: var(--bg); padding: 6px 14px; border-radius: 8px; font-size: 15px;
}

.results { padding: 18px 20px 28px; border-top: 1px solid var(--line); background: var(--panel); }
.cards { display: grid; grid-template-columns: 1.2fr repeat(3, 1fr) 1.4fr; gap: 12px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card .num { font-family: Fraunces, Georgia, serif; font-size: 30px; font-weight: 700; line-height: 1.1; }
.card .big-num { font-family: Fraunces, Georgia, serif; font-size: 44px; font-weight: 700; line-height: 1; }
.card .sub { font-size: 12px; color: var(--muted); }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 44px; margin-top: 4px; }
.spark div { flex: 1; max-width: 16px; background: var(--accent-2); border-radius: 2px 2px 0 0; opacity: 0.5; min-height: 2px; }
.spark div:last-child { opacity: 1; }
.result-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; margin: 8px 0; color: var(--muted); font-weight: 600; }
h3 .small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.insights, .trouble { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.insights li { padding-left: 16px; position: relative; }
.insights li::before { content: ''; position: absolute; left: 2px; top: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-2); }
.trouble li button {
  all: unset; cursor: pointer; display: flex; gap: 10px; align-items: baseline; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); width: 100%; box-sizing: border-box;
}
.trouble li button:hover { border-color: var(--accent-2); }
.trouble .bar { font-weight: 600; white-space: nowrap; }
.trouble .what { color: var(--muted); font-size: 13px; }
.word-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.w { padding: 3px 8px; border-radius: 6px; font-size: 14px; border: 1px solid transparent; }
.w.ok { background: color-mix(in srgb, var(--good) 16%, transparent); }
.w.close { background: color-mix(in srgb, var(--warn) 20%, transparent); }
.w.wrong, .w.missed { background: color-mix(in srgb, var(--bad) 16%, transparent); }
.w.missed { text-decoration: line-through; text-decoration-color: var(--bad); }
.w small { color: var(--muted); margin-left: 4px; }
.status-line { margin-top: 10px; color: var(--muted); font-size: 13px; }

/* ---------- history ---------- */
.link { all: unset; cursor: pointer; font-size: 12px; color: var(--accent); margin-top: 6px; align-self: flex-start; }
.link:hover { text-decoration: underline; }
.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.history-panel { display: flex; flex-direction: column; gap: 14px; }
.hist-empty { padding: 6px 0; }
.hist-head { display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap; }
.hist-head h3 { margin: 0 0 6px; }
.hist-part { text-transform: none; letter-spacing: 0; color: var(--fg); }
.hist-clear { margin-left: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 2px; }
.chip {
  appearance: none; font: inherit; font-size: 12px; color: var(--muted); background: transparent; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; display: inline-flex; align-items: center; gap: 6px;
}
.chip i { width: 10px; height: 3px; border-radius: 2px; background: currentColor; opacity: 0.4; }
.chip.on { color: var(--fg); border-color: var(--muted); }
.chip.on i { opacity: 1; }
.chip.s-overall.on i { background: var(--accent-2); }
.chip.s-pitch.on i { background: var(--s-pitch); }
.chip.s-timing.on i { background: var(--s-timing); }
.chip.s-words.on i { background: var(--s-words); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hist-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.stat .num { font-family: Fraunces, Georgia, serif; font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat .sub.up { color: var(--good); }
.stat .sub.down { color: var(--bad); }
.hist-chart { width: 100%; overflow: hidden; }
.hist-chart svg { display: block; }
.hist-chart .grid { stroke: var(--line); stroke-width: 1; }
.hist-chart .day { stroke: var(--line); stroke-dasharray: 2 3; }
.hist-chart .axis { fill: var(--muted); font-size: 10.5px; font-family: Inter, system-ui, sans-serif; }
.hist-chart .line { fill: none; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.hist-chart .line.s-overall { stroke: var(--accent-2); stroke-width: 2.25; }
.hist-chart .line.s-overall.faint { stroke-width: 1.25; opacity: 0.35; }
.hist-chart .line.s-overall.trend { stroke-width: 2.75; }
.hist-chart .line.s-pitch { stroke: var(--s-pitch); }
.hist-chart .line.s-timing { stroke: var(--s-timing); }
.hist-chart .line.s-words { stroke: var(--s-words); }
.hist-chart .dot { fill: var(--panel); stroke: var(--accent-2); stroke-width: 1.5; }
.hist-chart .dot:hover { fill: var(--accent-2); }
.hist-table-wrap { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.hist-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.hist-table th { position: sticky; top: 0; background: var(--panel); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.hist-table th, .hist-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.hist-table tr:last-child td { border-bottom: 0; }
.hist-table .n { text-align: right; }
.hist-table .strong { font-weight: 600; }
.hist-table .pass { white-space: normal; min-width: 120px; }
.hist-table .best { color: var(--accent-2); }
.hist-table .x { all: unset; cursor: pointer; color: var(--muted); padding: 0 4px; border-radius: 4px; font-size: 15px; line-height: 1; }
.hist-table .x:hover { color: var(--bad); }
.hist-table .x:focus-visible { outline: 2px solid var(--accent); }
.hist-table-wrap > .small { padding: 6px 10px; }

@media (max-width: 860px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .card.main, .card.history { grid-column: 1 / -1; }
  .result-cols { grid-template-columns: 1fr; }
  .group.right { margin-left: 0; }
  .live { width: 170px; }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px);
  transition: opacity 160ms, transform 160ms; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
