:root {
  --bg: #f6f7f6;
  --surface: #ffffff;
  --text: #17201d;
  --muted: #5f6b67;
  --line: #e2e6e4;
  --accent: #0f766e;
  --accent-soft: #d8efec;
  --warn-bg: #fff4e0;
  --warn-text: #8a4b00;
  --danger: #c0392b;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --mini-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #18201e;
    --text: #e8eeec;
    --muted: #97a39f;
    --line: #2a3431;
    --accent: #2dd4bf;
    --accent-soft: #123a35;
    --warn-bg: #3a2a10;
    --warn-text: #f5c27a;
    --danger: #ff7b6b;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
body.has-player { padding-bottom: calc(96px + var(--mini-h) + env(safe-area-inset-bottom)); }

button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { min-width: 44px; min-height: 44px; font-size: 24px; border-radius: 10px; color: var(--muted); }
.icon-btn:active { background: var(--line); }
.net-badge { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn-text); }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }

/* Cards, lists */
.card {
  display: block; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 14px;
}
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card.continue { border-color: var(--accent); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.card-title { font-weight: 600; font-size: 17px; margin: 2px 0; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.section-head h2 { margin: 0; font-size: 17px; }
.link { color: var(--accent); font-weight: 600; min-height: 44px; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 0; border-bottom: 1px solid var(--line); min-height: 60px; }
.row:last-child { border-bottom: 0; }
a.row { padding: 10px 12px 10px 16px; }
.row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 0 10px 16px; }
a.row .row-main { display: block; padding: 0; }
.row-title { display: block; font-weight: 500; overflow-wrap: anywhere; }
.chev { color: var(--muted); font-size: 22px; }

.episode .ep-index { width: 28px; flex: none; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.episode .ep-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.episode.current { background: var(--accent-soft); }
.episode.current .ep-index, .episode.current .row-title { color: var(--accent); }
.episode.done .row-title { color: var(--muted); }
.episode.unavailable { opacity: .45; }
.badge { margin-left: 8px; color: var(--accent); font-weight: 600; }
.dl-status { margin-left: 8px; color: var(--accent); }
.dl-status:empty { display: none; }

.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar.thin { height: 3px; margin-top: 2px; display: block; }
.bar-fill { height: 100%; background: var(--accent); border-radius: inherit; }

.empty { text-align: center; padding: 32px 16px; }
.banner { display: block; padding: 12px 14px; border-radius: 12px; margin: 0 0 14px; background: var(--accent-soft); color: var(--text); }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; margin-top: 8px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06201d; } }

.form { display: flex; flex-direction: column; gap: 14px; }
.form > .btn { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .login-card label { font-weight: 600; font-size: 14px; }
input[type="text"], input[type="url"], input[type="password"], select {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
input[type="file"] { padding: 10px 0; }
input:disabled { opacity: .5; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.upload-progress { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); overflow-wrap: anywhere; }

/* Floating add button */
.fab {
  position: fixed; right: 18px; z-index: 20;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: var(--shadow);
}
body.has-player .fab { bottom: calc(18px + var(--mini-h) + env(safe-area-inset-bottom)); }
@media (prefers-color-scheme: dark) { .fab { color: #06201d; } }

/* Mini player */
.miniplayer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center;
  min-height: var(--mini-h);
  padding: 0 8px env(safe-area-inset-bottom) 0;
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow);
}
.mini-bar { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--line); }
.mini-bar > div { height: 100%; width: 0; background: var(--accent); }
.mini-open { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: left; padding: 10px 16px; }
.mini-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-toggle { width: 52px; height: 52px; border-radius: 50%; font-size: 20px; background: var(--accent-soft); color: var(--accent); }

/* Full player */
.player-sheet {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg); overflow-y: auto; text-align: center;
}
.sheet-close { align-self: stretch; font-size: 28px; color: var(--muted); min-height: 44px; }
.sheet-art {
  width: min(56vw, 220px); aspect-ratio: 1; margin: 12px auto;
  display: grid; place-items: center; font-size: 72px;
  border-radius: 28px; background: var(--accent-soft);
}
.sheet-title { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.p-range { width: 100%; max-width: 520px; margin-top: 16px; accent-color: var(--accent); height: 32px; }
.p-times { width: 100%; max-width: 520px; display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.p-controls { display: flex; align-items: center; justify-content: center; gap: 28px; margin: 12px 0; }
.p-skip { width: 64px; height: 64px; font-size: 30px; color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.p-skip small { font-size: 11px; color: var(--muted); }
.p-toggle { width: 80px; height: 80px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 30px; box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .p-toggle { color: #06201d; } }
.p-extra { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.pill { min-height: 44px; padding: 0 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-variant-numeric: tabular-nums; }
.pill.active { border-color: var(--accent); color: var(--accent); }

/* Action sheet */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; justify-content: center; }
.action-sheet {
  width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.action-title { padding: 12px 16px; color: var(--muted); font-size: 14px; text-align: center; overflow-wrap: anywhere; }
.action { display: block; width: 100%; min-height: 52px; padding: 0 16px; text-align: center; font-size: 17px; border-top: 1px solid var(--line); }
.action.danger { color: var(--danger); }
.action.cancel { font-weight: 600; margin-top: 6px; border-top: 6px solid var(--bg); }

/* Toast */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 60;
  bottom: calc(90px + var(--mini-h) + env(safe-area-inset-bottom));
  max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: #1f2a27; color: #fff; text-align: center; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login-card h1 { margin: 0 0 8px; }
.login-card label { text-align: left; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
