/* Don't Panic Deck — web edition.
 * Lifted from the desktop app's stage CSS. Every value here was
 * tuned in the desktop app over multiple iterations; do not change
 * blindly. The voice-reactive halo coefficients in particular were
 * the result of three rounds of "too loud / too quiet / just right"
 * with the user. */

:root {
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --bg: #0a0a0a;
  --dim: #777;
  --voice-level: 0;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: #eee;
  font-family: var(--mono);
  height: 100%;
  overflow: hidden;
}

/* ---------------- Audience surfaces ---------------- */
/* Tiny LIVE badge in top-left mirroring cockpit STT state. Off-air
 * gray; live green with a soft halo. Tucked behind safe-area insets
 * for notched displays. */
.audience-state {
  position: fixed;
  top: max(18px, env(safe-area-inset-top, 18px));
  left: max(18px, env(safe-area-inset-left, 18px));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.10);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  pointer-events: none;
  z-index: 30;
}
.audience-state-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #555;
}
.audience-state.live {
  color: #6dd47e;
  border-color: rgba(109,212,126,0.35);
}
.audience-state.live .audience-state-dot {
  background: #6dd47e;
  box-shadow: 0 0 8px rgba(109,212,126,0.55);
  animation: live-blink 1.8s ease-in-out infinite;
}

/* Transcript overlay at the bottom of the audience stage. Hidden by
 * default; T (or the corner button) toggles. Persisted per device. */
.audience-transcript {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom, 28px));
  left: max(40px, env(safe-area-inset-left, 40px));
  right: max(40px, env(safe-area-inset-right, 40px));
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 28;
  pointer-events: none;
  text-align: center;
}
.audience-transcript[hidden] { display: none; }
.audience-transcript-line {
  font-family: var(--mono);
  font-size: clamp(14px, 1.5vw, 22px);
  line-height: 1.45;
  color: rgba(255,255,255,0.45);
}
.audience-transcript-line.fresh { color: #eee; }

/* Tiny T toggle in the corner — gives TVs without keyboards a tap
 * target to flip captions on. Stays out of the way otherwise. */
.audience-toggle {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  left: max(16px, env(safe-area-inset-left, 16px));
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.45);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  z-index: 31;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}
.audience-toggle:hover {
  color: #eee;
  border-color: rgba(255,255,255,0.30);
}
.audience-toggle.active {
  color: #6dd47e;
  border-color: rgba(109,212,126,0.55);
  background: rgba(109,212,126,0.10);
}

/* ---------------- Audience welcome ---------------- */
/* Calm "we're connected, talk hasn't started yet" card. Replaced when
 * the first slide event arrives via SSE. Not used by the cockpit. */
.welcome {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-items: center;
}
.welcome-eyebrow {
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.32);
  font-family: var(--mono);
}
.welcome-title {
  font-family: var(--mono);
  font-weight: 500;
  font-size: clamp(1.6rem, 3.6vw, 3.4rem);
  letter-spacing: -0.01em;
  color: rgba(255,255,255,0.7);
  max-width: 26ch;
  line-height: 1.25;
  animation: breathe 9s ease-in-out infinite;
}
.welcome-meta {
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(109,212,126,0.55);
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.welcome-meta::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: #6dd47e;
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* ---------------- Stage (cockpit + audience share) ---------------- */
.stage {
  position: fixed; inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  /* Kill the 300ms tap-zoom delay and let our pointerdown/up swipe
   * handlers measure clean horizontal deltas without browser
   * intercepting for double-tap-to-zoom. */
  touch-action: manipulation;
}
/* Cockpit Stage: bounded by chrome (top), side panel (right), and
 * transcript strip (bottom) so the operator sees a preview rather than
 * a full-screen slide. The audience Stage stays inset: 0. */
.stage.cockpit-mode {
  inset: 56px 38rem 26vh 0;
  border-right: 1px solid rgba(255,255,255,0.04);
}
@media (max-width: 1200px) {
  .stage.cockpit-mode { inset: 56px 0 26vh 0; }
}
.moment {
  text-align: center;
  max-width: 92vw;
  position: relative;
}
.moment .meta {
  position: absolute; top: clamp(1.5rem, 4vh, 3rem); left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--dim);
}
.moment .text {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(2.4rem, 7.2vw, 8.5rem);
  letter-spacing: -0.025em;
  line-height: 1.04;
  text-wrap: balance;
  text-align: center;
  max-width: 26ch;
  animation: breathe 9s ease-in-out infinite;
  text-shadow:
    0 0 calc(11px + var(--voice-level, 0) * 46px)
      rgba(255, 255, 255, calc(0.075 + var(--voice-level, 0) * 0.26));
  transition: text-shadow 130ms ease-out;
}
.moment .text.small {
  font-size: clamp(1.8rem, 4.4vw, 4.8rem);
  font-weight: 500;
  letter-spacing: -0.015em;
  max-width: 34ch;
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.006); }
}

.moment .word, .moment .ch {
  display: inline-block;
  will-change: transform, opacity, filter;
}
.moment .word { white-space: nowrap; }
.moment .word.emphasis {
  color: #6dd47e;
  animation: emphasis-pulse 5s ease-in-out infinite;
  text-shadow:
    0 0 calc(14px + var(--voice-level, 0) * 70px)
      rgba(109, 212, 126, calc(0.24 + var(--voice-level, 0) * 0.30));
}
@keyframes emphasis-pulse {
  0%, 100% { opacity: 0.92; }
  50%      { opacity: 1.0;  }
}

/* ---------------- Cockpit-only chrome ---------------- */
/* `contain` keeps voice-level CSS variable changes (set on :root at
 * ~15 Hz) from invalidating layout/style on these subtrees. Without
 * it, the activity panel + transcript strip get restyled on every
 * audio frame, which made Chrome lag. */
.chrome {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  padding: 14px 18px;
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
  pointer-events: none;
  contain: layout style;
}
.chrome > * { pointer-events: auto; }

.timer {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: rgba(255,255,255,0.45);
  transition: color 200ms ease;
}
.timer.live { color: rgba(255,255,255,0.92); }
.timer.pacing-warn { color: rgba(251, 191, 36, 0.95); }
.timer.pacing-over { color: rgba(248, 113, 113, 1); }

.status-pip {
  font-size: 10.5px;
  letter-spacing: 0.16em;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.03);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.status-pip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #555;
  flex-shrink: 0;
}
.status-pip.ok .dot { background: #6dd47e; }
.status-pip.warn .dot { background: #fbbf24; }
.status-pip.err .dot { background: #f87171; }

/* ---------------- Microphone level meter ---------------- */
/* Reads `--voice-level` (set by CockpitEngine._setLevel at ~10 Hz) and
 * paints a horizontal vu bar. Visible only while the mic is live so
 * it doesn't sit at zero and look broken when nothing's connected. */
.mic-meter {
  display: inline-flex;
  align-items: center;
  position: relative;
  width: 96px;
  height: 10px;
  border-radius: 5px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  overflow: hidden;
  flex: 0 0 auto;
}
.mic-meter[hidden] { display: none; }
.mic-meter-fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform-origin: left center;
  transform: scaleX(var(--voice-level, 0));
  background: linear-gradient(
    to right,
    rgba(109,212,126,0.85) 0%,
    rgba(109,212,126,0.85) 60%,
    #fbbf24 80%,
    #f87171 100%
  );
  transition: transform 90ms linear;
  will-change: transform;
}
.mic-meter-fill-peak {
  /* Slow-decaying peak indicator: jumps up instantly with the bar,
   * eases back. Browsers don't expose "decay-only" easily so we cheat
   * with a longer transition + a separate paint layer. */
  background: rgba(255,255,255,0.18);
  transform: scaleX(var(--voice-level, 0));
  transition: transform 1100ms cubic-bezier(0.16, 1, 0.3, 1);
}
@media (max-width: 480px) {
  .mic-meter { width: 64px; height: 8px; }
}

.share-link {
  background: rgba(109, 212, 126, 0.10);
  border: 1px solid rgba(109, 212, 126, 0.4);
  color: #6dd47e;
  padding: 4px 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 4px;
  text-decoration: none;
}
.share-link:hover { background: rgba(109, 212, 126, 0.18); }
.share-link.copied { background: #6dd47e; color: #0a0a0a; }

.chrome-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  color: rgba(255,255,255,0.7);
  padding: 4px 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 4px;
}
.chrome-btn:hover { background: rgba(255,255,255,0.08); color: #eee; }
.auth-btn {
  text-decoration: none;
  background: rgba(109,212,126,0.10);
  border-color: rgba(109,212,126,0.4);
  color: #6dd47e;
}
.auth-btn:hover { background: rgba(109,212,126,0.18); color: #6dd47e; }
.chrome-user {
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  color: rgba(255,255,255,0.55);
  padding: 4px 10px;
  border-radius: 4px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
}

.hotkey-hint {
  font-size: 10.5px;
  letter-spacing: 0.16em;
  color: rgba(255,255,255,0.45);
}

/* ---------------- Primary touch controls ---------------- */
/* Tap-friendly buttons for mobile / tablet operators. The chrome bar
 * stays the visual top bar; this row sits just below it and is the
 * primary interaction surface when there's no keyboard. Hidden on
 * desktop where hotkeys cover the same ground. */
.primary-bar {
  position: fixed;
  top: 56px; left: 0; right: 0;
  z-index: 49;
  display: none;
  gap: 8px;
  padding: 10px 14px env(safe-area-inset-bottom, 0px);
  background: rgba(10,10,10,0.92);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  overflow-x: auto;
  scrollbar-width: none;
}
.primary-bar::-webkit-scrollbar { display: none; }
.primary-btn {
  appearance: none;
  flex: 0 0 auto;
  min-width: 56px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: #eee;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.primary-btn:active { background: rgba(255,255,255,0.12); }
.primary-btn-go {
  background: rgba(109,212,126,0.14);
  border-color: rgba(109,212,126,0.5);
  color: #6dd47e;
  font-weight: 600;
  letter-spacing: 0.10em;
}
.primary-btn-go.live {
  background: #6dd47e;
  color: #0a0a0a;
}
.primary-btn-go:active { filter: brightness(1.1); }

/* ---------------- Language toggle ---------------- */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 2px 4px 2px 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  font-family: var(--mono);
}
.lang-toggle .lang-label {
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  margin-right: 8px;
}
.lang-toggle button {
  appearance: none;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.5);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.lang-toggle button:hover { color: #eee; background: rgba(255,255,255,0.06); }
.lang-toggle button.active {
  color: #6dd47e;
  background: rgba(109,212,126,0.12);
}

/* ---------------- Mobile / tablet responsive ---------------- */
/* On a phone the cockpit becomes a teleprompter: small slide-card
 * row up top (so you can confirm what the audience sees), manuscript
 * filling the rest as the primary reading surface. Guide and
 * Activity move to a bottom-sheet drawer (G/D toggles). Chrome bar
 * shrinks to the absolute essentials. */
@media (max-width: 900px) {
  .chrome {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }
  .hotkey-hint { display: none; }
  .lang-toggle { display: none; }       /* settings, not in chrome */
  .latency-label,
  #latency-pip { display: none !important; }
  #audience-pip { display: none; }      /* watching count not actionable */
  .share-link { display: none; }        /* code-badge already covers it */
  #profile-btn { display: none; }       /* dev surface */
  .code-badge .label { display: none; } /* drop "JOIN" + "·" verbiage */
  .code-badge .code { font-size: 13px; }
  .status-pip { padding: 6px 10px; min-height: 36px; }
  .mic-meter { width: 64px; height: 8px; }

  .primary-bar { display: flex; }

  /* Stack the main grid vertically. Right-rail (slide cards) row
   * stays compact so the manuscript gets the bulk of vertical space. */
  .cockpit-main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    gap: 12px;
    padding: 12px;
    top: 124px;          /* clear the chrome + primary-bar */
    bottom: 0;
  }
  .right-rail {
    grid-row: 1;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 0 0 auto;       /* don't let it eat the manuscript's space */
  }
  .right-rail::-webkit-scrollbar { display: none; }
  .slide-card { flex: 1 1 70%; min-width: 180px; padding: 12px 14px; }
  .slide-card.next { flex: 0 0 32%; }
  .slide-title { font-size: clamp(15px, 4.2vw, 22px); margin-top: 14px; }
  .slide-card.next .slide-title { font-size: clamp(13px, 3.4vw, 18px); }

  /* Manuscript stays on phone — that's the read-from-script surface.
   * Override the desktop right-rail hide rule (`.visible` is more
   * specific than the bare selector and was winning at 900px). */
  .right-rail .manuscript-section,
  .right-rail .manuscript-section.visible {
    display: block;
    grid-row: 2;
    flex: 1;
    min-height: 0;
    width: 100%;
    margin-top: 8px;
    overflow-y: auto;
    padding: 10px 12px;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    background: rgba(255,255,255,0.02);
  }
  /* Pulled out of the right-rail flex flow so it spans full width. */
  .right-rail { flex-wrap: wrap; }

  /* Guide pane goes to a tucked-away strip below the manuscript.
   * Hidden on mobile by default — operator opens via the Guide
   * button if they want to see it. */
  .guide-pane { display: none; }
  .guide-list .guide-entry { font-size: 13.5px; }

  /* Side panel becomes a bottom sheet. Toggle "visible" on the same
   * G hotkey / Guide button slides it up from below. */
  .cockpit-side {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.10);
    border-radius: 16px 16px 0 0;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(12px);
    transform: translateY(110%);
    transition: transform 280ms cubic-bezier(0.2,0.8,0.2,1);
    display: block;
    padding-top: 22px;
    padding-bottom: env(safe-area-inset-bottom, 14px);
  }
  .cockpit-side.visible { transform: translateY(0); }
  /* Subtle drag-handle on the bottom sheet so it reads as dismissable. */
  .cockpit-side::before {
    content: '';
    position: absolute;
    top: 8px; left: 50%;
    transform: translateX(-50%);
    width: 44px; height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.18);
  }

  /* Transcript strip would fight the primary bar for space — hide it
   * on phones; the operator can peek via Activity panel anyway. */
  .transcript-strip { display: none; }

  /* Manuscript paragraphs get bigger tap targets. */
  .ms-row { padding: 10px 8px; min-height: 44px; }
  .ms-para { padding: 10px 12px; font-size: 13px; }
}

@media (max-width: 480px) {
  .chrome { padding: 8px 10px; gap: 6px; }
  .timer .label { display: none; }
  .share-link { display: none; }   /* code badge is the share path on phones */
  .primary-btn { padding: 10px 14px; min-width: 48px; }
}

/* ---------------- Reduced motion ---------------- */
/* Honour the OS-level "minimize motion" preference. We keep colour
 * changes (still convey state) but freeze breathe / pulse / morph. */
@media (prefers-reduced-motion: reduce) {
  .moment .text,
  .welcome-title {
    animation: none !important;
  }
  .moment .word.emphasis {
    animation: none !important;
  }
  .ch {
    transition: opacity 0ms !important, transform 0ms !important, filter 0ms !important;
  }
  .cockpit-side { transition: none !important; }
}

/* ---------------- Cockpit main layout (Guide-centric) ----------- */
/* The operator's primary attention is on The Guide — the running
 * stream of intellectual support. The slide is shown as a small
 * inset card on the right rail with a clear LIVE label so the
 * operator knows what the audience sees right now; an optional NEXT
 * card appears below it when a manuscript is loaded and the aligner
 * has a cursor. */
.cockpit-main {
  position: fixed;
  top: 56px;
  bottom: 26vh;          /* leave room for the transcription strip */
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  gap: 24px;
  padding: 20px 28px;
  contain: layout style;
}

.guide-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.guide-pane .pane-head { margin-bottom: 16px; }

.pane-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.pane-label {
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  font-weight: 600;
}
.pane-hint {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.30);
}

.guide-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 12px;
  /* Big content; opt into independent scrolling so it doesn't fight
   * with the page. */
  scrollbar-gutter: stable;
}
.guide-list .guide-entry {
  border-left: 2px solid rgba(109,212,126,0.45);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: rgba(109,212,126,0.05);
  font-size: 14.5px;
  line-height: 1.65;
  border-radius: 0 6px 6px 0;
  transition: background-color 320ms ease, border-color 320ms ease;
}
.guide-list .guide-entry .kind {
  display: inline-block;
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(109,212,126,0.85);
  margin-right: 0.7em;
  font-weight: 600;
}
.guide-list .guide-entry-fresh {
  background: rgba(109,212,126,0.12);
  border-left-color: #6dd47e;
}

.right-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.slide-card {
  position: relative;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  padding: 22px 22px 18px;
  background: rgba(255,255,255,0.025);
  contain: layout style;
}
.slide-card.live {
  border-color: rgba(109,212,126,0.55);
  background: rgba(109,212,126,0.06);
  box-shadow: 0 0 0 1px rgba(109,212,126,0.18) inset;
}
.slide-card.next {
  opacity: 0.55;
  background: transparent;
}
.slide-tag {
  position: absolute;
  top: 10px;
  left: 18px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(109,212,126,0.85);
}
.slide-card.next .slide-tag { color: rgba(255,255,255,0.45); }
.slide-title {
  margin-top: 18px;
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(20px, 1.8vw, 30px);
  letter-spacing: -0.01em;
  line-height: 1.22;
  color: #eee;
  word-break: break-word;
}
.slide-card.next .slide-title {
  font-size: clamp(15px, 1.2vw, 20px);
  font-weight: 500;
}
.slide-title .emphasis { color: #6dd47e; }
.slide-card[hidden] { display: none; }

.right-rail .manuscript-section {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.right-rail .manuscript-section.visible { display: flex; flex-direction: column; }

/* ---------------- Script mode (manuscript loaded) ---------------- */
/* Teleprompter take-over: the manuscript is reparented (by JS in
 * applyScriptMode) to the left grid cell and the Guide tucks under
 * the slide cards on the right. The active paragraph stays bright
 * and centered vertically; surrounding paragraphs dim so the eye
 * lands on the right line. */
body.script-mode .cockpit-main {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
}
/* Manuscript becomes the centerpiece — own scroller, full grid cell. */
body.script-mode .cockpit-main > .manuscript-section,
body.script-mode .cockpit-main > .manuscript-section.visible {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: transparent;
  border: none;
  padding: 0;
  overflow-y: auto;
  /* No scroll-padding-block — scrollIntoView block:'center' handles
   * centering, and a large padding here would push targets off-axis. */
}
body.script-mode .cockpit-main > .manuscript-section .pane-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 4px 12px;
  background: linear-gradient(to bottom, rgba(10,10,10,0.95) 70%, rgba(10,10,10,0));
}
/* Guide squeezes into the right rail under the slide cards. */
body.script-mode .right-rail > .guide-pane {
  flex: 1;
  min-height: 0;
  margin-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 12px;
}
body.script-mode .right-rail > .guide-pane .guide-list .guide-entry {
  font-size: 12.5px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
body.script-mode .ms-slide {
  border-left: none;
  /* Tight vertical rhythm — operator wants overview alongside the
   * active line. Just enough headroom for center-scroll at edges. */
  padding: 2.5vh 20px;
  margin-bottom: 0;
}
body.script-mode .ms-slide .ms-row.ms-head {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 8px;
}
body.script-mode .ms-slide .ms-head .ms-title {
  font-size: 15px;
  font-weight: 600;
}
body.script-mode .ms-para {
  margin: 0 0 8px 2.4em;
  padding: 8px 14px;
  font-size: clamp(15px, 1.25vw, 18px);
  line-height: 1.55;
  color: rgba(255,255,255,0.34);
  border-left: 3px solid transparent;
  border-radius: 4px;
  opacity: 0.55;
  transition: color 220ms ease, background-color 220ms ease,
              border-color 220ms ease, opacity 220ms ease;
}
body.script-mode .ms-para.active {
  color: #fff;
  background: rgba(109,212,126,0.10);
  border-left-color: #6dd47e;
  opacity: 1;
}
/* Script-mode owns its own right-rail Guide. The full-height side
 * drawer (Activity) would just float in front of the manuscript and
 * dim it — keep it hidden unless the operator explicitly toggles it
 * with D. */
body.script-mode .cockpit-side { display: none; }
body.script-mode .cockpit-side.visible { display: block; }
@media (max-width: 900px) {
  body.script-mode .cockpit-main {
    grid-template-columns: minmax(0, 1fr);
  }
  body.script-mode .ms-slide { padding: 2vh 12px; }
  body.script-mode .ms-para {
    font-size: clamp(14px, 3.6vw, 18px);
    margin-left: 0;
    padding: 8px 12px;
  }
}

/* ---------------- Notes / Guide column (cockpit) ---------------- */
.cockpit-side {
  position: fixed;
  top: 56px; right: 0; bottom: 0;
  width: 38rem;
  max-width: 46vw;
  padding: 14px 18px 28px;
  background: rgba(0,0,0,0.55);
  border-left: 1px solid rgba(255,255,255,0.06);
  overflow-y: auto;
  font-size: 12px;
  display: none;
  contain: layout style;
}
.cockpit-side.visible { display: block; }
.cockpit-side > section,
.cockpit-side > div {
  margin-bottom: 1.4rem;
}
.cockpit-side h3 {
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 0.7rem;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.cockpit-side h3 .hint {
  font-size: 9.5px;
  letter-spacing: 0.18em;
  color: rgba(255,255,255,0.32);
  font-weight: 400;
  text-transform: none;
}

/* Guide is the top-priority panel — speaker reads from this.
 * Bigger type, more padding, more vertical room than activity. */
.guide-entry {
  border-left: 2px solid rgba(109,212,126,0.4);
  padding: 0.7em 0.9em;
  margin-bottom: 0.7em;
  background: rgba(109,212,126,0.04);
  font-size: 12.5px;
  line-height: 1.55;
}
.guide-entry .kind {
  display: inline-block;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(109,212,126,0.8);
  margin-right: 0.6em;
}

/* Drop overlay */
.drop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  display: none;
  place-items: center;
  z-index: 200;
  font-size: 14px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6dd47e;
  pointer-events: none;
}
.drop.visible { display: grid; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: rgba(0,0,0,0.85);
  border: 1px solid rgba(255,255,255,0.18);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #eee;
  z-index: 100;
  opacity: 0;
  transition: opacity 220ms ease;
  pointer-events: none;
}
.toast.visible { opacity: 1; }

/* ---------------- Rolling transcription strip (cockpit only) ----- */
/* Sits at the bottom of the cockpit. Shows the most recent finals plus
 * the in-flight delta. Operator-side audit channel — do not show to
 * the audience. */
.transcript-strip {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  padding: 14px 28px 18px;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 30%, rgba(0,0,0,0));
  font-size: 13px;
  line-height: 1.55;
  color: rgba(255,255,255,0.6);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 26vh;
  overflow: hidden;
  mask-image: linear-gradient(to top, black 60%, transparent);
  -webkit-mask-image: linear-gradient(to top, black 60%, transparent);
  contain: layout style;
}
.transcript-strip .line {
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: 0.005em;
  opacity: 0.55;
  transition: opacity 200ms ease;
}
.transcript-strip .line.fresh { opacity: 0.95; color: #eee; }
.transcript-strip .line.partial {
  opacity: 0.95;
  color: #6dd47e;
  font-style: italic;
}

/* ---------------- Manuscript list (cockpit-side) ------------------ */
.manuscript-section { display: none; }
.manuscript-section.visible { display: block; }
.ms-slide {
  margin-bottom: 0.9rem;
  border-left: 1px solid rgba(255,255,255,0.06);
  padding-left: 0.6em;
}
.ms-row {
  display: grid;
  grid-template-columns: 2.4em 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 6px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: background-color 120ms ease;
}
.ms-row.ms-head { font-weight: 600; }
.ms-row:hover { background: rgba(255,255,255,0.04); }
.ms-row .ms-idx {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.32);
  font-variant-numeric: tabular-nums;
}
.ms-row .ms-title {
  font-size: 12.5px;
  color: #ddd;
}
.ms-para {
  margin: 2px 0 2px 2.4em;
  padding: 6px 10px;
  font-size: 11.5px;
  line-height: 1.55;
  color: rgba(255,255,255,0.55);
  border-left: 2px solid transparent;
  border-radius: 2px;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}
.ms-para:hover { background: rgba(255,255,255,0.04); color: #ddd; }
.ms-para.active {
  color: #eee;
  background: rgba(109,212,126,0.10);
  border-left-color: rgba(109,212,126,0.7);
}

/* ---------------- Activity panel (cockpit-side) ------------------ */
.activity-section { opacity: 0.85; }
.activity-row {
  display: grid;
  grid-template-columns: 4.5em 5em 1fr;
  gap: 8px;
  align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 11px;
  line-height: 1.45;
}
.activity-row .ts {
  color: rgba(255,255,255,0.32);
  font-variant-numeric: tabular-nums;
}
.activity-row .kind {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  align-self: center;
}
.activity-row.kind-tool .kind  { color: #6dd47e; }
.activity-row.kind-gate .kind  { color: #fbbf24; }
.activity-row.kind-error .kind { color: #f87171; }
.activity-row.kind-session .kind { color: #93c5fd; }
.activity-row.kind-response .kind { color: #c4b5fd; }
.activity-row .body {
  color: #ddd;
  word-break: break-word;
}
.activity-row .body .detail {
  display: block;
  color: rgba(255,255,255,0.45);
  font-size: 10.5px;
  margin-top: 1px;
}

/* ---------------- Share-code badge (cockpit chrome) -------------- */
.code-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  font-family: var(--mono);
}
.code-badge .label {
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}
.code-badge .code {
  font-size: 13px;
  letter-spacing: 0.22em;
  font-weight: 700;
  color: #eee;
}

/* ---------------- Manual-slide overlay (M key) ------------------- */
.manual-overlay {
  position: fixed; inset: 0;
  display: none;
  place-items: center;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(6px);
  z-index: 150;
}
.manual-overlay.visible { display: grid; }
.manual-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(720px, 80vw);
  padding: 28px;
  background: rgba(20,20,20,0.95);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
}
.manual-form .label {
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--dim);
}
.manual-form input {
  font-family: var(--mono);
  font-size: 18px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  color: #eee;
  outline: none;
}
.manual-form input:focus { border-color: rgba(109,212,126,0.5); }
.manual-form .hint {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}

/* ---------------- Template modal ---------------- */
/* Generic dialog used for the script-template flow. Opens when the
 * operator drops a .md without slide markers OR clicks the Template
 * chrome button. Two action paths: copy a meta-prompt for an external
 * AI, or convert in place via the server's /manuscript/convert. */
.modal-overlay {
  position: fixed; inset: 0;
  display: none;
  place-items: center;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(6px);
  z-index: 160;
  padding: 24px;
}
.modal-overlay.visible { display: grid; }
.modal-overlay .modal {
  width: min(820px, 92vw);
  max-height: min(86vh, 760px);
  display: flex;
  flex-direction: column;
  background: rgba(20,20,20,0.97);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 22px 24px 20px;
  gap: 14px;
}
.modal-overlay .modal header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal-overlay .modal h2 {
  font-size: 14px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
  font-weight: 600;
  margin: 0;
  flex: 1;
}
.modal-close {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover { color: #eee; }
.modal-lead {
  font-size: 13px;
  line-height: 1.55;
  color: rgba(255,255,255,0.75);
  margin: 0;
}
.modal-lead code {
  font-family: var(--mono);
  font-size: 12px;
  padding: 1px 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  color: #eee;
}
.modal-template {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: rgba(255,255,255,0.78);
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal-actions .primary-btn { min-width: 120px; }
.modal-actions .primary-btn:disabled { opacity: 0.55; cursor: progress; }
