/* ==========================================================================
   Leo Console — additive layer.
   Tokens only (Vapor Cathedral rule 1). No raw values, no new colours.
   The base sheet ships .sidebar/.topbar at opacity:0 because the source page
   fades them in with GSAP; this layer does the same reveal in CSS.
   ========================================================================== */

.sidebar, .topbar { animation: leoIn var(--dur-slow) var(--ease-out) forwards; }
.sr { opacity: 0; animation: leoUp var(--dur-slow) var(--ease-out) forwards; }
.sr-group > * { opacity: 0; animation: leoUp var(--dur-slow) var(--ease-out) forwards; }
.sr-group > *:nth-child(2) { animation-delay: .05s }
.sr-group > *:nth-child(3) { animation-delay: .1s }
.sr-group > *:nth-child(4) { animation-delay: .15s }
.sr-group > *:nth-child(5) { animation-delay: .2s }
.sr-group > *:nth-child(6) { animation-delay: .25s }

@keyframes leoIn { to { opacity: 1 } }
@keyframes leoUp { from { opacity: 0; transform: translateY(var(--sp-5)) } to { opacity: 1; transform: none } }

/* section rhythm */
.leo-sec { scroll-margin-top: var(--sp-6); margin-bottom: var(--sp-16); }
.leo-sec:last-child { margin-bottom: var(--sp-10); }

/* the reel library: poster card built from .card + tokens */
.leo-reel { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.leo-poster {
  position: relative; aspect-ratio: 9 / 16; background: var(--surface-3);
  border-bottom: 1px solid var(--line); overflow: hidden; cursor: pointer;
}
.leo-poster img { width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform var(--dur-slow) var(--ease-out); }
.leo-poster:hover img { transform: scale(1.04); }
.leo-poster .leo-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: linear-gradient(180deg, transparent 45%, var(--scrim));
  opacity: 0; transition: opacity var(--dur-base) ease;
}
.leo-poster:hover .leo-play, .leo-poster:focus-visible .leo-play { opacity: 1; }
.leo-play span {
  width: 52px; height: 52px; border-radius: var(--r-full); background: var(--volt);
  color: var(--ink); display: grid; place-items: center; font-size: var(--fs-md);
  transition: transform var(--dur-base) var(--ease-spring);
}
.leo-poster:hover .leo-play span { transform: scale(1.08); }
.leo-poster:active .leo-play span { transform: scale(.96); }
.leo-stamp {
  position: absolute; left: var(--sp-2); top: var(--sp-2); z-index: 2;
  font-family: 'Source Code Pro', ui-monospace, monospace; font-size: var(--fs-xs);
  background: var(--scrim); color: var(--ink); padding: 2px var(--sp-2);
  border-radius: var(--r-full);
}
[data-theme="light"] .leo-stamp { color: var(--surface-1); }
.leo-reel-body { padding: var(--sp-4); display: grid; gap: var(--sp-2); }
.leo-reel-body h4 { font-size: var(--fs-sm); }
.leo-reel-meta {
  font-family: 'Source Code Pro', ui-monospace, monospace; font-size: var(--fs-xs);
  color: var(--text-3); display: flex; gap: var(--sp-2); flex-wrap: wrap;
}

/* live log */
.leo-log {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4); max-height: 260px; overflow: auto;
  font-family: 'Source Code Pro', ui-monospace, monospace; font-size: var(--fs-xs);
  line-height: 1.8; color: var(--text-2); white-space: pre-wrap; word-break: break-word;
}
.leo-log b { color: var(--volt); font-weight: 600; }
[data-theme="light"] .leo-log b { color: var(--outline-color); }

/* player dialog is wider than the stock .dialog */
.leo-player { max-width: 940px; width: min(94vw, 940px); }
.leo-player video {
  width: 100%; max-height: 62vh; border-radius: var(--r-md);
  background: var(--surface-3); border: 1px solid var(--line); display: block;
}
.leo-player-grid { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  gap: var(--sp-5); align-items: start; }
@media (max-width: 720px) { .leo-player-grid { grid-template-columns: 1fr; } }

/* shot strip */
.leo-shots { display: flex; gap: var(--sp-1); flex-wrap: wrap; }
.leo-shot {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: var(--r-sm);
  font-family: 'Source Code Pro', ui-monospace, monospace; font-size: var(--fs-xs);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2);
}
.leo-shot.ok { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--text); }
.leo-shot.warn { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--text); }
.leo-shot.bad { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--text); }

.leo-kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4);
  font-size: var(--fs-sm); }
.leo-kv dt { color: var(--text-3); font-family: 'Source Code Pro', ui-monospace, monospace;
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .1em; }
.leo-kv dd { color: var(--text); }

.leo-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.leo-mono { font-family: 'Source Code Pro', ui-monospace, monospace; }
.leo-scroll { max-height: 300px; overflow: auto; }

/* two-column blocks that may hold a wide table — both tracks must be allowed
   to shrink, or the table pushes its panel past the edge and gets clipped */
.leo-cols { display: grid; gap: var(--sp-5);
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); align-items: start; }
.leo-cols > * { min-width: 0; }

/* idea cards: the whole card is the hit target */
.leo-idea { cursor: pointer; display: flex; flex-direction: column; padding: 0; overflow: hidden;
  transition: border-color var(--dur-base) ease, transform var(--dur-base) var(--ease-spring); }
.leo-idea:hover { border-color: var(--volt); }
.leo-idea:active { transform: scale(.99); }
.leo-idea:focus-visible { outline: 2px solid var(--volt); outline-offset: 2px; }
.leo-idea-poster { position: relative; aspect-ratio: 16 / 10; background: var(--surface-3);
  border-bottom: 1px solid var(--line); overflow: hidden; }
.leo-idea-poster img { width: 100%; height: 100%; object-fit: cover; object-position: center 28%;
  display: block; transition: transform var(--dur-slow) var(--ease-out); }
.leo-idea:hover .leo-idea-poster img { transform: scale(1.05); }
.leo-idea-body { padding: var(--sp-4); display: grid; gap: var(--sp-2); }
.leo-idea-body p { font-size: var(--fs-sm); color: var(--text-2); }
.leo-idea-foot { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  margin-top: var(--sp-1); }

/* the now-rendering panel is one big button */
.leo-clickable { cursor: pointer; transition: border-color var(--dur-base) ease; }
.leo-clickable:hover { border-color: var(--volt); }
.leo-clickable:focus-visible { outline: 2px solid var(--volt); outline-offset: 2px; }
.leo-hint { font-size: var(--fs-xs); color: var(--text-3);
  font-family: 'Source Code Pro', ui-monospace, monospace; }

/* script view */
.leo-shot-row { border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--sp-4); background: var(--surface-1); margin-bottom: var(--sp-3); }
.leo-shot-head { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  margin-bottom: var(--sp-3); }
.leo-shot-n { width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: var(--r-sm); background: var(--volt); color: var(--ink); font-weight: 700;
  font-family: 'Source Code Pro', ui-monospace, monospace; font-size: var(--fs-xs); }
.leo-line { font-size: var(--fs-md); color: var(--text); margin: var(--sp-2) 0;
  padding-left: var(--sp-4); border-left: 2px solid var(--volt); }
.leo-dim { font-size: var(--fs-xs); color: var(--text-3); }
.leo-prose { font-size: var(--fs-sm); color: var(--text-2); }

/* ---------- generation indicators ---------- */
/* an element that is actively being produced: a slow accent breathe on its edge */
.leo-working { border-color: var(--line-strong); animation: leoWork 2.4s var(--ease-out) infinite; }
@keyframes leoWork {
  0%, 100% { border-color: var(--line); }
  50%      { border-color: var(--volt); }
}
.leo-shot.working { background: var(--volt-dim); border-color: var(--volt); }
.leo-shot.working .spinner-ring { width: 14px; height: 14px; border-width: 2px; }

/* the live progress bar keeps its shimmer even at 0% width */
.leo-progress-live { position: relative; }
.leo-progress-live::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(115deg, transparent 30%, var(--volt-dim) 50%, transparent 70%);
  animation: leoSweep 1.9s var(--ease-out) infinite;
}
@keyframes leoSweep { from { transform: translateX(-100%) } to { transform: translateX(100%) } }

.leo-poster-live { display: grid; place-items: center;
  background: linear-gradient(180deg, var(--surface-2), var(--surface-3)); cursor: pointer; }
.leo-live-center { display: grid; place-items: center; text-align: center; }

/* reduced motion: keep the meaning, drop the movement */
@media (prefers-reduced-motion: reduce) {
  .leo-working { animation: none; border-color: var(--volt); }
  .leo-progress-live::after { animation: none; opacity: 0; }
}


/* ---- per-reel review notes (team feedback, autosaved) ------------------- */
.leo-note {
  display: grid;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line);
}
.leo-note-label {
  font-size: var(--fs-xs);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.leo-note-box {
  width: 100%;
  min-height: 68px;
  resize: vertical;
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.leo-note-status {
  min-height: 1em;
  font-size: var(--fs-xs);
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}


/* ---- factory power panel ----------------------------------------------- */
.leo-control { display: grid; gap: var(--sp-3); }
.leo-control-state {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-md); font-weight: 600;
}
.leo-control-log {
  margin: 0; max-height: 190px; overflow: auto;
  font-family: 'Source Code Pro', ui-monospace, monospace;
  font-size: var(--fs-xs); line-height: 1.6; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--sp-3); white-space: pre-wrap;
}

/* ---- mobile bottom nav ------------------------------------------------- */
/* The sidebar is display:none under 900px, which left phones with no way to
   move between sections but scrolling. This is that nav. */
.leo-tabbar { display: none; }

@media (max-width: 900px) {
  .leo-tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 200;                      /* under dialogs (300) and toasts (210) */
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    align-items: stretch;
    background: color-mix(in srgb, var(--surface-1) 88%, transparent);
    backdrop-filter: blur(14px) saturate(1.3);
    -webkit-backdrop-filter: blur(14px) saturate(1.3);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .leo-tab {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 3px;
    padding: var(--sp-2) var(--sp-1) calc(var(--sp-2) + 2px);
    min-height: 56px;                  /* comfortable thumb target */
    font-size: 10px;
    letter-spacing: .04em;
    text-decoration: none;
    color: var(--text-3);
    border-top: 2px solid transparent;
    transition: color var(--dur-base) ease, border-color var(--dur-base) ease;
    -webkit-tap-highlight-color: transparent;
  }
  .leo-tab-ico {
    font-size: var(--fs-md);
    line-height: 1;
    transition: transform var(--dur-base) var(--ease-spring);
  }
  .leo-tab.active { color: var(--text); border-top-color: var(--volt); }
  /* The player/script sheet sits at z-index 100, below this bar — slide the bar
     out of the way instead of letting it float over an open sheet. */
  .leo-tabbar { transition: transform var(--dur-base) var(--ease-out); }
  body:has(.scrim.open) .leo-tabbar { transform: translateY(110%); }
  .leo-tab.active .leo-tab-ico { color: var(--volt); transform: translateY(-1px) scale(1.06); }
  .leo-tab:active .leo-tab-ico { transform: scale(.92); }

  /* keep the last section, toasts and open dialogs clear of the bar */
  .content { padding-bottom: calc(var(--sp-16) + env(safe-area-inset-bottom, 0px)); }
  .sonner { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); right: var(--sp-3); left: var(--sp-3); justify-items: stretch; }
  .leo-sec { scroll-margin-top: var(--sp-3); }
}

@media (prefers-reduced-motion: reduce) {
  .leo-tab, .leo-tab-ico { transition: none; }
}

/* ---- mobile scrolling -------------------------------------------------- */
/* Two separate freezes lived here, both from the base design system.

   1. The base sheet clips horizontal overflow on <body>. Body overflow
      propagates to the viewport, and on iOS Safari a clipped viewport whose
      scroller is the body can stop responding to touch entirely — the page
      scrolls with window.scrollTo but not with a finger. Clip on <html>
      instead: `clip` never creates a scroll container, and the axis left
      visible still resolves to auto, so vertical scrolling survives. */
html { overflow-x: hidden; overflow-x: clip; }
body { overflow-x: visible; }
/* nothing fixed may stick out sideways and re-create that clip pressure */
.orb { width: min(720px, 100vw); }

/*  2. Under 640px the base sheet morphs .dialog into a bottom sheet with
      `touch-action:none` (it was drag-to-dismiss on the source page; nothing
      here drags it) and no height cap. A reel player or a long script grew
      taller than the phone, so the sheet hung off the top of the screen with
      its close button above y=0, could not be scrolled, and sat over a body we
      had locked — a completely frozen screen with no way out but a reload.
      Below is a real bottom sheet instead: full-bleed, capped, scrolling
      inside itself, with a sticky head you can also drag down to dismiss. */
.leo-sheet-head > .row { justify-content: space-between; align-items: flex-start; margin-bottom: var(--sp-4); }

@media (max-width: 640px) {
  /* [data-theme] .dialog{overflow:hidden} in the generated layer outranks a
     bare .dialog — match its specificity or the sheet stays unscrollable */
  [data-theme] .dialog, [data-theme] .leo-player {
    width: 100%; max-width: none;
    max-height: 92dvh;
    padding: var(--sp-3) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom, 0px));
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }
  /* head rides along the top of the sheet: the ✕ is always one tap away, and
     it is the drag handle, so it takes the gesture instead of the scroller */
  .leo-sheet-head {
    position: sticky; top: calc(var(--sp-3) * -1); z-index: 5;
    margin: calc(var(--sp-3) * -1) calc(var(--sp-4) * -1) var(--sp-3);
    padding: var(--sp-3) var(--sp-4) var(--sp-2);
    background: var(--surface-1);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-bottom: 1px solid var(--line);
    touch-action: none;
    cursor: grab;
  }
  .leo-sheet-head:active { cursor: grabbing; }
  /* the base sheet stacks .dialog .row column-reverse for its footer buttons,
     which threw the head's title under a centred ✕ — the head is a title row */
  .leo-sheet-head > .row {
    flex-direction: row; align-items: flex-start; gap: var(--sp-3); margin-bottom: 0;
  }
  .leo-sheet-head > .row .btn { width: auto; height: 36px; min-height: 36px; flex: none; }
  .leo-sheet-head h3 { font-size: var(--fs-md); }
  .leo-sheet-head #plMeta, .leo-sheet-head #scMeta { font-size: 10.5px; }
  /* one scroller, not two — the sheet itself scrolls */
  #scBody.leo-scroll { max-height: none !important; overflow: visible; }
  /* portrait reels: size the frame from the video's own ratio instead of
     pillarboxing a 9:16 reel inside a full-width landscape box */
  .leo-player video {
    height: 50dvh; width: auto; max-width: 100%; margin: 0 auto;
    object-fit: contain; background: #0b0b0b;
  }
  .leo-player .leo-actions .btn { width: 100%; }
}
