/* Tokens match the videos (video/style-bible.md §3). */
:root {
  --canvas: #f3f4f8;
  --canvas-dot: #dadde6;
  --surface: #ffffff;
  --border: #e6e8ee;
  --text: #14161c;
  --text-muted: #6b7080;
  --skeleton: #e4e6ec;
  --accent: #3b6ef5;
  --accent-strong: #2c5ad8;
  --accent-soft: #e7eeff;
  --mint: #d6f2e6;
  --mint-text: #1d7a52;
  --radius-card: 20px;
  --radius-control: 12px;
  --shadow-float: 0 24px 48px -12px rgba(20, 22, 28, 0.12), 0 2px 6px rgba(20, 22, 28, 0.04);
  --shadow-soft: 0 1px 2px rgba(20, 22, 28, 0.05);
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background-color: var(--canvas);
  background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px);
  background-size: 24px 24px;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px;
  background: rgba(243, 244, 248, 0.86);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13px; letter-spacing: 0.02em;
}
.brand-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.course-progress { display: flex; align-items: center; gap: 12px; flex: none; }
.course-progress-label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.topbar-link { margin-left: 8px; color: var(--text-muted); font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap; }
.topbar-link:hover { color: var(--text); }
.meter { width: 160px; height: 6px; border-radius: 999px; background: var(--skeleton); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.4s var(--ease); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px 48px;
  align-items: start;
}

/* ---------- Stage ---------- */
.eyebrow {
  margin: 0 0 12px;
  font-size: 13px; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.eyebrow b { color: var(--accent); font-weight: 500; }
.eyebrow .sep { color: var(--canvas-dot); }

.player {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: #0f1116;
  box-shadow: var(--shadow-float);
}
.player video[hidden], .stream-frame[hidden], .video-missing[hidden] { display: none; }
.stream-frame { position: absolute; inset: 0; }
.stream-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.video-missing { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--canvas); color: var(--text-muted); text-align: center; }
.video-missing p { margin: 0; font-size: 16px; }
.player video { display: block; width: 100%; height: 100%; object-fit: contain; background: var(--canvas); }

/* Up next overlay */
.up-next {
  position: absolute; inset: 0;
  display: grid; place-items: center; padding: 20px;
  background: rgba(243, 244, 248, 0.82);
  backdrop-filter: blur(10px);
  animation: fade 0.3s var(--ease);
}
.up-next[hidden] { display: none; }
.up-next-card {
  display: flex; gap: 22px; align-items: center;
  width: min(640px, 100%);
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
  animation: rise 0.45s var(--ease);
}
.up-next-poster { width: 240px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); flex: none; }
.up-next-poster[hidden] { display: none; }
.up-next-body { min-width: 0; }
.up-next-kicker { margin: 0; font-size: 13px; color: var(--accent); font-weight: 500; }
.up-next-title { margin: 4px 0 4px; font-size: 21px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.25; }
.up-next-meta { margin: 0 0 16px; font-size: 13px; color: var(--text-muted); }
.up-next-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.countdown { width: 18px; height: 18px; transform: rotate(-90deg); flex: none; }
.countdown circle { fill: none; stroke-width: 3; }
.countdown-track { stroke: rgba(255, 255, 255, 0.35); }
.countdown-ring { stroke: #fff; stroke-linecap: round; stroke-dasharray: 62.83; stroke-dashoffset: 0; }
.countdown[hidden] { display: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  font-weight: 500; font-size: 14px;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), opacity 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover { border-color: #cfd3dd; }
.btn:disabled { opacity: 0.4; cursor: default; }

/* Chapter strip */
.chapters-strip {
  display: flex; gap: 4px;
  margin-top: 18px;
  height: 28px;
  align-items: center;
}
.seg {
  position: relative;
  height: 8px; min-width: 6px;
  border: 0; padding: 0;
  border-radius: 999px;
  background: var(--skeleton);
  cursor: pointer;
  overflow: visible;
  transition: height 0.2s var(--ease);
}
.seg::before { content: ""; position: absolute; inset: -10px 0; } /* bigger hit area */
.seg-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: #a9bdf7; }
.seg.done .seg-fill { width: 100%; }
.seg.current { height: 12px; }
.seg.current .seg-fill { background: var(--accent); }
.seg:hover { height: 12px; }
.seg-tip {
  position: absolute; bottom: calc(100% + 10px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 6px 10px; border-radius: 8px;
  background: var(--text); color: #fff; font-size: 12px; white-space: nowrap;
  pointer-events: none; opacity: 0; display: none;
  transition: opacity 0.15s, transform 0.15s var(--ease);
  z-index: 2;
}
.seg:hover .seg-tip, .seg:focus-visible .seg-tip { display: block; opacity: 1; transform: translateX(-50%) translateY(0); }
.seg:first-child .seg-tip { left: 0; transform: translateY(4px); }
.seg:first-child:hover .seg-tip { transform: none; }
.seg:last-child .seg-tip { left: auto; right: 0; transform: translateY(4px); }
.seg:last-child:hover .seg-tip { transform: none; }

.strip-meta {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 6px;
  font-size: 13px; color: var(--text-muted);
}
.strip-meta span:last-child { text-align: right; }
.strip-meta b { color: var(--text); font-weight: 500; }

.lesson-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 20px;
  margin-top: 22px; padding-top: 22px;
  border-top: 1px solid var(--border);
}
.lesson-title { margin: 0; font-size: 28px; font-weight: 500; letter-spacing: -0.02em; line-height: 1.2; }
.lesson-metaphor { margin: 6px 0 0; color: var(--text-muted); }
.lesson-nav { display: flex; gap: 8px; flex: none; }
.lesson-draft { display: inline-block; margin: 0 0 10px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 13px; font-weight: 500; }
.lesson-draft[hidden] { display: none; }
.resources { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--border); }
.resources-title { margin: 0 0 12px; font-size: 18px; font-weight: 500; }
.resource-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.resource { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-control); }
.resource-body { min-width: 0; }
.resource-name { margin: 0; font-weight: 500; }
.resource-note { margin: 3px 0 0; color: var(--text-muted); font-size: 14px; }
.resource-text { display: block; margin-top: 8px; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.resource-actions { display: flex; gap: 8px; flex: none; }
.resource-actions a.btn { color: inherit; text-decoration: none; }
.resource-actions a.btn[hidden] { display: none; }
@media (max-width: 640px) {
  .resource { flex-direction: column; align-items: flex-start; }
}

/* ---------- Outline ---------- */
.outline {
  position: sticky; top: 84px;
  max-height: calc(100vh - 108px);
  overflow: auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
}
.outline-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 2px 6px 12px; }
.outline-head h2 { margin: 0; font-size: 15px; font-weight: 500; }
.outline-sub { font-size: 13px; color: var(--text-muted); }

.module-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.module { border-radius: 14px; transition: background 0.2s var(--ease); }
.module.active { background: var(--canvas); }
.module-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px; border: 0; background: none; text-align: left; cursor: pointer;
  border-radius: 14px;
}
.module-btn:hover { background: rgba(20, 22, 28, 0.03); }
.module.active .module-btn:hover { background: none; }
.badge {
  position: relative; flex: none;
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 13px; font-weight: 500;
  background: var(--canvas); color: var(--text-muted);
  border: 1px solid var(--border);
}
.module.active .badge { background: var(--surface); }
.badge svg { position: absolute; inset: -1px; width: 34px; height: 34px; transform: rotate(-90deg); }
.badge circle { fill: none; stroke-width: 2.5; }
.badge .ring { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.4s var(--ease); }
.module.complete .badge { background: var(--mint); border-color: var(--mint); color: var(--mint-text); }
.module-text { min-width: 0; flex: 1; }
.module-kicker { display: block; font-size: 12px; color: var(--text-muted); }
.module-title { display: block; font-weight: 500; line-height: 1.3; }
.module-lock { flex: none; width: 15px; height: 15px; fill: none; stroke: var(--text-muted); stroke-width: 1.5; }
.module.locked .module-title { color: var(--text-muted); }
.module-time { font-size: 12px; color: var(--text-muted); flex: none; font-variant-numeric: tabular-nums; }

.chapter-list { list-style: none; margin: 0; padding: 2px 10px 10px 56px; display: none; }
.module.open .chapter-list { display: block; }
.chapter-btn {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 8px; border: 0; background: none; text-align: left; cursor: pointer;
  border-radius: 10px; font-size: 14px; color: var(--text-muted);
}
.chapter-btn:hover { background: rgba(20, 22, 28, 0.04); color: var(--text); }
.chapter-btn::before {
  content: ""; position: absolute; left: -27px; top: -8px; bottom: -8px; width: 2px; background: var(--border);
}
.chapter-list li:first-child .chapter-btn::before { top: 50%; }
.chapter-list li:last-child .chapter-btn::before { bottom: 50%; }
.dot {
  position: absolute; left: -32px; top: 50%; transform: translateY(-50%);
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--canvas-dot);
}
.chapter.done .dot { background: var(--accent); border-color: var(--accent); }
.chapter.current .dot { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); background: var(--surface); }
.chapter.current .chapter-btn { color: var(--text); font-weight: 500; background: var(--surface); box-shadow: var(--shadow-soft); }
.chapter-label { font-family: var(--mono); font-size: 12px; color: var(--accent); flex: none; min-width: 24px; }
.chapter-name { flex: 1; min-width: 0; }
.chapter-time { font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.now-playing { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; flex: none; }
.now-playing i { width: 3px; background: var(--accent); border-radius: 2px; animation: eq 0.9s ease-in-out infinite; }
.now-playing i:nth-child(2) { animation-delay: -0.3s; }
.now-playing i:nth-child(3) { animation-delay: -0.6s; }
.paused .now-playing i { animation-play-state: paused; }

.module.soon { opacity: 0.55; }
.module.soon .module-btn { cursor: default; }
.module.soon .module-btn:hover { background: none; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--canvas); color: var(--text-muted); border: 1px solid var(--border); flex: none; }
.divider { margin: 10px 10px 6px; font-size: 12px; color: var(--text-muted); }

.reset { margin: 14px 6px 2px; padding: 0; border: 0; background: none; font-size: 12px; color: var(--text-muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.reset:hover { color: var(--text); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 12px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .outline { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .meter { width: 72px; }
  .course-progress-label { display: none; }
  .layout { padding: 16px 16px 40px; gap: 20px; }
  .player { border-radius: 14px; }
  .lesson-head { flex-direction: column; }
  .lesson-title { font-size: 22px; }
  .up-next { padding: 10px; }
  .up-next-card { padding: 14px; gap: 12px; }
  .up-next-poster { display: none; }
  .up-next-title { font-size: 16px; }
  .up-next-meta { margin-bottom: 10px; }
  .btn { height: 36px; padding: 0 12px; }
  .strip-meta { flex-direction: column; gap: 2px; }
  .strip-meta span:last-child { text-align: left; }
}
