:root {
  --bg: #14161a;
  --bg-deep: #0d0f12;
  --surface: #1f232a;
  --surface-2: #262b33;
  --line: #2e333b;
  --text: #f4f1ea;
  --muted: #9aa1ab;
  --accent: #ff8a3d;
  --mute: #ffcc4d;
  --solo: #4da3ff;
  --danger: #ff5c5c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .35; cursor: default; }
input[type=text] { -webkit-user-select: text; user-select: text; }

#app { height: 100%; display: flex; flex-direction: column; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  min-height: calc(var(--safe-top) + 58px);
}
.top h1 { flex: 1; font-size: 24px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top h1.tappable { font-size: 20px; text-align: center; }
.back { color: var(--accent); font-size: 17px; padding: 8px 4px; white-space: nowrap; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; background: var(--surface); font-size: 26px; line-height: 1; display: grid; place-items: center; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px 24px; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border-radius: 14px; padding: 14px 16px; min-height: 64px;
}
.row:active { background: var(--surface-2); }
.row-colors { display: flex; gap: 3px; }
.row-colors i { width: 5px; height: 28px; border-radius: 3px; display: block; }
.row-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { color: var(--muted); font-size: 14px; }
.chev { color: var(--muted); font-size: 24px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 64px 16px; text-align: center; color: var(--muted); }
.hint { color: var(--muted); font-size: 15px; padding: 8px 4px 16px; }
.footnote { color: var(--muted); font-size: 13px; text-align: center; padding-top: 24px; }
.muted { color: var(--muted); }

.primary, .secondary {
  border-radius: 12px; padding: 14px 18px; font-weight: 600; min-height: 50px;
}
.primary { background: var(--accent); color: #14161a; }
.primary.danger { background: var(--danger); color: #fff; }
.secondary { background: var(--surface); }
.add-row { display: flex; gap: 10px; margin-top: 16px; }
.add-row > * { flex: 1; }

/* ---------- cards / transport ---------- */
.card { background: var(--surface); border-radius: 16px; padding: 14px 16px; margin-bottom: 12px; }
.tr-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.play {
  width: 60px; height: 60px; border-radius: 30px; background: var(--accent); color: #14161a;
  font-size: 22px; font-weight: 800; display: grid; place-items: center;
}
.play.on { background: var(--text); }
.small-btn { width: 44px; height: 44px; border-radius: 22px; background: var(--surface-2); font-size: 16px; }
.time { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 600; }
.loading-msg { color: var(--muted); font-size: 14px; min-height: 0; }
.loading-msg:empty { display: none; }
.loading-msg:not(:empty) { margin-top: 8px; }

.master { display: flex; align-items: center; gap: 12px; }
.master-label { font-weight: 700; width: 64px; }

/* ---------- range sliders ---------- */
input[type=range] {
  -webkit-appearance: none; appearance: none; flex: 1; height: 36px; background: transparent; --p: 0%;
  touch-action: none;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px;
  background: linear-gradient(to right, var(--fill, var(--text)) var(--p), var(--line) var(--p));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 14px; background: #fff;
  margin-top: -10px; box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
input[type=range]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--fill, var(--text)); }
input[type=range]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 14px; background: #fff; border: 0; }
.seek { width: 100%; --fill: var(--accent); }
.seek::-webkit-slider-runnable-track { background: var(--line); }
.pct { width: 36px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; }

/* ---------- stems ---------- */
.stems { display: flex; flex-direction: column; gap: 8px; }
.stem {
  background: var(--surface); border-radius: 14px; padding: 10px 12px 6px 14px;
  border-left: 6px solid var(--c); --fill: var(--c);
}
.stem.silent { opacity: .5; }
.stem-top { display: flex; align-items: center; gap: 8px; }
.stem-name {
  flex: 1; min-width: 0; text-align: left; font-weight: 600; font-size: 17px; padding: 6px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { min-width: 36px; height: 36px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--muted); padding: 0 6px; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.ms { width: 44px; height: 42px; border-radius: 10px; background: var(--surface-2); font-weight: 800; font-size: 16px; }
.ms.m.on { background: var(--mute); color: #14161a; }
.ms.s.on { background: var(--solo); color: #14161a; }
.stem-bottom { display: flex; align-items: center; gap: 10px; }

/* ---------- setlists ---------- */
.toggle-row { padding: 14px 16px; }
.switch-label { display: flex; align-items: center; gap: 12px; justify-content: space-between; font-size: 16px; }
.switch-label .muted { font-size: 14px; }
.switch {
  -webkit-appearance: none; appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line);
  position: relative; flex: none; transition: background .15s;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 13px; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.sl-list { display: flex; flex-direction: column; gap: 6px; }
.sl-row { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 12px; padding: 8px 8px 8px 14px; min-height: 58px; }
.sl-num { width: 24px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 700; }
.mini { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-2); font-size: 16px; }

/* ---------- live ---------- */
.live-top { gap: 10px; }
.live-top select {
  flex: 1; min-width: 0; height: 44px; border-radius: 12px; background: var(--surface); border: 0; padding: 0 12px; font-weight: 600;
  -webkit-appearance: none; appearance: none;
}
.lock { height: 44px; padding: 0 16px; border-radius: 12px; background: var(--surface); font-weight: 700; white-space: nowrap; }
.lock.on { background: var(--mute); color: #14161a; }
.live {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly;
  padding: 12px 20px; background: var(--bg-deep); text-align: center; overflow: hidden;
}
.live-pos { color: var(--muted); font-size: 16px; font-weight: 600; letter-spacing: .02em; }
.live-title { font-size: 34px; line-height: 1.15; font-weight: 800; max-width: 100%; overflow-wrap: anywhere; }
.live-progress { width: 100%; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.live-progress div { height: 100%; width: 0; background: var(--accent); }
.live-times { width: 100%; display: flex; justify-content: space-between; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 18px; }
.big {
  width: min(72vw, 42vh, 320px); height: min(72vw, 42vh, 320px); border-radius: 50%;
  background: var(--accent); color: #14161a; font-size: 44px; font-weight: 900; letter-spacing: .04em;
  box-shadow: 0 0 0 10px rgba(255,138,61,.15);
  transition: transform .08s;
}
.big:active { transform: scale(.97); }
.big.stop { background: var(--danger); color: #fff; box-shadow: 0 0 0 10px rgba(255,92,92,.18); }
.live-status { color: var(--mute); font-size: 15px; min-height: 20px; }
.live-next { color: var(--muted); font-size: 18px; }
.live-nav { display: flex; gap: 12px; width: 100%; }
.live-nav button { flex: 1; height: 56px; border-radius: 14px; background: var(--surface); font-size: 18px; font-weight: 700; }

/* ---------- tab bar / now playing ---------- */
.tabbar {
  display: flex; border-top: 1px solid var(--line); background: var(--bg);
  padding-bottom: var(--safe-bottom);
}
.tab { flex: 1; height: var(--tabbar-h); font-size: 15px; font-weight: 600; color: var(--muted); }
.tab.on { color: var(--accent); }
.nowbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; background: var(--surface-2);
  border-top: 1px solid var(--line);
}
.nowbar .dot { width: 10px; height: 10px; border-radius: 5px; background: var(--accent); animation: pulse 1.2s infinite; }
.nowbar-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nowbar-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.nowbar-stop { background: var(--danger); color: #fff; border-radius: 10px; padding: 8px 14px; font-weight: 700; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- modal / toast / busy ---------- */
.modal-wrap {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  padding: 0 8px calc(var(--safe-bottom) + 8px);
}
.modal {
  width: 100%; max-width: 520px; background: var(--surface); border-radius: 20px; padding: 20px;
  display: flex; flex-direction: column; gap: 14px; max-height: 85vh; overflow-y: auto;
}
.modal h2 { font-size: 20px; }
.modal-text { color: #c9ccd1; font-size: 16px; }
.modal input[type=text] { width: 100%; height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 14px; font-size: 17px; }
.actions { display: flex; gap: 10px; }
.actions button { flex: 1; min-height: 50px; border-radius: 12px; background: var(--surface-2); font-weight: 600; }
.actions button.primary { background: var(--accent); color: #14161a; }
.actions button.primary.danger { background: var(--danger); color: #fff; }
.danger-text { color: var(--danger); }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu button { min-height: 52px; border-radius: 12px; background: var(--surface-2); text-align: left; padding: 0 16px; font-weight: 600; }
.menu button.danger { color: var(--danger); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch input { display: none; }
.swatch i { display: block; width: 40px; height: 40px; border-radius: 20px; border: 3px solid transparent; }
.swatch input:checked + i { border-color: var(--text); }
.checklist { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.checklist label { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border-radius: 12px; padding: 12px 14px; min-height: 52px; }
.checklist input { width: 22px; height: 22px; accent-color: var(--accent); }
.checklist span { flex: 1; }
.checklist em { color: var(--muted); font-size: 13px; font-style: normal; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + var(--tabbar-h) + 16px); transform: translateX(-50%);
  background: var(--text); color: #14161a; padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 60;
  max-width: calc(100% - 32px); transition: opacity .3s;
}
.toast.out { opacity: 0; }
.busy { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 70; padding: 24px; }
.busy-box { background: var(--surface); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 340px; text-align: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- scrub (position) bar ---------- */
.scrub { position: relative; width: 100%; height: 40px; display: flex; align-items: center; touch-action: none; cursor: pointer; }
.scrub.disabled { opacity: .4; pointer-events: none; }
.scrub-track { width: 100%; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; pointer-events: none; }
.scrub-fill { height: 100%; width: 0; background: var(--accent); }
.scrub-knob {
  position: absolute; top: 50%; left: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 13px;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); pointer-events: none;
}
.scrub.live { height: 48px; }
.scrub.live .scrub-track { height: 10px; border-radius: 5px; }
.scrub.live .scrub-knob { width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 15px; }
.scrub.live.disabled { opacity: 1; }
.scrub.live.disabled .scrub-knob { display: none; }
.live-seek { width: 100%; display: flex; flex-direction: column; gap: 2px; }
