:root {
  --bg: #15171C;
  --panel: #1F2229;
  --panel-2: #191B21;
  --line: #2E323B;
  --line-2: #3A3F49;
  --text: #ECEAE4;
  --muted: #A3A6AE;
  --faint: #6B707B;
  --accent: #F2A541;
  --accent-ink: #15171C;
  --accent-soft: #2D2618;
  --teal: #5CC8B8;
  --danger: #F07A6A;
  --radius: 14px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Instrument Sans', 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 16px 56px; display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap-row { flex-wrap: wrap; }
.center { align-items: center; justify-content: center; }
.end { justify-content: flex-end; }
.spacer { flex: 1; }
.min0 { min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; font-size: 16px; }
.mono { font-family: var(--mono); }
.accent { color: var(--accent); }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.tight { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.label { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }

.btn { min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel); font-size: 14px; }
.btn:hover { border-color: #565c68; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.chip { min-height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2); background: transparent; font-size: 13px; }
.chip.sm { min-height: 32px; min-width: 36px; padding: 0 8px; }
.chip:hover { border-color: #565c68; }
.chip[aria-pressed="true"], .chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; font-size: 13px; }
.icon-btn { width: 44px; height: 44px; flex: none; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); font-size: 22px; display: inline-flex; align-items: center; justify-content: center; }
.select { background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; min-height: 32px; padding: 0 8px; }

.switch { width: 52px; height: 30px; flex: none; border-radius: 15px; border: none; padding: 3px; background: var(--line-2); display: flex; justify-content: flex-start; transition: background .15s; }
.switch span { width: 24px; height: 24px; border-radius: 50%; background: var(--text); display: block; }
.switch[aria-checked="true"] { background: var(--accent); justify-content: flex-end; }
.switch.teal[aria-checked="true"] { background: var(--teal); }

.segmented { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; gap: 4px; }
.seg { flex: 1; min-height: 36px; padding: 0 12px; border-radius: 8px; border: none; background: transparent; color: var(--muted); font-size: 13px; white-space: nowrap; }
.seg.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---------- upload ---------- */
.upload-grid { display: flex; flex-wrap: wrap; gap: 24px; padding-top: 24px; }
.upload-left, .upload-right { flex: 1 1 420px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.title { font-size: 28px; margin: 0; }
.upload-left > p { margin: 0; font-size: 15px; }
.drop { min-height: 320px; border: 2px dashed var(--line-2); border-radius: 16px; background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; cursor: pointer; padding: 24px; text-align: center; color: var(--accent); transition: border-color .15s, background .15s; }
.drop .drop-main { font-size: 18px; font-weight: 600; color: var(--text); }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.bar-track { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; font-size: 14px; }
.steps li { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.steps li.active, .steps li.done { color: var(--text); }
.steps li.active .step-state { color: var(--accent); font-family: var(--mono); }
.steps li.done .step-state { color: var(--teal); }
.recent { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.recent li { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.recent li:last-child { border-bottom: none; }
.recent .meta { font-family: var(--mono); color: var(--muted); white-space: nowrap; }

/* ---------- app ---------- */
.app-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.file-info { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 320px; }
.logo { width: 44px; height: 44px; flex: none; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; }
.song-name { font-size: 20px; font-weight: 700; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 16px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.num-input { flex: 1; min-width: 0; height: 44px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); text-align: center; font-family: var(--mono); font-size: 26px; font-weight: 700; -moz-appearance: textfield; }
.num-input::-webkit-outer-spin-button, .num-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.big-num { font-size: 22px; font-weight: 700; }
.key-display { flex: 1; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.key-name { font-size: 34px; font-weight: 700; line-height: 1.1; }

.beat-dots { display: flex; gap: 10px; }
.beat-dot { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 700; font-size: 14px; border: 1px solid var(--line-2); color: var(--muted); background: var(--bg); transition: background .05s; }
.beat-dot.down { border: 2px solid var(--teal); color: var(--teal); }
.beat-dot.lit { background: var(--teal); color: var(--accent-ink); border-color: var(--teal); }
.beat-dots.off .beat-dot { color: var(--faint); border-color: var(--line); background: var(--bg); }

.transport { gap: 14px; }
.play-btn { width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.processing { color: var(--accent); font-family: var(--mono); }
.wave { width: 100%; height: 72px; display: block; cursor: pointer; touch-action: none; }

.chord-area { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.chords-card { flex: 999 1 600px; gap: 16px; }
.side { flex: 1 1 280px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (min-width: 900px) { .side { position: sticky; top: 16px; } }

.bars { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.bar { position: relative; min-height: 76px; padding: 10px 12px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); text-align: left; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; overflow: hidden; }
.bar:hover { border-color: #565c68; }
.bar .num { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.bar .chs { display: flex; gap: 6px; font-family: var(--mono); font-size: 18px; font-weight: 700; }
.bar .ch { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .ch.cont { color: var(--faint); font-weight: 500; }
.bar.edited .num::after { content: ' · 已修改'; color: var(--accent); }
.bar.past { opacity: .62; }
.bar.active { background: var(--accent-soft); border: 2px solid var(--accent); padding: 9px 11px 11px; opacity: 1; }
.bar .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); width: 0; }
.bar.in-loop { box-shadow: inset 0 0 0 1px var(--teal); }
.editing .bar { border-style: dashed; }
.bar.pickup .num { color: var(--faint); }

.timeline-wrap { overflow-x: auto; padding-bottom: 6px; }
.timeline { position: relative; height: 92px; }
.tl-seg { position: absolute; top: 0; height: 64px; border-radius: 6px; background: #2A2E37; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; border: none; padding: 0 4px; }
.tl-seg.active { background: var(--accent); color: var(--accent-ink); }
.tl-bar { position: absolute; top: 68px; font-size: 11px; color: var(--muted); font-family: var(--mono); }
.tl-head { position: absolute; top: -2px; width: 2px; height: 70px; background: var(--text); pointer-events: none; }

.now-card { border-color: var(--accent); }
.now-chord { font-size: 48px; font-weight: 700; color: var(--accent); line-height: 1.05; min-height: 52px; overflow-wrap: anywhere; }
.next-card { flex-direction: row; align-items: center; justify-content: space-between; }
.next-chord { font-size: 28px; font-weight: 700; }
.diagram { min-height: 200px; display: flex; align-items: center; justify-content: center; }
.diagram svg { width: 100%; max-width: 220px; height: auto; }
.diagram .none { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 12px; border: 1px dashed var(--line-2); border-radius: 10px; width: 100%; }

.dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 16px; padding: 22px; width: min(520px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog form { display: flex; flex-direction: column; gap: 14px; }
.dialog h2 { margin: 0; }
.dialog p { margin: 0; }
.edit-beats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
.edit-beats label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.edit-beats input { height: 44px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg); font-family: var(--mono); font-size: 18px; font-weight: 700; text-align: center; min-width: 0; }
.edit-beats input.bad { border-color: var(--danger); }

@media (max-width: 520px) {
  .wrap { padding: 16px 12px 48px; gap: 16px; }
  .bars { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .now-chord { font-size: 40px; }
  .beat-dot { width: 34px; height: 34px; }
}
