/* Engine baseline. Neutral defaults only — visual identity is the host's. */

:root {
  --engine-bg: #ffffff;
  --engine-fg: #111111;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--engine-bg);
  color: var(--engine-fg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

.state {
  position: fixed;
  inset: 0;
  display: none;
  width: 100vw;
  height: 100vh;
}

.state.is-active {
  display: flex;
  animation: state-fade-in 450ms ease both;
}
@keyframes state-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

[data-reveal] {
  opacity: 0;
  transition: opacity 200ms ease;
}

[data-reveal].is-revealed {
  opacity: 1;
}

.engine-dev-overlay {
  position: fixed;
  bottom: 12px;
  right: 12px;
  padding: 6px 10px;
  font: 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 4px;
  pointer-events: none;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
}
/* `display: flex` above beats the user-agent's [hidden] { display: none },
   so the overlay (and its child home button) would stay visible at recording
   time. Re-assert hidden when the engine sets the attribute via `d`. */
.engine-dev-overlay[hidden] {
  display: none;
}

/* ────────────────────────── Per-state tweak panel ──────────────────────────
   Floating control panel used during construction. Lectures register a
   set of slider/button defs from each state's prepare hook via
   engine.tweaks(...); the panel is auto-hidden when the active state
   changes (each state owns its own surface) and only visible when dev
   mode is on. Invisible at recording time. */
/* Four scope panels arranged horizontally bottom-right.
   Order in DOM (left → right): reveal, state, section, lecture.
   Each panel rebuilds only when its own scope id changes. */
.engine-panels {
  position: fixed;
  bottom: 50px;
  right: 12px;
  display: flex;
  flex-direction: row;
  gap: 8px;
  z-index: 9998;
  pointer-events: none;
  align-items: flex-end;
}
.engine-panels[hidden] { display: none; }

.engine-panel {
  pointer-events: auto;
  /* Width fits the longest label + a usable slider + the number
     input without clipping. Animation labels like "Auto-fire (ms)"
     are the widest at the current monospace size. */
  width: 300px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 10px 12px 12px;
  font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.engine-panel[hidden] { display: none; }
.engine-panel-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.55);
}
.engine-panel-id {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.45);
  font-style: italic;
  margin-top: -6px;
  word-break: break-all;
}
.engine-panel-divider {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.4);
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: 2px;
}

/* Rows */
.engine-row {
  display: grid;
  align-items: center;
  gap: 6px;
}
.engine-row-audio {
  grid-template-columns: 14px auto 1fr 60px;
}
.engine-row-anim {
  /* Label column auto-sized so it never clips; slider flexes; number
     input fixed. With panel width 300px and ~24px of padding +
     gaps, we get plenty of slider room for any label we use. */
  grid-template-columns: auto 1fr 60px;
}
/* Shortcut row: monospace key chip, then a label that fills the rest. */
.engine-row-shortcut {
  grid-template-columns: 28px 1fr;
}
.engine-shortcut-key {
  display: inline-block;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  padding: 1px 0;
  text-transform: uppercase;
}
.engine-shortcut-label {
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
}
.engine-row-label {
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  font-size: 11px;
}
.engine-check {
  margin: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #fff;
}
.engine-num {
  width: 100%;
  padding: 3px 5px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  font: inherit;
  text-align: right;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.engine-num::-webkit-outer-spin-button,
.engine-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.engine-num:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.1);
}
.engine-num.engine-inherit {
  opacity: 0.4;
}

/* Sliders: bigger track + thumb than the OS default so they're
   easy to grab with a mouse or trackpad. */
.engine-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  margin: 0;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
.engine-row input[type="range"].engine-inherit {
  opacity: 0.4;
}
.engine-row input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: transparent;
  border-radius: 4px;
}
.engine-row input[type="range"]::-moz-range-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  border: none;
}
.engine-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -5px;
  background: #ffffff;
  border-radius: 50%;
  border: 0;
  cursor: grab;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.engine-row input[type="range"]:active::-webkit-slider-thumb {
  cursor: grabbing;
}
.engine-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  border: 0;
  cursor: grab;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.engine-row input[type="range"]:focus {
  outline: 2px solid rgba(255, 255, 255, 0.3);
  outline-offset: 2px;
}

.engine-button {
  grid-column: 1 / -1;
  font: inherit;
  color: inherit;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 3px;
  padding: 5px 9px;
  cursor: pointer;
  transition: background 120ms ease;
}
.engine-button:hover {
  background: rgba(255, 255, 255, 0.22);
}

.engine-dev-overlay .engine-dev-home {
  pointer-events: auto;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 3px;
  font: inherit;
  padding: 2px 7px;
  transition: background 120ms ease;
}
.engine-dev-overlay .engine-dev-home:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ────────────────────────── Host-mode states ──────────────────────────
   States authored as <section class="state" data-mode="host"> render
   the host's beat notes as a designed talking-points layout. Doubles as
   a teleprompter during recording (host footage will be composited over
   the entire canvas in post) and as an intentional visual aid when the
   lecture is delivered live to an audience.

   Authoring shape:
     <section class="state" data-mode="host">
       <ol class="beats">
         <li>First beat</li>
         <li>Second beat</li>
       </ol>
     </section>                                                          */

.state[data-mode="host"] {
  background: #000;
  color: #f3f3f3;
  align-items: center;
  justify-content: center;
  padding: 6vh 8vw;
}

.state[data-mode="host"] .beats {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: beat;
  display: flex;
  flex-direction: column;
  gap: clamp(1.4rem, 2.4vh, 2.4rem);
  max-width: 70ch;
  width: 100%;
}

/* Pause-then-fade so the editor has a clean black handoff before the
   beat notes appear. ~1.2s of silence, then each beat fades in with a
   small stagger to feel composed rather than "everything at once". */
.state[data-mode="host"] .beats li {
  display: flex;
  align-items: baseline;
  gap: clamp(1rem, 1.8vw, 1.8rem);
  font: 300 clamp(1.4rem, 2.1vw, 2.2rem) / 1.4
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: -0.005em;
  color: rgba(255, 255, 255, 0.92);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 500ms ease, transform 500ms ease;
}

.state[data-mode="host"].is-active .beats li { opacity: 1; transform: none; }
.state[data-mode="host"].is-active .beats li:nth-child(1)  { transition-delay: 1200ms; }
.state[data-mode="host"].is-active .beats li:nth-child(2)  { transition-delay: 1320ms; }
.state[data-mode="host"].is-active .beats li:nth-child(3)  { transition-delay: 1440ms; }
.state[data-mode="host"].is-active .beats li:nth-child(4)  { transition-delay: 1560ms; }
.state[data-mode="host"].is-active .beats li:nth-child(5)  { transition-delay: 1680ms; }
.state[data-mode="host"].is-active .beats li:nth-child(6)  { transition-delay: 1800ms; }
.state[data-mode="host"].is-active .beats li:nth-child(7)  { transition-delay: 1920ms; }
.state[data-mode="host"].is-active .beats li:nth-child(8)  { transition-delay: 2040ms; }
.state[data-mode="host"].is-active .beats li:nth-child(9)  { transition-delay: 2160ms; }
.state[data-mode="host"].is-active .beats li:nth-child(10) { transition-delay: 2280ms; }

/* ────────────────────────── Animation primitives ──────────────────────────
   Shared building blocks lectures use repeatedly. The JS for these lives in
   `lib/engine/animate.js`. Anything used in two or more lectures should
   end up here so it's available everywhere. */

/* Word-by-word reveal — used by .quote, .hero, .title, etc. The container
   is split into <span class="word"> tokens, each animated in via a stagger
   set on .transitionDelay by the JS helper. */
.word {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.25em);
  transition: opacity 350ms ease, transform 350ms ease;
}
.word.is-visible {
  opacity: 1;
  transform: none;
}

/* Marker highlight — `<mark>` defaults to invisible (text reads as normal
   copy) until JS adds .is-marked, at which point a left-to-right sweep
   draws the highlight. Color is driven by CSS custom properties so each
   use can pick its own (e.g., per-category for the changelog). */
mark {
  background-color: transparent;
  background-image: linear-gradient(
    to right,
    var(--mark-color, #fff21a),
    var(--mark-color, #fff21a)
  );
  background-repeat: no-repeat;
  background-position: left center;
  background-size: 0% 100%;
  color: inherit;
  padding: 0.05em 0.2em;
  border-radius: 2px;
  box-shadow: 0 0 0 transparent;
  transition:
    background-size 380ms cubic-bezier(0.4, 0, 0.2, 1),
    color 220ms ease-out 180ms,
    box-shadow 380ms ease-out;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
mark.is-marked {
  background-size: 100% 100%;
  color: var(--mark-text-color, #111);
  box-shadow: 0 0 0.7em var(--mark-glow, rgba(255, 234, 60, 0.55));
}

/* Screen wipe — single full-viewport overlay element appended once by
   `playScreenWipe()` and animated across the screen. Used to visually
   cut between distinct beats. */
.engine-wipe-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  transform: translateX(-100%);
}
@keyframes engine-wipe {
  0%   { transform: translateX(-100%); }
  50%  { transform: translateX(0); }
  100% { transform: translateX(100%); }
}

.state[data-mode="host"] .beats li::before {
  counter-increment: beat;
  content: counter(beat, decimal-leading-zero);
  flex: 0 0 auto;
  width: 2.2em;
  font: 400 0.55em / 1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: rgba(255, 255, 255, 0.32);
  letter-spacing: 0.08em;
  text-align: right;
  padding-top: 0.4em;
}


/* ─────────────────────── Slide-gallery browser overlay ───────────────────────
   Tab-toggled overlay showing every state as a thumbnail card. Hidden by
   default so the recording-time UI stays clean. Backdrop is semi-transparent
   so the host can momentarily orient against the underlying lecture. */

.engine-browser-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro Display", sans-serif;
  color: #f0ece4;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 220ms ease;
}
.engine-browser-overlay.is-open {
  opacity: 1;
}
.engine-browser-overlay[hidden] {
  display: none;
}
.eb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 10, 0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.eb-panel {
  position: absolute;
  inset: 4vh 4vw;
  display: flex;
  flex-direction: column;
  background: #14131a;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.eb-header {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 16px 22px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}
.eb-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.eb-progress {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: rgba(240, 236, 228, 0.55);
}
.eb-hint {
  margin-left: auto;
  font-size: 11px;
  color: rgba(240, 236, 228, 0.40);
  letter-spacing: 0.04em;
}
.eb-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 22px 28px;
}
.eb-section {
  margin-top: 22px;
}
.eb-section:first-child {
  margin-top: 0;
}
.eb-section-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(240, 236, 228, 0.50);
  margin: 0 0 10px 4px;
}
.eb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

/* ─── Card ─── */
.eb-card {
  width: 280px;
  display: flex;
  flex-direction: column;
  background: #1a1822;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  user-select: none;
}
.eb-card:hover {
  border-color: rgba(255, 255, 255, 0.32);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.eb-card.is-active {
  border-color: #5a9fd4;
  box-shadow: 0 0 0 2px rgba(90, 159, 212, 0.45), 0 6px 20px rgba(0, 0, 0, 0.35);
}
.eb-card.is-dragging {
  opacity: 0.5;
}
.eb-card.is-drop-target {
  border-color: #5a9fd4;
  box-shadow: -4px 0 0 0 #5a9fd4;
}
.eb-card-thumb {
  position: relative;
  width: 280px;
  height: 158px;            /* 16:9 */
  background: #000;
  overflow: hidden;
  pointer-events: none;
}
.eb-card-thumb.is-pending {
  display: flex;
  align-items: center;
  justify-content: center;
}
.eb-card-pending {
  font-size: 11px;
  font-style: italic;
  color: rgba(240, 236, 228, 0.32);
}
/* Captured state DOM is rendered at full lecture-viewport dimensions
   inside the card and scaled down via transform. */
.eb-card-fit {
  position: absolute;
  inset: 0;
  width: 1280px;
  height: 720px;
  transform: scale(0.21875);   /* 280 / 1280 */
  transform-origin: 0 0;
  pointer-events: none;
}
/* Override engine.css's fixed positioning + animation on captured
   states so they render statically inside their card. */
.eb-card-fit > .state,
.eb-card-fit .state {
  position: absolute !important;
  inset: 0 !important;
  width: 1280px !important;
  height: 720px !important;
  display: flex !important;
  animation: none !important;
  /* Keep the captured state visible regardless of `is-active` —
     the snapshot already had `is-active` when captured, but be
     defensive in case future captures don't. */
  opacity: 1 !important;
}
/* All reveals visible in thumbs (we walk through them during the
   capture, but force-show as a safety net for partial captures). */
.eb-card-fit [data-reveal] {
  opacity: 1 !important;
}

.eb-card-footer {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  font-size: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0));
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.eb-card-idx {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: rgba(240, 236, 228, 0.45);
  font-size: 11px;
  flex-shrink: 0;
}
.eb-card-label {
  color: #f0ece4;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.eb-card-class {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  color: rgba(240, 236, 228, 0.42);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Hide the capture iframe completely (it's already off-screen, but
   make sure it can't catch any pointer events or steal focus). */
.engine-capture-frame {
  visibility: hidden;
}
