:root {
  --bg: #f6f5f2; --card: #ffffff; --ink: #1d1d1f; --muted: #6b6b70; --line: #e4e2dd;
  --accent: #e2483d; --ref: #9a9aa2; --you: #e2483d; --good: #2f9e64; --warn: #d98a1c;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121214; --card: #1c1c1f; --ink: #f2f2f3; --muted: #a0a0a8; --line: #2e2e33; --ref: #77777f; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
main { max-width: 860px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
h3 { margin: 20px 0 8px; font-size: 1rem; }
.sub, .hint, footer { color: var(--muted); }
.hint { font-size: 0.9rem; margin: 8px 0 0; }
footer { text-align: center; font-size: 0.85rem; margin-top: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-top: 16px; }
.hidden { display: none !important; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }
button { font: inherit; border: 0; border-radius: 999px; padding: 10px 18px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
.or { color: var(--muted); font-size: 0.9rem; }
.file, .slider { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.file input { font-size: 0.85rem; max-width: 100%; }
.slider input { width: 100%; accent-color: var(--accent); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--accent); }
.seg small { color: var(--muted); margin-left: 4px; }
.status { margin-top: 10px; font-size: 0.9rem; min-height: 1.4em; }
canvas { width: 100%; display: block; border-radius: 10px; background: var(--bg); }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.note { font-weight: 700; font-variant-numeric: tabular-nums; }
.scoreRow { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.big { font-size: 4rem; font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.big small { font-size: 1.2rem; color: var(--muted); font-weight: 500; }
.bars { flex: 1; min-width: 220px; display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 72px 1fr 36px; align-items: center; gap: 10px; font-size: 0.9rem; }
.bar div { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.6s ease; }
.bar b { text-align: right; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; }
.legend .ref::before { background: var(--ref); } .legend .you::before { background: var(--you); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.tags span { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--line); margin: 1px 4px 1px 0; font-size: 0.8rem; }
td.tags span.ok { background: color-mix(in srgb, var(--good) 20%, transparent); }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.tab { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.tab.active { background: var(--ink); color: var(--card); border-color: var(--ink); }
button.small { padding: 8px 14px; font-size: 0.9rem; margin-left: auto; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.field.narrow { max-width: 260px; margin-top: 12px; }
.field input[type=url], .field input[type=number], .field select {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); width: 100%; }
.or { margin: 10px 0 0; }
code { font-size: 0.85em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.video { position: relative; width: 100%; aspect-ratio: 16 / 9; margin-bottom: 12px; border-radius: 10px; overflow: hidden; background: #000; }
.video iframe, .video #yt { position: absolute; inset: 0; width: 100%; height: 100%; }
.video.hidden { display: none; }
.sync { margin-top: 14px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.nudge { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.nudge input { width: 110px !important; text-align: center; }
button.small2 { padding: 6px 10px; font-size: 0.85rem; }
.field.from { max-width: 210px; }
.video.small { max-width: 360px; margin: 12px 0 0; }
.cmd { margin-top: 12px; }
.cmd pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; margin: 8px 0; }
#pane-youtube > .field { margin-top: 12px; }

/* Results: plot + phrase sidebar */
#results { width: min(1200px, calc(100vw - 32px)); position: relative; left: 50%; transform: translateX(-50%); }
.resultGrid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; margin-top: 8px; align-items: start; }
@media (max-width: 900px) { .resultGrid { grid-template-columns: minmax(0, 1fr); } }
.viewBar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 8px; }
.viewBar h3 { margin: 0; }
.viewSeg label { padding: 4px 10px; font-size: 0.85rem; }
.viewSeg input { margin: 0 4px 0 0; accent-color: var(--accent); }
#pitchPlot { cursor: pointer; }
.legend .gap::before { background: color-mix(in srgb, var(--warn) 55%, transparent); height: 10px; }
.legend .extra::before { background: color-mix(in srgb, var(--accent) 35%, transparent); height: 10px; }
.phraseCol h3 { margin: 12px 0 8px; }
.phraseList { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
@media (max-width: 900px) { .phraseList { max-height: 320px; } }
.phraseList li { padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 0.88rem; border-left: 3px solid transparent; }
.phraseList li:last-child { border-bottom: 0; }
.phraseList li:hover { background: color-mix(in srgb, var(--line) 50%, transparent); }
.phraseList li.active { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.phraseList .top { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.phraseList .top b { font-weight: 600; }
.phraseList .meta { color: var(--muted); font-size: 0.8rem; }
.phraseList .tags span { display: inline-block; padding: 0 7px; border-radius: 99px; background: var(--line); margin: 3px 4px 0 0; font-size: 0.75rem; }
.phraseList .tags span.ok { background: color-mix(in srgb, var(--good) 20%, transparent); }
#pitchPlot { height: 260px; }
#live { height: 220px; }
