:root {
  --bg: #121212;
  --bg-elevated: #1c1c1e;
  --bg-card: #1e1e20;
  --text: #f2f2f2;
  --text-dim: #9a9a9c;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --border: #2c2c2e;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f5f5f7;
  --bg-card: #f0f0f2;
  --text: #1a1a1a;
  --text-dim: #6e6e73;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --border: #d8d8dc;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.view:not([hidden]) {
  animation: viewIn 0.18s ease;
}

button, select, input { font-family: inherit; }

/* ── Sticky header ──────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.brand {
  flex: 1;
  font-weight: 600;
  font-size: 16px;
}

.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}

.sleep-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}
.sleep-btn:active { background: var(--accent-soft); }
.sleep-btn.sleep-active { color: var(--accent); }

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.theme-toggle:active { background: var(--accent-soft); }

/* ── Player bar ─────────────────────────────────────────── */
.player-bar {
  padding: 12px 20px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

/* Now-playing title sits above the seek bar so you always know what's playing
   (and can see it change on auto-advance). */
.player-now {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
  min-width: 0;
}
.player-ep-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-ep-sub {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  flex: none;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctrl-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctrl-btn:active { background: var(--accent-soft); }

.ctrl-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  padding: 0;
}
.ctrl-play:active { opacity: 0.85; background: var(--accent); }
.ctrl-play .icon-play { margin-left: 2px; }

/* Progress range input */
.progress-bar {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--pct, 0%),
    var(--border) var(--pct, 0%),
    var(--border) 100%
  );
  outline: none;
  cursor: pointer;
}
.progress-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.progress-bar::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
.progress-bar::-moz-range-progress {
  background: var(--accent);
  height: 4px;
  border-radius: 2px;
}

.player-time {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  flex: none;
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
  padding: 2px 4px;
}
.player-time:hover { color: var(--accent); }

.player-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.player-selects {
  display: flex;
  gap: 6px;
  flex: none;
}

.meta-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  max-width: 110px;
}

.speed-control {
  display: flex;
  align-items: center;
  flex: none;
  height: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  touch-action: manipulation;
}

.speed-arrow {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  width: 30px;
  height: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: background 0.1s, color 0.1s;
}
.speed-arrow:hover { background: var(--accent-soft); color: var(--accent); }
.speed-arrow:active { background: var(--accent); color: #fff; }

#btn-speed-down { border-right: 1px solid var(--border); }
#btn-speed-up   { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }

.speed-slider {
  width: 80px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  margin: 0 10px;
  flex: none;
}
.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.speed-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.speed-input {
  width: 38px;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  outline: none;
  padding: 0 2px 0 6px;
}
.speed-input:focus { background: var(--accent-soft); color: var(--accent); }

.speed-unit {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 0 8px 0 2px;
  white-space: nowrap;
  user-select: none;
}

/* ── Settings panel ─────────────────────────────────────── */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}
.setting-label { font-size: 14px; font-weight: 500; }
.setting-select { max-width: 160px; }
.setting-hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
  margin: 10px 0 0;
}
.setting-value { font-size: 14px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.setting-toggle { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.setting-btn-danger {
  margin-top: 14px;
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: #ef4444;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.setting-btn-danger:active { background: var(--accent-soft); }

/* ── Views ──────────────────────────────────────────────── */
.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

/* ── Continue banner ────────────────────────────────────── */
.continue-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  cursor: pointer;
}
.continue-banner:active { background: var(--accent-soft); }
.continue-info { flex: 1; min-width: 0; }
.continue-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 4px;
}
.continue-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 8px;
}
.continue-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.continue-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.continue-play {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ── Module list ────────────────────────────────────────── */
/* --- Subject picker (landing screen) --- */
.subjects-intro { margin: 4px 0 22px; }
.subjects-title { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 4px; }
.subjects-sub { color: var(--text-dim); font-size: 15px; margin: 0; }

.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.subject-tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  text-align: left;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}
.subject-tile:hover { border-color: var(--accent); background: var(--bg-elevated); }
.subject-tile:active { transform: scale(0.99); }
.subject-name { font-weight: 700; font-size: 17px; }
.subject-meta { font-size: 13px; color: var(--text-dim); }
.subject-track {
  display: block;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-top: 4px;
}
.subject-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.module {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  margin-bottom: 10px;
  overflow: hidden;
}

.module-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}
.module-toggle {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  color: var(--text);
  padding: 6px 4px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.module-toggle:active { background: var(--accent-soft); }
.module-start {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.module-name { font-weight: 600; font-size: 14px; }
.module-meta {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}
.module-chev {
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  transition: transform 0.15s ease;
}
.module.open .module-chev { transform: rotate(90deg); }

.module-progress-track {
  height: 2px;
  background: var(--border);
}
.module-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}

.module-episodes {
  display: none;
  border-top: 1px solid var(--border);
}
.module.open .module-episodes { display: block; }

.episode-row {
  display: grid;
  grid-template-columns: 22px 1fr 28px 28px 36px;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.episode-row:first-child { border-top: none; }
.episode-row:active { background: var(--accent-soft); }

.ep-index { font-size: 13px; color: var(--text-dim); }
.ep-index.ep-done { color: #22c55e; font-weight: 700; font-size: 15px; }
.ep-row-done .ep-title { color: var(--text-dim); }
.ep-main { min-width: 0; }
.ep-title {
  display: block;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ep-progress-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.ep-progress-fill { height: 100%; background: var(--accent); width: 0%; }

.ep-play {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ── Episode view ───────────────────────────────────────── */
.episode-heading {
  font-size: 20px;
  font-weight: 700;
  margin: 4px 0 16px;
  line-height: 1.3;
}

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.tab-btn.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.markdown-body {
  font-size: 16px;
  line-height: 1.75;
}
.markdown-body p { margin: 0 0 1em; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5 {
  line-height: 1.3;
  margin: 1.6em 0 0.5em;
  font-weight: 700;
}
.markdown-body h1 { font-size: 1.5em; }
.markdown-body h2 { font-size: 1.25em; }
.markdown-body h3 { font-size: 1.1em; }

.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin: 0 0 1em; }
.markdown-body li { margin-bottom: 0.3em; }

.markdown-body blockquote {
  margin: 1em 0;
  padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  color: var(--text-dim);
}

/* Code blocks */
.markdown-body pre {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 1em 0;
  overflow: hidden;
}
.markdown-body pre code {
  display: block;
  padding: 16px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.6;
  background: transparent;
  border-radius: 0;
  /* Custom scrollbar for code */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.markdown-body pre code::-webkit-scrollbar { height: 4px; }
.markdown-body pre code::-webkit-scrollbar-track { background: transparent; }
.markdown-body pre code::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Inline code */
.markdown-body code:not(pre code) {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 0.875em;
}

/* Copy button */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 5px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  font-family: var(--font);
}
.markdown-body pre:hover .copy-btn,
.markdown-body pre:focus-within .copy-btn { opacity: 1; }
/* Always visible on touch devices */
@media (hover: none) { .copy-btn { opacity: 0.55; } }
.copy-btn:hover { opacity: 1; }
.copy-btn:active { background: var(--accent); color: #fff; border-color: var(--accent); }
.copy-btn.copied { background: #16a34a; color: #fff; border-color: #16a34a; opacity: 1; }

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 14px;
}
.markdown-body th, .markdown-body td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.markdown-body th { background: var(--bg-card); font-weight: 600; }
.markdown-body tr:nth-child(even) td { background: var(--bg-card); }

.markdown-body img { max-width: 100%; border-radius: 8px; }

/* ── Icon buttons (stats, queue) ────────────────────────── */
.icon-btn {
  position: relative;
  background: none;
  border: none;
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:active { background: var(--accent-soft); }

.queue-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 14px;
  height: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
}

/* ── Episode row enhancements ───────────────────────────── */
.ep-title-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.ep-title-row .ep-title { flex: 1; }
.ep-duration {
  font-size: 11px;
  color: var(--text-dim);
  flex: none;
  white-space: nowrap;
}

.ep-queue-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.ep-queue-btn:active { background: var(--accent-soft); }
.ep-queue-btn.in-queue {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  font-size: 12px;
}

/* ── Download buttons (episode + module) ────────────────── */
.ep-dl-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.ep-dl-btn:active { background: var(--accent-soft); }
.ep-dl-btn.dl-done {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.module-dl {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.module-dl.dl-done { color: var(--accent); }

/* Spinner shown while a download is in progress */
.dl-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: dl-spin 0.7s linear infinite;
}
@keyframes dl-spin { to { transform: rotate(360deg); } }

/* ── Offline banner ─────────────────────────────────────── */
.offline-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #92400e;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  padding: 5px 12px;
}
/* Offline: visually de-emphasise play on episodes that aren't downloaded. */
body.offline .episode-row:not(.ep-downloaded) .ep-play { opacity: 0.4; }

/* ── Toast (download errors, status) ────────────────────── */
.toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
  z-index: 60;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ── Auto-advance toast ─────────────────────────────────── */
.advance-toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
  z-index: 50;
  min-width: 280px;
  max-width: calc(100vw - 32px);
}
.advance-info { flex: 1; min-width: 0; }
.advance-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  display: block;
  margin-bottom: 2px;
}
.advance-title {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.advance-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.advance-countdown {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  min-width: 20px;
  text-align: center;
}
.advance-cancel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.advance-cancel:active { background: var(--accent-soft); }

/* ── Stats overlay ──────────────────────────────────────── */
.stats-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.stats-panel {
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 20px 36px;
}
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.stats-heading {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}
.stats-close {
  background: var(--bg-card);
  border: none;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.stats-content { font-size: 14px; }

/* On wider screens, center the panel as a modal instead of a bottom sheet. */
@media (min-width: 640px) {
  .stats-overlay { align-items: center; }
  .stats-panel {
    border-radius: 16px;
    max-height: 85vh;
    margin: 0 16px;
  }
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
@media (min-width: 480px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.stats-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.stats-module { margin-bottom: 14px; }
.stats-module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
}
.stats-module-count { color: var(--text-dim); font-size: 12px; }
.stats-module-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.stats-module-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ── Quiz ───────────────────────────────────────────────── */

.quiz-empty {
  padding: 40px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

.quiz-picker-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  font-size: 12px;
}
.qps-count { color: var(--text-dim); }
.qps-score { color: var(--accent); font-weight: 600; }
.qps-due {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.quiz-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 420px) {
  .quiz-modes { grid-template-columns: 1fr; }
}

.quiz-mode-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 16px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.quiz-mode-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.quiz-mode-btn:active { background: var(--accent-soft); }
.quiz-mode-btn.qmb-disabled { opacity: 0.45; cursor: default; }
.quiz-mode-btn.qmb-disabled:hover { border-color: var(--border); background: var(--bg-card); }

.qmb-icon { font-size: 28px; margin-bottom: 10px; }
.qmb-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.qmb-desc { font-size: 12px; color: var(--text-dim); line-height: 1.4; }

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.quiz-exit-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
}
.quiz-exit-btn:hover { color: var(--text); }
.quiz-progress-text { font-size: 12px; color: var(--text-dim); }

.quiz-progress-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 24px;
}
.quiz-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.quiz-q-text {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  margin: 0 0 20px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.quiz-option {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: left;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  line-height: 1.45;
  transition: border-color 0.12s, background 0.12s;
}
.quiz-option:not([disabled]):hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.quiz-option:not([disabled]):active { background: var(--accent-soft); }
.quiz-option.opt-correct {
  border-color: #16a34a;
  background: rgba(22, 163, 74, 0.12);
  color: #16a34a;
  font-weight: 600;
}
.quiz-option.opt-wrong {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.10);
  color: #dc2626;
}
.quiz-option.opt-dim { opacity: 0.4; }

.quiz-feedback {
  margin-top: 4px;
  animation: viewIn 0.18s ease;
}
.quiz-feedback-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.feedback-verdict {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.verdict-correct { color: #16a34a; }
.verdict-wrong { color: #dc2626; }
.feedback-explanation {
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
  margin: 0;
}

.quiz-next-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.quiz-next-btn:active { opacity: 0.85; }

.quiz-summary {
  padding: 20px 0 40px;
  text-align: center;
}
.quiz-summary-score { margin-bottom: 32px; }
.summary-emoji { font-size: 52px; margin-bottom: 10px; }
.summary-fraction { font-size: 42px; font-weight: 700; color: var(--accent); }
.summary-pct { font-size: 16px; color: var(--text-dim); margin-top: 4px; }

.quiz-summary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
}
.quiz-action-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.quiz-action-btn:active { opacity: 0.85; }
.quiz-action-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}
.quiz-action-ghost {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
}

/* ── App footer (credit / beta / issue link) ────────────── */
.app-footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 16px calc(40px + var(--safe-bottom));
  text-align: center;
  border-top: 1px solid var(--border);
}
.beta-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 9px;
  margin-bottom: 12px;
}
.footer-disclaimer {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0 0 10px;
}
.footer-credit {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0;
}
.footer-credit a { color: var(--accent); text-decoration: none; }
.footer-credit a:hover { text-decoration: underline; }

/* ── Settings: sync section ─────────────────────────────── */
.settings-section {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 22px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.sync-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  padding: 9px 11px;
  border-radius: 8px;
  margin-bottom: 8px;
  outline: none;
}
.sync-input:focus { border-color: var(--accent); }
.sync-actions { display: flex; gap: 8px; margin-top: 4px; }
.setting-btn {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.setting-btn:active { opacity: 0.85; }
.setting-btn-ghost {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.setting-btn-ghost:active { background: var(--accent-soft); }

/* ── Stats: daily chart + voice breakdown ───────────────── */
.stats-section-title { margin-top: 24px; }
.day-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 72px;
  margin-bottom: 8px;
  padding: 0 1px;
}
.day-col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.day-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: height 0.3s ease;
}
.day-bar-empty { min-height: 3px; background: var(--border); border-radius: 2px; }
.day-bar-today { background: #22c55e; }
.voice-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.voice-name {
  width: 84px; flex: none; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.voice-track { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.voice-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.voice-time {
  width: 54px; flex: none; text-align: right;
  font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums;
}

/* Bottom-sheet drag handle — swipe the panel down to dismiss */
.stats-panel { position: relative; }
.sheet-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sheet-close:hover { color: var(--text); }
.sheet-close:active { background: var(--accent-soft); }
.q-head, .stats-header { padding-right: 40px; }

/* ── Queue panel (Spotify-style) ────────────────────────── */
/* Contained, fully-rounded card with the list scrolling inside (so the rounded
   bottom corners are always visible and the toolbar stays pinned). */
.queue-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 20px;
}
.q-head { margin-bottom: 8px; flex: none; }
.q-h-title { font-size: 26px; font-weight: 800; margin: 0; letter-spacing: -0.01em; }
.q-h-sub { font-size: 13px; color: var(--text-dim); margin: 2px 0 0; }
.q-h-sub span { color: var(--text); font-weight: 600; }
#queue-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }

.q-row, .q-now-row { position: relative; overflow: hidden; }
.q-swipe-bg {
  position: absolute;
  inset: 0;
  background: #e23b3b;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 22px;
  border-radius: 10px;
}
.q-row.q-will-remove .q-swipe-bg { background: #c92a2a; }
/* SortableJS drag states */
.q-ghost { opacity: 0.35; }
.q-chosen .q-fg { background: var(--bg-card); }
.sortable-drag .q-fg { box-shadow: 0 8px 24px rgba(0,0,0,0.4); border-radius: 10px; }
.q-fg {
  position: relative;
  background: var(--bg-elevated);
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 11px 2px;
  cursor: pointer;
  touch-action: pan-y;
  user-select: none;
}
.q-now-row .q-fg { grid-template-columns: 30px 1fr auto; cursor: default; }
.q-num {
  width: 30px;
  flex: none;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.q-num-now { color: var(--accent); display: flex; align-items: center; justify-content: center; }
.q-del {
  background: none;
  border: none;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.q-del:hover { color: #ef4444; }
.q-del:active { background: var(--accent-soft); }
.q-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.q-title {
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.q-sub {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.q-now-row .q-title { color: var(--accent); }
.q-pp {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: none;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: none;
}
.q-handle {
  color: var(--text-dim);
  display: flex; align-items: center;
  padding: 8px 6px;
  cursor: grab;
  touch-action: none;
}
.q-handle:active { cursor: grabbing; }
.q-dragging { z-index: 5; position: relative; }
.q-dragging .q-fg { background: var(--bg-card); box-shadow: 0 8px 24px rgba(0,0,0,0.4); border-radius: 8px; }

/* Bottom toolbar */
.q-toolbar {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.q-tool-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.q-tool-btn:active { background: var(--accent-soft); }

/* ── Transcript sync (Script tab) ───────────────────────── */
.sync-para {
  cursor: pointer;
  border-radius: 8px;
  padding: 3px 8px;
  margin-left: -8px;
  margin-right: -8px;
  transition: background 0.15s ease;
}
.sync-para:hover { background: var(--bg-card); }
.para-active { background: var(--accent-soft); }

/* --- Review / study hub --- */
.review-hub { display: flex; flex-direction: column; gap: 22px; }
.review-sec { display: flex; flex-direction: column; gap: 10px; }
.review-h { font-size: 15px; font-weight: 700; margin: 0; }
.review-sub { font-size: 13px; color: var(--text-dim); margin: 0; }
.review-mix-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.review-pill {
  flex: 1 1 auto; min-width: 56px; padding: 12px 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  font: 600 15px var(--font); cursor: pointer;
}
.review-pill:active { background: var(--accent-soft); border-color: var(--accent); }
.review-buckets { display: flex; gap: 8px; }
.rb { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 6px; border-radius: 10px; background: var(--bg-elevated); border: 1px solid var(--border); }
.rb-num { font-size: 22px; font-weight: 700; }
.rb-lbl { font-size: 11px; color: var(--text-dim); text-align: center; }
.rb-known .rb-num { color: #22c55e; }
.rb-weak .rb-num { color: var(--accent); }
.rb-new .rb-num { color: var(--text-dim); }
.review-drill {
  padding: 12px; border-radius: 10px; border: none; background: var(--accent); color: #fff;
  font: 600 14px var(--font); cursor: pointer;
}
.review-drill:disabled { background: var(--bg-elevated); color: var(--text-dim); cursor: default; }
.review-topics { display: flex; flex-direction: column; gap: 10px; }
.rt-row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.rt-name { font-weight: 600; }
.rt-pct { color: var(--text-dim); }
.rt-track { height: 6px; border-radius: 3px; background: var(--bg-elevated); overflow: hidden; }
.rt-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* Source label on a mixed-quiz question (which episode it's from) */
.quiz-source { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }

/* "After listening" active-recall prompt above the quiz modes */
.recall-prompt {
  background: var(--accent-soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 14px;
}
.recall-title { font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.recall-list { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text); }
.recall-list li { margin: 3px 0; }

/* Anki-style grade buttons (Again / Hard / Good / Easy) */
.grade-prompt { font-size: 12px; color: var(--text-dim); margin: 12px 0 6px; text-align: center; }
.quiz-grades { display: flex; gap: 6px; }
.grade-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px; border-radius: 10px; border: none; cursor: pointer;
  color: #fff; font: 600 14px var(--font); line-height: 1.1;
}
.grade-iv { font-size: 11px; opacity: 0.9; font-weight: 500; }
.grade-lbl { font-size: 14px; }
.g-again { background: #ef4444; }
.g-hard  { background: #f59e0b; }
.g-good  { background: #22c55e; }
.g-easy  { background: #3b82f6; }
.grade-btn:active { filter: brightness(0.88); }

/* Year 11 / Year 12 section headers in the library */
.year-header {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); margin: 20px 4px 8px;
}
.continue-banner + .year-header, .view > .year-header:first-child { margin-top: 6px; }

/* Topic chooser in the mixed-quiz launcher */
.mix-topics { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 2px; }
/* Collapsible per-subject dropdown in the study hub. */
.mix-subject { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); overflow: hidden; }
details.mix-subject > .mix-subject-sum {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  cursor: pointer; list-style: none; user-select: none;
}
.mix-subject-sum::-webkit-details-marker { display: none; }
.mix-subject-cb { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.mix-subject-name { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; }
.mix-subject-count {
  font-size: 11px; color: var(--text-dim); background: var(--bg-elevated);
  border-radius: 10px; padding: 1px 8px; flex: none;
}
.mix-sum-chev { color: var(--text-dim); font-size: 18px; line-height: 1; transition: transform 0.15s ease; flex: none; }
details.mix-subject[open] > .mix-subject-sum .mix-sum-chev { transform: rotate(90deg); }
.mix-subject-body { padding: 2px 12px 12px; border-top: 1px solid var(--border); }
.mix-topic { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.mix-topic input { width: 16px; height: 16px; accent-color: var(--accent); }
.mix-year-lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); margin-top: 6px; }
.mix-scope { display: flex; gap: 6px; flex-wrap: wrap; }
.mix-scope-btn {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font: 600 13px var(--font); cursor: pointer;
}
.mix-scope-btn.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Settings text input (learning steps) */
.setting-text {
  background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font: 500 14px var(--font); max-width: 130px; text-align: left;
}

/* ── Library search ─────────────────────────────────────── */
.library-search-wrap { max-width: 720px; margin: 0 auto; padding: 12px 16px 0; }
.library-search {
  width: 100%; box-sizing: border-box; padding: 11px 14px; font: 500 15px var(--font);
  color: var(--text); background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 10px; outline: none; -webkit-appearance: none;
}
.library-search::placeholder { color: var(--text-dim); }
.library-search:focus { border-color: var(--accent); }

/* Review-button due-count badge reuses .queue-badge; make the hidden attr win over its display:flex. */
.queue-badge[hidden] { display: none; }

/* Grey-highlight the episode that's currently loaded/playing in the library list. */
.ep-row-playing { background: var(--bg-elevated); }
.ep-row-playing .ep-title { color: var(--text); font-weight: 600; }

/* ── Respect reduced-motion preference (a11y / vestibular safety) ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
