:root {
  --bg: #1a1511;
  --panel: #241c17;
  --panel-alt: #2f251e;
  --text: #f1e7da;
  --text-dim: #b8a58e;
  --accent: #d99a52;
  --accent-ink: #2a1a0c;
  --border: #3c2f24;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Native subtitle cues: give the burned-in text room to breathe above the frame edge */
video::cue {
  background-color: rgba(20, 14, 9, 0.82);
  color: #f8f1e6;
  font-size: 1.05em;
  line-height: 1.5;
  padding: 0.15em 0.4em;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
  color: var(--text-dim);
  font-weight: 600;
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-col {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.episode-title {
  flex: 0 0 auto;
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: clamp(18px, 2.2vw, 26px);
  line-height: 1.25;
  color: var(--text);
  margin: 0 0 10px 0;
  letter-spacing: -0.01em;
}

video {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border-radius: 12px;
  background: #000;
  display: block;
  object-fit: contain;
}

/* Chapter rail: timeline directly under the video, ticks positioned by timestamp % of duration */
.chapter-rail {
  flex: 0 0 auto;
  position: relative;
  height: 30px;
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chapter-rail .tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: var(--text-dim);
  opacity: 0.55;
  border: none;
  padding: 0;
  cursor: pointer;
}

.chapter-rail .tick:hover,
.chapter-rail .tick:focus-visible {
  opacity: 1;
  background: var(--accent);
}

.chapter-rail .tick.active {
  opacity: 1;
  width: 4px;
  margin-left: -2px;
  background: var(--accent);
}

.chapter-rail .tick .tick-label {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 20;
}

.chapter-rail .tick:hover .tick-label,
.chapter-rail .tick:focus-visible .tick-label {
  opacity: 1;
}

.controls-row {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.episode-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel-alt) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23b8a58e'><path d='M5.5 7.5l4.5 5 4.5-5z'/></svg>") no-repeat right 12px center;
  background-size: 14px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 34px 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  flex: 1 1 220px;
  max-width: 360px;
}

.episode-select:hover {
  border-color: var(--accent);
}

.panel-toggle-btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 700;
  font-size: 13px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.5px;
}

.panel-toggle-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* Capitoli: floating dropdown, position/max-height set in JS (fixed, viewport-clamped)
   so it can never get clipped by the locked-viewport body and never pushes layout height */
.chapters-panel {
  position: fixed;
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-y: auto;
  scrollbar-color: var(--border) transparent;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.6);
  z-index: 30;
}

.bio-btn {
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 600;
  letter-spacing: 0;
}

.bio-panel {
  width: min(480px, 92vw);
}

.bio-panel h3 {
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 2px 0;
  color: var(--text);
}

.bio-aka {
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 10px 0;
  font-style: italic;
}

.bio-text {
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  margin: 0 0 12px 0;
}

.bio-sources {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.bio-sources a {
  color: var(--text-dim);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bio-sources a:hover { color: var(--accent); }

.chapters-panel h2, .transcript-row h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 10px 0;
  font-weight: 600;
}

.chapters-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chapters-list li {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text);
}

.chapters-list li:hover { background: var(--panel-alt); }

.chapters-list li.active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.chapters-list li.active .ts { color: var(--accent-ink); opacity: 0.7; }

.chapters-list li .ts {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-right: 8px;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.transcript-row {
  flex: 0 0 30vh;
  height: 30vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 4px;
}

.transcript-row.hidden { display: none; }

.transcript-row h2 { flex: 0 0 auto; }

.transcript {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  overflow-y: auto;
  scrollbar-color: var(--border) transparent;
}

.t-line {
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  font-size: 14px;
  line-height: 1.5;
}

.t-line:hover { background: var(--panel-alt); }

.t-line.active {
  background: var(--panel-alt);
  color: var(--text);
}

.t-line.active .speaker {
  color: var(--accent);
}

.t-line .speaker {
  font-weight: 700;
  margin-right: 6px;
}

.t-line .ts {
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  margin-right: 8px;
}

@media (max-width: 640px) {
  html, body { height: auto; }
  body { overflow: visible; }
  .layout { height: auto; padding: 14px 14px 40px; gap: 14px; }
  video { flex: 0 0 auto; height: 38vh; }
  .transcript-row { height: 32vh; flex-basis: 32vh; }
  .episode-select { max-width: none; flex-basis: 100%; }
  .chapter-rail .tick .tick-label { max-width: 200px; font-size: 12px; }
}
