/* ============================================================
   Media AI Box - Pro Video Editor (refined)
   Layout:
     - Back button floats top-left over preview (outside flow)
     - Preview = stage + transport in ONE rounded rectangle
     - Timeline auto-height (tools-bar + tracks only)
   ============================================================ */

.editor-shell {
  direction: ltr;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "preview"
    "timeline";
  gap: 8px;
  height: calc(100vh - var(--s-12));
  min-height: 540px;
  padding: 0;
  position: relative;
}

/* ── Editor Skeleton Loader ──────────────────────────────────────────────── */

/* Shimmer keyframe - a diagonal light sweep */
@keyframes sk-sweep {
  0% {
    background-position: -200% center;
  }
  100% {
    background-position: 200% center;
  }
}

/* Base shimmer block */
.sk-shim {
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.13) 40%,
    rgba(255, 255, 255, 0.22) 50%,
    rgba(255, 255, 255, 0.13) 60%,
    rgba(255, 255, 255, 0) 100%
  );
  background-size: 200% 100%;
  animation: sk-sweep 1.5s ease-in-out infinite;
}

/* Light mode shimmer for timeline area */
.sk-timeline .sk-shim {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.06) 40%,
    rgba(0, 0, 0, 0.1) 50%,
    rgba(0, 0, 0, 0.06) 60%,
    rgba(0, 0, 0, 0) 100%
  );
  background-size: 200% 100%;
  animation: sk-sweep 1.5s ease-in-out infinite;
}

/* Root skeleton - exact same grid as .editor-shell */
.editor-skeleton {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto;
  gap: 8px;
  pointer-events: all;
  opacity: 1;
  transition: opacity 0.35s ease;
  /* fill the gap between grid rows and any overflow */
  background: var(--bg, #f5f5f7);
  padding: 0;
}
.editor-skeleton.sk-done {
  opacity: 0;
  pointer-events: none;
}

/* ── Skeleton Preview (mimics .editor-preview) ─── */
.sk-preview {
  background: #0a0a0c; /* matches .editor-preview so the cross-fade is seamless */
  border-radius: var(--r-md, 10px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.sk-stage-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 0;
}

/* Opening screen: spinner + label (replaces black video frame) */
.sk-open-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  height: 100%;
}

.sk-open-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: rgba(255, 255, 255, 0.75);
  animation: sk-spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes sk-spin {
  to {
    transform: rotate(360deg);
  }
}

.sk-open-label {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: -0.01em;
  direction: rtl;
}

/* The actual video frame placeholder */
.sk-video-frame {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  /* height determined by aspect-ratio + max constraints */
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.06) 40%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.06) 60%,
    rgba(255, 255, 255, 0) 100%
  );
  background-size: 200% 100%;
  animation: sk-sweep 1.8s ease-in-out infinite;
  /* Fill available space respecting aspect ratio */
  align-self: center;
  flex-shrink: 0;
  /* Use aspect-ratio set inline from JS; limit height */
  height: min(100%, calc(100vw / 2));
  width: 100%;
  max-height: calc(100vh - 280px);
}

/* Transport skeleton bar */
.sk-transport {
  height: 48px;
  background: rgba(0, 0, 0, 0.45);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  flex-shrink: 0;
}

.sk-tr-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.07);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.12) 40%,
    rgba(255, 255, 255, 0.18) 50%,
    rgba(255, 255, 255, 0.12) 60%,
    rgba(255, 255, 255, 0) 100%
  );
  background-size: 200% 100%;
  animation: sk-sweep 1.5s ease-in-out infinite;
}
/* Play button is slightly larger */
.sk-tr-btn:nth-child(3) {
  width: 36px;
  border-radius: 14px;
}

.sk-tr-timecode {
  width: 90px;
  height: 14px;
  flex-shrink: 0;
  border-radius: 4px;
  margin: 0 4px;
}

.sk-tr-scrub {
  flex: 1;
  height: 4px;
  border-radius: 2px;
}

/* ── Skeleton Timeline (mimics .editor-timeline) ─── */
.sk-timeline {
  background: var(--surface, #fff);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tools bar - matches .timeline-tools-bar's spacing + groups */
.sk-tools-bar {
  min-height: 52px;
  border-bottom: 1px solid var(--divider, rgba(0, 0, 0, 0.06));
  background: var(--surface-2, #fafafa);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  flex-shrink: 0;
}

.sk-tool-pill {
  height: 26px;
  flex-shrink: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
}
/* Tool-bar groups so the skeleton reads as the real grouped layout */
.sk-tb-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.sk-tb-segment {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  border-radius: 9px;
  background: var(--surface, #fff);
  flex-shrink: 0;
}
.sk-tb-divider {
  width: 1px;
  height: 22px;
  background: var(--divider, rgba(0, 0, 0, 0.08));
  flex-shrink: 0;
}
.sk-tb-spacer {
  flex: 1;
  min-width: 12px;
}
.sk-tb-export {
  width: 92px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}

/* Ruler (time ticks) above the tracks */
.sk-ruler {
  display: grid;
  grid-template-columns: 52px 1fr;
  height: 24px;
  border-bottom: 1px solid var(--divider, rgba(0, 0, 0, 0.06));
  flex-shrink: 0;
}
.sk-ruler-track {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 8px 4px;
  overflow: hidden;
}
.sk-ruler-tick {
  width: 1px;
  height: 7px;
  background: var(--border-strong, rgba(0, 0, 0, 0.16));
  flex-shrink: 0;
}

/* Tracks area */
.sk-tracks {
  padding: 0 0 6px 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sk-track-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 0;
  overflow: hidden;
}

.sk-track-label {
  background: var(--surface-2, #fafafa);
  border-radius: 4px;
  margin: 3px 2px 3px 6px;
}

.sk-track-content {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 3px 6px 3px 2px;
  overflow: hidden;
}

/* Simplified full-width track fill (replaces individual sk-clip blocks) */
.sk-track-content-fill {
  border-radius: 5px;
  margin: 3px 6px 3px 2px;
  background: rgba(0, 0, 0, 0.05);
}

/* Simple ruler placeholder */
.sk-ruler-simple {
  height: 24px;
  border-bottom: 1px solid var(--divider, rgba(0, 0, 0, 0.06));
  background: var(--surface-2, #fafafa);
  flex-shrink: 0;
}

.sk-clip {
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
  min-width: 0;
}
/* Stagger the shimmer delay for a wave effect */
.sk-clip:nth-child(1) {
  animation-delay: 0s;
}
.sk-clip:nth-child(2) {
  animation-delay: 0.12s;
}
.sk-clip:nth-child(3) {
  animation-delay: 0.24s;
}
.sk-clip:nth-child(4) {
  animation-delay: 0.36s;
}
.sk-clip:nth-child(5) {
  animation-delay: 0.48s;
}
.sk-clip:nth-child(6) {
  animation-delay: 0.6s;
}

@media (prefers-reduced-motion: reduce) {
  .sk-shim,
  .sk-tr-btn,
  .sk-tr-timecode,
  .sk-tr-scrub,
  .sk-video-frame,
  .sk-clip,
  .sk-tool-pill {
    animation: none;
  }
}

/* ── end skeleton ─────────────────────────────────────────────────────────── */

.content-area:has(.editor-shell) {
  padding: var(--s-3) var(--s-4);
}

/* ===== Floating Back button (top-right of preview) ===== */
.editor-back-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  width: 34px;
  height: 34px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: white;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.08s;
}
.editor-back-btn:hover {
  background: rgba(0, 0, 0, 0.75);
}
.editor-back-btn:active {
  transform: scale(0.94);
}
.editor-back-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== Preview (stage + transport combined) ===== */
.editor-preview {
  grid-area: preview;
  background: #0a0a0c;
  border-radius: var(--r-md);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  min-height: 0;
}

.preview-stage-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.preview-stage {
  position: relative;
  background: #000;
  overflow: hidden;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 4px 24px rgba(0, 0, 0, 0.55),
    0 1px 4px rgba(0, 0, 0, 0.4);
}

.preview-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  /* No will-change here: promoting the video to its own GPU layer breaks
     screen-blend compositing of the VFX layer above it (siblings on separate
     layers can't blend against each other). The JS engine drives opacity/
     transform directly per-frame without needing this hint. */
}

.preview-video.poster-img {
  object-fit: contain;
}

/* Flash-frame overlay - white / light-leak blooms, driven by the transition
   engine above the clips so the clips themselves never get filter-mangled. */
.preview-flash {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
}

/* Movie fade in/out - black overlay above the picture and any transition. */
.preview-fade {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #000;
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
}

/* Movie-wide subtitles / lyrics band (above the fade; layout/colour set inline
   per the user's style so the preview matches the libass export). */
.preview-subtitle {
  box-sizing: border-box;
  overflow: hidden;
}
.preview-subtitle-text {
  display: inline-block;
  word-break: break-word;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  pointer-events: none;
  padding: var(--s-5);
}

.preview-empty .empty-icon {
  width: 44px;
  height: 44px;
  margin-bottom: 6px;
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  box-sizing: border-box;
}

.preview-empty .empty-icon svg {
  width: 100%;
  height: 100%;
}

.preview-empty .empty-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: -0.01em;
  direction: rtl;
}

.preview-empty .empty-sub {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  direction: rtl;
  line-height: 1.5;
  max-width: 150px;
}

.preview-aspect-badge {
  position: absolute;
  top: 12px;
  left: 14px;
  padding: 3px 9px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
  z-index: 5;
}

/* ===== Transport (inside preview, at bottom) ===== */
.preview-transport {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  z-index: 6;
}

.tr-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.85);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.08s;
}
.tr-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}
.tr-btn:active {
  transform: scale(0.92);
}
.tr-btn svg {
  width: 12px;
  height: 12px;
}

.tr-play {
  width: 36px;
  height: 30px;
  border-radius: var(--r-pill);
  background: white;
  color: black;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    transform 0.08s;
  margin-right: 4px;
  flex-shrink: 0;
}
.tr-play:hover {
  background: rgba(255, 255, 255, 0.92);
}
.tr-play:active {
  transform: scale(0.94);
}
.tr-play svg {
  width: 11px;
  height: 11px;
  fill: currentColor;
}

.tr-timecode {
  font-family: "SF Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.95);
  letter-spacing: 0.02em;
  min-width: 110px;
  text-align: center;
  flex-shrink: 0;
}

.tr-timecode .sep {
  opacity: 0.5;
  margin: 0 3px;
}
.tr-timecode .total {
  color: rgba(255, 255, 255, 0.55);
  font-weight: 500;
}

.tr-scrub {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: var(--r-pill);
  position: relative;
  cursor: pointer;
}

.tr-scrub-fill {
  position: absolute;
  inset-block: 0;
  left: 0;
  background: white;
  border-radius: var(--r-pill);
}

.tr-scrub-handle {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.tr-scrub:hover .tr-scrub-handle {
  opacity: 1;
}

.tr-fullscreen {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.85);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  margin-left: 4px;
  flex-shrink: 0;
  transition:
    background 0.15s,
    transform 0.08s;
}
.tr-fullscreen:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}
.tr-fullscreen:active {
  transform: scale(0.92);
}
.tr-fullscreen svg {
  width: 13px;
  height: 13px;
}

/* ===== Timeline panel (auto-height) ===== */
.editor-timeline {
  grid-area: timeline;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  direction: ltr;
}

/* Tools bar inside timeline */
.timeline-tools-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--divider);
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(20px) saturate(190%);
  -webkit-backdrop-filter: blur(20px) saturate(190%);
  min-height: 52px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  flex-shrink: 0;
}

/* Dark mode support or dark surface parent support for glassmorphism */
[data-theme="dark"] .timeline-tools-bar {
  background: rgba(30, 30, 30, 0.45);
}

/* BPM compact group */
.tb-bpm-group {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  height: 30px;
  padding: 0 6px 0 10px;
  gap: 6px;
  flex-shrink: 0;
  transition: all 0.15s var(--ease-out);
}
[data-theme="dark"] .tb-bpm-group {
  background: rgba(0, 0, 0, 0.15);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.tb-bpm-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.tb-bpm-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.02em;
}

.tb-bpm-unit {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.06em;
}

.tb-bpm-group input {
  width: 36px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0;
  color: var(--text);
}

.tb-bpm-group input:focus {
  outline: none;
}
.tb-bpm-group input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.tb-bpm-group button {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  background: transparent;
  border: none;
  cursor: pointer;
  transition:
    background 0.12s,
    color 0.12s;
}

.tb-bpm-group button:hover:not(:disabled) {
  background: var(--surface-pressed);
  color: var(--accent);
}

.tb-bpm-group button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tb-bpm-group button svg {
  width: 11px;
  height: 11px;
}

.tb-bpm-smart {
  color: var(--accent);
}

.beatsync-popover {
  width: 250px;
}
.beatsync-popover .speed-grid {
  grid-template-columns: repeat(4, 1fr);
}
.export-note {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.45;
  padding: 4px 0;
}

/* A cluster of related tool buttons, kept visually tight within the bar. */
.tb-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Clean tool button: icon centred, small label below ─────── */
.tb-btn {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 50px;
  height: 38px;
  padding: 4px 6px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.12s var(--ease-out);
}
/* תיקון / גודל / אפקטים — זמינים בלשונית עריכה; מוסתרים כאן בלבד */
.tb-btn.tb-btn--hidden-in-bar {
  display: none;
}
.tb-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  transition: transform 0.12s var(--ease-out);
}
.tb-btn-label {
  font-size: 8.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
}
.tb-btn:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text);
}
[data-theme="dark"] .tb-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}
.tb-btn.is-active {
  color: var(--text);
  background: var(--surface-pressed);
  box-shadow: none;
}
[data-theme="dark"] .tb-btn.is-active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}
.tb-btn:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}
.tb-btn:active:not(:disabled) {
  transform: scale(0.95);
}

/* Mobile-only tool bar actions (shown via polish.css ≤768px) */
.tb-mobile-only {
  display: none;
}

.tb-delete-clip:not(:disabled) {
  color: var(--red, #ff3b30);
}

.tb-delete-clip:not(:disabled):hover {
  background: color-mix(in srgb, var(--red, #ff3b30) 12%, transparent);
}

/* "Has a value set" - same gray pressed look as is-active, no dot */
.tb-btn-dot {
  display: none;
}
.tb-btn.has-value {
  color: var(--text);
  background: var(--surface-pressed);
}
[data-theme="dark"] .tb-btn.has-value {
  background: rgba(255, 255, 255, 0.1);
}

/* Segmented container - pill that groups related tb-btn buttons */
.tb-segment {
  display: inline-flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 9px;
  padding: 1.5px;
  gap: 1.5px;
  flex-shrink: 0;
}
[data-theme="dark"] .tb-segment {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.05);
}
.tb-segment .tb-btn {
  border-radius: 7.5px;
  height: 34px;
  min-width: 42px;
}
.tb-segment .tb-btn.is-active {
  background: var(--surface-pressed);
  color: var(--text);
  box-shadow: none;
}
[data-theme="dark"] .tb-segment .tb-btn.is-active {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

/* Tool buttons (snap toggle, fix, speed, fade) */
.tb-snap {
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  cursor: pointer;
  transition: all 0.12s var(--ease-out);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
[data-theme="dark"] .tb-snap {
  background: rgba(255, 255, 255, 0.03);
}
.tb-snap svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tb-snap:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}
.tb-snap.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
  box-shadow: none;
}
[data-theme="dark"] .tb-snap.is-active {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}
.tb-snap:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Zoom */
.tb-zoom {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  flex-shrink: 0;
}

.tb-zoom svg {
  width: 14px;
  height: 14px;
}

.tb-zoom input[type="range"] {
  width: 80px;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  outline: none;
  cursor: pointer;
}

.tb-zoom input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: white;
  border: 0.5px solid var(--border);
  border-radius: 50%;
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.12),
    0 0.5px 1px rgba(0, 0, 0, 0.04);
  cursor: grab;
  transition: transform 0.1s var(--ease-out);
}

.tb-zoom input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
}

.tb-zoom input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: white;
  border: 0.5px solid var(--border);
  border-radius: 50%;
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.12),
    0 0.5px 1px rgba(0, 0, 0, 0.04);
  cursor: grab;
  transition: transform 0.1s var(--ease-out);
}

.tb-zoom input[type="range"]::-moz-range-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
}

/* History buttons */
.tb-history {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.tb-history-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-2);
  border: none;
  cursor: pointer;
  transition:
    background 0.12s,
    color 0.12s,
    transform 0.08s;
}

.tb-history-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.tb-history-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.tb-history-btn:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}

.tb-history-btn svg {
  width: 13px;
  height: 13px;
}

.tb-divider {
  width: 1px;
  height: 22px;
  background: var(--divider);
  flex-shrink: 0;
}

.tb-spacer {
  flex: 1;
  min-width: 4px;
}

/* Export */
.tb-export {
  height: 32px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition: all 0.12s var(--ease-out);
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

.tb-export:hover {
  background: var(--accent-hover);
  box-shadow:
    0 4px 12px rgba(0, 113, 227, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.tb-export:active {
  transform: scale(0.96);
}
.tb-export svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== Mobile: tidy the timeline tools bar ===== */
@media (max-width: 640px) {
  .timeline-tools-bar {
    gap: 4px;
    padding: 4px 8px;
    min-height: 48px;
    -webkit-overflow-scrolling: touch;
  }
  /* Dividers just add clutter on a scrolling row */
  .timeline-tools-bar .tb-divider {
    display: none;
  }
  .timeline-tools-bar .tb-zoom input[type="range"] {
    width: 56px;
  }
  /* Pin the export button to the end so it's always reachable while the rest
     of the controls scroll under it. */
  .timeline-tools-bar .tb-export {
    position: sticky;
    inset-inline-end: 0;
    margin-inline-start: 6px;
    padding: 0;
    width: 34px;
    justify-content: center;
    box-shadow: -10px 0 8px -4px var(--surface-2);
  }
  .timeline-tools-bar .tb-spacer {
    flex: 1 1 auto;
    min-width: 4px;
  }
}

/* ===== Timeline tracks area ===== */
.timeline-scroll {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.timeline-inner {
  position: relative;
  min-width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Ruler */
.timeline-ruler {
  position: sticky;
  top: 0;
  height: 22px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
  z-index: 4;
  margin-left: 52px;
}

.ruler-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.ruler-tick.major {
  background: var(--border-strong);
}

.ruler-tick .label {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  font-family: "SF Mono", Consolas, monospace;
  color: var(--text-3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ruler-beat {
  position: absolute;
  bottom: 0;
  width: 1px;
  height: 6px;
  background: var(--purple);
  opacity: 0.5;
}

.ruler-beat.downbeat {
  height: 10px;
  opacity: 0.85;
  width: 2px;
}

.ruler-marker {
  position: absolute;
  bottom: 0;
  width: 2px;
  height: 12px;
  z-index: 5;
  pointer-events: none;
  transform: translateX(-50%);
  background: var(--orange, #ff9500);
  opacity: 0.75;
  border-radius: 1px;
}

/* Tracks */
.timeline-tracks-wrap {
  flex: 1;
  position: relative;
  padding: 4px 0 6px;
}

.track-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: stretch;
  min-height: 52px;
  margin-bottom: 3px;
}

.track-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  background: var(--surface-2);
  border-radius: var(--r-xs);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.06em;
  position: sticky;
  left: 0;
  z-index: 3;
}

.track-label .tl-sub {
  font-size: 8px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 1px;
  letter-spacing: 0;
}

.track-label.is-clickable {
  cursor: pointer;
  transition:
    background 0.12s var(--ease-out),
    color 0.12s var(--ease-out);
}
.track-label.is-clickable:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

.track-label-audio {
  flex-direction: row;
  align-items: stretch;
  padding: 0;
  gap: 0;
}

.track-label-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 2px;
}

.track-label-body.is-clickable {
  cursor: pointer;
  transition:
    background 0.12s var(--ease-out),
    color 0.12s var(--ease-out);
}

.track-label-body.is-clickable:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

.track-label-add {
  flex-shrink: 0;
  align-self: stretch;
  width: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-inline-start: 1px solid var(--divider);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition:
    background 0.12s var(--ease-out),
    color 0.12s var(--ease-out);
}

.track-label-add:hover {
  background: var(--surface-hover);
  color: var(--accent);
}

.track-content {
  position: relative;
  background: var(--surface-2);
  border-radius: var(--r-xs);
  min-height: 52px;
  height: 52px;
  overflow: hidden;
}

.track-content.video {
  min-height: 60px;
  height: 60px;
}
.track-content.audio {
  min-height: 44px;
  height: 44px;
}

.track-row.video .track-label,
.track-row.video .track-content {
  min-height: 60px;
  height: 60px;
}
.track-row.audio .track-label,
.track-row.audio .track-content {
  min-height: 44px;
  height: 44px;
}

.track-row-add .track-add-btn {
  border: 1px dashed var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text-3);
  width: 100%;
  min-height: 44px;
  transition:
    background 0.12s var(--ease-out),
    color 0.12s var(--ease-out),
    border-color 0.12s var(--ease-out);
}
.track-row-add .track-add-btn:hover {
  background: var(--surface-hover);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.track-row-add .track-add-content {
  background: transparent;
  border: 1px dashed var(--border);
  min-height: 44px;
  height: 44px;
}

/* Clip */
.tl-clip {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: var(--r-xs);
  background: linear-gradient(180deg, #2a3142, #1c2230);
  overflow: hidden;
  cursor: grab;
  transition:
    box-shadow 0.15s,
    transform 0.15s;
  border: 1.5px solid transparent;
  user-select: none;
  z-index: 1;
}

.tl-clip:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 2;
}

.tl-clip.is-selected {
  border-color: var(--orange);
  box-shadow:
    0 0 0 2px var(--orange),
    0 2px 10px rgba(255, 149, 0, 0.45);
  z-index: 3;
}

/* Lift the selected clip's image out of the dimmed crowd so it clearly reads
   as the active one. */
.tl-clip.is-selected .tl-clip-thumb-video,
.tl-clip.is-selected .tl-clip-thumb {
  filter: brightness(1);
}

.tl-clip.is-dragging {
  opacity: 0.85;
  cursor: grabbing;
  z-index: 10;
}

.tl-clip-thumb {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: brightness(0.7);
}

/* <video> element used as a clip's first-frame thumbnail */
.tl-clip-thumb-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.72);
  pointer-events: none;
  background: #000;
}

/* Audio waveform drawn over the clip's lower strip (visual only) */
.tl-clip-wave {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22px;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.35), transparent);
}
.tl-clip-wave canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Per-clip audio region editor (modal) ───────────────────────────────── */
.modal:has(.clip-audio-editor) {
  max-width: min(92vw, 520px);
}

.clip-audio-editor .cae-header {
  align-items: center;
  padding-bottom: var(--s-2, 8px);
}

.cae-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
  font-weight: 500;
}

.cae-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3, 12px);
  padding: 0 var(--s-4, 14px) var(--s-4, 14px);
}

.cae-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.cae-wave-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cae-wave-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2, 8px);
}

.cae-region-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.cae-play-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.cae-wave-outer {
  width: 100%;
}

.cae-time-ruler {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1px 3px;
  direction: ltr;
}

.cae-time-mark {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.cae-wave {
  position: relative;
  width: 100%;
  height: 96px;
  border-radius: var(--r-sm, 8px);
  background: #12151c;
  border: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.cae-wave-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cae-wave-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
}

.cae-overlay {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  z-index: 2;
}

.cae-region {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(220, 70, 70, 0.28);
  border-inline: 2px solid rgba(255, 120, 120, 0.75);
  box-sizing: border-box;
  cursor: pointer;
}

.cae-region.is-selected {
  background: rgba(220, 70, 70, 0.42);
  border-inline-color: rgba(255, 200, 200, 0.95);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  z-index: 3;
}

.cae-region.is-transient {
  background: rgba(220, 70, 70, 0.15);
  pointer-events: none;
  border-inline-style: dashed;
}

.cae-fade {
  position: absolute;
  top: 0;
  bottom: 0;
  pointer-events: none;
}

.cae-fade-in {
  left: 0;
  background: linear-gradient(to right, transparent, rgba(255, 72, 72, 0.45));
}

.cae-fade-out {
  right: 0;
  background: linear-gradient(to left, transparent, rgba(255, 72, 72, 0.45));
}

.cae-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 4;
}

.cae-handle-start {
  left: -4px;
}

.cae-handle-end {
  right: -4px;
}

.cae-handle:hover {
  background: rgba(255, 255, 255, 0.25);
}

.cae-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.75);
  pointer-events: none;
  display: none;
  z-index: 5;
}

.cae-regions {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 8px);
  min-height: 0;
}

.cae-region-list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.cae-region-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.cae-region-chip {
  padding: 4px 10px;
  border-radius: var(--r-pill, 999px);
  border: 1px solid var(--border);
  background: var(--surface-pressed);
  cursor: pointer;
  transition:
    border-color 0.12s,
    background 0.12s;
}

.cae-region-chip:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.cae-region-chip.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.cae-region-chip-time {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.cae-region-chip.is-selected .cae-region-chip-time {
  color: var(--text);
}

.cae-clear-all {
  flex-shrink: 0;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  color: var(--text-muted);
}

.cae-editor-panel {
  display: none;
}

.cae-editor-panel.is-visible {
  display: block;
  padding-top: var(--s-2, 8px);
  border-top: 1px solid var(--border);
}

.cae-editor-row {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3, 12px);
}

.cae-editor-label {
  flex-shrink: 0;
  width: 52px;
  padding-top: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.cae-fades {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3, 12px);
  min-width: 0;
}

.cae-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.cae-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.cae-field-head label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
}

.cae-slider {
  width: 100%;
  height: 4px;
  accent-color: var(--accent);
}

.cae-val {
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  direction: ltr;
}

.cae-delete {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--text-muted);
}

.cae-delete:hover {
  color: #e85d5d;
}

@media (max-width: 420px) {
  .cae-fades {
    grid-template-columns: 1fr;
  }

  .cae-editor-row {
    flex-wrap: wrap;
  }

  .cae-delete {
    margin-inline-start: auto;
  }
}

/* Per-clip mute toggle - professional NLE style.
   Unmuted = silent/hidden (normal state needs no indicator).
   Muted = always visible. Hover clip = ghost discovery hint. */
.tl-clip-mute {
  position: absolute;
  bottom: 5px;
  left: 6px;
  z-index: 7;
  width: 14px;
  height: 14px;
  border: none;
  background: none;
  padding: 0;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.tl-clip-mute span {
  width: 13px;
  height: 13px;
  display: flex;
  pointer-events: none;
}
.tl-clip-mute span svg {
  width: 100%;
  height: 100%;
  display: block;
}
/* muted = always show */
.tl-clip-mute.is-muted {
  opacity: 0.85;
}
/* on clip hover: ghost toggle hint for both states */
.tl-clip:hover .tl-clip-mute:not(.is-muted) {
  opacity: 0.3;
}
/* hovering the button: full white */
.tl-clip-mute:hover {
  opacity: 1 !important;
}

/* ===== Watermark removal time-range strip (on the timeline clip) ===== */
.tl-wm-strip {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 20px;
  height: 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  z-index: 8;
  pointer-events: auto;
  touch-action: none;
  opacity: 0.72;
  transition: opacity 0.15s;
}
.tl-clip:hover .tl-wm-strip,
.tl-clip.is-selected .tl-wm-strip {
  opacity: 1;
}
.tl-wm-fill {
  position: absolute;
  top: 1px;
  bottom: 1px;
  min-width: 22px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.55);
  box-shadow: none;
  cursor: grab;
}
.tl-wm-fill:active {
  cursor: grabbing;
  background: rgba(239, 68, 68, 0.72);
}
.tl-wm-fill.is-whole {
  background: rgba(239, 68, 68, 0.28);
}
.tl-wm-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.12s;
}
.tl-wm-handle::after {
  content: "";
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 2px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: none;
}
.tl-wm-handle-l {
  left: 0;
}
.tl-wm-handle-l::after {
  left: 2px;
}
.tl-wm-handle-r {
  right: 0;
}
.tl-wm-handle-r::after {
  right: 2px;
}
.tl-clip:hover .tl-wm-handle,
.tl-clip.is-selected .tl-wm-handle {
  opacity: 0.85;
}
.tl-wm-fill:hover .tl-wm-handle,
.tl-wm-fill:active .tl-wm-handle {
  opacity: 1;
}

/* ===== Watermark region marker (over the preview) ===== */
/* Clean marker: NO fill (so the watermark stays clearly visible underneath),
   just a crisp outline that reads on any background (accent line between a white
   and a dark hairline). Ellipse variant rounds to 50%. */
.wm-box {
  position: absolute;
  z-index: 8;
  background: transparent;
  /* Thin single accent line + one faint dark hairline so it still reads on a
     light background - no heavy double border. */
  border: 1px solid var(--accent, #0071e3);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);
  cursor: move;
}
.wm-box.is-ellipse {
  border-radius: 50%;
}

/* Corner resize handles — small L-brackets on the border, large invisible hit area. */
.wm-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: transparent;
  border: none;
  box-shadow: none;
  z-index: 2;
}
.wm-handle::before,
.wm-handle::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  border-radius: 1px;
}
.wm-handle-nw {
  left: 0;
  top: 0;
  cursor: nwse-resize;
}
.wm-handle-nw::before {
  left: 0;
  top: 0;
  width: 9px;
  height: 2px;
}
.wm-handle-nw::after {
  left: 0;
  top: 0;
  width: 2px;
  height: 9px;
}
.wm-handle-ne {
  right: 0;
  top: 0;
  cursor: nesw-resize;
}
.wm-handle-ne::before {
  right: 0;
  top: 0;
  width: 9px;
  height: 2px;
}
.wm-handle-ne::after {
  right: 0;
  top: 0;
  width: 2px;
  height: 9px;
}
.wm-handle-sw {
  left: 0;
  bottom: 0;
  cursor: nesw-resize;
}
.wm-handle-sw::before {
  left: 0;
  bottom: 0;
  width: 9px;
  height: 2px;
}
.wm-handle-sw::after {
  left: 0;
  bottom: 0;
  width: 2px;
  height: 9px;
}
.wm-handle-se {
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
}
.wm-handle-se::before {
  right: 0;
  bottom: 0;
  width: 9px;
  height: 2px;
}
.wm-handle-se::after {
  right: 0;
  bottom: 0;
  width: 2px;
  height: 9px;
}
.wm-box:hover .wm-handle::before,
.wm-box:hover .wm-handle::after {
  background: #fff;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.4),
    0 0 6px rgba(0, 113, 227, 0.35);
}

/* ── Movie logo (corner overlay across the whole film) ───────────────────── */
.preview-logo {
  position: absolute;
  height: auto;
  z-index: 3; /* below the movie-fade overlay so it fades in/out with the film */
  pointer-events: none;
  user-select: none;
  /* top + left/right + width are set inline by syncLogoOverlay() */
}

/* ── Logo modal ──────────────────────────────────────────────────────────── */
.modal:has(.logo-modal) {
  padding: 0;
  overflow: hidden;
  max-width: 420px;
}

.logo-modal {
  display: flex;
  flex-direction: column;
  direction: rtl;
  width: 100%;
}

/* Header */
.logo-modal-header {
  padding: var(--s-3) var(--s-5);
  margin-bottom: 0;
  flex-shrink: 0;
  align-items: center;
}

.logo-modal-body {
  display: flex;
  flex-direction: column;
  flex: 1;

  min-height: 0;
}

/* Footer - always visible, pinned at bottom */
.logo-modal-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--divider);
}
.logo-modal-footer[hidden] {
  display: none;
}
.logo-modal-footer .lm-remove {
  margin-inline-start: auto;
}

/* ── Sections ── */
.lm-section {
  padding: var(--s-3) var(--s-5);
  /* border-bottom: 1px solid var(--divider); */
  flex-shrink: 0;
}
.lm-section:last-child {
  border-bottom: none;
}

/* Preview section - fixed height container, child fills with correct aspect ratio */
.lm-section--preview {
  background: var(--surface-2);
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
  padding: var(--s-1) var(--s-5);
}

.lm-section--settings {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Section label */
.lm-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: -0.01em;
  margin-bottom: var(--s-3);
}

/* ── Preview frame ── */
.lm-preview-wrap {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lm-preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  pointer-events: none;
}

/* ── Checkerboard preview frame ── */
/* width/height/aspect-ratio set inline by applyPreviewAspect() */
.lm-pv {
  position: relative;
  border-radius: var(--r-sm);
  overflow: hidden;
  background-color: #1c1c1e;
  background-image:
    linear-gradient(45deg, #2c2c2e 25%, transparent 25%),
    linear-gradient(-45deg, #2c2c2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2c2c2e 75%),
    linear-gradient(-45deg, transparent 75%, #2c2c2e 75%);
  background-size: 14px 14px;
  background-position:
    0 0,
    0 7px,
    7px -7px,
    -7px 0;
  border: 1px solid var(--divider);
}
.lm-pv.is-empty .lm-pv-img {
  opacity: 0;
}
.lm-pv-img {
  position: absolute;
  height: auto;
  transition: opacity 0.15s;
}

/* ── Image picker ── */
.lm-picker {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.lm-picker::-webkit-scrollbar {
  height: 4px;
}
.lm-picker::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.lm-thumb {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
}
.lm-thumb img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 2.5px solid transparent;
  background: var(--surface-pressed);
  display: block;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.lm-thumb:hover img {
  border-color: var(--border-strong, rgba(0, 0, 0, 0.18));
}
.lm-thumb.sel img {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.lm-thumb-name {
  font-size: 10px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 48px;
}
.lm-thumb.sel .lm-thumb-name {
  color: var(--accent);
  font-weight: 600;
}

/* ── Settings rows - mirror export-form-row ── */
.lm-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--divider);
}
.lm-row:first-child {
  padding-top: 0;
}
.lm-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.lm-row--slider {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.lm-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* Mirror export-form-label */
.lm-row-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: -0.01em;
}
.lm-row-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ── Segmented control - identical to export-segment / seg-btn ── */
.lm-segment {
  flex: 1;
  display: flex;
  gap: 2px;
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  padding: 3px;
}
.lm-seg-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-2);
  background: none;
  border: none;
  cursor: pointer;
  transition:
    background 0.15s var(--ease-out),
    box-shadow 0.15s var(--ease-out),
    color 0.1s;
  white-space: nowrap;
  text-align: center;
  line-height: 1;
}
.lm-seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.1),
    0 1px 1px rgba(0, 0, 0, 0.06);
}

/* ── Slider - mirrors crf-slider style ── */
.lm-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-pressed);
  outline: none;
  cursor: pointer;
  display: block;
  border: none;
}
.lm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.18),
    0 0 0 1.5px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: transform 0.12s var(--ease-out);
}
.lm-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.lm-slider::-webkit-slider-thumb:active {
  transform: scale(1.2);
}
.lm-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 0.12s var(--ease-out);
}

.lm-bg-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
  line-height: 1;
}
.lm-bg-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.lm-bg-toggle.is-on {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
}
.lm-bg-toggle svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.lm-remove {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid color-mix(in srgb, var(--red, #ff3b30) 30%, var(--border));
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--red, #ff3b30);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1;
}
.lm-remove:hover {
  background: color-mix(in srgb, var(--red, #ff3b30) 8%, transparent);
}
.lm-remove svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ── Empty state ── */
.lm-empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.6;
}
.lm-empty strong {
  display: block;
  color: var(--text);
  margin-bottom: 6px;
  font-size: 15px;
}
.lm-empty p {
  margin: 0;
}

@media (max-width: 380px) {
  .lm-controls-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }
  .lm-controls-row .lm-field:first-child {
    grid-column: 1 / -1;
  }
  .lm-pills--compact {
    flex-direction: row;
  }
}

/* No-video placeholder clip */
.tl-clip.no-video {
  background: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.04),
    rgba(0, 0, 0, 0.04) 8px,
    transparent 8px,
    transparent 16px
  );
  background-color: var(--surface-2);
  border-color: var(--border-strong);
  border-style: dashed;
}

.tl-clip.no-video:hover {
  background-color: var(--surface-hover);
  box-shadow: none;
}

.tl-clip.no-video .tl-clip-title {
  color: var(--text-2);
  text-shadow: none;
}

.tl-clip.no-video .tl-clip-info {
  justify-content: center;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.tl-clip-no-video {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.tl-clip-info {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3px 7px;
  z-index: 2;
  pointer-events: none;
}

.tl-clip-title {
  font-size: 10px;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.tl-clip-dur {
  font-size: 9px;
  font-family: "SF Mono", Consolas, monospace;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  align-self: flex-end;
  font-variant-numeric: tabular-nums;
}

/* Trim handles - wide hit-area + small visible marker */
.tl-trim {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14px;
  cursor: ew-resize;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tl-clip:hover .tl-trim,
.tl-clip.is-selected .tl-trim {
  opacity: 1;
}

.tl-trim:hover::before {
  background: var(--accent);
  width: 4px;
  height: 26px;
}

.tl-trim::before {
  content: "";
  width: 3px;
  height: 22px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition:
    background 0.1s,
    width 0.1s,
    height 0.1s;
}

/* Stick the handle a bit outside the clip so it's easy to grab on tiny clips */
.tl-trim.left {
  left: -5px;
}
.tl-trim.right {
  right: -5px;
}

/* ── Touch support ──────────────────────────────────────────────────────────
   The timeline is driven by pointer events; tell the browser NOT to treat a
   drag on these as a scroll/zoom so the gesture reaches our handlers. */
.timeline-ruler,
.tl-clip,
.tl-trim,
.tl-audio-block {
  touch-action: none;
}

/* Trim handles only capture the pointer while they're VISIBLE - an invisible
   (opacity:0) handle still receives touches, so otherwise a tap near a clip edge
   would trim instead of selecting the clip (very easy to mis-hit with a finger). */
.tl-trim {
  pointer-events: none;
}
.tl-clip:hover .tl-trim,
.tl-clip.is-selected .tl-trim,
.tl-audio-block:hover .tl-trim {
  pointer-events: auto;
}

/* Touch: fatter trim handles, and reveal+grab them without hover (selected clip
   / the audio block) since there's no hover to surface them. */
@media (pointer: coarse) {
  .tl-trim {
    width: 22px;
  }
  .tl-clip.is-selected .tl-trim,
  .tl-audio-block .tl-trim {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Junction - cut marker between clips */
.tl-junction {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transform: translate(-50%, -50%);
  z-index: 6;
  color: var(--text-3);
  /* Exclude `left` - position must follow the clip instantly during trim/drag. */
  transition: transform 0.1s ease;
  box-shadow: none;
}

.tl-junction .ui-icon {
  font-size: 10px;
}

.tl-junction:hover {
  transform: translate(-50%, -50%) scale(1.15);
}

.tl-junction:active {
  transform: translate(-50%, -50%) scale(0.96);
}

/* Active transition - tinted background to signal it's set. */
.tl-junction.has-transition {
  background: #1a6abf;
  border-color: #0f4f9e;
  color: #ffffff;
  box-shadow: none;
}
.tl-junction.has-transition:hover {
  transform: translate(-50%, -50%) scale(1.15);
  border-color: rgba(0, 113, 227, 0.7);
  color: rgba(0, 113, 227, 1);
}

[data-theme="dark"] .tl-junction.has-transition {
  background: rgba(30, 80, 180, 0.45);
  border-color: rgba(56, 189, 248, 0.5);
  color: #7dd3fc;
}

/* Centered transition band - straddles the cut point. */
/* Transition band - flat and understated. */
.tl-tx-band {
  position: absolute;
  top: 6px;
  bottom: 6px;
  z-index: 5;
  pointer-events: none;
  border-radius: 4px;
  overflow: hidden;
  background: repeating-linear-gradient(
    -45deg,
    rgba(0, 113, 227, 0.05),
    rgba(0, 113, 227, 0.05) 6px,
    rgba(0, 113, 227, 0.12) 6px,
    rgba(0, 113, 227, 0.12) 12px
  );
  border-left: 2px solid #0071e3;
  border-right: 2px solid #0071e3;
}

[data-theme="dark"] .tl-tx-band {
  background: repeating-linear-gradient(
    -45deg,
    rgba(56, 189, 248, 0.05),
    rgba(56, 189, 248, 0.05) 6px,
    rgba(56, 189, 248, 0.12) 6px,
    rgba(56, 189, 248, 0.12) 12px
  );
  border-left: 2px solid #38bdf8;
  border-right: 2px solid #38bdf8;
}

/* Audio waveform */
.tl-waveform {
  position: absolute;
  inset: 3px 0;
  border-radius: var(--r-xs);
  background: linear-gradient(
    180deg,
    rgba(90, 200, 250, 0.18),
    rgba(90, 200, 250, 0.08)
  );
  border: 1px solid rgba(90, 200, 250, 0.3);
  overflow: hidden;
}

.tl-waveform canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== Flexible audio block (draggable / trimmable) ===== */
.tl-audio-block--pending {
  cursor: default;
  opacity: 0.85;
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
}
.tl-audio-pending {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  margin-top: 2px;
}

.tl-audio-block {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: var(--r-xs);
  cursor: grab;
  overflow: visible; /* let trim handles poke out (-5px); waveform clipped by .tl-waveform */
  border: 1.5px solid transparent;
  z-index: 1;
}
.tl-audio-block:hover {
  z-index: 2;
}
.tl-audio-block.is-selected {
  border-color: var(--orange);
  box-shadow:
    0 0 0 2px var(--orange),
    0 2px 10px rgba(255, 149, 0, 0.35);
  z-index: 3;
}
.tl-audio-block:active {
  cursor: grabbing;
}
.tl-audio-block:hover .tl-trim {
  opacity: 1;
}

/* Audio trim handles: center the visible bar exactly ON the block's edge.
   The handle zone is 14px wide; the bar (3px) is centered → half = 7px. */
.tl-audio-block .tl-trim.left {
  left: -7px;
}
.tl-audio-block .tl-trim.right {
  right: -7px;
}
.tl-audio-block .tl-waveform {
  left: 0;
  top: 0;
  bottom: 0;
  right: auto;
  width: 100%; /* overridden by inline style.width during trim drag */
  overflow: hidden;
}
.tl-audio-info {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 9px;
  pointer-events: none;
  z-index: 2;
}
.tl-audio-title {
  font-size: 10px;
  font-weight: 600;
  color: #eaf7ff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-audio-fx {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  color: #04222e;
  background: rgba(90, 200, 250, 0.95);
  border-radius: var(--r-pill);
  padding: 1px 7px;
  letter-spacing: 0.02em;
}

/* End-effect picker in the music popover */
/* Track name pill shown in the audio popover */
.audio-pop-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 7px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty-state upload zone inside the audio popover */
.audio-upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--r-sm);
  padding: 22px 12px 18px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  transition:
    background 0.15s,
    border-color 0.15s;
}
.audio-upload-zone:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}
.audio-upload-text {
  font-size: 12px;
  font-weight: 600;
}
.audio-upload-hint {
  font-size: 10px;
  color: var(--text-3);
}

.audio-upload-zone-compact {
  padding: 14px 12px;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.audio-pick-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  margin-bottom: 4px;
}

.audio-pick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface-2);
  cursor: pointer;
  text-align: start;
  color: var(--text);
  font-size: 12px;
  transition: background 0.12s var(--ease-out);
}
.audio-pick-item:hover {
  background: var(--surface-hover);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.audio-pick-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-fx-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.audio-fx-chip {
  padding: 8px 0;
  border: 1.5px solid var(--border);
  border-radius: var(--r-xs);
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  transition: all 0.12s var(--ease-out);
}
.audio-fx-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}
.audio-fx-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Frame-fit picker (clip popover) */
.fit-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.fit-chip {
  padding: 8px 0;
  border: 1.5px solid var(--border);
  border-radius: var(--r-xs);
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  transition: all 0.12s var(--ease-out);
}
.fit-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}
.fit-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.fit-blur-row,
.ws-fit-blur-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}

.fit-blur-row.is-disabled,
.ws-fit-blur-row.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.fit-blur-row input,
.ws-fit-blur-row input {
  accent-color: var(--accent);
}

.fit-blur-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

.vplayer-wrap .fit-blur-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.fit-blur-bg,
.preview-clip-blur {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.15);
  transform-origin: center center;
  filter: blur(28px);
  pointer-events: none;
  z-index: 0;
}

.preview-stage .fit-blur-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}
.fit-fg-contain-blur,
.preview-video.fit-fg-contain-blur {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  object-fit: contain;
}

/* ===== Server render - progress card (lives in #toastContainer) ===== */
.render-progress {
  --render-accent: #0071e3;
  --render-accent-soft: rgba(0, 113, 227, 0.12);
  position: relative;
  isolation: isolate;
  direction: rtl;
  width: min(380px, calc(100vw - 48px));
  pointer-events: auto;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--render-accent) 22%, var(--border));
  background-color: var(--surface);
  background-image: linear-gradient(
    145deg,
    color-mix(in srgb, var(--surface) 90%, #dbeafe) 0%,
    var(--surface) 52%,
    color-mix(in srgb, var(--surface) 94%, #eff6ff) 100%
  );
  box-shadow:
    0 10px 32px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
  animation: renderProgIn 0.32s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  overflow: hidden;
}
.render-progress--in-dock {
  margin-bottom: 4px;
}
.render-progress--floating {
  position: fixed;
  top: calc(var(--s-12, 48px) + 12px);
  inset-inline-end: 20px;
  z-index: 260;
}
.render-progress--record {
  --render-accent: #ff375f;
  --render-accent-soft: rgba(255, 55, 95, 0.12);
  border-color: color-mix(in srgb, var(--render-accent) 24%, var(--border));
  background-image: linear-gradient(
    145deg,
    color-mix(in srgb, var(--surface) 90%, #ffe4e8) 0%,
    var(--surface) 52%,
    color-mix(in srgb, var(--surface) 94%, #fff1f2) 100%
  );
}
.render-progress::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  background: linear-gradient(
    120deg,
    color-mix(in srgb, var(--render-accent) 55%, transparent),
    color-mix(in srgb, var(--render-accent) 12%, transparent) 42%,
    color-mix(in srgb, var(--render-accent) 40%, transparent)
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.render-progress-inner {
  position: relative;
  z-index: 1;
  padding: 12px 14px 13px;
}
.render-progress.is-minimized .render-progress-inner {
  padding-block: 10px;
}
.render-progress.is-minimized .render-progress-body {
  display: none;
}
.render-progress.is-done,
.render-progress.is-error {
  cursor: pointer;
}
@keyframes renderProgIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.render-progress-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.render-progress.is-minimized .render-progress-row {
  margin-bottom: 0;
  align-items: center;
}
.render-progress-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.render-progress-head-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.render-progress-icon {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--render-accent-soft);
  color: var(--render-accent);
}
.render-progress-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--render-accent) 18%, transparent);
  border-top-color: var(--render-accent);
  animation: renderProgSpin 0.75s linear infinite;
}
.render-progress.is-done .render-progress-spinner,
.render-progress.is-error .render-progress-spinner {
  border: none;
  animation: none;
  width: 16px;
  height: 16px;
  background: currentColor;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
}
.render-progress.is-done .render-progress-spinner {
  background: var(--green, #34c759);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M3.5 8.2l2.8 2.8 6.2-6.4' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.render-progress.is-error .render-progress-spinner {
  background: var(--red, #ff3b30);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M5 5l6 6M11 5l-6 6' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}
@keyframes renderProgSpin {
  to {
    transform: rotate(360deg);
  }
}
.render-progress-title {
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.012em;
  line-height: 1.25;
}
.render-progress-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  line-height: 1.3;
}
.render-progress-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.render-progress-pct {
  font-size: 12px;
  font-weight: 700;
  color: var(--render-accent);
  font-variant-numeric: tabular-nums;
  min-width: 2.6em;
  text-align: end;
}
.render-progress-minimize,
.render-cancel-btn {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition:
    background 0.15s,
    color 0.15s;
}
.render-progress-minimize:hover,
.render-cancel-btn:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text);
}
.render-cancel-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.render-progress-bar {
  height: 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}
.render-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--render-accent) 82%, #fff),
    var(--render-accent)
  );
  box-shadow: 0 0 12px color-mix(in srgb, var(--render-accent) 45%, transparent);
  transition: width 0.25s linear;
}
.render-progress-stage {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: -0.006em;
}
.render-progress-meta {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  min-height: 15px;
  letter-spacing: 0.01em;
}
.render-progress.is-done {
  --render-accent: #34c759;
  --render-accent-soft: rgba(52, 199, 89, 0.12);
}
.render-progress.is-done .render-progress-fill {
  background: linear-gradient(90deg, #5ad879, var(--green, #34c759));
  box-shadow: 0 0 10px rgba(52, 199, 89, 0.35);
}
.render-progress.is-done .render-progress-pct {
  color: var(--green, #34c759);
}
.render-progress.is-error {
  --render-accent: #ff3b30;
  --render-accent-soft: rgba(255, 59, 48, 0.1);
}
.render-progress.is-error .render-progress-fill {
  background: linear-gradient(90deg, #ff6b63, var(--red, #ff3b30));
}
.render-progress.is-error .render-progress-pct,
.render-progress.is-error .render-progress-title {
  color: var(--red, #ff3b30);
}

/* Timeline markers - thin guides, low visual weight */
.tl-markers-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.tl-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  transform: translateX(-50%);
  pointer-events: auto;
  cursor: ew-resize;
  z-index: 1;
}

.tl-marker-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: var(--orange, #ff9500);
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.12s var(--ease-out);
}

.tl-marker:hover .tl-marker-line,
.tl-marker:active .tl-marker-line {
  opacity: 0.85;
}

/* Playhead */
.tl-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--red);
  pointer-events: none;
  z-index: 7;
}

.tl-playhead::before {
  content: "";
  position: absolute;
  top: -2px;
  left: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--red);
  transform: translateX(-50%);
}

.tl-playhead-handle {
  position: absolute;
  top: 0;
  width: 12px;
  height: 14px;
  background: var(--red);
  border-radius: 2px 2px 0 0;
  left: 50%;
  transform: translateX(-50%);
  cursor: ew-resize;
  pointer-events: auto;
}

/* Drop indicator */
.tl-drop-indicator {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
  z-index: 9;
  box-shadow: 0 0 8px var(--accent);
}

/* Empty state */
.timeline-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-7) var(--s-4);
  color: var(--text-3);
  text-align: center;
  font-size: 12px;
  min-height: 100px;
}

/* ============================================================
   Popovers (color, transition)
   ============================================================ */
.popover {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--s-3);
  z-index: 100;
  animation: popIn 0.15s var(--ease-out);
  direction: rtl;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  /* Never wider than the viewport - keeps popovers on-screen on narrow phones
     (the JS clamps the left edge, this caps the width). */
  max-width: calc(100vw - 16px);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.popover-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.popover-clip-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--divider);
}

.popover-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.popover-section + .popover-section {
  padding-top: var(--s-2);
  border-top: 1px solid var(--divider);
}

/* Compact section label - stronger than .popover-subtle */
.popover-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-top: 2px;
}

/* Thin rule between sections inside a popover */
.popover-divider {
  height: 1px;
  background: var(--divider);
  margin: 6px 0 4px;
}

/* Side-by-side action buttons at the bottom of a popover section */
.popover-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--divider);
}
.popover-actions .btn {
  flex: 1;
}

.color-popover {
  width: 320px;
}

.speed-popover {
  width: 280px;
}

.fade-popover {
  width: 280px;
}

.fit-popover {
  width: 280px;
}

.audio-popover {
  width: 280px;
}

/* Speed slider - drag to set the clip's timeline duration */
.speed-slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.speed-slider .slider {
  width: 100%;
}
.speed-slider-ends {
  display: flex;
  justify-content: space-between;
  direction: ltr;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* Auto-correct - the headline action of the color popover */
.auto-correct-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.32);
  transition:
    transform 0.12s var(--ease-out),
    box-shadow 0.12s var(--ease-out),
    filter 0.12s var(--ease-out);
}
.auto-correct-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.42);
  filter: brightness(1.06);
}
.auto-correct-btn:active:not(:disabled) {
  transform: translateY(0);
}
.auto-correct-btn.is-analyzing {
  animation: autoPulse 1s ease-in-out infinite;
}
@keyframes autoPulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.18);
  }
}

.popover-subtle {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-align: center;
  letter-spacing: 0.02em;
  margin: 2px 0;
  text-transform: uppercase;
}

/* Transition popover */
.tx-popover {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--s-3);
  z-index: 100;
  width: 320px;
  animation: popIn 0.15s var(--ease-out);
  direction: rtl;
}

.tx-popover-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--s-2);
  letter-spacing: -0.01em;
}

.tx-popover .slider-row {
  margin-top: var(--s-2);
  padding-top: var(--s-2);
  border-top: 1px solid var(--divider);
}

/* ===== Source Monitor (in color popover) ===== */
.source-monitor {
  position: relative;
  background: #000;
  border-radius: var(--r-xs);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.source-monitor video,
.source-monitor img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.source-monitor-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 11px;
}

.io-bar {
  position: relative;
  height: 16px;
  background: var(--surface-2);
  border-radius: var(--r-xs);
  cursor: pointer;
  direction: ltr;
}

.io-track {
  position: absolute;
  inset: 4px 0;
  background: var(--surface-pressed);
  border-radius: 2px;
}

.io-selection {
  position: absolute;
  inset-block: 4px;
  background: var(--accent-soft-2);
  border-inline: 2px solid var(--accent);
  cursor: grab;
}

.io-handle {
  position: absolute;
  inset-block: -2px;
  width: 8px;
  background: var(--accent);
  border-radius: 2px;
  cursor: ew-resize;
  z-index: 2;
}

.io-handle.left {
  left: -4px;
}
.io-handle.right {
  right: -4px;
}

/* Touch: pointer-driven drag targets must not trigger native scroll/zoom, and
   the in/out handles need a fatter grab area for a finger. */
.wm-box,
.wm-handle,
.io-bar,
.io-handle {
  touch-action: none;
}
@media (pointer: coarse) {
  .io-handle {
    width: 14px;
  }
  .wm-handle {
    width: 22px;
    height: 22px;
  }
}

.io-times {
  display: flex;
  justify-content: space-between;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 10px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ===== Sliders (used in popovers) ===== */
.slider-row {
  display: grid;
  grid-template-columns: 70px 1fr 40px;
  align-items: center;
  gap: 8px;
}

.slider-row > label {
  font-size: 11px;
  color: var(--text-2);
  font-weight: 500;
}

.slider-row .value {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  text-align: end;
  font-family: "SF Mono", Consolas, monospace;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: linear-gradient(
    to right,
    var(--accent) var(--slider-fill, 50%),
    var(--surface-pressed) var(--slider-fill, 50%)
  );
  border-radius: var(--r-pill);
  outline: none;
  cursor: pointer;
  direction: ltr;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  box-shadow: var(--shadow-xs);
  cursor: grab;
}

.slider::-webkit-slider-thumb:active {
  cursor: grabbing;
}

.slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  box-shadow: var(--shadow-xs);
  cursor: grab;
}

/* ===== Look Presets ===== */
.look-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  direction: ltr;
}

/* Speed presets (slow-mo / fast-motion) */
.speed-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  direction: ltr;
}
.speed-chip {
  padding: 8px 0;
  border: 1.5px solid var(--border);
  border-radius: var(--r-xs);
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  transition: all 0.12s var(--ease-out);
}
.speed-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}
.speed-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.look-chip {
  aspect-ratio: 16 / 9;
  border-radius: var(--r-xs);
  border: 1.5px solid var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background-image: linear-gradient(135deg, #5a8ec0 0%, #9b6b4a 100%);
  transition: all 0.15s var(--ease-out);
}

.look-chip[data-look="natural"] {
  background-image: linear-gradient(135deg, #b9c3cf, #8c9aa8);
}
.look-chip[data-look="cinematic"] {
  background-image: linear-gradient(135deg, #2e3a4b, #c69a6a);
}
.look-chip[data-look="cool"] {
  background-image: linear-gradient(135deg, #1f3957, #4ea6e0);
}
.look-chip[data-look="warm"] {
  background-image: linear-gradient(135deg, #6a3b1d, #e8a85a);
}
.look-chip[data-look="bw"] {
  background-image: linear-gradient(135deg, #1d1d1f, #d0d0d3);
}
.look-chip[data-look="vivid"] {
  background-image: linear-gradient(135deg, #1a6b4a, #f0c040);
}

.look-chip:hover {
  transform: scale(1.05);
  border-color: var(--text-3);
}
.look-chip.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft-2);
}

.look-chip .look-name {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  font-size: 8px;
  font-weight: 700;
  color: white;
  text-align: center;
  padding: 2px 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  letter-spacing: 0.02em;
}

/* ===== Scene preset chips (one-click grade + VFX looks) ===== */
.scene-preset-group-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.02em;
  margin: 8px 0 4px;
}
.scene-preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.scene-preset-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2, var(--surface));
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.12s var(--ease-out);
}
.scene-preset-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}
.scene-preset-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft-2, var(--accent-soft));
  color: var(--text);
}

/* ===== Transition picker chips ===== */
.transition-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  /* Order the chips right-to-left: first transition appears top-right. */
  direction: rtl;
}

.transition-chip {
  aspect-ratio: 1.4;
  border-radius: var(--r-xs);
  border: 1.5px solid var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background: #1a1a1c;
  transition: all 0.15s var(--ease-out);
}

.transition-chip:hover {
  border-color: var(--text-3);
  transform: translateY(-1px);
}

.transition-chip.is-selected {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px var(--accent),
    0 0 14px rgba(0, 113, 227, 0.55);
}

/* A clear ✓ badge so it's obvious which transition is chosen. */
.transition-chip.is-selected::after {
  content: "✓";
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.transition-chip .tx-name {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 5;
  min-height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 600;
  line-height: 1.15;
  color: white;
  text-align: center;
  padding: 2px 3px;
  background: rgba(0, 0, 0, 0.88);
  letter-spacing: 0.02em;
  white-space: normal;
  word-break: keep-all;
  pointer-events: none;
}

.transition-chip .tx-preview {
  position: absolute;
  inset: 0;
  /* Keep animated previews (esp. zoom-punch) from painting over the label. */
  bottom: 18px;
  overflow: hidden;
}

.tx-preview .tx-a,
.tx-preview .tx-b {
  position: absolute;
  inset: 0;
  overflow: hidden;
  will-change: opacity, transform, filter;
}

.tx-preview .tx-a {
  background: linear-gradient(135deg, #5a8ec0, #1f3957);
}
.tx-preview .tx-b {
  background: linear-gradient(135deg, #c69a6a, #6a3b1d);
}
.tx-preview .tx-flash {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
}

/* Slider area inside transition popover */
.tx-popover .tx-slider-area {
  min-height: 0;
}

.tx-popover .tx-slider-area:not(:empty) {
  margin-top: var(--s-2);
  padding-top: var(--s-3);
  border-top: 1px solid var(--divider);
}

.tx-popover .tx-slider-area .slider-row {
  margin-top: 0 !important;
  padding-top: 0 !important;
  border-top: none !important;
}

.tx-popover .tx-hint {
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-3);
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ===== Export Modal ===== */

.modal:has(.export-modal) {
  padding: 0;
  overflow: hidden;
  max-width: 440px;
}

.export-modal {
  display: flex;
  flex-direction: column;
  direction: rtl;
  width: 100%;
  max-height: 90vh;
}

.export-modal .modal-header {
  padding: var(--s-5) var(--s-6);
  margin-bottom: 0;
  flex-shrink: 0;
}

/* Scrollable body */
.export-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* ── Info area (filename + stats) ───────────────────────────────── */
.export-info-area {
  background: var(--surface-2);
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.export-fn-row {
  display: flex;
  align-items: center;
  direction: rtl; /* RTL so filename is on the right, badge on the left */
  gap: 8px;
  margin-bottom: var(--s-4);
}
.export-fn-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  direction: rtl;
  text-align: right;
  outline: none;
  padding: 2px 0 4px;
  line-height: 1.3;
  transition: border-color 0.15s;
}
.export-fn-input::placeholder {
  color: var(--text-3);
  font-weight: 400;
}
.export-fn-input:focus {
  border-bottom-color: var(--accent);
}
.export-fn-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  background: var(--surface-pressed);
  border-radius: var(--r-xs);
  padding: 2px 6px;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  user-select: none;
}

/* Stats: 4-column flex, no borders */
.export-stats {
  display: flex;
  direction: ltr;
}
.export-stat {
  flex: 1;
  text-align: center;
}
.export-stat .lbl {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.export-stat .val {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.export-light-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: var(--s-4) var(--s-6) 0;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-2);
}

.export-light-note-icon {
  display: inline-flex;
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 1px;
}

.export-segment.is-locked .seg-btn {
  opacity: 0.55;
  pointer-events: none;
}

/* ── Warning ──────────────────────────────────────────────────── */
.export-warning {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: var(--s-4) var(--s-6) 0;
  background: rgba(245, 180, 60, 0.1);
  border: 1px solid rgba(245, 180, 60, 0.35);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  flex-shrink: 0;
}
.export-warning .warn-icon {
  color: #f5b43c;
  font-size: 14px;
  flex-shrink: 0;
}

/* ── Controls ─────────────────────────────────────────────────── */
.export-controls {
  display: flex;
  flex-direction: column;
  padding: var(--s-5) var(--s-6);
  flex: 1;
}

.export-form-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--divider);
}
.export-form-row:first-child {
  padding-top: 0;
}
.export-form-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.export-form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: -0.01em;
}

/* ── Segmented control (iOS) ──────────────────────────────────── */
.export-segment {
  display: flex;
  gap: 2px;
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  padding: 3px;
}
.seg-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-2);
  background: none;
  border: none;
  cursor: pointer;
  transition:
    background 0.15s var(--ease-out),
    box-shadow 0.15s var(--ease-out),
    color 0.1s;
  white-space: nowrap;
  text-align: center;
  line-height: 1;
}
.seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.1),
    0 1px 1px rgba(0, 0, 0, 0.06);
}

/* ── CRF slider ──────────────────────────────────────────────── */
.crf-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.crf-display {
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.crf-display-val {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.04em;
  line-height: 1;
}
.crf-display-note {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
}
.crf-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  direction: ltr;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--fill, 100%),
    var(--surface-pressed) var(--fill, 100%),
    var(--surface-pressed) 100%
  );
  outline: none;
  cursor: pointer;
  border: none;
}
.crf-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.18),
    0 0 0 1.5px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: transform 0.12s var(--ease-out);
}
.crf-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.crf-slider::-webkit-slider-thumb:active {
  transform: scale(1.2);
  box-shadow:
    0 2px 10px rgba(0, 113, 227, 0.25),
    0 0 0 3px rgba(0, 113, 227, 0.15);
}
.crf-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
.crf-hints {
  display: flex;
  justify-content: space-between;
  direction: ltr;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  padding: 0 2px;
  margin-top: -4px;
}

/* ── Footer ──────────────────────────────────────────────────── */
.export-footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--divider);
  flex-shrink: 0;
  gap: var(--s-2);
}
.export-footer-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  width: 100%;
}
.export-alt-link {
  align-self: center;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 11px;
  color: var(--text-3);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.export-alt-link:hover {
  color: var(--text-2);
}
.export-codec-text {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  direction: ltr;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.export-footer-btns {
  display: flex;
  gap: var(--s-2);
  flex-shrink: 0;
}
.export-btn-submit {
  min-width: 100px;
  justify-content: center;
}

/* ===== VFX modal ===== */
.modal:has(.vfx-modal) {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: min(1420px, 98vw);
  width: 100%;
  height: min(900px, 94vh);
  min-height: 680px;
  max-height: 94vh;
}

.vfx-modal {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: 100%;
  direction: rtl;
  background: var(--surface-2);
  overflow: hidden;
}

.vfx-modal .modal-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  background: var(--surface);
}

.vfx-m-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.vfx-modal .modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.vfx-m-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: 99px;
  white-space: nowrap;
  margin-inline-start: auto;
}

.vfx-modal-body {
  display: grid;
  grid-template-columns: minmax(480px, 1fr) minmax(260px, 330px) minmax(320px, 390px);
  grid-template-rows: minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  gap: 14px;
  padding: 14px;
}

/* Shared panel chrome */
.vfx-m-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03);
  overflow: hidden;
}

.vfx-m-panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
}

.vfx-m-panel-head svg {
  flex-shrink: 0;
  opacity: 0.75;
}

.vfx-m-panel-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

/* Tabs */
.vfx-m-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 10px 14px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.vfx-m-tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: none;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  cursor: pointer;
  transition:
    color 0.12s,
    background 0.12s;
}

.vfx-m-tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.vfx-m-tab.active {
  color: var(--text);
  background: var(--surface-2);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.vfx-m-tab-badge {
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 7px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}

.vfx-m-panel--preview {
  grid-column: 1;
  grid-row: 1;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  height: auto;
}

.vfx-m-panel--preview .vfx-modal-preview-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.vfx-tab-panels {
  grid-column: 2;
  grid-row: 1;
  grid-column-end: 4;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.vfx-tab-panel {
  display: none;
  grid-template-columns: minmax(250px, 0.9fr) minmax(300px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 10px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0 4px;
  -webkit-overflow-scrolling: touch;
}

.vfx-tab-panel.is-active {
  display: grid;
}

.vfx-m-panel--library,
.vfx-m-panel--active {
  flex: 0 0 auto;
  min-height: 0;
  height: 100%;
}

.vfx-m-panel--library {
  grid-column: 1;
  grid-row: 1;
}

.vfx-m-panel--active {
  grid-column: 2;
  grid-row: 1;
}

.vfx-m-panel--setup,
.vfx-prep-strip {
  grid-column: 1 / -1;
  grid-row: 1;
  flex: 0 0 auto;
}

.vfx-tab-panel:has(.vfx-m-panel--setup) .vfx-m-panel--library,
.vfx-tab-panel:has(.vfx-m-panel--setup) .vfx-m-panel--active,
.vfx-tab-panel:has(.vfx-prep-strip) .vfx-m-panel--library,
.vfx-tab-panel:has(.vfx-prep-strip) .vfx-m-panel--active {
  grid-row: 2;
}

.vfx-tab-panel:has(.vfx-m-panel--setup),
.vfx-tab-panel:has(.vfx-prep-strip) {
  grid-template-rows: auto minmax(0, 1fr);
}

.vfx-prep-strip {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 0 0 2px;
}

.vfx-m-panel--setup .vfx-setup-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 10px;
  padding: 10px 12px 12px;
}

.vfx-m-panel--setup .vfx-setup-body--single {
  grid-template-columns: minmax(0, 1fr);
}

.vfx-m-panel--library > .vfx-m-rails,
.vfx-m-panel--active > .vfx-m-active-wrap {
  padding: 10px 12px 12px;
}

.vfx-m-panel--library > .vfx-m-rails {
  min-height: 0;
}

.vfx-m-panel--active > .vfx-m-active-wrap {
  overflow-x: hidden;
  overflow-y: auto;
}

.vfx-m-setup-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-3);
}

.vfx-modal-preview-wrap {
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.vfx-modal-preview {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vfx-modal-monitor {
  position: relative;
  aspect-ratio: var(--mon-ar, 16 / 9);
  height: 100%;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  border-radius: var(--r-sm);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.vfx-modal-monitor video,
.vfx-modal-monitor img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.vfx-anchor-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  display: none;
}
.vfx-anchor-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.vfx-anchor-marker:active {
  cursor: grabbing;
}
.vfx-anchor-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}
.vfx-anchor-label {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.vfx-anchor-marker--handRight .vfx-anchor-dot,
.vfx-anchor-marker--handLeft .vfx-anchor-dot {
  background: var(--purple);
}
.vfx-anchor-marker--head .vfx-anchor-dot {
  background: var(--teal);
}
.vfx-anchor-marker--chest .vfx-anchor-dot {
  background: var(--orange);
}

.vfx-m-active-wrap {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.vfx-m-active {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  padding: 2px;
  -webkit-overflow-scrolling: touch;
}

.vfx-m-hint {
  margin: 0;
  padding: 18px 10px;
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.015);
}

.vfx-m-hint.is-busy {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

/* active effect card */
.vfx-m-card {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition:
    border-color 0.12s,
    box-shadow 0.12s,
    background 0.12s;
}

.vfx-m-card.is-selected {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: inset 0 0 0 1px var(--accent-soft);
  cursor: default;
}

.vfx-m-card-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.vfx-m-card:not(.is-selected) .vfx-m-card-head {
  border-bottom: none;
}

.vfx-m-card-thumb {
  width: 42px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.vfx-m-card-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.vfx-m-card-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vfx-m-card-meta {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vfx-m-card-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.vfx-m-card-x:hover {
  color: var(--red);
  background: rgba(220, 38, 38, 0.08);
}

.vfx-m-card-body {
  flex: 0 0 auto;
  min-width: 0;
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.vfx-m-control-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 10px 0 0;
  border: none;
  border-top: 1px solid var(--divider);
  border-radius: 0;
  background: transparent;
  overflow: hidden;
}

.vfx-m-control-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.05em;
}

.vfx-m-control-section-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
}

.vfx-m-slider-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px 10px;
  min-width: 0;
}

.vfx-m-card-body .slider-row,
.vfx-m-slider-row {
  grid-template-columns: minmax(0, 52px) minmax(0, 1fr) minmax(0, 32px);
  gap: 5px;
  min-width: 0;
}

.vfx-m-card-body .slider-row > label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vfx-m-card-body .slider-row .slider {
  height: 4px;
  width: 100%;
  min-width: 0;
}

.vfx-m-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.vfx-m-color {
  width: 34px;
  height: 28px;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--r-xs);
  cursor: pointer;
}

.vfx-m-targets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.vfx-m-target {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition:
    border-color 0.12s,
    background 0.12s;
}

.vfx-m-target:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
}

.vfx-m-target.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* category rails */
.vfx-m-rails {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0 0;
  -webkit-overflow-scrolling: touch;
}

.vfx-m-rail-block {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 0 10px;
  border: none;
  border-bottom: 1px solid var(--divider);
  border-radius: 0;
  background: transparent;
}

.vfx-m-rail-cat {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  padding-inline-start: 0;
  border-inline-start: none;
}

.vfx-m-rail {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 10px;
  height: auto;
  overflow: visible;
  -webkit-overflow-scrolling: touch;
}

.vfx-m-tile {
  width: 100%;
  height: 92px;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition:
    border-color 0.12s,
    transform 0.12s,
    box-shadow 0.12s;
}

.vfx-m-tile:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
}

.vfx-m-tile.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.vfx-m-tile img {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  object-fit: cover;
  display: block;
  background: #000;
}

.vfx-m-tile span {
  flex: 0 0 auto;
  padding: 5px 4px 6px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
  line-height: 1.2;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .modal:has(.vfx-modal) {
    max-width: 100%;
    width: 100%;
    height: min(92dvh, 92vh);
    min-height: 0;
    max-height: min(92dvh, 92vh);
    padding: 0;
    overflow: hidden;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }

  .modal:has(.vfx-modal)::before {
    flex-shrink: 0;
    margin: 10px auto 0;
  }

  .vfx-modal {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    max-height: none;
    overflow: hidden;
  }

  .vfx-modal .modal-header {
    padding: 10px 14px;
    flex-shrink: 0;
  }

  .vfx-modal .modal-title {
    font-size: 15px;
  }

  .vfx-m-tabs {
    padding: 6px 10px 0;
  }

  .vfx-m-tab {
    padding: 8px 10px;
    font-size: 12px;
  }

  .vfx-modal-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding: 6px 10px 0;
    gap: 6px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  }

  /* Preview stays pinned at top with a real height box for the monitor */
  .vfx-m-panel--preview {
    flex: 0 0 auto;
    flex-shrink: 0;
    height: auto;
    border-radius: var(--r-md);
  }

  .vfx-m-panel--preview .vfx-m-panel-head {
    padding: 6px 10px;
  }

  .vfx-m-panel--preview .vfx-m-panel-title {
    font-size: 10px;
  }

  .vfx-m-panel--preview .vfx-modal-preview-wrap {
    flex: none;
    min-height: clamp(168px, 36dvh, 300px);
    height: clamp(168px, 36dvh, 300px);
    padding: 6px;
    background: #0a0a0a;
  }

  .vfx-tab-panels {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: 4px;
  }

  .vfx-tab-panel {
    overflow: visible;
    gap: 8px;
    padding: 0 0 8px;
  }

  .vfx-m-panel--library .vfx-m-panel-head,
  .vfx-m-panel--active .vfx-m-panel-head {
    padding: 8px 10px;
  }

  .vfx-modal-preview {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    width: 100%;
  }

  .vfx-modal-monitor {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: unset;
  }

  .vfx-m-rails {
    overflow: visible;
    gap: 10px;
    max-height: none;
    padding: 0;
  }

  .vfx-m-rail-block {
    padding-bottom: 6px;
  }

  /* Horizontal swipe rails — saves vertical space on small screens */
  .vfx-m-rail {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding-bottom: 4px;
  }

  .vfx-m-rail::-webkit-scrollbar {
    display: none;
  }

  .vfx-m-tile {
    flex: 0 0 76px;
    width: 76px;
    height: 84px;
    scroll-snap-align: start;
  }

  .vfx-m-tile span {
    font-size: 10px;
    min-height: 24px;
  }

  .vfx-m-active-wrap {
    overflow-x: hidden;
    overflow-y: visible;
    min-height: 0;
  }

  .vfx-m-active {
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;
    gap: 10px;
    padding: 0;
  }

  .vfx-m-card {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
  }

  .vfx-m-panel--setup .vfx-setup-body {
    grid-template-columns: 1fr;
  }

  .vfx-m-slider-grid {
    grid-template-columns: 1fr;
  }

  .vfx-m-card-body .slider-row,
  .vfx-m-slider-row {
    grid-template-columns: minmax(0, 62px) minmax(0, 1fr) minmax(0, 40px);
  }

  .vfx-m-card-body .slider,
  .vfx-m-card-body input[type="range"] {
    height: 28px;
  }

  .vfx-m-card-body .slider::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  .vfx-m-card-body .slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  .vfx-m-targets {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .vfx-m-target {
    min-height: 40px;
    font-size: 12px;
    padding: 8px 6px;
  }

  .vfx-prep-strip {
    gap: 4px;
  }

  .vfx-prep-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px 10px;
  }

  .vfx-prep-row-end {
    margin-inline-start: 0;
    width: 100%;
    justify-content: space-between;
  }

  .vfx-prep-redo {
    min-height: 36px;
  }

  .vfx-picker-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    padding-bottom: 2px;
  }

  .vfx-picker-chip {
    flex-shrink: 0;
    min-height: 36px;
    padding: 6px 12px;
  }
}

.vfx-m-analyze {
  align-self: flex-start;
  width: 100%;
}

/* VFX studio — subject & background panel */
.vfx-subject-wrap,
.vfx-subject {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Two distinct preparation cards (#1 attach-to-point, #2 isolate-from-bg) so the
   user stops conflating "זיהוי גוף" with "בידוד דמות". */
.vfx-prep-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 11px 12px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.vfx-prep-card--track {
  border-inline-start: 3px solid var(--purple);
}
.vfx-prep-card--isolate {
  border-inline-start: 3px solid var(--teal);
}

.vfx-prep-head {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.vfx-prep-num {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--border-strong, var(--border));
  color: var(--text-2);
  font-size: 11px;
  font-weight: 800;
}
.vfx-prep-num.is-done {
  background: var(--green);
  color: #fff;
}
.vfx-prep-ic {
  flex: 0 0 auto;
  color: var(--text-3);
}
.vfx-prep-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.vfx-prep-status {
  flex: 0 0 auto;
  margin-inline-start: auto;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  background: var(--border);
}
.vfx-prep-status.is-done {
  color: #fff;
  background: var(--green);
}
.vfx-prep-desc {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-2);
}
.vfx-prep-use {
  margin: 0;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
}
.vfx-prep-use.is-active {
  color: var(--text);
}
.vfx-prep-target {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-2);
}
.vfx-prep-target b {
  font-weight: 700;
  color: var(--text);
}

/* One compact preparation line: state · title · target ··· status · quality · redo. */
.vfx-prep-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex-wrap: wrap;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  transition: border-color 0.15s ease;
}
.vfx-prep-row--body {
  border-inline-start-color: var(--purple);
}
.vfx-prep-row--character {
  border-inline-start-color: var(--teal);
}
.vfx-prep-row.is-busy {
  border-inline-start-color: var(--accent);
}
.vfx-prep-row.is-done {
  border-inline-start-color: var(--green);
}
.vfx-prep-row-state {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-3);
}
.vfx-prep-row-state.is-busy {
  background: var(--accent-soft);
  color: var(--accent);
}
.vfx-prep-row-state.is-done {
  background: var(--green);
  color: #fff;
}
.vfx-prep-row-title {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.vfx-prep-row-target {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  color: var(--text-3);
}
.vfx-prep-row-end {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.vfx-prep-row-status {
  flex: 0 0 auto;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  background: var(--border);
  color: var(--text-3);
}
.vfx-prep-row-status.is-busy {
  background: var(--accent-soft);
  color: var(--accent);
}
.vfx-prep-row-status.is-done {
  background: var(--green);
  color: #fff;
}
.vfx-prep-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.vfx-prep-redo {
  flex: 0 0 auto;
}

/* VFX studio — character picker (above the two prep cards) */
.vfx-picker-wrap:not(:empty) {
  padding: 0;
}
.vfx-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}
.vfx-picker-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-3);
}
.vfx-picker-lbl {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
}
.vfx-picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.vfx-picker-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.vfx-picker-chip:hover {
  border-color: var(--border-strong);
}
.vfx-picker-chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent, #fff);
}

/* VFX studio — tappable person markers on the monitor */
.vfx-person-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}
.vfx-person-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.vfx-person-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
  color: #fff;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.vfx-person-marker:hover .vfx-person-dot,
.vfx-person-marker:active .vfx-person-dot {
  transform: scale(1.12);
}
.vfx-person-check {
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.vfx-person-marker.is-selected .vfx-person-dot {
  background: var(--accent);
  border-color: #fff;
}
.vfx-person-marker.is-selected .vfx-person-check {
  opacity: 1;
  transform: scale(1);
}
.vfx-person-label {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}
.vfx-person-marker.is-selected .vfx-person-label {
  background: var(--accent);
}

.vfx-subject-lbl {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 600;
}

@media (max-width: 1100px) and (min-width: 769px) {
  .vfx-modal-body {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  }

  .vfx-tab-panels {
    grid-column: 2;
    grid-column-end: 3;
  }

  .vfx-tab-panel.is-active {
    display: flex;
    flex-direction: column;
  }

  .vfx-m-panel--library,
  .vfx-m-panel--active,
  .vfx-m-panel--setup,
  .vfx-prep-strip {
    grid-column: auto;
    grid-row: auto;
    height: auto;
  }

  .vfx-m-panel--setup .vfx-setup-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .vfx-tab-panel.is-active {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .vfx-m-panel--library,
  .vfx-m-panel--active,
  .vfx-m-panel--setup,
  .vfx-prep-strip {
    grid-column: auto;
    grid-row: auto;
    height: auto;
    min-height: 0;
  }

  .vfx-m-panel--library > .vfx-m-rails,
  .vfx-m-panel--active > .vfx-m-active-wrap {
    padding: 8px 10px 10px;
  }
}

/* ── Slip-source modal — "בחר חלק מהסרטון" ───────────────────────────────── */
.slip-modal {
  display: flex;
  flex-direction: column;
  max-width: 760px;
}

.slip-body {
  padding: 14px 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Full source timeline; the highlighted window is the fixed-length slot. */
.slip-track {
  position: relative;
  height: 46px;
  background: var(--surface-pressed);
  border-radius: var(--r-xs);
  cursor: pointer;
  direction: ltr;
  overflow: hidden;
  touch-action: none;
}

.slip-dim {
  position: absolute;
  inset-block: 0;
  background: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.slip-window {
  position: absolute;
  inset-block: 0;
  background: var(--accent-soft-2);
  border-inline: 2px solid var(--accent);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 8px;
}

.slip-window:active {
  cursor: grabbing;
}

.slip-window-grip {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--accent);
  opacity: 0.85;
  background-image: repeating-linear-gradient(
    90deg,
    transparent 0 3px,
    rgba(255, 255, 255, 0.55) 3px 4px
  );
}

.slip-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}

.slip-meta-strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  direction: ltr;
}

.slip-meta-dim {
  font-size: 12px;
  color: var(--text-3);
  direction: ltr;
}

.slip-actions {
  display: flex;
  justify-content: center;
}

.slip-noslack {
  font-size: 12px;
  color: var(--amber, #d08700);
  text-align: center;
}

.slip-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
}

/* ── Subtitles / lyrics modal ─────────────────────────────────────────────── */
.modal:has(.sub-modal) {
  padding: 0;
  max-width: 900px;
  overflow: hidden;
}
.sub-modal {
  display: flex;
  flex-direction: column;
  max-height: 86vh;
  text-align: right;
}
.sub-modal-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--divider);
}
.sub-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.sub-modal-title .ui-icon {
  color: var(--accent);
}
.sub-modal-body {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 22px;
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
}
.sub-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.sub-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sub-field-head label,
.sub-col-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.sub-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid var(--divider);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.sub-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.sub-textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--divider);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
  font-family: "Segoe UI", system-ui, sans-serif;
}
.sub-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.sub-summary {
  font-size: 12.5px;
  color: var(--text-3);
}
.sub-summary.is-ok {
  color: var(--green, #1a9d52);
  font-weight: 500;
}
.sub-summary.is-warn {
  color: var(--amber, #d08700);
}
.sub-hint {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-3);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
}
.sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sub-row-label {
  flex-shrink: 0;
  width: 64px;
  font-size: 13px;
  color: var(--text-2);
}
.sub-select {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--divider);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
}
.sub-range-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sub-range {
  flex: 1;
  accent-color: var(--accent);
}
.sub-row-value {
  flex-shrink: 0;
  width: 46px;
  text-align: left;
  font-size: 12.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.sub-color-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sub-color {
  width: 38px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.sub-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.sub-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s;
}
.sub-swatch:hover {
  transform: scale(1.15);
}
.sub-seg {
  flex: 1;
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 10px;
}
.sub-seg-btn {
  flex: 1;
  padding: 7px 4px;
  border: none;
  border-radius: 7px;
  background: none;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sub-seg-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.1));
}
.sub-toggles {
  flex: 1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.sub-toggle {
  padding: 7px 12px;
  border: 1px solid var(--divider);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.sub-toggle.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.sub-modal-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--divider);
}
.sub-footer-spacer {
  flex: 1;
}
.sub-enable {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.sub-enable.is-on {
  background: color-mix(in srgb, var(--green, #1a9d52) 12%, transparent);
  border-color: var(--green, #1a9d52);
  color: var(--green, #1a9d52);
}
.sub-clear {
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text-3);
  font-size: 13px;
  cursor: pointer;
}
.sub-clear:hover {
  color: var(--red, #d62f2f);
}
.sub-done {
  padding: 9px 22px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.sub-done:hover {
  filter: brightness(1.05);
}
@media (max-width: 720px) {
  .sub-modal-body {
    grid-template-columns: 1fr;
  }
}
