/* Light chrome, dark stage. Every colour in the UI is one of these tokens;
   the few literals live in js/captions.js, js/scene.js and js/overlay.js,
   which draw inside the video frame. */
:root {
  /* Depth stack (deepest to lightest) */
  --bg-deep: #e9ebef;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --surface: #f1f3f6;
  --surface-2: #e6e9ee;
  --line: #dfe3e9;
  /* The stage sits on a neutral dark field so footage and the 9:16 frame pop */
  --stage-surround: #2b2f36;

  --text: #111827;
  --text-dim: #4b5563;
  --text-faint: #5f6672; /* 4.75:1 even on --surface-2 */

  /* Brand (amber). The fill is amber with dark ink on it; --brand-hi is the
     amber dark enough to be *text* on white. Never amber text on white. */
  --brand: #f59e0b;
  --brand-hi: #b45309;
  --brand-soft: rgba(245, 158, 11, .16);
  --brand-border: rgba(245, 158, 11, .5);
  /* Contrast companions (WCAG 2.2 AA; ratios against the surfaces they sit on):
     --brand-text: amber text on a --brand-soft tint (5.7:1; --brand-hi is
       only 4.0–4.4:1 there, fine on plain white at 5:1);
     --brand-press: hover/pressed fill for amber buttons, ink on it 5.6:1
       (ink on --brand-hi is 3.6:1). */
  --brand-text: #92400e;
  --brand-press: #d97706;

  --red: #e11d48;        /* white on it 4.7:1 */
  --red-press: #be123c;  /* hover fill for danger buttons, white on it 6.3:1 */
  --green: #047857;      /* text on white 5.5:1, on --surface 4.9:1 */
  /* Form-field outlines: 3:1 against the panel (WCAG 1.4.11); --line is for
     dividers and decorative card edges only. */
  --field-line: #868e9a;

  /* Timeline track semantics (fills on white: 3:1 against the panel) */
  --track-voice: #f59e0b;
  --track-sfx: #0d9488;
  --track-anim: #7c3aed;
  --track-scene: #059669;
  --track-video: #0284c7;
  --track-text: #db2777;
  --track-image: #ea580c;
  --tick: #cfd4dc;
  --tick-minor: #e3e6eb;
  --grid: #e8eaee;

  --scroll-thumb: #c9ced8;
  --scroll-thumb-hover: #aab1be;

  /* Ink on brand / light fills, and the few translucent surfaces */
  --ink: #0f172a;
  --white: #ffffff;
  --glass: rgba(255, 255, 255, .94);
  --scrim: rgba(17, 24, 39, .45);
  --stage-bg: #05070b;
  --stage-ring: rgba(17, 24, 39, .35);
  --stage-shadow: 0 20px 50px rgba(17, 24, 39, .35);
  --shadow-1: 0 1px 3px rgba(17, 24, 39, .08);
  --shadow-2: 0 16px 48px rgba(17, 24, 39, .18);
  --shadow-thumb: 0 1px 3px rgba(17, 24, 39, .25);
  --size-own: #0284c7; /* a size adjusting its own framing (sizesBar.js): the stage ring */
  --size-own-ink: #0369a1; /* the same, as a fill under white text (5.9:1) */
  --badge: rgba(17, 24, 39, .78); /* type badges over thumbnails: white text 7:1+ on any picture */
  --stage-ring-preview: rgba(255, 255, 255, .45);
  --warn: #c2410c;
  --warn-soft: rgba(249, 115, 22, .08);
  --warn-border: rgba(249, 115, 22, .4);
  /* Drawn by js/timelineThumbs.js and js/timeline.js (read once per render) */
  --waveform: rgba(146, 64, 14, .5);
  --fade-fill: rgba(17, 24, 39, .22);
  --fade-line: rgba(17, 24, 39, .7);

  /* Type scale — nothing in the chrome goes below --fs-small */
  --fs-body: 13px;
  --fs-label: 12px;
  --fs-small: 11px;
  --fs-h: 16px;
  --fs-script: 15px; /* script text; the mirror under each textarea must match it */

  /* Stacking, bottom to top, for everything that floats over the page.
     (Values under 10 are local to the stage and the timeline.) */
  --z-popover: 30;
  --z-card-menu: 31;
  --z-topbar: 40;
  --z-modal: 50;
  --z-dialog: 60;
  --z-toast: 70;
  --z-tooltip: 80;
  --z-dragtip: 90;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  /* Spacing rhythm (sidebar) */
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --dock-h: 200px;
  --tl-ruler-h: 22px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* The hidden attribute always wins — component rules that set display
   (flex rows, grids) must not resurrect elements app.js has hidden. */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

/* Slim scrollbars everywhere */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

/* ---- Icons ---- */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  pointer-events: none;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 16px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex: none;
  /* backdrop-filter makes a stacking context; lift it so header popovers
     (Export) sit above the panels below, but under modals (z 50). */
  position: relative;
  z-index: var(--z-topbar);
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.logo-tile {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: var(--ink);
  font-size: var(--fs-h);
  font-weight: 800;
}

.topbar h1 {
  font-size: 15px;
  letter-spacing: 2px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}
.topbar h1 span { color: var(--brand-hi); font-weight: 800; }

/* Center segmented aspect-ratio switch */
.ratio-switch {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.ratio-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  position: relative;
  background: none;
  border: none;
  border-radius: 9px;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: var(--fs-label);
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.ratio-btn:hover { color: var(--text); }
.ratio-btn.active {
  background: var(--brand);
  color: var(--ink);
}
.ratio-sub { font-weight: 500; }
/* A tab is its button plus, on the active one, an options caret. */
.ratio-tab { position: relative; display: flex; align-items: center; border-radius: 9px; }
.ratio-tab.active { background: var(--brand); }
.ratio-tab.active .ratio-btn { background: none; }
.ratio-main { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.ratio-dot { width: 7px; height: 7px; border-radius: 50%; margin-left: 2px; flex: none; }
.ratio-dot--own { background: var(--size-own); }
.ratio-dot--check { background: none; border: 1.5px solid currentColor; }
.ratio-tab.active .ratio-dot--own { box-shadow: 0 0 0 1.5px var(--white); }
.ratio-more, .ratio-add {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: inherit; padding: 4px 6px 4px 0; border-radius: 9px;
}
.ratio-more { color: var(--text-faint); padding-left: 0; margin-left: -6px; }
.ratio-more:hover { color: var(--text); }
.ratio-tab.active .ratio-more { color: var(--ink); }
.ratio-more .icon { width: 14px; height: 14px; }
.ratio-add { color: var(--text-dim); padding: 6px 8px; position: relative; }
.ratio-add:hover { color: var(--text); background: var(--panel); }
.ratio-add .icon { width: 14px; height: 14px; }
.ratio-add--labelled { display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; font: 700 var(--fs-label) var(--font); }
.ratio-ready { margin-left: 6px; white-space: nowrap; }
.ratio-switch .ratio-menu { top: calc(100% + 8px); bottom: auto; left: 0; min-width: 210px; }
.ratio-switch .ratio-menu .script-hint { margin: 0 2px; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ---- Editor layout: viewport left, control panel right ---- */
.studio {
  flex: 1;
  display: flex;
  min-height: 0;
}

.viewport {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 16px 10px;
  background: var(--stage-surround);
}

/* Floating glass toolbars over the stage */
.stage-toolbar {
  position: absolute;
  top: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: var(--fs-label);
  color: var(--text-dim);
}
.stage-toolbar--left { left: 14px; }
.stage-safe-toggle { font-size: var(--fs-label); color: var(--text-dim); white-space: nowrap; }
.stage-safe-toggle input { accent-color: var(--brand-hi); }
/* Placeholder text: the browser's grey is 4.3:1 on the field background. */
::placeholder { color: var(--text-faint); opacity: 1; }
/* Every checkbox: dark amber, so the checked box reads against white (5:1). */
input[type="checkbox"] { accent-color: var(--brand-hi); }

/* Safe-zone guides pinned over the stage. Vertical (9:16) shows the regions
   short-video apps reserve for their UI; other formats show a plain title-safe frame. */
.safe-zone { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.sz { position: absolute; background: color-mix(in srgb, var(--red) 12%, transparent); border: 1px dashed color-mix(in srgb, var(--red) 45%, transparent); display: none; }
.sz-top { top: 0; left: 0; right: 0; height: 6%; border-width: 0 0 1px; }
.sz-bottom { bottom: 0; left: 0; right: 0; height: 13%; border-width: 1px 0 0; }
.sz-rail { top: 40%; right: 0; bottom: 13%; width: 16%; border-width: 1px 0 1px 1px; }
.stage-wrap[data-format="vertical"] .sz { display: block; }
.sz-frame {
  position: absolute;
  inset: 5%;
  border: 1px dashed color-mix(in srgb, var(--text) 35%, transparent);
  border-radius: 4px;
}
.stage-wrap[data-format="vertical"] .sz-frame { display: none; }

/* Phone-frame look: outline (not border) so js/scene.js inline sizing is unaffected */
.stage-wrap {
  position: relative;
  background: var(--stage-bg);
  border-radius: var(--r-lg);
  outline: 2px solid var(--stage-ring);
  outline-offset: -2px;
  overflow: hidden;
  box-shadow: var(--stage-shadow);
}
.stage-wrap:fullscreen {
  border-radius: 0;
  outline: none;
  box-shadow: none;
}

#stage { width: 100%; height: 100%; display: block; cursor: grab; }
#stage.dragging { cursor: grabbing; }

/* Caption / Text Overlay graphic layer: pinned over the stage, click-through
   so STAN dragging still reaches the WebGL canvas underneath. */
.stage-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Exporting: a white pill with a blinking red dot (only the dot blinks). */
.rec-badge {
  position: absolute;
  top: 12px;
  left: 14px;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: .5px;
  box-shadow: var(--shadow-thumb);
}
.rec-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s steps(2) infinite;
}
.rec-badge.on { display: inline-flex; }
@keyframes blink { 50% { opacity: .25; } }

/* ---- Player bar under the stage ---- */
.player-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(640px, 100%);
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 6px 12px;
}

/* Scrub bar: a slim range the whole width between the time and the ratio */
.player-scrub {
  flex: 1;
  min-width: 80px;
  height: 4px;
  margin: 0 4px;
}
.player-scrub::-webkit-slider-thumb { width: 12px; height: 12px; border-width: 2px; }
.player-scrub:disabled { opacity: .35; }

.pbtn {
  background: none;
  border: none;
  color: var(--text);
  padding: 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: background .15s, color .15s;
}
.pbtn:hover:not(:disabled) { background: var(--surface); color: var(--brand-hi); }
.pbtn:disabled { opacity: .35; cursor: default; }

.player-time {
  font-family: var(--mono);
  font-size: var(--fs-label);
  flex: none;
  font-variant-numeric: tabular-nums;
  color: var(--brand-hi);
}
.player-total { color: var(--text-dim); }

#playerPlayBtn {
  width: 28px;
  height: 28px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
  background: var(--brand);
  color: var(--ink);
}
#playerPlayBtn:hover:not(:disabled) { background: var(--brand-press); color: var(--ink); }
.player-ratio {
  font-size: var(--fs-small);
  flex: none;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 8px;
  white-space: nowrap;
}

/* ---- Left panel: tabs for what you add; right panel: the selected clip ---- */
.side {
  flex: none;
  width: var(--side-w, 340px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-width: 0;
}

.tabbar {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line);
}
.tab-btn {
  flex: 1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 9px;
  min-width: 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-dim);
  font: 600 var(--fs-small) var(--font);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab-btn .icon { width: 17px; height: 17px; }
.tab-btn:hover { color: var(--text); }
.tab-btn[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }

.tab-pane {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-4);
  flex-direction: column;
  gap: var(--sp-5);
}
.tab-pane.active { display: flex; }
.tab-pane[data-tab="script"] { padding: 0; }
.tab-actions { display: flex; flex-direction: column; gap: 8px; }
.tab-actions--row { flex-direction: row; flex-wrap: wrap; align-items: center; }
/* Popover menus inside a tab open downward, under their button. */
.tab-menu-host { position: relative; }
.tab-menu-host .dock-menu { bottom: auto; top: calc(100% + 6px); left: 0; right: auto; }

/* The inspector: only ever the selected clip. */
.inspector {
  flex: none;
  width: 280px;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding: var(--sp-4);
  background: var(--panel);
  border-left: 1px solid var(--line);
}
.inspector-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: var(--fs-body);
  line-height: 1.45;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
}
.inspector-empty .icon { width: 22px; height: 22px; color: var(--text-faint); }

.control-group { display: flex; flex-direction: column; gap: var(--sp-3); }

/* Group heading */
.group-title,
.group-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-body);
  color: var(--text);
  font-weight: 700;
}
.group-title .icon, .group-label .icon { width: 15px; height: 15px; color: var(--text-dim); }

/* Label naming a single control (e.g. "Transition in", "Speed") */
.field-label {
  font-size: var(--fs-label);
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-dim);
  font-weight: 600;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr; /* chips need the row; the Settings window keeps its three columns */
  gap: 12px;
}
.modal .control-grid { grid-template-columns: 1fr 1fr 1fr; }

.slider-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 32px;
  font-size: var(--fs-label);
  color: var(--text-dim);
}
.slider-row > label { flex: none; width: 64px; font-weight: 600; }
.slider-val {
  flex: none;
  min-width: 72px;
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-label);
  color: var(--text);
}
.slider-row input[type="range"]:disabled { opacity: .35; }

/* Caption and text style tiles: a sample in the style's own colours */
.cap-preset-grid, .text-preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cap-preset, .text-preset {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  transition: border-color .15s, background .15s;
}
.cap-preset:hover, .text-preset:hover { border-color: var(--text-dim); }
.cap-preset.active { background: var(--brand-soft); border-color: var(--brand-border); }
.cap-preset-name { font-size: var(--fs-label); font-weight: 700; color: var(--text); }
.cap-preset.active .cap-preset-name { color: var(--brand-text); }
.cap-sample, .text-sample {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3em;
  height: 44px;
  border-radius: 6px;
  background: var(--stage-bg);
  color: var(--cap, var(--white));
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
}
.cap-sample b { color: var(--hi, var(--brand)); }
.cap-sample--lg { font-size: 17px; }
.cap-sample--sm { font-size: 12px; font-weight: 600; }
.text-sample--lg { font-size: 17px; }
.text-sample--sm { font-size: 12px; font-weight: 600; align-items: flex-end; padding-bottom: 6px; }


/* Picture tiles standing in for a select (js/tiles.js) */
.tile-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.tile:hover { border-color: var(--text-dim); }
.tile.active { border-color: var(--brand-hi); box-shadow: 0 0 0 1px var(--brand-hi); } /* 5:1 on white; plain amber is 2.2:1 */
.tile:disabled, .tile-row.is-disabled .tile { opacity: .45; cursor: default; }
.tile-pic {
  display: block;
  aspect-ratio: 16 / 9;
  border-radius: 5px;
  overflow: hidden;
  background: var(--stage-bg);
}
.tile-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-pic--glyph { display: grid; place-items: center; background: var(--surface-2); color: var(--text-dim); }
.tile-pic--glyph .icon { width: 18px; height: 18px; }
.tile-label { font-size: var(--fs-small); font-weight: 600; color: var(--text-dim); padding: 0 2px 2px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile.active .tile-label { color: var(--text); }
/* Mood glyphs on the performance chips */
.preset .icon { width: 13px; height: 13px; margin-right: 5px; vertical-align: -2px; opacity: .8; }

/* Asset tile actions live behind hover (or the "…" button on touch) */
@media (hover: none) { .asset-more { opacity: 1; } }

/* Text clip gizmo on the stage (js/stageGestures.js) */
#textGizmo {
  position: absolute;
  border: 1.5px dashed var(--track-text);
  border-radius: 4px;
  cursor: ns-resize;
  touch-action: none;
  z-index: 6;
}
#textGizmo .gizmo-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--track-text);
  border: 2px solid var(--white);
  cursor: nwse-resize;
  touch-action: none;
}

/* Crop frame over the stage: pan grip + zoom handle (js/stageGestures.js) */
#cropGizmo {
  position: absolute;
  inset: 0;
  border: 1.5px dashed color-mix(in srgb, var(--track-video) 80%, transparent);
  border-radius: inherit;
  pointer-events: none;
  z-index: 6;
}
#cropGizmo .crop-grip {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  padding: 4px 10px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font: 600 var(--fs-small) var(--font);
  cursor: move;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}
#cropGizmo .gizmo-handle {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--track-video);
  border: 2px solid var(--white);
  cursor: nwse-resize;
  pointer-events: auto;
  touch-action: none;
}
/* Height handle above STAN */
#liftHandle {
  position: absolute;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--white);
  box-shadow: var(--shadow-thumb);
  cursor: ns-resize;
  touch-action: none;
  z-index: 6;
}
#liftHandle::after { content: ''; position: absolute; left: 50%; top: 100%; width: 2px; height: 14px; margin-left: -1px; background: color-mix(in srgb, var(--brand) 70%, transparent); }

/* Script field: a mirror behind the textarea draws pause markers and [tags]
   as chips under the real characters (same font, padding and wrapping). */
.script-field { position: relative; margin: -4px -7px; }
.script-field .script-text { position: relative; z-index: 1; margin: 0; background: transparent; }
.script-field:focus-within { border-radius: var(--r-sm); background: var(--bg); }
.script-mirror {
  position: absolute;
  inset: 0;
  padding: 4px 7px;
  border: 1px solid transparent;
  font: 500 var(--fs-script)/1.45 var(--font);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: transparent;
  pointer-events: none;
  overflow: hidden;
}
.script-mirror mark { color: transparent; border-radius: 6px; background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand-border); }
.script-mirror mark.script-tagmark { background: color-mix(in srgb, var(--track-anim) 14%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--track-anim) 45%, transparent); }

/* Audio tiles: the waveform fades in over the mic placeholder */
.asset-thumb .asset-wave { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .2s; }
.asset-thumb:not(.placeholder) .asset-wave { opacity: 1; }
.asset-thumb.placeholder .asset-wave[src] { opacity: 1; }

/* Media tiles drag onto the timeline */
.asset-card[draggable="true"] { cursor: grab; }
.asset-card.dragging { opacity: .5; }
.tl-dropline { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--brand); box-shadow: 0 0 0 1px var(--white); pointer-events: none; z-index: 6; }

/* ---- Bottom dock: toolbar + multi-track timeline ---- */
.dock {
  flex: none;
  height: var(--dock-h);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top: 1px solid var(--line);
  position: relative;
}

.dock-resizer {
  position: absolute;
  top: -3px;
  left: 0;
  right: 0;
  height: 7px;
  cursor: ns-resize;
  z-index: 5;
}
.dock-resizer:hover { background: var(--brand-soft); }

.dock-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.toolbar-zone { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.toolbar-right { justify-content: flex-end; }

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--line);
  margin: 0 4px;
  flex: none;
}

.zoom-controls { display: flex; align-items: center; gap: 6px; }
.zoom-controls input[type="range"] { width: 100px; flex: none; }

.dock-timeline {
  flex: 1;
  min-height: 0;
  display: flex;
}

.tl-headers {
  flex: none;
  width: 96px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
  /* Room for the tracks' horizontal scrollbar, so a scrollTop mirrored from
     .tl-scroll is always reachable here too. */
  padding-bottom: 20px;
}
.tl-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  font-size: var(--fs-small);
  font-weight: 700;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
}
.tl-header--ruler {
  height: var(--tl-ruler-h);
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
}

/* Small header buttons (add/remove a voice lane). */
.tl-header-action {
  flex: none;
  margin-left: auto;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  font-size: var(--fs-small);
  line-height: 1;
  cursor: pointer;
}
.tl-header-action + .tl-header-action { margin-left: 4px; }
.tl-header-action:hover { color: var(--text); border-color: var(--text-dim); }

.tl-track-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}
.tl-track-dot--scene { background: var(--track-scene); }
.tl-track-dot--text { background: var(--track-text); }
.tl-track-dot--video { background: var(--track-video); }
.tl-track-dot--voice { background: var(--track-voice); }
.tl-track-dot--sfx { background: var(--track-sfx); }
.tl-track-dot--anim { background: var(--track-anim); }
.tl-track-dot--image { background: var(--track-image); }

.tl-scroll {
  flex: 1;
  min-width: 0;
  /* Both axes: tracks scroll vertically when the dock is shorter than the
     stack; the header column follows scrollTop (timeline.js). */
  overflow: auto;
  background: var(--bg-deep);
}

.tl-content {
  position: relative;
  min-height: 100%;
  min-width: 100%;
  cursor: pointer;
}

.tl-track {
  position: relative;
  border-bottom: 1px solid var(--line);
}

.tl-snapline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--brand);
  pointer-events: none;
  z-index: 4;
}

/* ---- Components ---- */
.btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 14px;
  font-family: var(--font);
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.btn-primary { background: var(--brand); color: var(--ink); border-color: var(--brand); font-weight: 800; }
.btn.btn-primary:hover:not(:disabled) { background: var(--brand-press); border-color: var(--brand-press); }

.btn-small { padding: 6px 12px; font-size: var(--fs-label); }
.btn-icon { padding: 6px 8px; }
.btn-icon .icon { width: 15px; height: 15px; }

/* ---- Timeline tracks & clips ---- */
.tl-ruler {
  position: sticky; /* stays put while tracks scroll vertically */
  top: 0;
  z-index: 4;
  height: var(--tl-ruler-h);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.tl-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--tick);
}
.tl-tick--minor {
  top: auto;
  height: 6px;
  bottom: 0;
  background: var(--tick-minor);
}
.tl-tick-label {
  position: absolute;
  top: 3px;
  left: 4px;
  font-family: var(--mono);
  font-size: var(--fs-small);
  color: var(--text-dim);
  white-space: nowrap;
}
.tl-grid {
  position: absolute;
  top: var(--tl-ruler-h);
  bottom: 0;
  width: 1px;
  background: var(--grid);
  pointer-events: none;
}

.tl-thumb {
  position: absolute;
  top: 0;
  bottom: 0;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  opacity: .85;
}

/* Every clip: a tint of its track colour, a 3px bar of the full colour on the
   left, and body text. The tint comes from color-mix so the same rule reads on
   a light panel once the palette flips. */
.tl-clip {
  --clip: var(--track-voice);
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: color-mix(in srgb, var(--clip) 26%, var(--panel));
  border: none;
  border-left: 3px solid var(--clip);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--clip) 40%, transparent);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1;
  overflow: hidden;
  white-space: nowrap;
  cursor: grab;
  user-select: none;
  display: flex;
  align-items: center;
  z-index: 1;
}
.tl-clip-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Type glyph in front of the label (masked SVG so it takes currentColor). */
.tl-clip-label::before {
  content: '';
  flex: none;
  width: 11px;
  height: 11px;
  background: currentColor;
  opacity: .8;
  mask: var(--clip-glyph) center / contain no-repeat;
}
.tl-clip.dragging { cursor: grabbing; filter: brightness(1.12); z-index: 3; }
.tl-clip.selected {
  outline: 2px solid var(--text);
  outline-offset: -1px;
  z-index: 2;
}

/* Faux waveform texture across audio clips (real waveform thumb draws on top) */
.tl-clip--voice::before,
.tl-clip--sfx::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--clip) 55%, transparent) 0 2px, transparent 2px 5px);
  opacity: .25;
  pointer-events: none;
}
.tl-clip--voice { --clip: var(--track-voice); --clip-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='9' y='2' width='6' height='12' rx='3'/%3E%3Cpath d='M5 11a7 7 0 0 0 14 0M12 18v4M8 22h8' stroke='%23000' stroke-width='2.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); }
.tl-clip--sfx { --clip: var(--track-sfx); --clip-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 9v6h4l5 4V5L8 9z'/%3E%3Cpath d='M16 9a4 4 0 0 1 0 6M18.5 6.5a8 8 0 0 1 0 11' stroke='%23000' stroke-width='2.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); }
.tl-clip--anim { --clip: var(--track-anim); --clip-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M13 2L4 14h7l-1 8 9-12h-7z'/%3E%3C/svg%3E"); }
.tl-clip--scene { --clip: var(--track-scene); --clip-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 9h18v12H3zM3 9l2-5 4 1-2 5M9 5l4 1-2 5M13 6l4 1-2 5'/%3E%3C/svg%3E"); }
.tl-clip--video { cursor: default; --clip: var(--track-video); --clip-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 4h18v16H3zM7 4v16M17 4v16M3 9h4M3 15h4M17 9h4M17 15h4' stroke='%23000' stroke-width='2' fill='none'/%3E%3Crect x='3' y='4' width='18' height='16' fill='none' stroke='%23000' stroke-width='2.5'/%3E%3C/svg%3E"); }
.tl-clip--text { --clip: var(--track-text); --clip-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 4h16v5h-3V7h-3.5v11H16v3H8v-3h2.5V7H7v2H4z'/%3E%3C/svg%3E"); }
.tl-clip--image { --clip: var(--track-image); --clip-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 4h18v16H3z' fill='none' stroke='%23000' stroke-width='2.5'/%3E%3Ccircle cx='8.5' cy='9' r='2'/%3E%3Cpath d='M4 19l5-6 4 4 3-3 4 5z'/%3E%3C/svg%3E"); }

.tl-clip--scene .tl-clip-transition {
  flex: none;
  align-self: stretch;
  background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--clip) 45%, transparent) 0 3px, transparent 3px 6px);
  border-right: 1px solid color-mix(in srgb, var(--clip) 60%, transparent);
  pointer-events: none;
}

.anim-clip-row .select { flex: 1; padding: 5px 8px; font-size: var(--fs-label); }

/* A filmstrip speaks for itself: the name only shows while thumbs are missing. */
.tl-clip--video.has-thumbs .tl-clip-label { display: none; }

/* Audio clips carry a waveform image stretched across the clip */
.tl-clip--voice .tl-thumb,
.tl-clip--sfx .tl-thumb { object-fit: fill; opacity: 1; }

/* Trim handles — shown on the selected clip */
.tl-clip-h {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9px;
  cursor: ew-resize;
  z-index: 3;
  display: none;
}
.tl-clip-h--l { left: 0; border-radius: var(--r-sm) 0 0 var(--r-sm); }
.tl-clip-h--r { right: 0; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.tl-clip-h::after {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 55%;
  width: 3px;
  border-radius: 2px;
  background: var(--white);
  box-shadow: var(--shadow-thumb);
}
.tl-clip-h--l::after { left: 3px; }
.tl-clip-h--r::after { right: 3px; }
.tl-clip.selected .tl-clip-h { display: block; }
.tl-clip-h:hover { background: var(--brand-soft); }

.tl-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--brand);
  pointer-events: none;
  z-index: 5;
}

.tl-playhead-cap {
  position: sticky; /* rides the sticky ruler when tracks scroll */
  top: 0;
  margin-left: -5px;
  width: 12px;
  height: 15px;
  background: var(--brand-hi);
  clip-path: polygon(0 0, 100% 0, 100% 55%, 50% 100%, 0 55%);
  pointer-events: auto;
  cursor: ew-resize;
}

.anim-clip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-label);
  color: var(--text-dim);
}
.anim-clip-row input[type="number"] {
  width: 64px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--field-line);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: var(--fs-label);
}
.anim-clip-row .script-input { flex: 1; }
.scene-bg-row { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.scene-bg-summary { flex: 1; min-width: 0; font-size: var(--fs-label); font-weight: 600; color: var(--text); }

.clip-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.clip-kind {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: var(--fs-small);
  font-weight: 700;
  padding: 3px 6px;
}
.clip-kind:hover { color: var(--text); border-color: var(--brand-hi); }

.preset-row { display: flex; gap: 6px; flex-wrap: wrap; }

.preset {
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: var(--fs-label);
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  flex: 1;
}
.preset:hover { color: var(--text); }
.preset.active {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-text);
}

/* Segmented variant for short, non-wrapping rows (Speed, Animate in/out…) */
.preset-row--seg {
  flex-wrap: nowrap;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.preset-row--seg .preset {
  background: none;
  border: none;
  border-radius: calc(var(--r-md) - 3px);
  min-width: 0;
}
.preset-row--seg .preset.active { background: var(--brand-soft); }

.energy-cap { font-size: var(--fs-label); color: var(--text-dim); font-weight: 600; }
.slider-row .energy-cap:first-child { flex: none; width: 64px; }

/* Voice direction in the audio inspector */

.edit-voice-words { margin: 0 0 6px; font-size: var(--fs-body); line-height: 1.4; color: var(--text); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.voice-advanced { margin-top: 8px; }
.voice-advanced summary {
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.voice-advanced summary:hover { color: var(--text); }
.voice-adv-grid { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* Range sliders: brand-filled track (--fill driven from js/sliderUI.js) */
input[type="range"] {
  --fill: 50%;
  flex: 1;
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right,
    var(--brand) 0 var(--fill),
    var(--surface-2) var(--fill) 100%);
  outline: none;
  cursor: pointer;
}
input[type="range"]:focus-visible {
  box-shadow: 0 0 0 2px var(--brand-soft), 0 0 0 3px var(--brand-border);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: 3px solid var(--panel);
  /* A dark-amber edge outside the white ring: the thumb has to read 3:1
     against the panel (amber alone is 2.2:1). */
  box-shadow: 0 0 0 1px var(--brand-hi), var(--shadow-thumb);
  transition: transform .12s ease, box-shadow .12s ease;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.2);
  box-shadow: 0 0 0 1px var(--brand-hi), 0 0 0 5px var(--brand-soft);
}
input[type="range"]:disabled { cursor: default; }
input[type="range"]:disabled::-webkit-slider-thumb { transform: none; }

.select {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  border: 1px solid var(--field-line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: var(--fs-body);
  cursor: pointer;
  outline: none;
  width: 100%;
}
.select:focus,
.anim-clip-row input[type="number"]:focus { border-color: var(--brand-hi); box-shadow: 0 0 0 3px var(--brand-soft); }

.script-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--field-line);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  font-size: var(--fs-body);
  font-family: inherit;
  resize: vertical;
  min-height: 56px;
  outline: none;
  width: 100%;
}
.script-input:focus { border-color: var(--brand-hi); box-shadow: 0 0 0 3px var(--brand-soft); }
.script-input::placeholder { color: var(--text-dim); }

.caption-input { min-height: unset; resize: none; }

.script-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.script-hint { font-size: var(--fs-label); color: var(--text-dim); line-height: 1.4; }

.stan-pos-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.key-row { display: flex; align-items: center; gap: 10px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-body);
  color: var(--text);
  cursor: pointer;
}

.color-swatch {
  width: 44px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel);
  cursor: pointer;
  flex: none;
}

/* Narrow windows: the panels stack under the stage and the page scrolls */
@media (max-width: 760px) {
  :root { --dock-h: 150px; }
  .studio { flex-direction: column; overflow-y: auto; }
  .viewport { flex: none; order: -1; }
  .side { width: 100%; border-right: none; border-top: 1px solid var(--line); }
  .tab-pane { max-height: 60vh; }
  .inspector { width: 100%; border-left: none; border-top: 1px solid var(--line); }
  body { overflow: auto; }
  .tl-headers { width: 58px; }
  .tl-header { padding: 0 6px; font-size: var(--fs-small); }
  .zoom-controls input[type="range"] { display: none; }
  .ratio-btn { padding: 5px 8px; }
  .ratio-btn .ratio-sub { display: none; }
  .ratio-ready span { display: none; }
}

/* Visually hidden, read by screen readers (and by the tests): the status
   live region every message still lands in. */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- Project title (click to rename) + settings ---- */
.project-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 5px 10px;
  font: 600 var(--fs-body) var(--font);
  color: var(--text);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.project-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-name .icon { width: 13px; height: 13px; color: var(--text-faint); }
.project-name:hover { border-color: var(--line); background: var(--surface); }
.project-name:hover .icon { color: var(--text); }

/* Export is the one primary action in the top bar */
.btn.btn-export { background: var(--text); color: var(--panel); border-color: var(--text); font-weight: 700; }
.btn.btn-export:hover:not(:disabled) { background: var(--text-dim); border-color: var(--text-dim); }

/* ---- Project cards ---- */
.projects-bar { flex-wrap: nowrap; }
.projects-bar input { flex: 1; min-width: 0; }
.project-grid {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
  align-content: start;
  padding: 2px;
}
.project-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.project-card:hover { border-color: var(--text-dim); }
.project-card.current { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.project-card.p-version { margin-left: 14px; }
.project-poster {
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  overflow: hidden;
  background: var(--stage-bg);
  display: grid;
  place-items: center;
  color: var(--text-faint);
}
.project-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.project-poster .icon { width: 22px; height: 22px; }
.project-card-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding-right: 26px; }
.project-card-name { font-size: var(--fs-body); font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-card-when { font-size: var(--fs-small); color: var(--text-dim); }
.project-card-menu { position: absolute; right: 8px; bottom: 8px; padding: 2px 7px; font-weight: 800; line-height: 1; }
.project-card-actions { bottom: auto; top: calc(100% - 6px); left: auto; right: 8px; min-width: 150px; z-index: var(--z-card-menu); }
.project-card-actions .btn { justify-content: flex-start; }
.dialog-field { display: flex; flex-direction: column; gap: 6px; }

/* ---- History: milestones (milestonesPanel.js) ---- */
.history-bar .script-hint { flex: 1; min-width: 180px; }
.milestone-list { flex: 1; min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; }
.milestone { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); }
.milestone .project-poster { width: 72px; flex: none; }
.milestone-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.milestone-label { font-size: var(--fs-body); font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.milestone-tag { font-size: var(--fs-small); font-weight: 500; color: var(--text-dim); margin-left: 6px; }
.milestone-note { font-size: var(--fs-small); color: var(--text-faint); }
.milestone-actions { display: flex; gap: 6px; flex: none; }
.milestone.too-old .milestone-actions .btn:not(.btn-danger) { opacity: .5; }
.milestone-auto-toggle { align-self: flex-start; margin-top: 6px; }
.dialog-field textarea { min-height: 72px; resize: vertical; }

/* One line of save state next to the title (saving is automatic) */
.save-state {
  font-size: var(--fs-small);
  color: var(--text-faint);
  white-space: nowrap;
  padding: 3px 4px;
}
.save-state[data-state='saved']::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--green);
  vertical-align: 1px;
}
.save-state[data-state='saving'] { color: var(--text-dim); }
.save-state[data-state='dirty'] { color: var(--text-dim); }
.save-state[data-state='conflict'] { color: var(--red); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---- Progress line in the player bar (anything in flight) ---- */
.player-progress {
  flex: none;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-small);
  color: var(--text-dim);
}
.player-progress::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--brand); animation: progressPulse 1s ease-in-out infinite; vertical-align: 1px; }
@keyframes progressPulse { 50% { opacity: .3; } }

/* ---- Toasts: outcomes at the bottom of the stage; errors stay until dismissed ---- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + 16px);
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 9px 12px 9px 14px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  color: var(--text);
  font-size: var(--fs-body);
  pointer-events: auto;
  animation: toastIn .18s ease-out;
}
.toast--out { opacity: 0; transition: opacity .18s; }
.toast--error { border-color: color-mix(in srgb, var(--red) 55%, transparent); }
.toast--error .toast-text::before { content: '!'; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-right: 8px; border-radius: 50%; background: var(--red); color: var(--white); font-size: var(--fs-small); font-weight: 800; vertical-align: -3px; }
.toast-x { border: 0; background: none; color: var(--text-dim); font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px; }
.toast-x:hover { color: var(--text); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } }

/* ---- Tooltip (js/tooltip.js) ---- */
.tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 280px;
  padding: 6px 9px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-1);
  color: var(--text);
  font-size: var(--fs-label);
  font-weight: 600;
  pointer-events: none;
}
.tooltip kbd {
  padding: 1px 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: var(--fs-small);
  color: var(--text-dim);
}
.tooltip-more { flex-basis: 100%; font-weight: 400; color: var(--text-dim); line-height: 1.35; }

/* ---- Stage shimmer while a project's media is still decoding ---- */
body.media-loading .stage-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--white) 8%, transparent) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: var(--z-modal);
}

.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: min(560px, calc(100dvh - 48px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-2);
}

.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 {
  font-size: var(--fs-h);
  font-weight: 700;
  color: var(--text);
}

.modal-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.project-empty { grid-column: 1 / -1; font-size: var(--fs-label); color: var(--text-dim); padding: 10px 2px; }

/* Home: no video is open, so Projects is the page. It sits under the top bar
   (account menu still reachable, so z below it) and the top bar drops the
   controls that act on a video. */
.modal-backdrop.is-home {
  top: var(--topbar-h, 57px);
  z-index: calc(var(--z-topbar) - 1);
  background: var(--bg);
  backdrop-filter: none;
  place-items: start center;
  padding-top: 32px;
  overflow-y: auto;
}
.modal-backdrop.is-home .modal { width: min(960px, calc(100vw - 32px)); max-height: none; }
.modal-backdrop.is-home #projectsClose { display: none; }
body.no-video :is(#ratioSwitch, #projectName, #saveState, #closeVideoBtn, #historyBtn, .dock-export, #projectsBtn, #settingsBtn) { display: none; }

.modal-foot {
  display: flex;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* ---- Asset library ---- */
.modal--wide {
  width: min(860px, calc(100vw - 32px));
  max-height: min(680px, calc(100dvh - 48px));
}

.modal-head-actions { display: flex; align-items: center; gap: 8px; }

.library-filter-row { flex-wrap: nowrap; }
.library-filter-row input { flex: 1; min-width: 0; }
.library-filter-row .select { width: 180px; flex: none; }

.asset-grid {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-content: start;
}

.asset-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  min-width: 0;
}
/* Hover actions (rename, star, delete) and the "…" menu on a card */
.asset-card .asset-actions { display: none; position: absolute; right: 6px; top: 6px; gap: 2px; padding: 3px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-1); z-index: 2; }
.asset-card:hover .asset-actions, .asset-card.menu-open .asset-actions, .asset-card:focus-within .asset-actions { display: flex; }
.asset-more { position: absolute; left: 6px; top: 6px; padding: 1px 7px; font-weight: 800; line-height: 1; z-index: 2; opacity: 0; }
.asset-card:hover .asset-more, .asset-card.menu-open .asset-more, .asset-card:focus-within .asset-more { opacity: 1; }

.asset-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
}
.asset-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.asset-thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--text-dim);
}
.asset-thumb.placeholder .icon { width: 22px; height: 22px; }

.asset-card.pickable .asset-thumb { cursor: pointer; }
.asset-card.pickable:hover { border-color: var(--brand-border); }
.asset-card.pickable:hover .asset-name { color: var(--brand-hi); }

.asset-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  color: var(--white);
  background: var(--badge);
  border-radius: 4px;
  pointer-events: none;
}

/* Global (★) marker — top-left so it never collides with the type badge. */
.asset-badge--global {
  right: auto;
  bottom: auto;
  left: 4px;
  top: 4px;
  color: var(--brand); /* amber reads on the dark badge (8:1); --brand-hi wouldn't */
}

.asset-actions .is-global { color: var(--brand-hi); }

.library-scope-row { flex: 1; }

.asset-name {
  font-size: var(--fs-label);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-actions { display: flex; gap: 4px; justify-content: flex-end; }

.asset-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.asset-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width .2s;
}

/* Sidebar mini-grid: two readable columns; names wrap to two lines. */
.assets-mini-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-content: start;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}
.asset-card.compact { padding: 4px; gap: 4px; }
.asset-card.compact .asset-name {
  font-size: var(--fs-small);
  line-height: 1.3;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Side-by-side layout: the library section takes the tab's spare height and
   the grid takes the section's (scrolling on its own), so search and Browse
   stay put. contain: size keeps the grid's cards out of the section's minimum
   height, so on a short window the section stops shrinking at "everything
   but the grid + 120px" and the tab scrolls, instead of the grid and Browse
   spilling over "Add at the playhead" below. */
@media (min-width: 761px) {
  .tab-pane[data-tab="media"] > .control-group:first-child { flex: 1; }
  .tab-pane[data-tab="media"] .assets-mini-grid { flex: 1; min-height: 120px; max-height: none; contain: size; }
}
.asset-card.compact .asset-badge { font-size: var(--fs-small); }

.asset-use-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--brand-border);
  border-radius: var(--r-md);
}
.asset-use-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* Why a card matched the search when the hit isn't in the visible name. */
.asset-match {
  font-size: var(--fs-small);
  color: var(--text-dim);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Library detail view (swaps in for the grid inside #libraryModal) ---- */
.asset-grid--detail { display: block; }

.asset-detail { display: flex; flex-direction: column; gap: 12px; }
.asset-detail > .btn { align-self: flex-start; }
.asset-detail > .btn .icon { transform: rotate(90deg); } /* chevron → back arrow */

.asset-detail-body {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.asset-detail-thumb {
  flex: 0 0 260px;
  max-width: 40%;
}
.asset-detail-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.asset-detail-field { display: flex; flex-direction: column; gap: 4px; }
.asset-detail-meta { font-variant-numeric: tabular-nums; }
.asset-detail-desc { min-height: 60px; resize: vertical; }

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 8px;
  font-size: var(--fs-small);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.tag-chip-x {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: var(--fs-body);
  line-height: 1;
  padding: 0 3px;
  cursor: pointer;
}
.tag-chip-x:hover { color: var(--text); }
.tag-input { flex: 1; min-width: 120px; }

.asset-detail-script {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
.asset-detail-script-text {
  width: 100%;
  max-height: 140px;
  overflow-y: auto;
  padding: 8px 10px;
  font-size: var(--fs-label);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  white-space: pre-wrap;
}

@media (max-width: 640px) {
  .asset-detail-body { flex-direction: column; }
  .asset-detail-thumb { flex: none; max-width: 100%; width: 100%; }
}

/* ---- Inspector: which clip / scope is being edited ---- */
.edit-context {
  margin: 0;
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--brand-hi);
}

/* ---- Popover menus (+ Audio, Add a reaction, Export, size options) ---- */
.dock-add-audio { position: relative; }
.dock-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: var(--z-popover);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 190px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.dock-menu .btn { justify-content: flex-start; }

/* Audio inspector: read-only clip name + kind toggle in the Edit panel */
#audioClipGroup .clip-name { font-size: var(--fs-label); }

/* The timecode is centered by balancing the flexible side zones, but the
   left zone's button row must never shrink under its content and paint over
   it — let it claim its width and give the zoom zone the slack. */
.toolbar-left { min-width: max-content; }
@media (max-width: 1300px) {
  :root { --side-w: 300px; }
}
@media (max-width: 1150px) {
  .dock-toolbar { flex-wrap: wrap; gap: 6px; }
  .dock-toolbar .toolbar-zone { flex: none; }
}

/* ---- Image overlay gizmo: drag frame + corner resize handle on the stage ---- */
#imageGizmo {
  position: absolute;
  border: 1.5px dashed var(--track-image);
  border-radius: 2px;
  cursor: grab;
  touch-action: none;
  z-index: 6; /* above the overlay canvas, below fullscreen chrome */
}
#imageGizmo:active { cursor: grabbing; }
#imageGizmo .gizmo-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--track-image);
  border: 2px solid var(--ink);
  cursor: nwse-resize;
  touch-action: none;
}

/* ---- Light from: a 3×3 map seen from above (camera at the bottom) ---- */
.light-block { display: flex; flex-direction: column; gap: 8px; }
.light-title { display: inline-flex; align-items: center; gap: 6px; }
.light-title .icon { width: 14px; height: 14px; }
.light-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.light-grid .preset { padding: 7px 4px; font-size: var(--fs-small); text-align: center; min-width: 0; }
.light-grid .light-default { background: var(--surface-2); }
.light-grid .light-default.active { background: var(--brand-soft); }
.light-height { flex: 0 0 auto; width: 128px; }
.light-actions .btn { flex: 1; justify-content: center; }
.light-actions .btn[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand-border); color: var(--brand-text); }

/* The ring on the floor around STAN; the sun on it is the drag handle. */
#lightRing {
  position: absolute;
  border: 1.5px dashed var(--brand-hi);
  border-radius: 50%;
  pointer-events: none;
  z-index: 6;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .35);
}
#lightRing.is-default { border-style: dotted; }
#lightRing .light-sun {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  padding: 0;
  border-radius: 50%;
  background: var(--brand-hi);
  color: var(--white);
  border: 2px solid var(--white);
  display: grid;
  place-items: center;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
#lightRing .light-sun:active { cursor: grabbing; }
#lightRing .light-sun .icon { width: 14px; height: 14px; }

/* Walk into the photo: the horizon line across the stage, dragged by its grip. */
.floor-block { display: flex; flex-direction: column; gap: 8px; }
#floorLine {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1.5px dashed var(--brand-hi);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .35);
  pointer-events: none;
  z-index: 6;
}
#floorLine .floor-line-grip {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  padding: 4px 10px;
  border-radius: 999px;
  border: 2px solid var(--white);
  background: var(--brand-hi);
  color: var(--white);
  font: inherit;
  font-size: var(--fs-small);
  font-weight: 600;
  white-space: nowrap;
  cursor: ns-resize;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
body.framing-locked #floorLine { display: none; }

/* "Tap where the light comes from": one click anywhere on the stage. */
#lightPick {
  position: absolute;
  inset: 0;
  z-index: 7;
  cursor: crosshair;
  background: rgba(0, 0, 0, .08);
  display: grid;
  place-items: end center;
  padding-bottom: 14px;
}
.light-pick-hint {
  background: var(--ink);
  color: var(--white);
  font-size: var(--fs-label);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  pointer-events: none;
}

/* ---- Fade wedges + corner fade handles ---- */
.tl-fade {
  position: absolute;
  top: 0;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}
.tl-fade--l { left: 0; }
.tl-fade--r { right: 0; }
.tl-fade svg { display: block; width: 100%; height: 100%; }

.tl-fade-h {
  display: none;
  position: absolute;
  top: -5px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 0 0 1.5px var(--ink), var(--shadow-thumb);
  cursor: ew-resize;
  z-index: 5;
}
.tl-fade-h--l { left: 9px; }
.tl-fade-h--r { right: 9px; }
.tl-clip.selected .tl-fade-h { display: block; }
.tl-fade-h:hover { background: var(--brand-hi); }

/* ---- Drag feedback tooltip: duration / position + signed delta ---- */
.tl-dragtip {
  position: fixed;
  z-index: var(--z-dragtip);
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 4px 8px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: var(--fs-label);
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
}
.tl-dragtip-delta.pos { color: var(--green); }
.tl-dragtip-delta.neg { color: var(--red); }

/* ---- Snapping magnet toggle ---- */
#snapBtn.active {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-text);
}

/* ---- Export popover (same pattern as "+ Audio") ---- */
.dock-export { position: relative; }
.dock-export .dock-menu { left: auto; right: 0; min-width: 210px; }
/* In the top header the menu opens downward, below the button. */
.topbar .dock-export .dock-menu { bottom: auto; top: calc(100% + 8px); }

/* ---- Looks: one-tap color grades with live-preview swatches ---- */
.look-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.look-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-size: var(--fs-small);
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.look-chip:hover { color: var(--text); border-color: var(--brand-border); }
.look-chip.active {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-text);
}
.look-swatch {
  width: 100%;
  height: 30px;
  border-radius: 4px;
  /* The Construction Site tile, graded by each look (the chip sets filter) */
  background: url('../assets/tiles/bg-construction.png') center / cover;
}
.look-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* ---- Keyboard shortcut sheet ---- */
.shortcut-list { display: flex; flex-direction: column; gap: 8px; padding: 4px 2px 8px; overflow-y: auto; }
.shortcut-group { margin: 8px 0 2px; font-size: var(--fs-small); font-weight: 700; color: var(--text-faint); }
.shortcut-group:first-child { margin-top: 0; }
.shortcut-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-body);
  color: var(--text-dim);
}
.shortcut-row span { flex: 1; }
.shortcut-row kbd {
  min-width: 28px;
  padding: 3px 7px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: var(--fs-small);
  color: var(--text);
}

/* The timeline folded to its toolbar strip (dockToggleBtn) */
body.dock-collapsed .dock-timeline { display: none; }
body.dock-collapsed .dock-resizer { display: none; }
#dockToggleBtn .icon { transform: rotate(180deg); transition: transform .18s; }
body.dock-collapsed #dockToggleBtn .icon { transform: rotate(0deg); }

/* While an export renders, editing is locked (see blockDuringExport in app.js). */
body.exporting .dock,
body.exporting #panel { opacity: .55; cursor: progress; }

/* Guidance in an empty track row (the first Voice row on a new project). */
.tl-empty-hint {
  position: sticky;
  left: 0;
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 12px;
  font-size: var(--fs-label);
  color: var(--text-dim);
  pointer-events: none;
  white-space: nowrap;
}

/* Sizes (js/sizesBar.js): the stage label and outline off the main size.
   Preview (step 1) is neutral; adjusting one size's framing (step 2) is sky,
   so it never reads as a warning. */
.size-note {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 3px 12px 4px;
  border-radius: 0 0 var(--r-sm) var(--r-sm);
  background: var(--glass);
  color: var(--text-dim);
  font-size: var(--fs-small);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: auto;
}
.stage-wrap.size-own { outline: 2px solid var(--size-own); }
.stage-wrap.size-own .size-note { background: var(--size-own-ink); color: var(--white); }
.stage-wrap.size-preview { outline: 2px dashed var(--stage-ring-preview); }
/* Preview-only: nothing on the stage moves STAN or pans/zooms. */
body.framing-locked #imageGizmo,
body.framing-locked #cropGizmo,
body.framing-locked #liftHandle { display: none !important; }
body.framing-locked #stage { cursor: default; }

/* Suggested clips (auto Moves from the voice): dashed and translucent — a
   click turns one into a real, editable Move. */
.tl-clip--ghost {
  opacity: .55;
  background: transparent !important;
  border: 1px dashed currentColor;
  cursor: copy;
}
.tl-clip--ghost .tl-clip-label { font-style: italic; }
.tl-clip--anim.tl-clip--ghost { border-color: var(--track-anim); color: var(--track-anim); }
.tl-clip--ghost .tl-clip-label::before { display: none; }

.auto-perform-row { font-size: var(--fs-body); color: var(--text); margin: -4px 0 4px; }

/* ===== Script view (js/scriptView.js), in the Script tab of the left panel ===== */
.script-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 14px 24px;
}
.script-paste, .script-rows { display: grid; gap: 14px; }
.script-title { margin: 0; font-size: 18px; font-weight: 800; text-wrap: balance; }
.script-lede { margin: 0; color: var(--text-dim); font-size: var(--fs-body); line-height: 1.5; max-width: 64ch; }
.script-paste-box {
  width: 100%; min-height: 240px; resize: vertical;
  border: 1px solid var(--field-line); border-radius: var(--r-md); background: var(--bg);
  color: var(--text); font: 500 var(--fs-script)/1.6 var(--font); padding: 14px 16px;
}
.script-paste-box.small { min-height: 90px; }
.script-paste-box:focus { outline: none; border-color: var(--brand-hi); box-shadow: 0 0 0 3px var(--brand-soft); }
.script-bar, .script-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.script-head-actions { margin-left: auto; display: flex; gap: 8px; }
.script-count { font: 500 var(--fs-small) var(--mono); color: var(--text-faint); font-variant-numeric: tabular-nums; }
.script-callout { margin: 0; font-size: var(--fs-label); color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: var(--r-sm); padding: 8px 12px; }

.script-lines { display: grid; gap: 6px; }
.script-line {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 11px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.script-line.playing { border-color: var(--brand-border); box-shadow: 0 0 0 3px var(--brand-soft); }
.script-line.changed, .script-line.missing { border-color: var(--warn-border); }
.script-line.pending { border-style: dashed; }
.script-body { display: grid; gap: 7px; min-width: 0; }
.script-text {
  width: 100%; resize: none; overflow: hidden; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text); font: 500 var(--fs-script)/1.45 var(--font); padding: 4px 7px;
}
.script-text:hover { border-color: var(--line); }
.script-text:focus { outline: none; border-color: var(--brand-hi); }
.script-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.script-chip { border: 1px solid var(--line); background: var(--bg); color: var(--text-dim); border-radius: 999px; padding: 3px 10px; font: 600 var(--fs-label) var(--font); cursor: pointer; }
.script-chip[aria-pressed="true"] { background: var(--brand); color: var(--ink); border-color: var(--brand); }
.script-tag { border: 1px dashed var(--line); background: none; color: var(--text-faint); border-radius: 999px; padding: 3px 8px; font: 500 var(--fs-small) var(--mono); cursor: pointer; }
.script-tag:hover { color: var(--text); border-color: var(--text-faint); }
.script-sep { width: 1px; height: 14px; background: var(--line); }
.script-move { font-size: var(--fs-small); font-weight: 600; color: var(--track-anim); background: color-mix(in srgb, var(--track-anim) 14%, transparent); border: 1px dashed color-mix(in srgb, var(--track-anim) 55%, transparent); border-radius: 999px; padding: 2px 9px; }
.script-move.none { color: var(--text-faint); background: none; border-color: var(--line); }
.script-dur { font: 500 var(--fs-small) var(--mono); color: var(--text-faint); font-variant-numeric: tabular-nums; }
.script-status { font-size: var(--fs-small); font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.script-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.script-status.ready { color: var(--green); }
.script-status.changed, .script-status.missing { color: var(--warn); }
.script-status.pending { color: var(--text-faint); }
.script-status.generating { color: var(--brand-hi); }
.script-status.generating::before { animation: scriptPulse .8s infinite alternate; }
@keyframes scriptPulse { to { opacity: .2; } }
.script-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.script-action-row { display: flex; gap: 4px; }
.script-actions .icon-btn { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--bg); border-radius: var(--r-sm); color: var(--text-dim); cursor: pointer; font-size: var(--fs-label); }
.script-actions .icon-btn:hover:not(:disabled) { color: var(--text); border-color: var(--text-faint); }
.script-actions .icon-btn:disabled { opacity: .35; cursor: default; }
.script-voice-btn { border: 1px solid var(--line); background: var(--bg); color: var(--text-dim); border-radius: var(--r-sm); padding: 5px 10px; font: 600 var(--fs-label) var(--font); cursor: pointer; white-space: nowrap; }
.script-line.pending .script-voice-btn,
.script-line.changed .script-voice-btn,
.script-line.missing .script-voice-btn { background: var(--brand); color: var(--ink); border-color: var(--brand); }
.script-voice-btn:disabled { opacity: .5; cursor: default; }
.script-gap { display: flex; align-items: center; gap: 6px; padding-left: 32px; color: var(--text-faint); font-size: var(--fs-small); }
.script-gap button { border: 0; background: none; color: var(--text-dim); font: 500 var(--fs-small) var(--mono); padding: 1px 4px; border-radius: 4px; cursor: pointer; }
.script-gap button[aria-pressed="true"] { color: var(--brand-text); background: var(--brand-soft); }
.script-add { border: 1px dashed var(--line); background: none; color: var(--text-dim); border-radius: var(--r-md); padding: 11px 12px; font: 600 var(--fs-body) var(--font); text-align: left; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; width: 100%; }
.script-add:hover { border-color: var(--brand-border); color: var(--brand-hi); }
.script-add-box { display: grid; gap: 8px; justify-items: start; }
.script-foot { margin: 4px 0 0; font-size: var(--fs-label); line-height: 1.5; color: var(--text-faint); max-width: 70ch; }
.script-lanes .mode-btn { border: 0; background: none; color: var(--text-dim); font: 600 var(--fs-label) var(--font); padding: 5px 12px; border-radius: 9px; cursor: pointer; }
.script-lanes .mode-btn[aria-pressed="true"] { background: var(--brand); color: var(--ink); }
.script-lanes { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); }
.script-file { font-size: var(--fs-label); color: var(--text-dim); display: inline-flex; align-items: center; gap: 5px; }
.script-file .icon { width: 12px; height: 12px; }
.script-status.recording { color: var(--track-sfx); }
.script-status.recording-missing { color: var(--warn); }
.script-line.recording { border-left: 3px solid var(--track-sfx); }
.script-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.script-top .script-lanes { margin-bottom: 0; }
#langVersionBtn { margin-left: auto; }
.script-voice-pick { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-label); font-weight: 600; color: var(--text-dim); }
.script-voice-pick .select { width: auto; min-width: 170px; }
.script-langbox { display: grid; gap: 10px; margin-bottom: 16px; padding: 14px; background: var(--surface); border: 1px solid var(--brand-border); border-radius: var(--r-md); }
.script-name-input { min-width: 220px; flex: 1; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg); color: var(--text); font: 500 var(--fs-body) var(--font); padding: 7px 10px; }
.script-original { font-size: var(--fs-label); color: var(--text-faint); margin: -2px 0 2px; }
.script-original b { color: var(--text-dim); font-weight: 700; font-size: var(--fs-small); margin-right: 6px; }
.script-status.translate { color: var(--brand-hi); }
.script-line.translate { border-style: dashed; border-color: var(--brand-border); }
/* Language versions in the Projects list */
.p-lang { display: inline-block; min-width: 26px; margin-right: 8px; padding: 1px 6px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-text); font: 700 var(--fs-small) var(--mono); text-align: center; letter-spacing: .5px; }

/* dialog.js: confirm / prompt / notice — above any modal that opened it */
.app-dialog { z-index: var(--z-dialog); }
.app-dialog .modal { width: min(420px, calc(100vw - 32px)); }
.btn.btn-danger { background: var(--red); color: var(--white); border-color: var(--red); font-weight: 800; }
/* Its own hover: the generic .btn:hover would turn it light grey under white text. */
.btn.btn-danger:hover:not(:disabled) { background: var(--red-press); border-color: var(--red-press); }

/* ---- Director tab: the review, its cards, and the question box ---- */
.director-pane { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.director-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.director-usage { margin-left: auto; font-variant-numeric: tabular-nums; }
.director-usage.over { color: var(--brand-hi); font-weight: 600; }
.director-intro { max-width: 52ch; }
.director-summary { margin: 0; font-size: var(--fs-body); line-height: 1.5; color: var(--text); }
.director-stale { color: var(--brand-hi); font-weight: 600; }
.director-cards { display: flex; flex-direction: column; gap: 10px; }
.director-cards.is-stale .director-card:not(.is-applied) { opacity: .55; }
.director-card {
  border: 1px solid var(--line); border-left: 3px solid var(--brand); border-radius: var(--r-md);
  background: var(--panel); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
}
.director-card--hook { border-left-color: var(--brand); }
.director-card--pace { border-left-color: var(--track-video); }
.director-card--visual { border-left-color: var(--track-anim); }
.director-card--voice { border-left-color: var(--track-scene); }
.director-card--text { border-left-color: var(--track-text); }
.director-card.is-applied { background: var(--bg); }
.director-card-head { display: flex; align-items: center; gap: 8px; }
.director-card-title { margin: 0; font-size: var(--fs-body); font-weight: 700; flex: 1; min-width: 0; }
.director-chip {
  flex: none; font: 600 var(--fs-small) var(--mono); font-variant-numeric: tabular-nums;
  color: var(--text-dim); background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 8px; cursor: pointer;
}
.director-chip:hover { color: var(--text); border-color: var(--text-dim); }
.director-card-why { margin: 0; font-size: var(--fs-label); line-height: 1.45; color: var(--text-dim); }
.director-card-actions { display: flex; align-items: center; gap: 8px; }
.director-advice, .director-applied { font-size: var(--fs-small); font-weight: 600; color: var(--text-faint); }
.director-applied { color: var(--text-dim); }
.director-chat { display: flex; flex-direction: column; gap: 10px; }
.director-turn { display: flex; flex-direction: column; gap: 8px; }
.director-turn--user { align-items: flex-end; }
.director-bubble {
  max-width: 100%; font-size: var(--fs-label); line-height: 1.5; padding: 8px 12px;
  border-radius: var(--r-md); background: var(--bg); color: var(--text); white-space: pre-wrap;
}
.director-turn--user .director-bubble { background: var(--brand-soft); }
.director-bubble--busy { color: var(--text-faint); font-style: italic; }
.director-ask { display: flex; gap: 8px; align-items: flex-end; margin-top: auto; }
.director-question {
  flex: 1; min-width: 0; resize: none;
  border: 1px solid var(--field-line); border-radius: var(--r-md); background: var(--bg);
  color: var(--text); font: 500 var(--fs-body)/1.45 var(--font); padding: 8px 10px;
}
.director-question:focus { outline: none; border-color: var(--brand-hi); box-shadow: 0 0 0 3px var(--brand-soft); }

/* "What are you making?" — the new-video size picker (js/sizePicker.js) */
.app-dialog .modal:has(.size-picker) { width: min(520px, calc(100vw - 32px)); }
.size-picker { display: flex; flex-direction: column; gap: 10px; }
.size-picker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.size-tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 6px 10px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
.size-tile:hover { border-color: var(--brand-border); }
.size-tile.on { border-color: var(--brand); background: var(--brand-soft); }
.size-tile-art { display: flex; align-items: center; justify-content: center; height: 36px; }
.size-tile-frame { display: block; border: 2px solid currentColor; border-radius: 3px; color: var(--text-dim); }
.size-tile.on .size-tile-frame { color: var(--brand-hi); }
.size-tile-name { font-weight: 700; font-size: var(--fs-label); white-space: nowrap; }
.size-tile-hint { font-size: var(--fs-small); color: var(--text-faint); line-height: 1.3; }
.size-picker-main {
  position: absolute; top: 6px; right: 6px;
  padding: 1px 6px; border-radius: 999px;
  background: var(--brand); color: var(--ink);
  font-size: var(--fs-small); font-weight: 700;
}
.size-picker-all { align-self: flex-start; }
.size-picker-note { margin: 0; }
@media (max-width: 560px) { .size-picker-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---- Sign-in (js/auth.js): covers the page until someone is signed in ---- */
.signin {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-dialog) - 1); /* over modals; a dialog can still open on top */
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg-deep);
}
.signin-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 24px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.signin-brand { display: flex; align-items: center; gap: 10px; }
.signin-brand h1 { font-size: 15px; letter-spacing: 2px; font-weight: 800; color: var(--text); }
.signin-brand h1 span { color: var(--brand-hi); }
.signin-lead { margin: 0; font-size: var(--fs-body); color: var(--text); }
.signin-card .script-hint { margin: 0; }
.signin-card .btn-primary { justify-content: center; padding: 10px 14px; }
.signin-error { margin: 0; font-size: var(--fs-label); font-weight: 600; color: var(--red); }
.signin-code {
  display: block;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  overflow-wrap: anywhere;
  user-select: all;
}
body.signed-out .topbar, body.signed-out .studio { visibility: hidden; }

/* ---- Account button (top right) ---- */
.account { position: relative; }
.account-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--field-line);
  background: var(--surface);
  color: var(--text);
  font: 800 var(--fs-small) var(--font);
  letter-spacing: .5px;
  cursor: pointer;
}
.account-btn:hover, .account-btn[aria-expanded="true"] { background: var(--surface-2); }
.account-menu { top: calc(100% + 8px); bottom: auto; left: auto; right: 0; min-width: 220px; }
.account-who { display: flex; flex-direction: column; gap: 2px; padding: 2px 4px 8px; border-bottom: 1px solid var(--line); }
.account-who strong { font-size: var(--fs-body); color: var(--text); }
.account-who span { font-size: var(--fs-small); color: var(--text-dim); overflow-wrap: anywhere; }

/* ---- Users (usersModal.js, admins only) ---- */
.users-bar .script-hint { flex: 1; min-width: 200px; }
.user-list { flex: 1; min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); }
.user-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.user-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-body); font-weight: 600; color: var(--text); }
.user-email { font-size: var(--fs-label); color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-note { font-size: var(--fs-small); color: var(--text-faint); }
.user-tag { padding: 1px 7px; border-radius: 999px; background: var(--surface-2); font-size: var(--fs-small); font-weight: 600; color: var(--text-dim); }
.user-tag--admin { background: var(--brand-soft); color: var(--brand-text); }
.user-row.is-off .user-name, .user-row.is-off .user-email { color: var(--text-faint); }
.user-actions { display: flex; gap: 6px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.dialog-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.dialog-check .field-label { font-size: var(--fs-label); }
@media (max-width: 640px) { .user-row { flex-direction: column; align-items: stretch; } .user-actions { justify-content: flex-start; } }

/* ---- Server settings (serverSettingsModal.js, admins only) ---- */
.settings-body { flex: 1; min-height: 160px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding-right: 4px; }
.settings-section { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.settings-section h3 { font-size: var(--fs-body); font-weight: 700; color: var(--text); }
.settings-section > .script-hint { margin: -6px 0 0; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.settings-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.settings-field--wide { grid-column: 1 / -1; }
.settings-note { font-size: var(--fs-small); color: var(--text-dim); line-height: 1.4; }
.settings-note--locked { color: var(--brand-text); font-weight: 600; }
.settings-note--warn { color: var(--warn); font-weight: 600; }
/* Read-only (set in config.php): a filled field, text still dark enough to read. */
.settings-field .select:disabled, .settings-field .script-input:disabled { background: var(--surface); color: var(--text-dim); cursor: default; }
.settings-secret-wrap { display: flex; flex-direction: column; gap: 6px; }
.settings-secret { display: flex; gap: 6px; }
.settings-secret input { flex: 1; min-width: 0; }
.voices-editor { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.voices-table { display: grid; grid-template-columns: minmax(80px, .8fr) minmax(120px, 1.6fr) minmax(120px, 1.4fr) minmax(56px, .6fr) auto; gap: 6px 8px; align-items: center; width: 100%; }
.voices-table .script-input { min-width: 0; }
.settings-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.settings-status { font-size: var(--fs-label); color: var(--text-dim); line-height: 1.4; }
.settings-status.is-ok { color: var(--green); font-weight: 600; }
.settings-status.is-bad { color: var(--warn); font-weight: 600; }
.settings-last { padding-top: 10px; border-top: 1px solid var(--line); }
@media (max-width: 640px) { .settings-grid { grid-template-columns: 1fr; } .voices-table { grid-template-columns: 1fr 1fr; } .voices-table .field-label { display: none; } }

/* ---- Shared projects: who's editing, Trash (projectsModal.js) ---- */
.projects-bar .project-show { width: 140px; flex: none; }
.project-card-lock { align-self: flex-start; padding: 1px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-text); font-size: var(--fs-small); font-weight: 600; }
.project-card.is-trashed { cursor: default; }
.project-card.is-trashed:hover { border-color: var(--line); }
.project-card-buttons { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
