:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --side: #efede8;
  --text: #1d1c1a;
  --muted: #6c6963;
  --line: #e2dfd8;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --hover: #f3f1ec;
  --shadow: 0 8px 30px rgba(0, 0, 0, .12);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --panel: #1f1e1c;
    --side: #1a1918;
    --text: #edebe6;
    --muted: #9a968e;
    --line: #2f2d2a;
    --accent: #f97316;
    --accent-ink: #1a0f06;
    --ok: #4ade80;
    --ok-bg: #12301d;
    --warn: #fbbf24;
    --warn-bg: #33270b;
    --danger: #f87171;
    --hover: #272522;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
a.btn { text-decoration: none; display: inline-block; color: var(--text); }
a.btn.primary { color: var(--accent-ink); }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
code { font-size: 12px; background: var(--hover); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

/* Sidebar */
.sidebar { background: var(--side); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 6px; }
.brand { font-weight: 700; font-size: 16px; padding: 0 8px 12px; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 0 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.playlist-list { list-style: none; margin: 0; padding: 0; flex: 1; }
.playlist-list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.playlist-list li:hover { background: var(--hover); }
.playlist-list li.active { background: var(--panel); box-shadow: 0 1px 0 var(--line); font-weight: 600; }
.playlist-list .count { color: var(--muted); font-weight: 400; font-size: 12px; }
.side-foot { padding: 8px; }

/* Buttons */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; border-radius: 6px; width: 30px; height: 30px; cursor: pointer; color: var(--muted); font-size: 15px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.link-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; }
.link-btn:hover { color: var(--text); }

/* Main */
.main { padding: 22px 28px 60px; max-width: 1100px; width: 100%; }
.pl-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.pl-title-wrap { flex: 1; min-width: 260px; }
.pl-name { font-size: 24px; font-weight: 700; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 2px 6px; margin-left: -7px; width: 100%; }
.pl-name:hover, .pl-name:focus { border-color: var(--line); outline: none; background: var(--panel); }
.pl-stats { color: var(--muted); margin-top: 2px; }
.pl-actions { display: flex; gap: 8px; align-items: center; }

/* Search */
.search { position: relative; margin: 20px 0 14px; }
.search-row { display: flex; gap: 8px; }
#searchInput { flex: 1; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); font-size: 15px; }
#searchInput:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px); list-style: none; margin: 0; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 420px; overflow: auto; }
.results li { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 6px 8px; border-radius: 8px; }
.results li:hover, .results li.kb { background: var(--hover); }
.results .meta { min-width: 0; }
.results .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .s { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .acts { display: flex; gap: 6px; }
.results .note { color: var(--muted); padding: 10px; grid-template-columns: 1fr; }
.art { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--hover); display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.replace-banner { margin-top: 8px; padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); display: flex; justify-content: space-between; align-items: center; }

/* Checkout */
.checkout { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.checkout .bar { flex: 1; min-width: 160px; height: 8px; border-radius: 99px; background: var(--hover); overflow: hidden; }
.checkout .bar span { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.checkout .label { font-weight: 600; }
.checkout .hint { color: var(--muted); font-size: 12.5px; width: 100%; }

/* Tracks */
.tracks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.track { display: grid; grid-template-columns: 22px 28px 44px minmax(0, 1fr) auto; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.track.dragging { opacity: .4; }
.track.drop-target { outline: 2px dashed var(--accent); outline-offset: 2px; }
.track.file-over { outline: 2px solid var(--ok); outline-offset: 2px; }
.handle { cursor: grab; color: var(--muted); text-align: center; user-select: none; }
.num { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.track .info { min-width: 0; }
.track .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track .s { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track .cue { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.track .cue input { width: 100%; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 3px 6px; margin-left: -7px; font-size: 13px; }
.track .cue input:hover, .track .cue input:focus { border-color: var(--line); background: var(--bg); outline: none; }
.track .cue input.notes { color: var(--muted); }
.track .right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.track .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pill { font-size: 12px; font-weight: 600; border-radius: 99px; padding: 3px 9px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.missing { background: var(--warn-bg); color: var(--warn); }
.pill.unconfirmed { background: var(--hover); color: var(--muted); }
.play.playing { color: var(--accent); }

.empty { color: var(--muted); text-align: center; padding: 40px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); width: min(480px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h3 { margin: 0 0 8px; }
dialog label { display: block; margin: 10px 0; font-weight: 600; font-size: 13px; }
dialog input, dialog textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-weight: 400; }
dialog textarea { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.drop-overlay { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; z-index: 50; pointer-events: none; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 420px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .playlist-list { display: flex; gap: 6px; overflow-x: auto; }
  .main { padding: 16px; }
  .track { grid-template-columns: 22px 44px minmax(0, 1fr); }
  .track .num { display: none; }
  .track .right { grid-column: 1 / -1; align-items: stretch; }
  .track .row { justify-content: flex-start; }
}
.pill.toggle { border: 0; cursor: pointer; }
.pill.toggle:hover { filter: brightness(.95); outline: 1px solid currentColor; }

/* Sign-in */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(420px, 100%); box-shadow: var(--shadow); }
.auth-card .brand { padding: 0 0 8px; font-size: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.auth-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.auth-msg { min-height: 1.4em; margin: 12px 0 0; color: var(--muted); }
.side-foot { padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.user-email { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Files */
.work { font-size: 12.5px; color: var(--accent); font-weight: 600; white-space: nowrap; }

/* Archive */
.archive-section { padding: 4px 0 8px; }
.archive-section .link-btn { padding: 6px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.playlist-list.archived { flex: none; color: var(--muted); }
#archivedBanner { margin: 16px 0 0; }

/* Bulk upload */
.bulk-dlg { width: min(720px, calc(100vw - 32px)); }
.bulk-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow: auto; }
.bulk-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 12px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.bulk-list li.unmatched { background: var(--warn-bg); }
.bulk-file { min-width: 0; }
.bulk-file .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-file .s { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-list select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; font-size: 13px; }
.bulk-list select.dupe { border-color: var(--danger); }
@media (max-width: 600px) { .bulk-list li { grid-template-columns: 1fr; } }
.results .owned { margin-left: 8px; font-size: 11px; font-weight: 600; color: var(--ok); background: var(--ok-bg); border-radius: 99px; padding: 1px 7px; }

/* Loudness */
.track .loud { margin-top: 3px; font-size: 12px; color: var(--ok); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track .loud.capped { color: var(--warn); }
.pl-actions { flex-wrap: wrap; justify-content: flex-end; }
.from-files { margin: 0 8px 10px; }
.from-label { font-size: 11.5px; margin-bottom: 4px; }
.from-buttons { display: flex; gap: 6px; }
.from-pick { display: flex; gap: 6px; align-items: center; min-width: 0; }
.from-pick select { flex: 1; min-width: 0; }
