:root {
  --bg: #f4eee3;
  --paper: #fffbf4;
  --paper-2: #f8f1e5;
  --ink: #2f2620;
  --ink-2: #67574a;
  --ink-3: #9a8878;
  --line: #e5d9c6;
  --accent: #b0582a;
  --accent-2: #cb8442;
  --accent-soft: #f4e3d1;
  --accent-ink: #fffaf3;
  --live: #5f7f45;
  --live-soft: #e6eedb;
  --danger: #a3402f;
  --wave: #d9c7ae;
  --wave-sel: #cb8442;
  --wave-played: #8a4a22;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171411; --paper: #221d19; --paper-2: #2a241f; --ink: #f1e7d8; --ink-2: #c2b2a0; --ink-3: #8c7c6c;
    --line: #3a322b; --accent: #e0915a; --accent-2: #d99a5c; --accent-soft: #3d2c20; --accent-ink: #1d1611;
    --live: #9cc27a; --live-soft: #26301e; --danger: #e57c68; --wave: #4a4038; --wave-sel: #d99a5c; --wave-played: #f3c28f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171411; --paper: #221d19; --paper-2: #2a241f; --ink: #f1e7d8; --ink-2: #c2b2a0; --ink-3: #8c7c6c;
  --line: #3a322b; --accent: #e0915a; --accent-2: #d99a5c; --accent-soft: #3d2c20; --accent-ink: #1d1611;
  --live: #9cc27a; --live-soft: #26301e; --danger: #e57c68; --wave: #4a4038; --wave-sel: #d99a5c; --wave-played: #f3c28f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; flex: none; }
kbd { font: 11px/1 ui-monospace, Menlo, monospace; padding: 2px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; color: var(--ink-2); background: var(--paper); }
.num, .dur, .dk-times, .time-in, output { font-variant-numeric: tabular-nums; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  cursor: pointer; white-space: nowrap; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:focus-visible, .cbtn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--paper-2); filter: none; }
.btn.soft { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.btn.primary { background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; border-radius: 7px; }
.btn.icon { width: 36px; padding: 0; justify-content: center; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- 顶栏 ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--paper);
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.home { color: var(--ink-3); text-decoration: none; font-size: 12px; letter-spacing: .08em; }
.home:hover { color: var(--accent); }
.brand h1 { margin: 0; font: 600 21px/1.3 "Songti SC", "STSong", serif; letter-spacing: .04em; outline: none; border-radius: 6px; padding: 0 4px; }
.brand h1:focus { background: var(--paper-2); }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.folder-info { color: var(--ink-2); font-size: 12.5px; display: inline-flex; align-items: center; gap: 5px; margin-right: 6px; }
.folder-info button { color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }

.banner {
  margin: 14px 24px 0; padding: 14px 18px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--ink); display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
.banner[hidden] { display: none; }
.banner p { margin: 0; flex: 1 1 300px; color: var(--ink-2); }
.banner b { color: var(--ink); }

/* ---------- 布局 ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start;
  max-width: 1440px; margin: 0 auto; padding: 18px 24px 60px;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 40px; }
  .deck { order: -1; position: static !important; }
  .top { padding: 12px 16px; }
  .banner { margin: 12px 16px 0; }
}

/* ---------- 环节卡片 ---------- */
.board { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.seg { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.seg.pool { background: transparent; border-style: dashed; box-shadow: none; }
.seg.drop-on { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.seg.live { border-color: var(--live); }
.seg-h { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 14px; flex-wrap: wrap; }
.seg-no { font: 600 13px/1 ui-monospace, Menlo, monospace; color: var(--accent-2); width: 22px; }
.seg-name {
  flex: 1 1 160px; min-width: 0; font: 600 16px/1.3 "Songti SC", "STSong", serif; border: 1px solid transparent;
  background: transparent; border-radius: 6px; padding: 3px 6px; margin-left: -6px;
}
.seg-name:hover { border-color: var(--line); }
.seg-name:focus { outline: none; border-color: var(--accent-2); background: var(--paper-2); }
.seg-title { margin: 0; font: 600 15px/1.3 "Songti SC", "STSong", serif; flex: 1; }
.seg-meta { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
.seg-after { height: 28px; border: 1px solid var(--line); background: var(--paper); border-radius: 7px; padding: 0 6px; font-size: 12.5px; color: var(--ink-2); }
.seg-tools { display: flex; gap: 2px; }
.seg-tools button { width: 28px; height: 28px; border: 0; background: none; color: var(--ink-3); border-radius: 6px; cursor: pointer; display: grid; place-items: center; }
.seg-tools button:hover { background: var(--paper-2); color: var(--ink); }
.seg-tools button[disabled] { opacity: .3; cursor: default; background: none; }
.seg-tools svg { width: 16px; height: 16px; }

.songs { list-style: none; margin: 0; padding: 0 8px 8px; min-height: 8px; }
.songs .empty { color: var(--ink-3); font-size: 13px; padding: 14px 12px; border: 1px dashed var(--line); border-radius: 9px; text-align: center; }
.drop-line { height: 3px; margin: -1px 6px; background: var(--accent-2); border-radius: 2px; list-style: none; }

.song {
  --p: 0; position: relative; display: grid; grid-template-columns: 20px 34px minmax(0, 1fr) auto auto; align-items: center; gap: 8px;
  padding: 7px 8px 7px 4px; border-radius: 9px; cursor: default; user-select: none; overflow: hidden;
}
.song + .song { margin-top: 2px; }
.song:hover { background: var(--paper-2); }
.song.cued { background: var(--accent-soft); }
.song.playing { background: var(--live-soft); }
.song.playing::after { content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: calc(var(--p) * 100%); background: var(--live); }
.song.dragging { opacity: .4; }
.song.missing .t { color: var(--danger); text-decoration: line-through; }
.grip { color: var(--ink-3); cursor: grab; display: grid; place-items: center; }
.grip svg { width: 16px; height: 16px; }
.play { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--paper-2); color: var(--accent); display: grid; place-items: center; cursor: pointer; }
.play svg { width: 15px; height: 15px; }
.play:hover { background: var(--accent); color: var(--accent-ink); }
.song.playing .play { background: var(--live); color: var(--paper); }
.meta { min-width: 0; }
.meta .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .a { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .a .trim { color: var(--accent); }
.meta .note { color: var(--ink-3); font-size: 12.5px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dur { color: var(--ink-2); font-size: 13px; }
.edit-btn { width: 30px; height: 30px; border: 0; background: none; color: var(--ink-3); border-radius: 7px; cursor: pointer; display: grid; place-items: center; }
.edit-btn:hover { background: var(--paper); color: var(--accent); }
.edit-btn svg { width: 16px; height: 16px; }
.eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 11px; margin-right: 5px; vertical-align: -1px; }
.eq i { width: 2.5px; background: var(--live); border-radius: 1px; animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.3s; } .eq i:nth-child(3) { animation-delay: -.6s; }
.paused .eq i { animation-play-state: paused; }
@keyframes eq { 0%, 100% { height: 3px; } 50% { height: 11px; } }

.add-seg { align-self: flex-start; }

/* ---------- 播放台 ---------- */
.deck {
  position: sticky; top: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 18px 18px 14px; display: flex; flex-direction: column; gap: 10px;
}
.deck-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.deck-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.deck.is-playing .deck-status .dot { background: var(--live); box-shadow: 0 0 0 4px var(--live-soft); }
.deck.is-fading .deck-status .dot { background: var(--accent-2); }
.dk-seg { margin-left: auto; color: var(--accent); font-weight: 600; max-width: 55%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dk-title { font: 600 22px/1.3 "Songti SC", "STSong", serif; overflow-wrap: anywhere; }
.dk-artist { color: var(--ink-2); font-size: 13px; margin-top: -6px; min-height: 19px; }
.dk-wave { width: 100%; height: 64px; display: block; cursor: pointer; border-radius: 6px; background: var(--paper-2); }
.dk-times { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); margin-top: -4px; }
#dkRemain { font-size: 20px; font-weight: 600; color: var(--ink); }
.dk-controls { display: flex; justify-content: center; align-items: center; gap: 18px; padding: 4px 0; }
.cbtn { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.cbtn:hover { background: var(--paper-2); }
.cbtn svg { width: 22px; height: 22px; }
.cbtn.main { width: 72px; height: 72px; border: 0; background: var(--accent); color: var(--accent-ink); }
.cbtn.main svg { width: 32px; height: 32px; }
.deck.is-playing .cbtn.main { background: var(--live); }
.dk-controls2 { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.dk-controls2 .btn { justify-content: center; height: 42px; }
.dk-controls2 kbd { margin-left: 4px; }
.dk-row { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 13px; }
.dk-row input[type=range] { flex: 1; accent-color: var(--accent); }
.dk-row select { margin-left: auto; height: 28px; border: 1px solid var(--line); background: var(--paper); border-radius: 7px; }
.dk-next { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.dk-next:empty { display: none; }
.dk-next .row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dk-next .k { color: var(--ink-3); flex: none; width: 52px; }
.dk-next .v { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dk-keys { margin: 2px 0 0; color: var(--ink-3); font-size: 12px; line-height: 2; }

/* ---------- 浮层 ---------- */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); padding: 0; }
dialog::backdrop { background: rgba(30, 20, 10, .45); }
.editor { width: min(940px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
.editor[open] { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px; }
.ed-head { display: flex; align-items: center; justify-content: space-between; }
.ed-head h2 { margin: 0; font: 600 18px/1.3 "Songti SC", "STSong", serif; }
.ed-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ed-grid label, .ed-note { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.ed-grid input, .ed-note textarea, .time-in {
  border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 7px 10px; font-size: 14px; color: var(--ink);
}
.ed-grid input:focus, .ed-note textarea:focus, .time-in:focus { outline: none; border-color: var(--accent-2); }
.ed-note textarea { resize: vertical; }
.ed-wave { width: 100%; height: 150px; display: block; border-radius: 10px; background: var(--paper-2); touch-action: none; }
.ed-hint { color: var(--ink-3); font-size: 12px; margin-top: 6px; }
.ed-trim { display: flex; gap: 12px 20px; flex-wrap: wrap; align-items: center; }
.trim-box { display: flex; align-items: center; gap: 5px; }
.trim-box .lbl { color: var(--ink-2); font-size: 13px; margin-right: 2px; }
.time-in { width: 84px; text-align: center; padding: 4px 6px; }
.trim-sum { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 13px; }
.trim-sum b { color: var(--ink); }
.ed-preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cursor-at { margin-left: auto; color: var(--ink-2); font-size: 13px; }
.cursor-at b { font-variant-numeric: tabular-nums; color: var(--ink); }
.ed-fx { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.ed-fx label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.ed-fx input { flex: 1; min-width: 0; accent-color: var(--accent); }
.ed-fx output { width: 44px; text-align: right; color: var(--ink); }
.ed-foot { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.ed-file { color: var(--ink-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.spacer { flex: 1; }
@media (max-width: 720px) {
  .ed-grid, .ed-fx { grid-template-columns: 1fr; }
  .trim-sum, .cursor-at { margin-left: 0; }
}
.confirm { width: min(420px, calc(100vw - 32px)); }
.confirm[open] { padding: 20px; }
.confirm p { margin: 0 0 18px; line-height: 1.7; white-space: pre-line; }
.cf-foot { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- 提示 ---------- */
.toasts { position: fixed; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--paper); border-radius: 10px; padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }
.toast .bar { height: 3px; background: rgba(255,255,255,.2); border-radius: 2px; margin-top: 7px; overflow: hidden; }
.toast .bar i { display: block; height: 100%; width: 0; background: var(--accent-2); transition: width .2s; }

/* ---------- 空态 ---------- */
.welcome { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 34px 30px; text-align: center; box-shadow: var(--shadow); }
.welcome h2 { margin: 0 0 10px; font: 600 20px/1.4 "Songti SC", "STSong", serif; }
.welcome p { margin: 0 auto 18px; color: var(--ink-2); max-width: 520px; line-height: 1.8; }
.welcome .btn { height: 44px; padding: 0 22px; font-size: 15px; }
.welcome .fine { font-size: 12.5px; color: var(--ink-3); margin-top: 16px; margin-bottom: 0; }
