:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #20242d;
  --line: #2c313c;
  --text: #e8eaf0;
  --muted: #8b93a3;
  --accent: #f5b544;
  --good: #22c55e;
  --bad: #ef4444;
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: rgba(15, 17, 21, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; }
.ver { font-weight: 400; font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 12px; }
.tab-btn { border: 0; background: none; padding: 6px 12px; border-radius: 9px; color: var(--muted); cursor: pointer; }
.tab-btn.active { background: var(--panel-2); color: var(--text); }

main { max-width: 860px; margin: 0 auto; padding: 12px 16px 40px; }
.tab { display: none; }
.tab.active { display: block; }

.songbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
select, input, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
select { flex: 1 1 220px; min-width: 0; }

.stage { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.card {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; align-items: center; text-align: center;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
  min-width: 0;
}
.card-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); align-self: stretch; text-align: left; }
.chord-name { font-size: clamp(56px, 16vw, 104px); font-weight: 800; line-height: 1; margin: 4px 0 6px; }
.chord-name.small { font-size: clamp(32px, 8vw, 52px); color: var(--muted); }
.diagram { width: min(150px, 60%); color: var(--text); }
.diagram.small { width: min(90px, 80%); color: var(--muted); }
.diagram svg { display: block; width: 100%; height: auto; }
.progress { align-self: stretch; height: 6px; background: var(--panel-2); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); }

.card.active { border-color: var(--accent); }
.card.hit { border-color: var(--good); background: color-mix(in srgb, var(--good) 16%, var(--panel)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 25%, transparent); }
.card.hit .chord-name { color: var(--good); }
.card.hit .progress > div { background: var(--good); }
.card.miss { border-color: var(--bad); }
.card.miss .chord-name { color: var(--bad); }
.card.count .chord-name { color: var(--accent); }

#lane { display: block; width: 100%; height: 116px; margin: 12px 0; background: var(--panel); border-radius: 12px; }

.modebar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.seg { display: flex; background: var(--panel); padding: 4px; border-radius: 12px; gap: 2px; flex: 1 1 320px; }
.seg button { flex: 1; border: 0; background: none; color: var(--muted); padding: 7px 6px; border-radius: 9px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.seg button.active { background: var(--accent); color: #1b1405; font-weight: 700; }
.speed { display: flex; align-items: center; gap: 4px; background: var(--panel); border-radius: 12px; padding: 4px; }
.speed button { width: 34px; height: 32px; border: 0; border-radius: 9px; background: var(--panel-2); cursor: pointer; font-size: 18px; }
.speed span { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
#modeHint { margin: 6px 2px 12px; }

.card.demo { border-color: #5b8def; }
.card.demo .card-label { color: #9db8ef; }

.strum {
  display: grid; gap: 4px; margin-top: 12px; background: var(--panel); border-radius: 12px; padding: 8px;
}
.strum .slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 8px; padding: 4px 0; background: var(--panel-2); transition: background-color .1s, transform .1s;
}
.strum .g { font-size: clamp(22px, 6vw, 34px); font-weight: 800; line-height: 1.1; }
.strum .n { font-size: 12px; color: var(--muted); }
.strum .rest { background: transparent; }
.strum .rest .g { color: #4b5567; }
.strum .mute .g { color: #c9b8ff; }
.strum .demo .g { color: #9db8ef; }
.strum .hit { background: color-mix(in srgb, var(--good) 35%, var(--panel-2)); }
.strum .ok { background: color-mix(in srgb, var(--accent) 35%, var(--panel-2)); }
.strum .miss { background: color-mix(in srgb, var(--bad) 35%, var(--panel-2)); }
.strum .now { outline: 2px solid var(--accent); transform: scale(1.06); }
.arrows { color: var(--text); letter-spacing: 2px; }
.strum .bass .g { color: #7dd3fc; }
.strum.dense { gap: 2px; padding: 6px; }
.strum.dense .g { font-size: clamp(15px, 3.6vw, 26px); }
.strum.dense .n { font-size: 10px; }

.lyrics { margin-top: 12px; background: var(--panel); border-radius: 12px; padding: 10px 14px; text-align: center; }
.lyrics[hidden] { display: none; }
.ly { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; min-height: 1.4em; }
.ly .chunk { display: inline-flex; flex-direction: column; align-items: flex-start; }
.ly .chunk b { font-size: .7em; color: var(--accent); font-weight: 700; min-height: 1.2em; padding-right: 4px; }
.ly.cur { font-size: clamp(20px, 4.6vw, 30px); font-weight: 600; margin: 4px 0; }
.ly.cur .chunk.past span { color: var(--muted); }
.ly.cur .chunk.on span { color: var(--good); }
.ly.cur .chunk.on b { color: var(--good); }
.ly.prev, .ly.next { font-size: 15px; color: var(--muted); }
.ly .chunk.word span { padding: 0 .45em; }
.ly.cur .chunk.word.on span { background: color-mix(in srgb, var(--good) 22%, transparent); border-radius: 8px; }
.ly-section { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); min-height: 1.2em; }
.ly.prev b, .ly.next b { color: #6b7385; }
.empty { text-align: center; padding: 40px 12px; }
.empty[hidden], #trainBody[hidden] { display: none; }

.hear { background: var(--panel); border-radius: 12px; padding: 10px 12px; }
.hear-row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 15px; }
.stats { color: var(--muted); font-size: 14px; margin-top: 6px; }
.stats b { color: var(--text); }
.meter { position: relative; height: 6px; background: var(--panel-2); border-radius: 3px; margin: 8px 0; overflow: hidden; }
.meter > div:first-child { height: 100%; width: 0; background: var(--good); transition: width .05s; }
.meter .thr { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); }
.chroma { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; height: 54px; align-items: end; }
.chroma .bar { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.chroma .bar i { display: block; width: 100%; background: #4b5567; border-radius: 3px 3px 0 0; min-height: 2px; }
.chroma .bar.on i { background: var(--accent); }
.chroma .bar span { font-size: 10px; color: var(--muted); margin-top: 2px; }

.controls { display: flex; justify-content: center; margin: 14px 0; }
button.primary {
  border: 0; background: var(--accent); color: #1b1405; font-weight: 700;
  padding: 12px 28px; border-radius: 999px; font-size: 18px; cursor: pointer; min-width: 180px;
}
button.primary.stop { background: var(--panel-2); color: var(--text); }
button.ghost { border: 1px solid var(--line); background: none; padding: 10px 18px; border-radius: 999px; cursor: pointer; }

.settings { background: var(--panel); border-radius: 12px; padding: 10px 14px; }
.settings summary { cursor: pointer; color: var(--muted); }
.settings label { display: block; margin: 12px 0; font-size: 14px; }
.settings output { float: right; color: var(--muted); }
.settings input[type=range] { width: 100%; padding: 0; accent-color: var(--accent); }
.settings .check { display: flex; gap: 8px; align-items: center; }

.card.big { padding: 20px; margin: 8px 0 12px; }
.card.big .chord-name { font-size: clamp(72px, 22vw, 140px); }
.top3 { display: flex; gap: 16px; justify-content: center; list-style: none; padding: 0; margin: 0 0 12px; color: var(--muted); }

.song-list { list-style: none; padding: 0; margin: 0 0 20px; }
.song-list li {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--panel);
  border-radius: 12px; margin-bottom: 8px;
}
.song-list .t { flex: 1; min-width: 0; }
.song-list .t small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-list button { border: 1px solid var(--line); background: none; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.song-list button.play { background: var(--accent); color: #1b1405; border: 0; font-weight: 700; }

.editor { background: var(--panel); border-radius: 12px; padding: 14px; }
.editor h2 { margin: 0 0 8px; font-size: 18px; }
.editor label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
.editor input, .editor textarea { display: block; width: 100%; margin-top: 4px; color: var(--text); }
.editor textarea { font-family: ui-monospace, Consolas, monospace; resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.hint { font-size: 13px; color: var(--muted); }
.hint code { color: var(--text); }
.error { color: var(--bad); min-height: 1em; margin: 4px 0; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal.hidden { display: none; }
.modal-box { background: var(--panel); border-radius: var(--radius); padding: 22px; max-width: 360px; width: 100%; text-align: center; }
.modal-box h2 { margin: 0; }
.res-big { font-size: 64px; font-weight: 800; color: var(--good); }
.modal-box .row { justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(30px); opacity: 0;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px;
  max-width: calc(100% - 32px); transition: .2s; pointer-events: none; z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 520px) {
  .top { flex-direction: column; align-items: stretch; gap: 8px; }
  .tabs { justify-content: stretch; }
  .tab-btn { flex: 1; padding: 6px 4px; }
  .seg button { font-size: 13px; padding: 7px 2px; }
  .speed { margin-left: auto; }
  .stage { grid-template-columns: 1.6fr 1fr; gap: 8px; }
  button.primary { width: 100%; }
}

.transport { gap: 10px; align-items: center; }
.transport .primary { min-width: 170px; }
button.round { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 18px; cursor: pointer; flex: none; }
.seekbar { display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.seekbar input { flex: 1; min-width: 0; padding: 0; accent-color: var(--accent); background: none; border: 0; }
@media (max-width: 520px) { .transport .primary { width: auto; flex: 1; min-width: 0; } }
