:root {
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #1f2228;
  --border: #2a2e36;
  --text: #e9ebee;
  --muted: #9aa1ac;
  --accent: #8b8aff;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f8;
    --surface: #ffffff;
    --surface-2: #eeeef2;
    --border: #dcdde3;
    --text: #17181c;
    --muted: #666c77;
    --accent: #4f46e5;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
h1, h2, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); font-size: 0.875rem; }
.wordmark { font-weight: 800; letter-spacing: 0.14em; font-size: 1.05rem; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.bar .ghost, .back { color: var(--muted); font-size: 0.9rem; }
.bar .ghost { margin-left: auto; white-space: nowrap; }
.bar .ghost:hover, .back:hover { color: var(--text); }
.player .bar .wordmark { margin-left: auto; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--surface-2); color: var(--text); }

/* Theme filter */
.themes { display: flex; gap: 8px; padding: 14px 16px 2px; overflow-x: auto; scrollbar-width: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.8rem; color: var(--muted); white-space: nowrap;
}
a.chip:hover { color: var(--text); }
.chip.active { background: var(--surface-2); color: var(--text); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--theme, var(--muted)); flex: none; }

/* Library grid */
.grid {
  display: grid; gap: 20px; padding: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card:hover { border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.badge {
  position: absolute; padding: 2px 6px; border-radius: 6px;
  font-size: 0.72rem; font-weight: 600; background: rgb(0 0 0 / 0.72); color: #fff;
}
.badge.duration { right: 8px; bottom: 8px; font-variant-numeric: tabular-nums; }
.badge.watched { left: 8px; top: 8px; }
.badge.pending { left: 8px; bottom: 8px; }
.card-body { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px 14px; }
.card-body h2 {
  font-size: 0.98rem; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot { display: flex; align-items: center; gap: 8px; min-height: 24px; }
.star { color: #f5b301; }
.empty { padding: 80px 16px; text-align: center; color: var(--muted); display: grid; gap: 12px; }
.empty a { color: var(--accent); }

/* Login */
.login { max-width: 340px; margin: 18vh auto 0; padding: 0 20px; display: grid; gap: 14px; }
.login .wordmark { font-size: 1.6rem; }
.login input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; width: 100%;
}
.primary { background: var(--accent); color: #fff; border-radius: 10px; padding: 11px 12px; text-align: center; font-weight: 600; }
.primary:disabled { opacity: 0.6; cursor: default; }
.form-error { color: #ff6b6b; font-size: 0.875rem; min-height: 1.3em; }

/* Player */
.player-main {
  display: grid; gap: 20px; padding: 16px;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
  align-items: start; max-width: 1500px; margin: 0 auto;
}
.stage { display: grid; gap: 10px; }
.stage video, .no-video { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); display: block; }
.no-video { display: grid; place-items: center; color: #9aa1ac; }
.stage h1 { font-size: 1.3rem; line-height: 1.25; margin-top: 4px; }
.stage a { color: var(--accent); }
.tldr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; font-size: 0.95rem; }
.pane {
  position: sticky; top: 64px;
  display: flex; flex-direction: column;
  height: calc(100vh - 80px); height: calc(100dvh - 80px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.pane-tabs { display: flex; border-bottom: 1px solid var(--border); }
.pane-tabs button { flex: 1; text-align: center; padding: 10px; color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.pane-tabs button.active { color: var(--text); box-shadow: inset 0 -2px var(--accent); }
.pane-body { position: relative; flex: 1; overflow-y: auto; padding: 8px; }
.time { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; flex: none; min-width: 3.2em; padding-top: 2px; }

.chapter { padding: 8px; border-radius: 10px; }
.chapter + .chapter { margin-top: 4px; }
.chapter.active { background: var(--surface-2); }
.row { display: flex; gap: 8px; width: 100%; }
.chapter-title { font-weight: 600; }
.row:hover .chapter-title { color: var(--accent); }
.summary { margin: 6px 0 0 calc(3.2em + 8px); font-size: 0.9rem; color: var(--muted); }
.insights { margin: 8px 0 0 calc(3.2em + 8px); display: grid; gap: 6px; }
.insight { font-size: 0.9rem; padding-left: 12px; border-left: 2px solid var(--border); }
.insight:hover { border-left-color: var(--accent); }

.segment { display: flex; gap: 8px; width: 100%; padding: 6px 8px; border-radius: 8px; font-size: 0.92rem; }
.segment:hover { background: var(--surface-2); }
.segment.active { background: var(--surface-2); box-shadow: inset 2px 0 var(--accent); }

@media (max-width: 900px) {
  .player-main { grid-template-columns: minmax(0, 1fr); padding: 0 0 16px; gap: 12px; }
  /* Flatten the stage so the picture can stay pinned under the bar for the
     whole page, not just while the title is on screen. */
  .stage { display: contents; }
  .stage > * { margin: 0 14px; }
  .stage > video, .stage > .no-video { position: sticky; top: 49px; z-index: 4; margin: 0; border-radius: 0; }
  .pane { position: static; height: auto; margin: 0 14px; }
  .pane-body { max-height: none; overflow: visible; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 12px; }
  .bar { gap: 10px; }
}
