:root {
  --bg: #2b2622;
  --cream: #f3ecdf;
  --muted: rgba(243, 236, 223, 0.45);
  --bar-bg: rgba(243, 236, 223, 0.14);
  --hairline: rgba(243, 236, 223, 0.10);

  --pad: 16px;                          /* outer padding in info mode */
  --gap: 12px;                          /* gap between header and video */
  --header-h: clamp(84px, 16vh, 150px); /* the strip for title+summary (~15%) */
}

/* Collapsed: the header folds away and the video fills the whole viewport. */
body.has-info.collapsed {
  --header-h: 0px;
  --gap: 0px;
  --pad: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; } /* both modes fill the viewport, no page scroll */

/* ---- Layout ------------------------------------------------------------ */

#scroll {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.has-info #scroll { height: 100%; align-items: stretch; }

/* Immersive (no info): shell == full-bleed 16:9. */
#shell {
  width: min(100vw, 177.78vh);
  display: flex;
  flex-direction: column;
}
#video { width: 100%; }

/* Info mode: a fixed compact header strip on top, video fills the rest. */
body.has-info #shell {
  width: 100%;
  height: 100%;
  align-items: center;
  gap: var(--gap);
  padding: var(--pad);
  transition: gap 0.3s ease, padding 0.3s ease;
}
body.has-info #info {
  flex: 0 0 auto;
  height: var(--header-h);
  width: 100%;
  max-width: 1100px;
  transition: height 0.3s ease, opacity 0.25s ease;
}
body.has-info.collapsed #info {
  opacity: 0;
  pointer-events: none;
}
body.has-info #video {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Largest 16:9 box that fits the remaining viewport (width- or height-bound). */
body.has-info #stage {
  width: auto;
  height: min(100%, calc((100vw - 2 * var(--pad)) * 9 / 16));
  max-width: 100%;
  max-height: 100%;
}

/* ---- Highlight header (title + summary) -------------------------------- */

#info {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  overflow: hidden;
}
#info[hidden] { display: none; }

#info .badge {
  width: 34px; height: 34px;
  border-radius: 8px;
  flex: 0 0 auto;
}

#info .info-text {
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: opacity 0.15s ease;
}
#info .info-text.swap { opacity: 0; } /* crossfade while swapping highlights */

.counter {
  flex: 0 0 auto;
  margin-bottom: 4px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

#title {
  flex: 0 0 auto;
  margin: 0 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: clamp(16px, 2.2vw, 22px);
  line-height: 1.18;
  /* keep the title to two lines so it never crowds out the summary */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#summary {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  font-size: clamp(12.5px, 1.4vw, 14px);
  line-height: 1.55;
  color: rgba(243, 236, 223, 0.78);
  white-space: pre-wrap;  /* preserve line breaks */
  overflow-y: auto;       /* scroll if the summary is long; video stays put */
}

/* ---- Video stage ------------------------------------------------------- */

#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

#player, #player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Segment progress bar */
#progress {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--bar-bg);
  z-index: 3;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#stage.playing #progress { opacity: 1; }
#progress-fill {
  height: 100%;
  width: 0%;
  background: var(--cream);
  transition: width 0.18s linear;
}
/* Boundaries between highlights */
#progress .tick {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--bg);
  transform: translateX(-1px);
}

/* Corner watermark (hidden when the header already shows the brand) */
#mark {
  position: absolute;
  top: 12px; left: 12px;
  width: 26px; height: 26px;
  border-radius: 6px;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
#stage.playing #mark { opacity: 0.6; }
body.has-info #mark { display: none; }

/* ---- Collapse / expand toggle ------------------------------------------ */

#toggle {
  position: fixed;
  top: 14px; right: 14px;
  z-index: 6;
  width: 34px; height: 34px;
  display: none;                 /* shown only when there is info to toggle */
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  color: var(--cream);
  background: rgba(43, 38, 34, 0.55);
  border: 1px solid rgba(243, 236, 223, 0.18);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: background 0.2s ease;
}
body.has-info #toggle { display: inline-flex; }
#toggle:hover { background: rgba(43, 38, 34, 0.85); }
#toggle svg {
  width: 16px; height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s ease;
}
body.has-info.collapsed #toggle svg { transform: rotate(180deg); }

/* ---- Overlays (start / end / error) ------------------------------------ */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: var(--bg);
  text-align: center;
  padding: 24px;
  cursor: pointer;
  user-select: none;
}
.overlay[hidden] { display: none; }
.overlay.error { cursor: default; }

.overlay img.logo {
  width: 96px; height: 96px;
  border-radius: 18px;
}

.overlay .action {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--cream);
  border: 1px solid rgba(243, 236, 223, 0.25);
  border-radius: 999px;
  padding: 10px 20px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.overlay:hover .action { border-color: rgba(243, 236, 223, 0.6); }
.overlay .action svg { width: 14px; height: 14px; fill: currentColor; }

.overlay .sub {
  font-size: 13px;
  color: var(--muted);
  max-width: 420px;
  line-height: 1.5;
}
.overlay .sub code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--cream);
  background: rgba(243, 236, 223, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}
