:root {
  --bg: #0e1014;
  --panel: #161920;
  --panel-2: #1d2129;
  --line: #2a2f3a;
  --text: #e8e6e1;
  --muted: #9aa0ab;
  --accent: #e9a23b;
  --accent-ink: #1a1206;
  --danger: #ef6a5b;
  --ok: #6fcf97;
  --radius: 10px;
  --player-h: 84px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
a:hover { color: var(--accent); }
h1 { font-size: 1.7rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
h3 { margin: 0 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { color: var(--accent); }
.pre { white-space: pre-line; }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); letter-spacing: .2em; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; height: calc(100vh - var(--player-h)); }
.sidebar {
  display: flex; flex-direction: column; gap: 2px; padding: 18px 12px;
  background: var(--panel); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.2rem; text-decoration: none; padding: 4px 10px 18px; letter-spacing: -.01em; }
.brand.big { font-size: 1.6rem; justify-content: center; padding-bottom: 8px; }
.brand-mark { color: var(--accent); font-size: 1.3em; line-height: 1; }
.nav-link { display: block; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav-link:hover { background: var(--panel-2); color: var(--text); }
.nav-link.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav-user { padding: 8px 12px; }
.main { overflow-y: auto; outline: none; }
.page { max-width: 1100px; margin: 0 auto; padding: 28px 32px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.page-head .actions { margin: 0; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #3a4150; color: var(--text); background: #232834; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #f4b354; color: var(--accent-ink); }
.btn.subtle { background: transparent; border-color: transparent; color: var(--muted); }
.btn.subtle:hover { color: var(--text); background: var(--panel-2); }
.btn.small { padding: 4px 9px; font-size: .82rem; }
.btn.round { width: 38px; height: 38px; padding: 0; border-radius: 50%; flex: none; font-size: .9rem; }
.btn.wide { width: 100%; padding: 11px; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.linklike:hover { color: var(--accent); }

input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); outline: none; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=number] { width: 90px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label.check, label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.form { display: flex; flex-direction: column; gap: 14px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { padding: 0 6px; color: var(--muted); font-size: .85rem; }
.history-opts { display: flex; flex-direction: column; gap: 10px; }
.history-opts[hidden], [hidden] { display: none !important; }
.form-error { color: var(--danger); margin: 0; min-height: 1em; }

.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 8px 0 6px; }
.progress-fill { height: 100%; background: var(--accent); }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); margin-right: 8px; vertical-align: 1px; }
.badge.alt { color: var(--accent); border-color: #4a3b22; }

/* ---------- art ---------- */
.art, .hero-art, .ep-art, .result-art { display: block; object-fit: cover; background: var(--panel-2); border-radius: 8px; }
.art-empty { display: grid; place-items: center; color: var(--muted); font-size: 1.6rem; }

/* ---------- home / runs ---------- */
.run-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.run-card { display: flex; gap: 14px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.run-card-art .art { width: 96px; height: 96px; }
.run-card-body { flex: 1; min-width: 0; }
.run-card-title { font-weight: 600; text-decoration: none; font-size: 1.02rem; }
.run-card-next { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.run-next-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-card-next > div { min-width: 0; }

.empty-state { padding: 28px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); max-width: 640px; }
.empty-state h3 { color: var(--text); }

/* ---------- library ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 20px; margin-top: 8px; }
.tile { text-decoration: none; display: flex; flex-direction: column; gap: 4px; }
.tile .art { width: 100%; aspect-ratio: 1; transition: transform .15s; }
.tile:hover .art { transform: translateY(-2px); box-shadow: 0 8px 24px #0008; }
.tile-title { font-weight: 600; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- podcast / run hero ---------- */
.hero { display: flex; gap: 24px; align-items: flex-start; margin-bottom: 8px; }
.hero-art { width: 200px; height: 200px; flex: none; box-shadow: 0 10px 30px #0009; }
.hero-text { flex: 1; min-width: 0; }
.hero-text h1 { margin-bottom: 4px; }
.desc { margin-top: 10px; color: var(--muted); max-width: 70ch; }
.desc summary { cursor: pointer; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 2rem 0 .75rem; }
.toolbar h2 { margin: 0; }
.search-small { width: 180px; }

/* ---------- episode rows ---------- */
.ep-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.ep-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.ep-row:hover { background: #ffffff05; }
.ep-art { width: 44px; height: 44px; flex: none; }
.ep-main { flex: 1; min-width: 0; padding-top: 2px; }
.ep-title { font-weight: 500; }
.ep-title.heard { color: var(--muted); }
.ep-meta { margin-top: 2px; }
.ep-main .progress { max-width: 260px; }
.ep-desc { margin-top: 6px; color: var(--muted); max-width: 80ch; }
.ep-desc:empty { display: none; }
.ep-actions { display: flex; gap: 4px; flex: none; opacity: .75; }
.ep-row:hover .ep-actions, .ep-actions:focus-within { opacity: 1; }
.ep-list.compact .ep-row { padding: 10px 4px; }

/* ---------- search ---------- */
.search-big { width: 100%; font-size: 1.1rem; padding: 12px 14px; margin-bottom: 8px; }
.results { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }
.result { display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 8px; }
.result:hover { background: var(--panel); }
.result-art { width: 56px; height: 56px; flex: none; }
.result-text { flex: 1; min-width: 0; }

/* ---------- auth ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }

/* ---------- modal ---------- */
.modal { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, 94vw); max-height: 90vh; }
.modal.wide { width: min(640px, 94vw); }
.modal::backdrop { background: #000a; }
.modal-body { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-body h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.preview { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 4px; min-height: 3em; font-size: .9rem; }
.preview ol { margin: 6px 0 0; padding-left: 22px; }
.preview p { margin: 4px 0 0; }

/* ---------- settings ---------- */
.device-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); max-width: 720px; }
.device-row { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.device-icon { font-size: 1.3rem; width: 28px; text-align: center; }
.device-main { flex: 1; min-width: 0; }
.device-main .badge { margin-left: 8px; }
.pair-code {
  font: 600 2.4rem/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .12em;
  text-align: center; padding: 18px; margin: 4px 0; border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
  user-select: all;
}
.pair.expired .pair-code { opacity: .35; text-decoration: line-through; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--player-h) + 16px); transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 10px 30px #000a; opacity: 0; pointer-events: none; transition: .2s; max-width: min(560px, 92vw); z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: #6b2e28; }

/* ---------- player bar ---------- */
.playerbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--player-h);
  display: grid; grid-template-columns: minmax(200px, 1fr) minmax(320px, 2fr) minmax(80px, 1fr); align-items: center; gap: 16px;
  padding: 0 18px; background: #12141a; border-top: 1px solid var(--line); z-index: 5;
}
.playerbar.empty > * { visibility: hidden; }
.pb-now { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pb-art .art { width: 56px; height: 56px; }
.pb-text { min-width: 0; }
.pb-title { display: block; font-weight: 600; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-sub { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pb-controls { display: flex; align-items: center; gap: 10px; }
.pb-btn { background: none; border: 0; color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.pb-btn:hover { background: var(--panel-2); }
.pb-play { width: 40px; height: 40px; border-radius: 50%; background: var(--text); color: var(--bg); font-size: .9rem; }
.pb-play:hover { background: #fff; }
.pb-seek { display: flex; align-items: center; gap: 10px; width: 100%; }
.pb-time { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 52px; text-align: center; }
.pb-scrub { flex: 1; accent-color: var(--accent); padding: 0; border: 0; background: none; }
.pb-right { display: flex; justify-content: flex-end; }
.pb-speed { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 10px; font: inherit; font-size: .85rem; cursor: pointer; font-variant-numeric: tabular-nums; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  :root { --player-h: 128px; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 4px 8px; }
  .nav-user { display: none; }
  .page { padding: 18px 14px 32px; }
  .hero { flex-direction: column; }
  .hero-art { width: 140px; height: 140px; }
  .playerbar { grid-template-columns: 1fr auto; grid-template-rows: auto auto; padding: 8px 12px; gap: 6px; }
  .pb-center { grid-column: 1 / -1; grid-row: 2; }
  .ep-actions { flex-direction: column; }
}
