/* ==========================================================================
   Videobolt 3.0 editor — stylesheet

   Implements the Videobolt design kit (D:\Projects\videobolt-design-kit\design.md):
     - Sinter weights are SEPARATE FAMILIES. Never `font-weight` on a Sinter face.
     - Never `letter-spacing`, anywhere.
     - Cyan (--accent) is a highlight only — focus rings, active markers,
       progress. Never a text background. Primary buttons are ink.
     - Every colour, size and radius is a token. No magic numbers below §2.
     - Hover changes colour, border or fill — never position or size.

   Sections: 1 Sinter · 2 Tokens · 3 Type roles · 4 Base · 5 Buttons ·
             6 Fields · 7 Segmented, chips, dropdown · 8 Top bar ·
             9 Library · 10 Editor layout & panel · 11 Field controls ·
             12 Preview · 13 Transport · 14 Render panel · 15 States ·
             16 Scrollbars · 17 Narrow viewports
   ========================================================================== */

/* --- 1. Sinter ---------------------------------------------------------- */
/* Metric overrides optically centre labels inside buttons and controls. */

@font-face {
  font-family: 'Sinter';
  src: url('../fonts/sinter-regular.woff2') format('woff2');
  font-display: swap;
  ascent-override: 82%;
  descent-override: 14%;
  line-gap-override: 4%;
}
@font-face {
  font-family: 'Sinter Medium';
  src: url('../fonts/sinter-medium.woff2') format('woff2');
  font-display: swap;
  ascent-override: 82%;
  descent-override: 14%;
  line-gap-override: 4%;
}
@font-face {
  font-family: 'Sinter Bold';
  src: url('../fonts/sinter-bold.woff2') format('woff2');
  font-display: swap;
  ascent-override: 82%;
  descent-override: 14%;
  line-gap-override: 4%;
}
@font-face {
  font-family: 'Sinter Black';
  src: url('../fonts/sinter-black.woff2') format('woff2');
  font-display: swap;
  ascent-override: 82%;
  descent-override: 14%;
  line-gap-override: 4%;
}

/* --- 2. Tokens ---------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Kit palette */
  --background: oklch(99% 0 267);
  --foreground: #02040e;
  --surface: oklch(100% 0 267);
  --muted: #edeef3;
  --muted-foreground: #7f86a3;
  --accent: #00d2dc;
  --primary: var(--foreground);
  --primary-foreground: var(--background);
  --border: oklch(10.4% 0.072 264 / 7.5%);
  --scrim: oklch(0% 0 0 / 8%);
  --shadow-overlay: 0 8px 24px oklch(10% 0.03 267 / 10%);
  --success: #95d315;
  --warning: #f9a06e;
  --destructive: #ff4a4e;
  --destructive-foreground: #ffffff;

  /* Kit spacing — 8px base, 4px sub-grid (+ a 2px step for insets) */
  --space-3xs: 0.125rem;
  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 1rem;
  --radius-pill: 100vw;

  /* Project: media. Video frames sit on a dark neutral floor in both themes,
     so anything drawn ON media is theme-independent. */
  --media-floor: oklch(17% 0.012 268);
  --on-media: #ffffff;
  --on-media-muted: oklch(100% 0 0 / 55%);
  --media-chip: oklch(0% 0 0 / 60%);
  --media-edge: oklch(100% 0 0 / 6%);
  /* Transparency checkerboard behind image thumbnails: mid greys, so white
     and black logos both stay visible. */
  --checker-a: oklch(80% 0.006 268);
  --checker-b: oklch(70% 0.006 268);
  --checker-size: 0.75rem;

  /* Project: lines, focus, markers */
  --hairline: 1px;
  --focus-ring: 2px;
  --focus-offset: 2px;
  --marker: 2px;
  --dot-size: 0.5rem;
  --disabled-opacity: 0.45;

  /* Type scale (the kit's role sizes, named) */
  --text-xs: 0.75rem;         /* 12px — caption, label, overline */
  --text-sm: 0.875rem;        /* 14px — body-sm, button */
  --text-md: 1rem;            /* 16px — body */
  --text-lg: 1.25rem;         /* 20px — title */
  --text-xl: 2rem;            /* 32px — heading-2 */

  /* Project: control and icon sizes */
  --control-h: 2.25rem;       /* 36px */
  --control-h-sm: 1.75rem;    /* 28px */
  --icon-size: 1.125rem;      /* 18px */
  --icon-size-sm: 1rem;       /* 16px */
  --mark-size: 1.5rem;        /* 24px brand mark */
  --state-icon: 3rem;         /* 48px round icon in empty/error states */

  /* Project: layout */
  --topbar-h: 3.5rem;         /* 56px */
  --page-max: 90rem;          /* 1440px — the kit's page cap */
  --card-min: 18rem;
  --card-min-portrait: 12.5rem;
  --card-min-square: 15rem;
  --panel-w: 22.5rem;         /* 360px */
  --render-panel-w: 23.5rem;
  --thumb-size: 4.5rem;       /* image field thumbnail */
  --scene-index-w: 1.25rem;
  --transport-h: 3.75rem;
  --scrub-h: 2rem;
  --scrub-knob: 0.625rem;
  --progress-h: 0.375rem;
  --render-btn-min: 9.5rem;   /* "Rendering 100%" without the button resizing */
  --reading-max: 32rem;
  --render-video-max: 50vh;
  --skeleton-w: 60%;
  --skeleton-w-short: 35%;
  --scrollbar-inset: 3px;
  --textarea-min: 3.5rem;     /* two lines */
  --textarea-max: 12rem;
  --range-knob: 0.875rem;     /* 14px volume slider knob */
  --switch-w: 2.25rem;        /* 36px toggle track */
  --switch-h: 1.25rem;        /* 20px */

  /* Project: motion (UI chrome only) and stacking */
  --duration-fast: 120ms;
  --duration-fade: 200ms;
  --duration-pulse: 1.2s;
  --pulse-opacity: 0.45;
  --z-topbar: 10;
  --z-banner: 5;
  --z-overlay: 20;

  /* Theme-dependent visibility for the two brand marks */
  --mark-light-display: block;
  --mark-dark-display: none;
}

/* A theme flip rewrites token values; kill transitions for one frame so
   themed properties cut over instead of animating between palettes. */
[data-theme-switching] *,
[data-theme-switching] *::before,
[data-theme-switching] *::after { transition: none !important; }

[data-theme='dark'] {
  color-scheme: dark;

  --background: oklch(23.5% 0.028 268);
  --foreground: oklch(97.5% 0.004 268);
  --surface: oklch(24.5% 0.03 268);
  --muted: oklch(27.5% 0.028 268);
  --muted-foreground: oklch(72% 0.02 268);
  --border: oklch(12% 0.03 268 / 35%);
  --shadow-overlay: 0 8px 24px oklch(0% 0 0 / 35%);

  --media-floor: oklch(18% 0.022 268);
  --mark-light-display: none;
  --mark-dark-display: block;
}

/* --- 3. Type roles ------------------------------------------------------ */

.heading-1 { font-family: 'Sinter Black'; font-size: clamp(2.5rem, 5vw, 4rem); line-height: 1.1; }
.heading-2 { font-family: 'Sinter Bold'; font-size: var(--text-xl); line-height: 1.2; }
.title     { font-family: 'Sinter Bold'; font-size: var(--text-lg); line-height: 1.3; }
.body      { font-family: 'Sinter'; font-size: var(--text-md); line-height: 1.5; }
.body-sm   { font-family: 'Sinter'; font-size: var(--text-sm); line-height: 1.5; }
.caption   { font-family: 'Sinter'; font-size: var(--text-xs); line-height: 1.4; }
.overline  { font-family: 'Sinter Bold'; font-size: var(--text-xs); line-height: 1.4; text-transform: uppercase; }
.label     { font-family: 'Sinter Medium'; font-size: var(--text-xs); line-height: 1.4; }
.button    { font-family: 'Sinter Medium'; font-size: var(--text-sm); }
/* Project role: names inside dense UI (card names, top bar, panel titles). */
.subtitle  { font-family: 'Sinter Bold'; font-size: var(--text-sm); line-height: 1.4; }

.muted { color: var(--muted-foreground); }

/* --- 4. Base ------------------------------------------------------------ */

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--background);
  color: var(--foreground);
  font-family: 'Sinter', system-ui, sans-serif;
  font-size: var(--text-sm);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* The roles pick the family; the UA's bold on headings would synthetic-bold it. */
h1, h2, h3, p { margin: 0; font-weight: normal; }

a { color: inherit; }

:focus-visible {
  outline: var(--focus-ring) solid var(--accent);
  outline-offset: var(--focus-offset);
}

.visually-hidden {
  position: absolute;
  width: var(--hairline);
  height: var(--hairline);
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex: none;
  display: block;
}

/* --- 5. Buttons --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  height: var(--control-h);
  padding: 0 var(--space-md);
  border: var(--hairline) solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--foreground);
  font-family: 'Sinter Medium';
  font-size: var(--text-sm);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}
.btn .icon { width: var(--icon-size-sm); height: var(--icon-size-sm); }

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}
.btn-primary:hover:not(:disabled) { background: color-mix(in oklab, var(--primary) 88%, var(--background)); }

.btn-secondary {
  background: var(--background);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: color-mix(in oklab, var(--border) 50%, var(--background));
  border-color: color-mix(in oklab, var(--foreground) 5%, var(--border));
}

.btn-ghost:hover:not(:disabled) { background: color-mix(in oklab, var(--border) 50%, var(--background)); }

.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon .icon { width: var(--icon-size); height: var(--icon-size); }

.btn-sm {
  height: var(--control-h-sm);
  padding: 0 var(--space-sm);
  gap: var(--space-2xs);
  font-size: var(--text-xs);
}
.btn-sm .icon { width: var(--icon-size-sm); height: var(--icon-size-sm); }

.btn-icon-sm {
  width: var(--control-h-sm);
  height: var(--control-h-sm);
  padding: 0;
  border-radius: var(--radius-sm);
}
.btn-icon-sm .icon { width: var(--icon-size-sm); height: var(--icon-size-sm); }

.btn:disabled { opacity: var(--disabled-opacity); cursor: default; }

/* --- 6. Fields ---------------------------------------------------------- */

.input {
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--space-sm);
  background: var(--surface);
  color: var(--foreground);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-md);
  font-family: 'Sinter';
  font-size: var(--text-sm);
  line-height: 1.4;
  transition: border-color var(--duration-fast) ease;
}
.input:hover { border-color: color-mix(in oklab, var(--foreground) 15%, var(--border)); }
.input:focus-visible { outline-offset: 0; border-color: transparent; }
.input[aria-invalid='true'] { border-color: var(--destructive); }
.input::placeholder { color: var(--muted-foreground); }

.textarea {
  height: auto;
  min-height: var(--textarea-min);
  max-height: var(--textarea-max);
  padding: var(--space-xs) var(--space-sm);
  resize: vertical;
  field-sizing: content;
}
/* The default resize grip is a bright triangle on dark surfaces. */
.textarea::-webkit-resizer { background: transparent; }

/* --- 7. Segmented, chips, dropdown -------------------------------------- */

.seg {
  display: inline-flex;
  gap: var(--space-3xs);
  padding: var(--space-3xs);
  background: var(--surface);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-md);
}
.seg-item {
  height: calc(var(--control-h) - 2 * var(--space-3xs) - 2 * var(--hairline));
  padding: 0 var(--space-sm);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
  font-family: 'Sinter Medium';
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease;
}
.seg-item:hover { color: var(--foreground); }
.seg-item[aria-checked='true'] {
  background: var(--muted);
  color: var(--foreground);
}
.seg-item:focus-visible { outline-offset: 0; }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  height: var(--control-h-sm);
  padding: 0 var(--space-sm);
  background: var(--surface);
  color: var(--foreground);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-pill);
  font-family: 'Sinter Medium';
  font-size: var(--text-xs);
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}
.chip:hover { background: color-mix(in oklab, var(--border) 50%, var(--surface)); }
.chip-count {
  font-family: 'Sinter';
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
.chip[aria-pressed='true'] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}
.chip[aria-pressed='true'] .chip-count { color: color-mix(in oklab, var(--primary-foreground) 60%, var(--primary)); }

.dropdown { position: relative; }
.dropdown-trigger { gap: var(--space-xs); padding: 0 var(--space-sm); font-size: var(--text-xs); }
.dropdown-chevron {
  color: var(--muted-foreground);
  transition: transform var(--duration-fast) ease;
}
.dropdown.is-open .dropdown-chevron { transform: rotate(180deg); }
.dropdown.is-open .dropdown-trigger { border-color: color-mix(in oklab, var(--foreground) 20%, var(--border)); }
.dropdown-list {
  position: absolute;
  top: calc(100% + var(--space-2xs));
  right: 0;
  z-index: var(--z-overlay);
  min-width: 100%;
  padding: var(--space-2xs);
  background: var(--surface);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay);
}
.dropdown-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  cursor: pointer;
}
.dropdown-option.is-active { background: var(--muted); }
.dropdown-option[aria-selected='true'] { box-shadow: inset var(--marker) 0 0 var(--accent); }
.dropdown-option[aria-selected='true'] .dropdown-option-label { font-family: 'Sinter Medium'; }
.dropdown-option-hint { color: var(--muted-foreground); font-variant-numeric: tabular-nums; }

/* --- 8. Top bar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  height: var(--topbar-h);
  padding: 0 var(--space-md);
  background: var(--background);
  border-bottom: var(--hairline) solid var(--border);
}
.topbar-spacer { flex: 1; min-width: var(--space-xs); }
.topbar-divider {
  flex: none;
  width: var(--hairline);
  height: var(--space-lg);
  margin: 0 var(--space-2xs);
  background: var(--border);
}

/* The library centres its content; its top bar lines up with that column. */
.app-library .topbar {
  padding-inline: max(var(--space-2xl), calc((100% - var(--page-max)) / 2 + var(--space-2xl)));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  height: var(--control-h);
  padding: 0 var(--space-xs);
  margin-left: calc(var(--space-xs) * -1);
  border-radius: var(--radius-md);
  color: var(--foreground);
  text-decoration: none;
}
.brand-mark { width: var(--mark-size); height: var(--mark-size); flex: none; }
.brand-mark-light { display: var(--mark-light-display); }
.brand-mark-dark { display: var(--mark-dark-display); }

.topbar-back { padding: 0 var(--space-sm) 0 var(--space-xs); margin-left: calc(var(--space-xs) * -1); }
.topbar-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-left: var(--space-2xs);
}
.topbar-name,
.topbar-meta {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* --- 9. Library --------------------------------------------------------- */

.library {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-2xl) var(--space-3xl);
}
.library-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}
.library-summary { font-variant-numeric: tabular-nums; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding-bottom: var(--space-lg);
  margin-bottom: var(--space-lg);
  border-bottom: var(--hairline) solid var(--border);
}
.filters-aspect { display: flex; align-items: center; gap: var(--space-sm); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
  gap: var(--space-xl) var(--space-lg);
}
.grid[data-aspect='9x16'] { --card-min: var(--card-min-portrait); }
.grid[data-aspect='4x5'],
.grid[data-aspect='1x1'] { --card-min: var(--card-min-square); }

.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-md);
}
.card:focus-visible { outline-offset: var(--space-xs); }

.card-media {
  position: relative;
  aspect-ratio: var(--frame-ratio, 16 / 9);
  overflow: hidden;
  container-type: size;
  background: var(--media-floor);
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 var(--hairline) var(--border);
  transition: box-shadow var(--duration-fast) ease;
}
.card:hover .card-media { box-shadow: 0 0 0 var(--hairline) color-mix(in oklab, var(--foreground) 30%, transparent); }

/* The thumbnail keeps the template's own ratio, contained in the card frame
   (pillarboxed when "All" shows a template that has no 16:9). */
.card-thumb {
  --ratio: 1.7778;
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100cqw, calc(100cqh * var(--ratio)));
  height: min(100cqh, calc(100cqw / var(--ratio)));
}
.card-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  pointer-events: none;
  opacity: 0;
}
.card.is-ready .card-frame { opacity: 1; }

.media-chip {
  position: absolute;
  right: var(--space-xs);
  bottom: var(--space-xs);
  padding: var(--space-3xs) var(--space-xs);
  border-radius: var(--radius-sm);
  background: var(--media-chip);
  color: var(--on-media);
  font-family: 'Sinter';
  font-size: var(--text-xs);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.card-meta {
  display: grid;
  gap: var(--space-3xs);
  min-width: 0;
}
.card-name,
.card-cats {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  margin-top: var(--space-2xs);
}
.badge {
  padding: 0 var(--space-2xs);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted-foreground);
  font-family: 'Sinter';
  font-size: var(--text-xs);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge.is-current {
  color: var(--foreground);
  border-color: color-mix(in oklab, var(--foreground) 22%, transparent);
}

.card-skeleton .card-media { background: var(--muted); box-shadow: none; }
.skeleton-line {
  grid-column: 1 / -1;
  height: var(--space-sm);
  width: var(--skeleton-w);
  border-radius: var(--radius-sm);
  background: var(--muted);
}
.skeleton-line.is-short { width: var(--skeleton-w-short); }
.card-skeleton .card-media,
.card-skeleton .skeleton-line { animation: pulse var(--duration-pulse) ease-in-out infinite; }
@keyframes pulse { 50% { opacity: var(--pulse-opacity); } }

.empty,
.state-error {
  display: grid;
  justify-items: center;
  gap: var(--space-xs);
  padding: var(--space-3xl) var(--space-lg);
  text-align: center;
}
.state-error { grid-column: 1 / -1; }
.empty .btn,
.state-error .btn { margin-top: var(--space-sm); }
.empty-icon,
.page-state-icon {
  display: grid;
  place-items: center;
  width: var(--state-icon);
  height: var(--state-icon);
  margin-bottom: var(--space-xs);
  border-radius: var(--radius-pill);
  background: var(--muted);
  color: var(--muted-foreground);
}
.empty-icon.is-error,
.page-state-icon.is-error { color: var(--destructive); }

/* --- 10. Editor layout & panel ------------------------------------------ */

.app-editor {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
}

.panel {
  min-height: 0;
  overflow-y: auto;
  background: var(--background);
  border-right: var(--hairline) solid var(--border);
}
.panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
  height: calc(var(--control-h) + var(--space-md));
  padding: 0 var(--space-sm) 0 var(--space-md);
  background: var(--background);
  border-bottom: var(--hairline) solid var(--border);
}
.panel-note {
  padding: var(--space-md);
}
.panel-note.is-warning { color: var(--foreground); }

.scene { border-bottom: var(--hairline) solid var(--border); }
.scene-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  border: 0;
  color: var(--foreground);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--duration-fast) ease;
}
.scene-head:hover:not(:disabled):not(.is-static) { background: color-mix(in oklab, var(--border) 50%, var(--background)); }
.scene-head:disabled,
.scene-head.is-static { cursor: default; }
.scene-head:focus-visible { outline-offset: calc(var(--focus-ring) * -1); }
/* The active marker: a cyan bar on the scene under the playhead. */
.scene-head::before {
  content: '';
  position: absolute;
  left: 0;
  top: var(--space-xs);
  bottom: var(--space-xs);
  width: var(--marker);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: transparent;
  transition: background-color var(--duration-fast) ease;
}
.scene.is-active .scene-head::before { background: var(--accent); }
.scene-index {
  flex: none;
  min-width: var(--scene-index-w);
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
.scene-style-icon { width: var(--icon-size-sm); height: var(--icon-size-sm); }
.scene-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.scene-time {
  flex: none;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
.scene.is-active .scene-time { color: var(--foreground); }
.scene-fields {
  display: grid;
  gap: var(--space-md);
  padding: var(--space-2xs) var(--space-md) var(--space-md);
}
.scene-empty { padding: 0 var(--space-md) var(--space-md) calc(var(--space-md) + var(--scene-index-w) + var(--space-xs)); }

/* --- 11. Field controls ------------------------------------------------- */

.field { display: grid; gap: var(--space-xs); min-width: 0; }
.field-head {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: var(--control-h-sm);
}
.field-dot {
  flex: none;
  width: var(--dot-size);
  height: var(--dot-size);
  border-radius: var(--radius-pill);
  background: var(--accent);
}
.field-reset { margin-left: auto; color: var(--muted-foreground); }
.field-reset:hover { color: var(--foreground); }
.field-foot {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-top: calc(var(--space-2xs) * -1);
}
.field-help { flex: 1; }
.field-count {
  margin-left: auto;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
.field-count.is-full { color: var(--foreground); font-family: 'Sinter Medium'; }
.field-error { color: var(--destructive); }

/* Image */
.dropzone {
  position: relative;
  display: grid;
  grid-template-columns: var(--thumb-size) minmax(0, 1fr);
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs);
  background: var(--surface);
  border: var(--hairline) dashed color-mix(in oklab, var(--foreground) 20%, transparent);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) ease;
}
.dropzone:hover { border-color: color-mix(in oklab, var(--foreground) 35%, transparent); }
.dropzone.is-over { border-color: var(--accent); border-style: solid; }
.dropzone.is-busy { cursor: progress; }
.dropzone-hint {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  border-radius: inherit;
  background: color-mix(in oklab, var(--surface) 90%, transparent);
  color: var(--foreground);
  pointer-events: none;
}
.dropzone.is-over .dropzone-hint { display: flex; }

.image-thumb {
  width: var(--thumb-size);
  height: var(--thumb-size);
  padding: var(--space-2xs);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--checker-a);
  background-image: conic-gradient(var(--checker-b) 25%, transparent 0 50%, var(--checker-b) 0 75%, transparent 0);
  background-size: var(--checker-size) var(--checker-size);
  cursor: pointer;
}
.image-thumb-img { display: block; width: 100%; height: 100%; object-fit: contain; }
.image-info { display: grid; gap: var(--space-3xs); min-width: 0; }
.image-title {
  font-family: 'Sinter Medium';
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.image-meta { font-variant-numeric: tabular-nums; }
.image-actions { display: flex; flex-wrap: wrap; gap: var(--space-2xs); margin-top: var(--space-2xs); }

/* Colour */
.color-row { display: flex; gap: var(--space-xs); }
.swatch-wrap {
  position: relative;
  flex: none;
  width: var(--control-h);
  height: var(--control-h);
  overflow: hidden;
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-md);
}
.swatch-wrap:has(.swatch:focus-visible) {
  outline: var(--focus-ring) solid var(--accent);
  outline-offset: var(--focus-offset);
}
.swatch {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.swatch:focus-visible { outline: none; }
.swatch::-webkit-color-swatch-wrapper { padding: 0; }
.swatch::-webkit-color-swatch { border: 0; border-radius: 0; }
.swatch::-moz-color-swatch { border: 0; }
.input-hex { font-variant-numeric: tabular-nums; }

/* Audio (the global Audio section) */
.audio-thumb {
  display: grid;
  place-items: center;
  width: var(--thumb-size);
  height: var(--thumb-size);
  padding: 0;
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--muted);
  color: var(--muted-foreground);
  cursor: pointer;
  transition: color var(--duration-fast) ease;
}
.audio-thumb:hover { color: var(--foreground); }
.dropzone.is-custom .audio-thumb { color: var(--foreground); }

.range-value {
  margin-left: auto;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
.range-value + .field-reset { margin-left: 0; }

.range {
  --p: 0;
  display: block;
  width: 100%;
  height: var(--space-md);
  margin: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
}
.range:focus-visible { outline: none; }
.range::-webkit-slider-runnable-track {
  height: var(--progress-h);
  border-radius: var(--radius-pill);
  background: linear-gradient(to right, var(--foreground) calc(var(--p) * 100%), var(--muted) 0);
}
.range::-webkit-slider-thumb {
  width: var(--range-knob);
  height: var(--range-knob);
  margin-top: calc((var(--progress-h) - var(--range-knob)) / 2);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--foreground);
  box-shadow: 0 0 0 var(--focus-offset) var(--background);
  appearance: none;
}
.range:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 var(--focus-offset) var(--background), 0 0 0 calc(var(--focus-offset) + var(--focus-ring)) var(--accent);
}
.range::-moz-range-track { height: var(--progress-h); border-radius: var(--radius-pill); background: var(--muted); }
.range::-moz-range-progress { height: var(--progress-h); border-radius: var(--radius-pill); background: var(--foreground); }
.range::-moz-range-thumb {
  width: var(--range-knob);
  height: var(--range-knob);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--foreground);
}
.range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 var(--focus-offset) var(--background), 0 0 0 calc(var(--focus-offset) + var(--focus-ring)) var(--accent); }

.field-switch .switch { margin-left: auto; }
.switch {
  position: relative;
  flex: none;
  width: var(--switch-w);
  height: var(--switch-h);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--muted);
  cursor: pointer;
  transition: background-color var(--duration-fast) ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: var(--space-3xs);
  left: var(--space-3xs);
  width: calc(var(--switch-h) - 2 * var(--space-3xs));
  height: calc(var(--switch-h) - 2 * var(--space-3xs));
  border-radius: var(--radius-pill);
  background: var(--muted-foreground);
  transition: transform var(--duration-fast) ease, background-color var(--duration-fast) ease;
}
.switch:hover { background: color-mix(in oklab, var(--foreground) 12%, var(--muted)); }
.switch[aria-checked='true'] { background: var(--primary); }
.switch[aria-checked='true']:hover { background: color-mix(in oklab, var(--primary) 88%, var(--background)); }
.switch[aria-checked='true']::after {
  background: var(--primary-foreground);
  transform: translateX(calc(var(--switch-w) - var(--switch-h)));
}

/* --- 12. Preview -------------------------------------------------------- */

.preview {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.stage-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  overflow: hidden;
  background: var(--media-floor);
  cursor: pointer;
}
.stage-area.is-draggable { cursor: grab; touch-action: pan-y; }
.take-keys { display: flex; gap: var(--space-xs); }
.take-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-h-sm);
  height: var(--control-h-sm);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted-foreground);
  font-family: 'Sinter Medium';
  font-size: var(--text-xs);
  transition: border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}
.take-key.is-down { border-color: var(--accent); color: var(--foreground); }
.field[data-type='take'] > .btn { justify-self: start; }
.stage-area.is-dragging { cursor: grabbing; user-select: none; }
.stage-box {
  position: relative;
  flex: none;
  box-shadow: 0 0 0 var(--hairline) var(--media-edge);
}
.stage-frame {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: none;
}
.stage-box.is-loading .stage-frame { opacity: 0; }
.preview-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-media-muted);
  pointer-events: none;
}

.preview-error {
  position: absolute;
  top: var(--space-md);
  left: var(--space-md);
  right: var(--space-md);
  z-index: var(--z-banner);
  max-width: var(--reading-max);
  margin: 0 auto;
  cursor: default;
}
.preview-error,
.notice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
  background: var(--surface);
  color: var(--foreground);
  border: var(--hairline) solid var(--border);
  border-left: var(--marker) solid var(--warning);
  border-radius: var(--radius-md);
}
.preview-error { border-left-color: var(--destructive); box-shadow: var(--shadow-overlay); }
.notice.is-error { border-left-color: var(--destructive); }
.notice { grid-template-columns: auto minmax(0, 1fr); padding-right: var(--space-md); }
.notice-icon { color: var(--warning); padding-top: var(--space-3xs); }
.preview-error .notice-icon,
.notice.is-error .notice-icon { color: var(--destructive); }
.notice-icon .icon { width: var(--icon-size-sm); height: var(--icon-size-sm); }
.notice-body { display: grid; gap: var(--space-2xs); min-width: 0; }
.notice-text { overflow-wrap: anywhere; color: var(--foreground); }

/* --- 13. Transport ------------------------------------------------------ */

.transport {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  height: var(--transport-h);
  padding: 0 var(--space-md) 0 var(--space-sm);
  background: var(--background);
  border-top: var(--hairline) solid var(--border);
}
.transport-play .icon { width: var(--icon-size); height: var(--icon-size); }
.transport-clock {
  display: flex;
  gap: var(--space-2xs);
  flex: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.transport-now { font-family: 'Sinter Medium'; }
.transport-sep,
.transport-total { color: var(--muted-foreground); }
.transport-loop[aria-pressed='true'] { color: var(--accent); }
.transport-loop[aria-pressed='false'] { color: var(--muted-foreground); }
.transport-mute { color: var(--muted-foreground); }
.transport-mute:hover:not(:disabled) { color: var(--foreground); }
.transport-mute[aria-pressed='true'] { color: var(--foreground); }
.transport-extra {
  flex: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.scrubber {
  --p: 0;
  position: relative;
  flex: 1;
  min-width: 0;
  height: var(--scrub-h);
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.scrub-track {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--muted);
}
.scrub-segs { position: absolute; inset: 0; }
.scrub-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  padding: 0 var(--space-xs);
  overflow: hidden;
  /* A hairline of page colour between segments reads as a cut. */
  box-shadow: inset var(--hairline) 0 0 var(--background);
}
.scrub-seg:first-child { box-shadow: none; }
.scrub-seg::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--marker);
  background: transparent;
}
.scrub-seg.is-active::after { background: var(--accent); }
.scrub-seg-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted-foreground);
  font-family: 'Sinter';
  font-size: var(--text-xs);
  line-height: 1;
}
.scrub-seg.is-active .scrub-seg-label { color: var(--foreground); font-family: 'Sinter Medium'; }
.scrub-played {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(var(--p) * 100%);
  background: color-mix(in oklab, var(--foreground) 7%, transparent);
  pointer-events: none;
}
.scrub-head {
  position: absolute;
  top: calc(var(--space-2xs) * -1);
  bottom: calc(var(--space-2xs) * -1);
  left: calc(var(--p) * 100%);
  width: var(--marker);
  margin-left: calc(var(--marker) / -2);
  border-radius: var(--radius-pill);
  background: var(--foreground);
  pointer-events: none;
}
.scrub-head::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--scrub-knob);
  height: var(--scrub-knob);
  margin: calc(var(--scrub-knob) / -2) 0 0 calc(var(--scrub-knob) / -2);
  border-radius: var(--radius-pill);
  background: var(--foreground);
}
.scrubber.is-dragging { cursor: grabbing; }

/* --- 14. Render panel --------------------------------------------------- */

.render-btn { min-width: var(--render-btn-min); font-variant-numeric: tabular-nums; }

.render-panel {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  z-index: var(--z-overlay);
  display: grid;
  gap: var(--space-md);
  width: var(--render-panel-w);
  max-width: calc(100% - 2 * var(--space-sm));
  max-height: calc(100% - 2 * var(--space-sm));
  overflow-y: auto;
  padding: var(--space-md) var(--space-lg) var(--space-lg);
  background: var(--surface);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
}
.render-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-right: calc(var(--space-xs) * -1);
}
.render-job { display: grid; gap: var(--space-xs); }
.render-state { display: flex; align-items: center; gap: var(--space-xs); min-width: 0; }
.render-desc {
  margin-left: auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.status-dot {
  flex: none;
  width: var(--dot-size);
  height: var(--dot-size);
  border-radius: var(--radius-pill);
  background: var(--muted-foreground);
}
.status-dot.is-submitting,
.status-dot.is-rendering,
.status-dot.is-encoding { background: var(--accent); }
.status-dot.is-done { background: var(--success); }
.status-dot.is-error { background: var(--destructive); }

.progress {
  height: var(--progress-h);
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--muted);
}
.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--duration-fade) linear;
}
.render-stats {
  display: flex;
  justify-content: space-between;
  gap: var(--space-sm);
  font-variant-numeric: tabular-nums;
}
.render-actions { display: flex; justify-content: flex-end; gap: var(--space-xs); margin-top: var(--space-2xs); }
.render-actions .btn-primary { flex: 1; }
.render-video {
  max-height: var(--render-video-max);
  margin: 0 auto;
  width: 100%;
  overflow: hidden;
  background: var(--media-floor);
  border-radius: var(--radius-md);
}
.render-video video { display: block; width: 100%; height: 100%; }

.render-recent {
  display: grid;
  gap: var(--space-xs);
  padding-top: var(--space-md);
  border-top: var(--hairline) solid var(--border);
}
.render-recent-list { display: grid; gap: var(--space-3xs); margin: 0; padding: 0; list-style: none; }
.render-recent-row { display: flex; align-items: center; gap: var(--space-xs); }
.render-recent-open {
  flex: 1;
  display: flex;
  justify-content: space-between;
  gap: var(--space-sm);
  min-width: 0;
  padding: var(--space-2xs) var(--space-xs);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--foreground);
  text-align: left;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.render-recent-open:hover { background: color-mix(in oklab, var(--border) 50%, var(--surface)); }
.render-recent-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* --- 15. States --------------------------------------------------------- */

.page-state {
  display: grid;
  justify-items: center;
  gap: var(--space-xs);
  max-width: var(--reading-max);
  margin: 0 auto;
  padding: var(--space-3xl) var(--space-lg);
  text-align: center;
}
.page-state-actions { display: flex; gap: var(--space-xs); margin-top: var(--space-sm); }

/* --- 16. Scrollbars ----------------------------------------------------- */
/* Chrome ignores ::-webkit-scrollbar-* on elements that set the standard
   scrollbar-color/width, so those go only to engines without the pseudos. */

::-webkit-scrollbar { width: var(--space-sm); height: var(--space-sm); }
::-webkit-scrollbar-track,
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--muted);
  border: var(--scrollbar-inset) solid transparent;
  border-radius: var(--radius-pill);
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted-foreground); background-clip: content-box; }

@supports not selector(::-webkit-scrollbar) {
  html { scrollbar-color: var(--muted) var(--background); scrollbar-width: thin; }
}

/* --- 17. Narrow viewports ----------------------------------------------- */

@media (max-width: 72rem) {
  :root { --panel-w: 20rem; }
  .transport-extra { display: none; }
}

@media (max-width: 60rem) {
  .library { padding: var(--space-lg) var(--space-md) var(--space-2xl); }
  .app-library .topbar { padding-inline: var(--space-md); }
  .topbar-meta,
  .topbar-back span { display: none; }
  .render-btn { min-width: 0; }
}

@media (max-width: 48rem) {
  :root { --card-min: 100%; --card-min-portrait: 45%; --card-min-square: 45%; }
  .app-editor { height: auto; min-height: 100vh; overflow: visible; }
  .topbar { flex-wrap: wrap; height: auto; padding-block: var(--space-xs); }
  .editor-body { grid-template-columns: minmax(0, 1fr); }
  .preview { order: -1; height: 60vh; }
  .panel { border-right: 0; overflow: visible; }
  .render-panel { position: fixed; top: auto; bottom: var(--space-sm); left: var(--space-sm); right: var(--space-sm); width: auto; max-height: 80vh; }
}

/* Select field: a segmented control that fills the panel width. */
.seg.seg-field { display: flex; width: 100%; }
.seg.seg-field .seg-item { flex: 1; }
