/* Files tab */
.files-panel {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

/* Jump-to-top — only after scrolling down */
.files-scroll-top {
  position: fixed;
  z-index: 36;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  inset-inline-end: max(20px, env(safe-area-inset-inline-end, 0px));
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    color 0.12s ease,
    background 0.12s ease,
    border-color 0.12s ease,
    box-shadow 0.12s ease;
}

.files-scroll-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.files-scroll-top:hover,
.files-scroll-top:focus-visible {
  color: var(--accent);
  background: var(--bg-2);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border-strong));
  box-shadow: var(--shadow-md);
  outline: none;
}

.files-scroll-top:focus-visible {
  box-shadow:
    0 0 0 2px var(--accent-soft),
    var(--shadow-sm);
}

.files-scroll-top:active {
  transform: translateY(1px);
}

.files-panel--with-folder-import .files-main,
.files-panel--with-compact-tree .files-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

/* One quiet row: section jumps + compact folder import */
.files-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  flex-wrap: wrap;
  width: 100%;
  margin: -4px 0 -2px;
}

/* Quiet jump links: images · videos · audio · exports — not a full toolbar */
.files-jump-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 0;
  flex: 1 1 auto;
  min-width: 0;
  width: fit-content;
  max-width: 100%;
  margin: 0;
  padding: 0;
  color: var(--text-3);
}

.files-jump-btn {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 5px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  transition:
    color 0.12s ease,
    background 0.12s ease;
}

.files-jump-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--surface-pressed) 55%, transparent);
}

.files-jump-btn.is-active {
  color: var(--accent);
  background: transparent;
}

.files-jump-count {
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.files-jump-sep {
  display: inline-flex;
  align-items: center;
  padding: 0 1px;
  color: var(--text-3);
  opacity: 0.45;
  font-size: 12px;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.files-section[data-section-key] {
  scroll-margin-top: 12px;
}

.files-section.is-jump-flash {
  animation: files-jump-flash 0.7s ease;
}

@keyframes files-jump-flash {
  0%,
  100% {
    border-color: var(--border);
  }
  40% {
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  }
}

/* Browser folder import — subtle control on the left of the jump row */
.folder-import-bar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  margin-inline-start: auto;
  border-radius: 6px;
  transition:
    background 0.12s ease,
    box-shadow 0.12s ease;
}

.folder-import-bar.is-drop-over {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}

.folder-import-pick {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 6px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  transition:
    color 0.12s ease,
    background 0.12s ease;
}

.folder-import-pick:hover,
.folder-import-pick:focus-visible {
  color: var(--text);
  background: color-mix(in srgb, var(--surface-pressed) 55%, transparent);
  outline: none;
}

.folder-import-pick:disabled {
  opacity: 0.55;
  cursor: default;
}

.folder-import-pick-label {
  letter-spacing: -0.01em;
}

@media (max-width: 520px) {
  .files-top-row {
    gap: 4px 8px;
  }

  .folder-import-pick-label {
    /* Keep the control tiny on narrow screens — icon + tooltip still work */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

/* ── Add-to-project modal ───────────────────────────────────────────────── */
.modal:has(.add-local-modal) {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  max-width: 440px;
  width: min(440px, 96vw);
  max-height: min(92vh, 860px);
  min-height: 0;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.modal.modal-lg:has(.add-local-modal--video) {
  max-width: 680px;
  width: min(680px, 96vw);
}

.add-local-modal {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
  direction: rtl;
}

.add-local-modal .modal-header {
  padding: var(--s-4) var(--s-5);
  margin-bottom: 0;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
  background: var(--surface);
}

.add-local-modal .modal-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.add-local-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

/* Video: media right, controls left (RTL grid) */
.add-local-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 252px);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.add-local-media-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #000;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.add-local-media-col .vplayer-wrap {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 278px;
  border-radius: 0;
  max-width: none;
  margin: 0;
  align-items: stretch;
  background: transparent;
}

.add-local-media-col .vplayer-video {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  object-fit: contain;
}

.add-local-side,
.add-local-options {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  background: var(--surface-2);
}

.add-local-side {
  overflow-y: auto;
  padding: var(--s-3) var(--s-4);
  border-inline-start: 1px solid var(--divider);
}

.add-local-side .export-form-row,
.add-local-options .export-form-row {
  gap: 8px;
  padding: var(--s-3) 0;
}

.add-local-side .export-form-row:first-child,
.add-local-options .export-form-row:first-child {
  padding-top: 0;
}

.add-local-side .export-form-row:last-child,
.add-local-options .export-form-row:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.add-local-side .export-form-label,
.add-local-options .export-form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: -0.01em;
}

.add-local-side .export-segment,
.add-local-side .cselect-trigger,
.add-local-options .export-segment,
.add-local-options .cselect-trigger {
  width: 100%;
}

.add-local-side .field-hint,
.add-local-options .field-hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.add-local-side .prep-trim-bar {
  gap: 6px;
}

.add-local-side .prep-trim-actions {
  gap: 4px;
}

.add-local-side .prep-trim-actions .btn {
  flex: 1;
  min-width: 0;
  padding-inline: 6px;
}

/* Image / audio preview */
.add-local-preview.lightbox-body {
  flex-shrink: 0;
  padding: var(--s-3) var(--s-5);
  background: var(--surface-2);
}

.add-local-preview--image {
  display: flex;
  align-items: center;
  justify-content: center;
}

.add-local-preview--image .lightbox-media {
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
}

.add-local-preview--audio {
  padding-block: var(--s-4);
}

.add-local-preview .aplayer {
  width: 100%;
  direction: ltr;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  background: var(--surface);
}

.add-local-options {
  padding: var(--s-3) var(--s-5) var(--s-4);
  border-top: 1px solid var(--divider);
}

.add-local-role {
  padding-top: 2px;
}

.add-local-role .export-segment {
  width: 100%;
}

.add-local-modal .modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: 0;
  padding: var(--s-3) var(--s-5);
  flex-shrink: 0;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

@media (max-width: 640px) {
  .add-local-split {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .add-local-side {
    border-inline-start: none;
    border-top: 1px solid var(--divider);
    order: 2;
  }

  .add-local-media-col {
    order: 1;
    min-height: min(40vh, 320px);
  }

  .add-local-modal .modal-header,
  .add-local-preview.lightbox-body,
  .add-local-options,
  .add-local-side,
  .add-local-modal .modal-footer {
    padding-inline: var(--s-4);
  }
}

.local-source-compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}

.local-source-compact-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

.local-source-path {
  flex: 1 1 120px;
  min-width: 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}

.local-source-sort-btn {
  margin-inline-start: auto;
}

.local-source-hint {
  margin: var(--s-2) 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.badge.local-badge {
  font-size: 10px;
  padding: 2px 6px;
  margin-inline-start: 6px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border-radius: var(--r-sm);
}

.badge.folder-badge {
  font-size: 10px;
  padding: 2px 6px;
  margin-inline-start: 4px;
  flex-shrink: 0;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface-pressed);
  color: var(--text-2);
  border-radius: var(--r-sm);
}

.file-item-name-row .badge {
  margin-inline-start: 0;
}

.files-library-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.files-folder-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.files-folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  cursor: pointer;
  transition:
    border-color 0.12s,
    background 0.12s,
    color 0.12s;
  max-width: 100%;
}

.files-folder-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.files-folder-chip.is-active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
  font-weight: 600;
}

.files-folder-chip-count {
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  padding: 0 6px;
  line-height: 1.5;
}

.files-folder-chip.is-active .files-folder-chip-count {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.files-folder-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.files-folder-group-head {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  padding: 4px 6px 4px 4px;
  border-radius: var(--r-md);
  transition: background 0.1s;
}

.files-folder-group-head:hover {
  background: var(--surface-hover);
}

.files-folder-group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: start;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.files-folder-group-toggle:hover {
  background: color-mix(in srgb, var(--text) 4%, transparent);
}

.files-folder-group-delete {
  flex-shrink: 0;
  opacity: 0.55;
  color: var(--text-3);
}

.files-folder-group-head:hover .files-folder-group-delete,
.files-folder-group-delete:focus-visible {
  opacity: 1;
}

.files-folder-group-delete:hover {
  color: var(--danger, #c44);
}

.files-folder-group-caret,
.files-folder-group-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-3);
}

.files-folder-group-icon {
  color: var(--accent);
}

.files-folder-group-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: end;
}

.files-folder-group-count {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  padding: 0 7px;
}

.files-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-xs);
  transition:
    border-color 0.12s ease,
    background 0.12s ease;
}

/* Drag a file over a media section → highlight it as a drop target. */
.files-section.is-drop-over {
  border-color: var(--accent);
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.files-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--divider);
}

.files-section-head.files-section-head--collapsed {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.files-section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  text-align: inherit;
  font: inherit;
  color: inherit;
  border-radius: var(--r-sm);
}

.files-section-toggle:hover {
  color: var(--text);
}

.files-section-toggle:hover .files-section-caret {
  color: var(--text-2);
}

.files-section-caret {
  display: flex;
  flex-shrink: 0;
  color: var(--text-3);
}

.files-section.is-collapsed .files-section-body {
  display: none;
}

.files-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.files-section-count {
  background: var(--surface-pressed);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--r-pill);
}

.files-empty {
  padding: var(--s-5);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--s-3);
}

.file-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.15s;
}

.file-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.file-item-thumb {
  aspect-ratio: 16/9;
  background: var(--surface-pressed);
  cursor: pointer;
  overflow: hidden;
}

.file-item-thumb img,
.file-item-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-item-info {
  padding: var(--s-3);
  flex: 1;
  min-width: 0;
}

.file-item-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-width: 0;
}

.file-item-name-row .file-item-name {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
  border-radius: 3px;
  padding: 1px 3px;
  margin: -1px -3px;
  transition: background 0.12s;
}

.file-item-name:hover {
  background: var(--surface-hover);
}

.file-item-name-input {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-hover);
  border: 1.5px solid var(--accent);
  border-radius: 3px;
  padding: 1px 5px;
  outline: none;
  width: 100%;
  min-width: 0;
}

.file-item-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.file-item-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 6px;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

/* ── Audio library: play + time on the top thumb ───────────────────────── */
.audio-item.is-main {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 4%, var(--surface-2));
  box-shadow: none;
}

.audio-thumb {
  position: relative;
  aspect-ratio: 2 / 1;
  background: var(--surface-pressed);
  overflow: hidden;
}

.audio-item.is-main .audio-thumb {
  background: color-mix(in srgb, var(--accent) 6%, var(--surface-pressed));
}

.audio-main-badge {
  position: absolute;
  top: 8px;
  left: 8px; /* opposite aplayer times (direction:ltr, right:8px) */
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  background: var(--accent);
  pointer-events: none;
}

.audio-thumb .aplayer,
.audio-thumb .aplayer--files {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  direction: ltr;
  cursor: default;
}

.audio-thumb .aplayer-btn {
  width: 44px;
  height: 44px;
  z-index: 1;
}

.audio-thumb .aplayer-track {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  width: auto;
  height: 3px;
  margin: 0;
}

.audio-thumb .aplayer-times {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 0;
  font-size: 11px;
  color: var(--text-2);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  pointer-events: none;
}

.files-audio-main-btn {
  color: var(--text-3);
  margin-inline-end: auto;
}

.files-audio-main-btn.is-active,
.files-audio-main-btn[aria-pressed="true"] {
  color: #fff;
  background: var(--accent);
}

.files-audio-main-btn.is-active:hover,
.files-audio-main-btn[aria-pressed="true"]:hover {
  color: #fff;
  background: var(--accent-hover, var(--accent));
}

/* ── Audio chooser (audio-driven video models) ──────────────────────────── */
.video-card-footer .video-audio-field {
  margin-bottom: var(--s-1);
}

.audio-chooser {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--divider);
  border-radius: var(--r-2, 8px);
  background: var(--surface);
}

/* RTL: play sits on the right of the track name (first in row = inline-end). */
.audio-chooser-track {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 1;
  min-width: 0;
  direction: rtl;
}

.audio-chooser-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: start;
}

.audio-chooser-play-wrap {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.audio-chooser-preview-audio {
  display: none;
}

/* ── Motion source (the clip the character has to imitate) ─────────────── */
.motion-chooser {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--divider);
  border-radius: var(--r-2, 8px);
  background: var(--surface);
}

.motion-chooser-preview {
  width: 72px;
  height: 48px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: var(--r-1, 6px);
  background: #000;
}

.motion-chooser-meta {
  flex: 1;
  min-width: 0;
}

.motion-chooser-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.motion-chooser-sub {
  font-size: 11px;
  color: var(--text-dim, var(--text-muted));
  margin-top: 2px;
}

.motion-chooser-sub--warn {
  color: var(--warning, #d98324);
}

/* Both ways out of a singing/model mismatch sit on one row. */
.singing-mismatch-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}

/* ── Motion source picker (record / upload / trim) ──────────────────────── */
.motion-src-modal {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.motion-src-hint {
  font-size: 12px;
  color: var(--text-dim, var(--text-muted));
  line-height: 1.5;
}

.motion-src-hint--warn {
  color: var(--warning, #d98324);
}

.motion-src-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  border-radius: var(--r-2, 8px);
  background: #000;
  overflow: hidden;
}

.motion-src-video {
  max-width: 100%;
  max-height: 46vh;
  display: block;
  /* Mirror the live camera so acting to the screen feels like a mirror. The
     recorded stream itself is NOT mirrored - the model gets the real take. */
}

.motion-src-stage > video[autoplay] {
  transform: scaleX(-1);
}

.motion-src-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  color: var(--text-dim, var(--text-muted));
}

.motion-src-empty-text {
  font-size: 13px;
}

.motion-src-trim {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text);
}

.motion-src-trim-range {
  flex: 1;
  min-width: 160px;
}

.motion-src-trim-label {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim, var(--text-muted));
}

.motion-src-status {
  min-height: 18px;
  font-size: 12px;
  color: var(--text-dim, var(--text-muted));
}

.motion-src-status[data-kind="err"] {
  color: var(--danger, #e05252);
}

.motion-src-status[data-kind="rec"] {
  color: var(--danger, #e05252);
  font-variant-numeric: tabular-nums;
}

.motion-src-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.motion-src-actions .is-recording {
  background: var(--danger, #e05252);
  border-color: var(--danger, #e05252);
}

.motion-src-working {
  font-size: 12px;
  color: var(--text-dim, var(--text-muted));
}

/* ── Singing shots (perform the project's own song) ─────────────────────── */
.video-avatar-audio {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Equal-weight source choice: sing from song OR pick uploaded audio. */
.avatar-audio-mode-toggle {
  width: 100%;
  display: flex;
  align-self: stretch;
}

.avatar-audio-mode-toggle .mode-pill {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-inline: 10px;
  padding-block: 6px;
  min-width: 0;
  font-size: 12px;
}

/* Singing: one chooser row in three zones - range | options | change. */
.singing-field,
.speech-language-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.singing-chooser {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 0;
  padding: 6px 8px;
  min-width: 0;
}

.singing-chooser > .ui-icon,
.singing-chooser .audio-chooser-track > .ui-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.singing-chooser-track {
  flex: 1 1 auto;
  min-width: 0;
  gap: 8px;
  padding-inline-end: 10px;
}

.singing-window-range {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.singing-window-len {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  white-space: nowrap;
}

/* A hand-picked range no longer follows the timeline - say so, quietly. */
.singing-window-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 7px;
  border-radius: var(--r-pill);
  flex-shrink: 0;
}

.singing-chooser-opts {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
  padding-inline: 10px;
  border-inline-start: 1px solid var(--divider);
  min-width: 0;
}

.singing-style-select {
  min-width: 0;
}

.singing-style-select .cselect-trigger {
  min-height: 0;
  padding: 2px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2, var(--text-muted));
  background: transparent;
  border: none;
  border-radius: 4px;
  box-shadow: none;
}

.singing-style-select .cselect-trigger:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2, rgba(0, 0, 0, 0.04));
}

.singing-style-select .cselect-trigger:disabled {
  opacity: 0.45;
}

.singing-style-select .cselect-trigger-chevron {
  opacity: 0.55;
  width: 12px;
  height: 12px;
}

.singing-isolate-toggle {
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.singing-isolate-toggle .control-toggle-check {
  width: 13px;
  height: 13px;
}

.singing-change-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  margin-inline-start: 8px;
}

.singing-note {
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-muted);
  padding-inline: 2px;
}

@media (max-width: 720px) {
  .singing-chooser {
    flex-wrap: wrap;
    gap: 6px;
  }

  .singing-chooser-track {
    flex-basis: 100%;
    padding-inline-end: 0;
  }

  .singing-chooser-opts {
    flex: 1 1 auto;
    border-inline-start: none;
    padding-inline: 0;
  }

  .singing-change-btn {
    margin-inline-start: auto;
  }
}

.singing-pick-fallback {
  align-self: flex-start;
}

/* ── Singing range picker modal ─────────────────────────────────────────── */
.modal:has(.singing-range-modal) {
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 640px);
  overflow: hidden;
  min-height: 0;
}

.singing-range-modal {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.singing-range-title-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.singing-range-sub {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

.singing-range-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-8) var(--s-4);
  color: var(--text-muted);
  font-size: 13px;
}

.singing-range-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-3) 0 var(--s-2);
  min-height: 0;
  flex: 1;
}

.singing-range-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  min-width: 0;
}

.singing-range-song-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.singing-range-meta {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s-2);
  font-variant-numeric: tabular-nums;
}

.singing-range-meta-range {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.singing-range-meta-len {
  font-size: 12px;
  color: var(--text-muted);
}

.singing-range-play {
  flex-shrink: 0;
}

.singing-range-strip {
  position: relative;
  height: 88px;
  border-radius: var(--r-2, 8px);
  background: #0f1419;
  overflow: hidden;
  cursor: crosshair;
  direction: ltr;
  touch-action: none;
  user-select: none;
  outline: none;
}

.singing-range-strip:focus-visible {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
}

.singing-range-wave-host {
  position: absolute;
  inset: 0;
  opacity: 0.85;
  pointer-events: none;
}

.singing-range-wave-host canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.singing-range-sel {
  position: absolute;
  top: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  cursor: grab;
  box-sizing: border-box;
  outline: none;
}

.singing-range-sel:active {
  cursor: grabbing;
}

.singing-range-sel:focus-visible,
.singing-range-handle:focus-visible {
  box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--accent);
}

.singing-range-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: ew-resize;
  touch-action: none;
  z-index: 1;
}

.singing-range-handle--start {
  left: -1px;
}

.singing-range-handle--end {
  right: -1px;
}

.singing-range-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 28px;
  border-radius: 2px;
  background: var(--accent);
}

.singing-range-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-inline-start: -1px;
  background: #fff;
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.45);
}

.singing-range-hint {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
}

.singing-range-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: auto;
}

.singing-range-footer .btn-ghost {
  margin-inline-end: auto;
}

@media (max-width: 600px) {
  .singing-range-toolbar .singing-range-song-name {
    flex-basis: 100%;
  }

  .singing-range-play {
    width: 100%;
  }

  .singing-range-footer .btn {
    flex: 1 1 42%;
  }

  .singing-range-footer .btn-ghost {
    flex-basis: 100%;
    margin-inline-end: 0;
  }
}

/* ── Audio picker modal ─────────────────────────────────────────────────── */
.modal:has(.audio-picker-modal) {
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 720px);
  overflow: hidden;
  min-height: 0;
}

.audio-picker-modal {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.audio-picker-modal .modal-header.audio-picker-header {
  flex-shrink: 0;
  margin-bottom: 0;
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--divider);
}

.audio-picker-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-4) 0 0;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.audio-picker-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
  flex-shrink: 0;
}

.audio-picker-quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 96px;
  padding: var(--s-3);
  border: 1.5px dashed var(--border-strong, var(--border));
  border-radius: var(--r-md, 10px);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition:
    border-color 0.15s,
    background 0.15s,
    transform 0.12s var(--ease-out);
}

.audio-picker-quick-btn:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}

.audio-picker-quick-btn:active {
  transform: scale(0.98);
}

.audio-picker-quick-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-pressed);
  color: var(--text-muted);
  transition: color 0.15s;
}

.audio-picker-quick-btn:hover .audio-picker-quick-icon {
  color: var(--accent);
}

.audio-picker-quick-btn--ai .audio-picker-quick-icon {
  color: var(--accent);
}

.audio-picker-quick-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.audio-picker-quick-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

.audio-picker-library {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.audio-picker-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-inline: 2px;
  flex-shrink: 0;
}

.audio-picker-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 2px;
  margin: -2px;
}

.audio-picker-empty {
  padding: var(--s-5) var(--s-4);
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--r-md, 10px);
  background: var(--surface-pressed);
}

.audio-picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md, 10px);
  background: var(--surface);
  overflow: hidden;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.audio-picker-row:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.audio-picker-row.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}

.audio-picker-row-select {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: start;
  font: inherit;
  color: inherit;
  transition: background 0.12s;
}

.audio-picker-row:hover .audio-picker-row-select {
  background: color-mix(in srgb, var(--accent) 3%, transparent);
}

/* .audio-picker-row.is-selected .audio-picker-row-select {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
} */

.audio-picker-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.audio-picker-row-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.audio-picker-row-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

.audio-picker-row-play {
  align-self: center;
  margin-inline: 6px 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-pressed);
  flex-shrink: 0;
}

.audio-picker-row-play:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-pressed));
  color: var(--accent);
}

.audio-picker-preview-audio {
  display: none;
}

@media (max-width: 480px) {
  .audio-picker-quick {
    grid-template-columns: 1fr;
  }

  .audio-picker-quick-btn {
    flex-direction: row;
    justify-content: flex-start;
    min-height: 0;
    text-align: start;
    padding: var(--s-3) var(--s-4);
  }
}

.files-section-actions {
  display: flex;
  gap: var(--s-2, 6px);
  flex-wrap: wrap;
}

/* Project exports (render-server jobs) — same card grid as library media */
.files-section--exports .files-exports-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.files-export-sub {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  min-height: 1em;
}

.files-export-item .file-item-name {
  cursor: default;
}

.files-export-item .file-item-name:hover {
  background: transparent;
}

.files-export-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: default;
  color: var(--text-3);
}

.files-export-thumb--run {
  color: var(--accent, #4f7cff);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-pressed));
}

.files-export-thumb--err {
  color: #ff8a8a;
  background: color-mix(in srgb, #ff8a8a 10%, var(--surface-pressed));
}

.files-export-thumb-label {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.files-export-status {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0 6px;
  color: var(--text-3);
}

.files-export-status--run {
  color: var(--accent, #4f7cff);
}

.files-export-status--err {
  color: #ff8a8a;
}

/* Mobile: section actions stack cleanly; audio cards stay 2-up with a tidy square */
@media (max-width: 768px) {
  .files-section {
    padding: var(--s-3);
  }

  .files-section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .files-section-toggle {
    flex: 0 0 auto;
    width: 100%;
  }

  .files-section-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  .files-section-actions > .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    padding-inline: 8px;
  }

  /* Keep 2 cards per row — only tidy the square thumb so overlays don't collide */
  .audio-item .audio-thumb {
    aspect-ratio: 1 / 1;
  }

  .audio-thumb .aplayer-btn {
    width: 40px;
    height: 40px;
  }

  /* Duration already in meta — times pill was covering the main badge */
  .audio-thumb .aplayer-times {
    display: none;
  }

  .audio-thumb .aplayer-track {
    left: 10px;
    right: 10px;
    bottom: 8px;
    height: 4px;
  }

  .audio-main-badge {
    top: 6px;
    left: 6px;
    padding: 2px 6px;
    font-size: 10px;
    gap: 2px;
  }

  .audio-item .file-item-info {
    padding: 8px;
  }

  .audio-item .file-item-name {
    font-size: 12px;
  }

  .audio-item .file-item-meta {
    font-size: 10px;
  }

  .audio-item .file-item-actions {
    padding: 4px 6px;
    gap: 2px;
  }

  .audio-item .file-item-actions .btn {
    min-width: 32px;
    min-height: 32px;
    padding: 4px;
  }

  .files-audio-main-btn {
    margin-inline-end: auto;
  }
}

/* ── «עיצוב קול» - designed voices (stacked over the speech creator) ────── */
.voice-designer {
  width: 100%;
  min-width: 0;
}
.voice-designer-gender {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.voice-designer-chip {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.voice-designer-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.voice-designer-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.voice-designer-empty {
  margin: 0;
  font-size: 13px;
  color: var(--text-3);
}
.voice-designer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.voice-designer-row-text {
  flex: 1;
  min-width: 0;
}
.voice-designer-row-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.voice-designer-row-desc {
  overflow: hidden;
  font-size: 12px;
  color: var(--text-3);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.voice-designer-delete {
  white-space: nowrap;
}
/* .field is display:flex, which beats the browser's [hidden] (the two modes hide each other's fields). */
.voice-designer [hidden] {
  display: none !important;
}
.voice-designer-file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.voice-designer-file-name {
  overflow: hidden;
  font-size: 13px;
  color: var(--text-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* «מי מדבר» (OmniHuman 1.5): a box dragged over the speaker on the opening picture. */
.speaker-picker-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
.speaker-picker-img {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  border-radius: var(--r-md);
}
.speaker-picker-box {
  position: absolute;
  border: 2px solid #fff;
  border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.speaker-picker-box[hidden] {
  display: none;
}
.video-dub {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.video-dub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
}
.video-dub-who {
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--text);
}
.video-dub-row .cselect-trigger {
  min-width: 0;
  flex: 1 1 auto;
}
.video-dub-status {
  font-size: 12px;
  color: var(--text-3);
}
.video-dub-status--warn {
  color: var(--warning, #b45309);
}
.video-dub-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.voice-designer-consent {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

/* ── Speech creator (AI narration / TTS) modal ──────────────────────────── */
.speech-creator-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-3);
}
.speech-creator-body .field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 6px);
}
.speech-suggestions {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 6px);
}
.speech-suggestions:empty {
  display: none;
}

.speech-suggestion-card .speech-suggestion-block-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #888);
  margin-top: 8px;
  margin-bottom: 3px;
}

.speech-suggestion-card .speech-suggestion-block-label:first-of-type {
  margin-top: 0;
}

.speech-suggestion-style-block {
  margin-top: 2px;
}

.suggestion-card-style {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-2, var(--text));
  font-style: italic;
}
.speech-voice-hint {
  font-size: 11.5px;
  color: var(--text-muted, #888);
  line-height: 1.45;
  margin-top: 4px;
}

.speech-voice-hint:empty {
  display: none;
}

.speech-cartoon-design-btn {
  margin-top: 8px;
  align-self: flex-start;
}

.cartoon-voice-lead {
  font-size: 13px;
  color: var(--text-2, var(--text));
  line-height: 1.5;
  margin: 0 0 var(--s-3, 12px);
}

.cartoon-voice-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted, #888);
  padding: var(--s-4, 16px) 0;
}

.cartoon-voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-3, 12px);
}

.cartoon-voice-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: var(--s-3, 12px);
  border: 1px solid var(--divider);
  border-radius: var(--radius, 8px);
  background: var(--surface-2, var(--surface));
}

.cartoon-voice-card-title {
  font-size: 13px;
  font-weight: 600;
}

.cartoon-voice-error {
  color: var(--danger, #c44);
  font-size: 13px;
}

.speech-creator-hint {
  font-size: 11.5px;
  color: var(--text-muted, #888);
  line-height: 1.4;
}
.speech-creator-result {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 6px);
  padding: var(--s-3);
  border: 1px solid var(--divider);
  border-radius: var(--radius, 8px);
  background: var(--surface-2, var(--surface));
}
.speech-creator-result[hidden] {
  display: none;
}
.speech-creator-result-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2, var(--text));
}
.speech-creator-result-meta {
  font-size: 11.5px;
  color: var(--text-muted, #888);
}
.speech-creator-result-audio {
  width: 100%;
  height: 36px;
  margin-top: 2px;
}
.speech-creator-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding-top: var(--s-2, 6px);
  border-top: 1px solid var(--divider);
}
.speech-price {
  font-size: 12.5px;
  color: var(--text-muted, #888);
  font-variant-numeric: tabular-nums;
}

/* ── Auto soundtrack + speech modal (matches logo / sub / templates) ───── */
.modal.modal-lg:has(.auto-soundtrack-modal),
.modal:has(.auto-soundtrack-modal) {
  display: flex;
  flex-direction: column;
  width: min(1040px, 96vw);
  max-width: min(1040px, 96vw);
  max-height: min(90dvh, 820px);
  padding: 0;
  overflow: hidden;
}

.auto-soundtrack-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: inherit;
  min-height: 0;
  direction: rtl;
  text-align: right;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

.auto-soundtrack-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px 11px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
}

.auto-soundtrack-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
}

.auto-soundtrack-title-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
}

.auto-soundtrack-title-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.auto-soundtrack-title-main {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.auto-soundtrack-title-sub {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.auto-soundtrack-mode-step {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
}

.auto-soundtrack-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.auto-soundtrack-section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-2);
  text-transform: none;
}

.auto-soundtrack-mode-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.auto-soundtrack-mode-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  margin: 0;
  padding: 10px 10px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: right;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.auto-soundtrack-mode-card:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: var(--surface);
}

.auto-soundtrack-mode-card.is-active {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent);
}

.auto-soundtrack-mode-card-title {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.auto-soundtrack-mode-card-desc {
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--text-3);
}

.auto-soundtrack-mode-card.is-active .auto-soundtrack-mode-card-desc {
  color: var(--text-2);
}

.auto-soundtrack-mode-desc {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-2);
}

.auto-soundtrack-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.auto-soundtrack-tab {
  appearance: none;
  margin: 0;
  border: 0;
  border-radius: 9px;
  padding: 9px 10px;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}

.auto-soundtrack-tab:hover {
  color: var(--text);
}

.auto-soundtrack-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.auto-soundtrack-speech-modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.auto-soundtrack-speech-modes[hidden],
.auto-soundtrack-scenes-panel[hidden],
.auto-soundtrack-body[hidden],
.auto-soundtrack-footer[hidden] {
  display: none !important;
}

.auto-soundtrack-scenes-panel {
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  overflow: auto;
  background: var(--surface-2);
}

.auto-soundtrack-scenes-panel:not([hidden]) {
  display: flex;
}

.auto-soundtrack-modal--scenes .auto-soundtrack-scenes {
  flex: 1;
  gap: 10px;
  padding: 12px 16px 16px;
}

.auto-soundtrack-modal--speech .auto-soundtrack-music-section > .auto-soundtrack-section-head {
  display: none;
}

.auto-soundtrack-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(0, 1.15fr);
  gap: 12px;
  padding: 12px;
  overflow: hidden;
  align-items: stretch;
  background: var(--surface-2);
}

.auto-soundtrack-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.auto-soundtrack-col--controls {
  overflow: auto;
}

.auto-soundtrack-col--scripts {
  overflow: hidden;
}

.auto-soundtrack-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 2px;
}

.auto-soundtrack-col-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.auto-soundtrack-speech-extras,
.auto-soundtrack-music-section,
.auto-soundtrack-dub-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auto-soundtrack-music-section {
  padding-top: 10px;
  border-top: 1px dashed var(--divider);
}

.auto-soundtrack-top-grid,
.auto-soundtrack-prompt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}

.auto-soundtrack-options-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
}

.auto-soundtrack-options-row .auto-soundtrack-lipsync {
  flex: 1 1 180px;
  margin: 0;
  min-width: 160px;
}

.auto-soundtrack-mode-toggle {
  width: 100%;
  display: flex;
}

.auto-soundtrack-mode-toggle .mode-pill {
  flex: 1;
  text-align: center;
  padding-inline: 10px;
}

.auto-soundtrack-scope-field .ai-modal-mode-toggle {
  width: 100%;
}

.auto-soundtrack-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.auto-soundtrack-check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.auto-soundtrack-dub-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

.auto-soundtrack-lipsync[hidden],
.auto-soundtrack-clips-section[hidden],
.auto-soundtrack-dub-hint[hidden],
.auto-soundtrack-mood-field[hidden],
.auto-soundtrack-speech-extras[hidden],
.auto-soundtrack-style-field[hidden],
.auto-soundtrack-check[hidden],
.auto-soundtrack-col[hidden],
.auto-soundtrack-scripts[hidden],
.auto-soundtrack-cast[hidden],
.auto-soundtrack-scope-field[hidden],
.auto-soundtrack-engine-field[hidden],
.auto-soundtrack-mood-examples-wrap[hidden],
.auto-soundtrack-mood-groups[hidden],
.auto-soundtrack-mood-examples[hidden] {
  display: none !important;
}

.auto-soundtrack-mood-examples-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.auto-soundtrack-mood-examples-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
}

/* Family row: one line, scrolls sideways rather than stacking on the chips. */
.auto-soundtrack-mood-groups {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.auto-soundtrack-mood-group {
  margin: 0;
  padding: 5px 10px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.auto-soundtrack-mood-group:hover {
  color: var(--text);
  background: var(--surface-2);
}

.auto-soundtrack-mood-group.is-active {
  color: var(--text);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px
    color-mix(in srgb, var(--accent) 45%, transparent);
}

.auto-soundtrack-mood-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 118px;
  overflow-y: auto;
  align-content: flex-start;
  scrollbar-width: thin;
}

.auto-soundtrack-mood-chip {
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    color 0.15s ease;
}

.auto-soundtrack-mood-chip:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  color: var(--text);
  background: var(--surface);
}

.auto-soundtrack-mood-chip.is-active {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: var(--accent-soft);
  color: var(--text);
}

.auto-soundtrack-modal--music .auto-soundtrack-body {
  grid-template-columns: 1fr;
  justify-content: center;
  align-content: start;
  overflow: auto;
}

.auto-soundtrack-modal--music .auto-soundtrack-col--scripts {
  display: none !important;
}

.auto-soundtrack-modal--music .auto-soundtrack-col--controls {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  gap: 14px;
  padding: 18px 18px 16px;
}

.auto-soundtrack-modal--music .auto-soundtrack-col-head {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.auto-soundtrack-modal--music .auto-soundtrack-col-title {
  font-size: 15px;
}

.auto-soundtrack-modal--music .auto-soundtrack-music-section {
  padding-top: 0;
  border-top: none;
  gap: 12px;
}

.auto-soundtrack-engine-field {
  margin: 0;
}

.auto-soundtrack-engine-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auto-soundtrack-engine-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.auto-soundtrack-engine-card:hover {
  border-color: var(--border-strong, var(--border));
  background: var(--surface-2);
}

.auto-soundtrack-engine-card.is-active {
  border-color: var(--accent, #3b82f6);
  background: color-mix(in srgb, var(--accent, #3b82f6) 10%, var(--surface));
  box-shadow: inset 0 0 0 1px
    color-mix(in srgb, var(--accent, #3b82f6) 35%, transparent);
}

.auto-soundtrack-engine-card-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}

.auto-soundtrack-engine-card-desc {
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.35;
}

.auto-soundtrack-engine-card.is-active .auto-soundtrack-engine-card-desc {
  color: var(--text-2);
}

.auto-soundtrack-modal--music .auto-soundtrack-section-head {
  display: none;
}

.auto-soundtrack-modal--music .auto-soundtrack-mood-field {
  margin: 0;
}

.auto-soundtrack-modal--music .auto-soundtrack-mood-field .field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.auto-soundtrack-modal--music .auto-soundtrack-mood-field .textarea {
  min-height: 140px;
  font-size: 14px;
  line-height: 1.45;
  padding: 12px 14px;
  border-radius: 10px;
  resize: vertical;
}

.auto-soundtrack-modal--music .auto-soundtrack-mood-hint {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.4;
}

.auto-soundtrack-scripts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  margin: 0;
}

.auto-soundtrack-scripts .field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.auto-soundtrack-scripts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  margin: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.auto-soundtrack-script-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.auto-soundtrack-script-row[hidden] {
  display: none;
}

.auto-soundtrack-script-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.auto-soundtrack-script-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.auto-soundtrack-script-label {
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.auto-soundtrack-script-kind {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-3);
}

.auto-soundtrack-script-speaker {
  flex: 0 0 auto;
  min-width: 110px;
  max-width: 160px;
}

.auto-soundtrack-script-speaker[hidden] {
  display: none;
}

.auto-soundtrack-script-speaker .cselect-trigger {
  max-width: 160px;
  min-width: 110px;
}

.auto-soundtrack-script-regen {
  flex-shrink: 0;
  padding: 3px 8px;
  font-size: 11.5px;
  white-space: nowrap;
}

.auto-soundtrack-script-regen[hidden] {
  display: none;
}

.auto-soundtrack-script-area {
  width: 100%;
  min-height: 44px;
  max-height: 88px;
  resize: vertical;
  font-size: 13px;
  line-height: 1.35;
}

.auto-soundtrack-script-wrap {
  position: relative;
  width: 100%;
}

.auto-soundtrack-script-wrap.is-loading .auto-soundtrack-script-area {
  opacity: 0.35;
  color: transparent;
  caret-color: transparent;
  resize: none;
}

.auto-soundtrack-script-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: inherit;
  background: color-mix(in srgb, var(--surface) 82%, var(--accent, #0a6b76) 8%);
  pointer-events: none;
  z-index: 1;
}

.auto-soundtrack-script-loading[hidden] {
  display: none !important;
}

.auto-soundtrack-script-loading .ai-textarea-spinner-ring {
  width: 22px;
  height: 22px;
  border-width: 2.5px;
}

.auto-soundtrack-script-loading-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  text-align: center;
  line-height: 1.35;
  max-width: 100%;
}

.auto-soundtrack-scripts-status {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

.auto-soundtrack-scripts-status[hidden] {
  display: none !important;
}

.auto-soundtrack-scripts-status.is-writing {
  color: var(--text-2);
}

.auto-soundtrack-clip-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(160px, 22vh);
  overflow: auto;
  margin: 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.auto-soundtrack-clip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 4px 6px;
  border-radius: 6px;
}

.auto-soundtrack-clip-row:hover {
  background: var(--surface-hover, var(--surface-pressed));
}

.auto-soundtrack-clip-name {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.auto-soundtrack-clip-speaker {
  flex: 0 1 128px;
  min-width: 100px;
}

.auto-soundtrack-clip-speaker[hidden] {
  display: none;
}

.auto-soundtrack-mode-chips {
  display: inline-flex;
  gap: 3px;
  flex-shrink: 0;
}

.auto-soundtrack-mode-chips[hidden] {
  display: none;
}

.auto-soundtrack-mode-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 11.5px;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: var(--r-pill, 999px);
  cursor: pointer;
  line-height: 1.2;
}

.auto-soundtrack-mode-chip.is-active {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
  font-weight: 600;
}

.auto-soundtrack-cast-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auto-soundtrack-cast-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.auto-soundtrack-cast-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.auto-soundtrack-cast-name {
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
}

.auto-soundtrack-cast-reason {
  font-size: 11.5px;
  color: var(--text-3);
}

.auto-soundtrack-cast-reason:empty {
  display: none;
}

.auto-soundtrack-cast-status {
  display: block;
  min-height: 0;
  font-size: 12px;
  color: var(--text-3);
}

.auto-soundtrack-cast-status:empty {
  display: none;
}

.auto-soundtrack-modal .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.auto-soundtrack-modal .field-label {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-2);
}

.auto-soundtrack-modal .field-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

.auto-soundtrack-modal .textarea {
  min-height: 48px;
}

.auto-soundtrack-modal .auto-soundtrack-prompt-grid .textarea {
  min-height: 44px;
  max-height: 72px;
  resize: vertical;
}

.auto-soundtrack-modal .cselect-trigger {
  width: 100%;
  max-width: 240px;
}

.auto-soundtrack-cast-row .cselect-trigger {
  max-width: 220px;
}

.auto-soundtrack-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 10px 14px;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

.auto-soundtrack-footer .speech-price {
  font-size: 12.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 820px) {
  .auto-soundtrack-mode-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .auto-soundtrack-engine-cards {
    grid-template-columns: 1fr;
  }
  .auto-soundtrack-body {
    grid-template-columns: 1fr;
    overflow: auto;
  }
  .auto-soundtrack-col--controls,
  .auto-soundtrack-col--scripts {
    overflow: visible;
  }
  .auto-soundtrack-scripts-list {
    max-height: min(280px, 36vh);
  }
  .auto-soundtrack-top-grid,
  .auto-soundtrack-prompt-grid {
    grid-template-columns: 1fr;
  }
  .modal.modal-lg:has(.auto-soundtrack-modal),
  .modal:has(.auto-soundtrack-modal) {
    max-width: min(640px, 96vw);
    width: min(640px, 96vw);
    max-height: min(92dvh, 900px);
  }
}

@media (max-width: 768px) {
  .auto-soundtrack-modal {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }

  .auto-soundtrack-head {
    padding: 8px 14px 10px;
    gap: 10px;
  }

  .auto-soundtrack-title-icon {
    width: 30px;
    height: 30px;
  }

  .auto-soundtrack-title-main {
    font-size: 16px;
  }

  .auto-soundtrack-title-sub {
    -webkit-line-clamp: 1;
  }

  .auto-soundtrack-mode-step {
    padding: 8px 12px 8px;
    gap: 8px;
  }

  .auto-soundtrack-tabs {
    gap: 2px;
    padding: 3px;
  }

  .auto-soundtrack-tab {
    min-height: 44px;
    padding: 8px 4px;
    font-size: 13.5px;
  }

  .auto-soundtrack-speech-modes {
    gap: 6px;
  }

  .auto-soundtrack-mode-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .auto-soundtrack-mode-card {
    padding: 8px 6px;
    min-height: 44px;
    justify-content: center;
  }

  .auto-soundtrack-mode-card-desc {
    display: none;
  }

  .auto-soundtrack-mode-desc {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 12.5px;
    line-height: 1.4;
  }

  .auto-soundtrack-scenes-panel {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }

  .auto-soundtrack-scenes {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 8px 12px 8px;
  }

  .auto-soundtrack-scenes .auto-soundtrack-section-head {
    flex-wrap: wrap;
    align-items: flex-start;
    margin-bottom: 6px;
  }

  .auto-soundtrack-section-sub {
    flex: 1 1 100%;
    margin-inline-start: 0;
    line-height: 1.35;
  }

  .auto-soundtrack-scenes-list {
    max-height: none;
  }

  .auto-soundtrack-scene {
    padding: 12px;
  }

  .auto-soundtrack-scene-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name time"
      "action action";
    align-items: center;
    column-gap: 8px;
    row-gap: 8px;
  }

  .auto-soundtrack-scene-top .ass-name {
    grid-area: name;
  }

  .auto-soundtrack-scene-top .ass-time {
    grid-area: time;
    justify-self: start;
  }

  .auto-soundtrack-scene-top .btn {
    grid-area: action;
    width: 100%;
    margin-inline-start: 0;
    justify-content: center;
    min-height: 40px;
  }

  .auto-soundtrack-scene-need {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
  }

  .auto-soundtrack-scene-need.is-status {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .auto-soundtrack-scene-need .asn-text {
    white-space: normal;
  }

  .auto-soundtrack-scene-need .asn-pill,
  .auto-soundtrack-scene-need .asn-undo {
    justify-self: end;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
  }

  .asn-text-input,
  .auto-soundtrack-modal .textarea,
  .auto-soundtrack-script-area {
    font-size: 16px;
  }

  .auto-soundtrack-body {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: 1fr;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 12px 12px;
    gap: 10px;
  }

  .auto-soundtrack-col,
  .auto-soundtrack-modal--music .auto-soundtrack-col--controls {
    padding: 10px;
    overflow: visible;
  }

  .auto-soundtrack-col--controls,
  .auto-soundtrack-col--scripts {
    overflow: visible;
  }

  .auto-soundtrack-scripts-list {
    max-height: none;
  }

  .auto-soundtrack-script-head {
    flex-wrap: wrap;
  }

  .auto-soundtrack-script-head-actions {
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  .auto-soundtrack-script-speaker {
    min-width: 0;
    max-width: none;
    flex: 1;
  }

  .auto-soundtrack-cast-row {
    flex-wrap: wrap;
  }

  .auto-soundtrack-cast-row .cselect-trigger {
    width: 100%;
    max-width: none;
  }

  .auto-soundtrack-clip-row {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .auto-soundtrack-clip-name {
    flex: 1 1 100%;
  }

  .auto-soundtrack-modal .cselect-trigger,
  .auto-soundtrack-cast-row .cselect-trigger,
  .auto-soundtrack-script-speaker,
  .auto-soundtrack-script-speaker .cselect-trigger {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .auto-soundtrack-check {
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
  }

  .auto-soundtrack-clip-list {
    max-height: none;
  }

  .auto-soundtrack-modal--music .auto-soundtrack-mood-field .textarea {
    min-height: 96px;
    max-height: 160px;
  }

  .auto-soundtrack-footer {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 10px 12px max(12px, env(safe-area-inset-bottom, 12px));
  }

  .auto-soundtrack-footer .speech-price {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .auto-soundtrack-footer .btn {
    flex: 0 0 auto;
    min-height: 44px;
    justify-content: center;
  }
}

/* ── Local image edit modal (erase / fill) ──────────────────────────────── */
.modal.modal-lg:has(.ime-modal) {
  max-width: min(1120px, 96vw);
  width: min(1120px, 96vw);
  max-height: min(90dvh, 860px);
  height: min(90dvh, 860px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(
    180deg,
    var(--bg-2) 0%,
    var(--surface) 42%,
    var(--surface) 100%
  );
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.ime-modal {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-ui);
}

.ime-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  margin-bottom: 0;
  border-bottom: 1px solid var(--divider);
  background: linear-gradient(
    180deg,
    rgba(251, 252, 254, 0.96) 0%,
    rgba(238, 242, 247, 0.55) 100%
  );
}

.ime-title-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ime-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.ime-header .modal-title {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
}

.ime-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ime-subtitle {
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(640px, 78vw);
}

.ime-status {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  color: var(--red);
  background: rgba(214, 69, 69, 0.08);
  border-bottom: 1px solid rgba(214, 69, 69, 0.18);
  padding: var(--s-2) var(--s-5);
}

.ime-status[hidden] {
  display: none;
}

.ime-stage {
  flex: 1;
  min-height: 0;
  margin: var(--s-3) var(--s-5);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background-color: var(--surface-2);
  background-image:
    linear-gradient(45deg, rgba(14, 28, 48, 0.045) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(14, 28, 48, 0.045) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(14, 28, 48, 0.045) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(14, 28, 48, 0.045) 75%);
  background-size: 16px 16px;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
  overflow: hidden;
}

.ime-canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: var(--s-4);
}

.ime-view-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
  max-height: 100%;
  isolation: isolate;
  z-index: 1;
}

.ime-view {
  position: relative;
  z-index: 1;
  display: block;
  cursor: none;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  touch-action: none;
  outline: 1px solid rgba(14, 28, 48, 0.08);
}

.ime-view-wrap--result .ime-view {
  cursor: default;
}

.ime-cursor {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  background: rgba(10, 107, 118, 0.22);
  box-shadow:
    0 0 0 1.5px rgba(10, 22, 40, 0.45),
    0 0 0 3.5px rgba(10, 107, 118, 0.28);
  transform: translate3d(-9999px, -9999px, 0) translate(-50%, -50%);
  will-change: transform;
  z-index: 5;
  transition:
    width 0.06s ease,
    height 0.06s ease;
}

.ime-cursor.is-erase {
  background: rgba(255, 255, 255, 0.28);
  box-shadow:
    0 0 0 1.5px rgba(10, 22, 40, 0.45),
    0 0 0 3.5px rgba(90, 107, 125, 0.35);
}

/* The busy state itself is the shared .aiw overlay (polish.css). */
.ime-controls[hidden],
.ime-composer[hidden] {
  display: none;
}

.ime-toolbar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-5)
    max(var(--s-4), env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--divider);
  background: linear-gradient(
    180deg,
    rgba(238, 242, 247, 0.55) 0%,
    var(--surface) 40%
  );
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.ime-composer {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.ime-field-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-3);
  margin-bottom: 6px;
}

.ime-prompt-row,
.ime-ref-row {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ime-prompt {
  width: 100%;
  min-height: 56px;
  max-height: 110px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  padding: 10px 12px;
  box-sizing: border-box;
  direction: rtl;
  text-align: right;
  transition:
    border-color 0.15s var(--ease-out),
    box-shadow 0.15s var(--ease-out),
    background 0.15s var(--ease-out);
}

.ime-prompt::placeholder {
  direction: rtl;
  text-align: right;
  opacity: 0.72;
}

.ime-prompt:hover {
  border-color: var(--border-strong);
}

.ime-prompt:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

.ime-ref-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px 4px;
  scrollbar-width: thin;
}

.ime-ref-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-2);
  border-radius: var(--r-pill);
  padding: 5px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  max-width: 200px;
  transition:
    background 0.12s var(--ease-out),
    border-color 0.12s var(--ease-out),
    color 0.12s var(--ease-out),
    box-shadow 0.12s var(--ease-out);
}

.ime-ref-chip--img {
  border-radius: var(--r-md);
  padding: 4px 12px 4px 4px;
  background: var(--surface);
}

.ime-ref-chip:hover {
  border-color: var(--accent-soft-2);
  color: var(--text);
  background: var(--accent-soft);
}

.ime-ref-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ime-ref-thumb {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--surface-pressed);
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.ime-ref-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ime-ref-empty {
  font-size: 12px;
  color: var(--text-muted);
  align-self: center;
  padding-inline: 6px;
}

.ime-controls {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-width: min-content;
  padding: 4px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.ime-spacer {
  flex: 1 1 12px;
  min-width: 8px;
}

.ime-controls .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.ime-model-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ime-model-select[hidden] {
  display: none;
}

.ime-model-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.ime-model-select .cselect-trigger {
  min-width: 150px;
}

.ime-tool-group {
  display: inline-flex;
  background: var(--surface-pressed);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}

.ime-tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 650;
  padding: 7px 12px;
  border-radius: calc(var(--r-md) - 3px);
  cursor: pointer;
  transition:
    background 0.12s var(--ease-out),
    color 0.12s var(--ease-out),
    box-shadow 0.12s var(--ease-out);
}

.ime-tool:hover {
  color: var(--text);
}

.ime-tool.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.ime-size {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  flex-shrink: 0;
  padding-inline: 4px;
}

.ime-size-label {
  font-weight: 650;
}

.ime-range {
  width: 120px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.ime-size-val {
  min-width: 3ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px 6px;
}

.ime-apply {
  min-width: 132px;
  justify-content: center;
}

.ime-hold {
  touch-action: none;
  user-select: none;
}

.ime-hold.is-pressed {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 720px) {
  .modal.modal-lg:has(.ime-modal) {
    width: 100vw;
    max-width: 100vw;
    max-height: 94dvh;
    height: 94dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }

  .modal.modal-lg:has(.ime-modal)::before {
    display: none;
  }

  .ime-modal {
    height: 100%;
  }

  .ime-header,
  .ime-toolbar {
    padding-inline: var(--s-3);
  }

  .ime-header {
    padding-block: var(--s-3);
  }

  .ime-stage {
    margin: var(--s-2) var(--s-3);
    border-radius: var(--r-lg);
  }

  .ime-status {
    padding-inline: var(--s-3);
    font-size: 12px;
  }

  .ime-toolbar {
    gap: var(--s-2);
    padding-bottom: max(var(--s-3), env(safe-area-inset-bottom, 0px));
    overflow-x: visible;
  }

  .ime-composer {
    padding: var(--s-2);
  }

  .ime-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    row-gap: var(--s-2);
    width: 100%;
    min-width: 0;
  }

  .ime-spacer {
    flex: 0 0 100%;
    width: 100%;
    height: 0;
  }

  .ime-tool-group {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
  }

  .ime-tool-group .ime-tool {
    flex: 1;
    justify-content: center;
  }

  .ime-size {
    flex: 1 1 0;
    min-width: 0;
  }

  .ime-controls:not(:has(.ime-tool-group)) > .btn:nth-child(-n + 3) {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
  }

  .ime-spacer ~ .btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    justify-content: center;
  }

  .ime-spacer + .btn {
    margin-inline-start: auto;
  }

  .ime-tool {
    padding: 6px 10px;
    font-size: 12px;
  }

  .ime-range {
    flex: 1;
    width: auto;
    max-width: none;
  }
}

/* ── Auto image fix modal ───────────────────────────────────────────────── */
.modal.modal-lg:has(.iaf-modal) {
  max-width: min(1080px, 96vw);
  width: min(1080px, 96vw);
  max-height: min(90dvh, 820px);
  height: min(90dvh, 820px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(
    180deg,
    var(--bg-2) 0%,
    var(--surface) 42%,
    var(--surface) 100%
  );
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.iaf-modal {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-ui);
}

.iaf-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  margin-bottom: 0;
  border-bottom: 1px solid var(--divider);
}

.iaf-title-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.iaf-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.iaf-header .modal-title {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.iaf-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft-2);
  font-size: 11px;
  font-weight: 700;
}

.iaf-subtitle {
  font-size: 12.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(640px, 78vw);
}

.iaf-status {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--red);
  background: rgba(214, 69, 69, 0.08);
  border-bottom: 1px solid rgba(214, 69, 69, 0.18);
  padding: var(--s-2) var(--s-5);
}

.iaf-status[hidden] {
  display: none;
}

.iaf-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(240px, 0.9fr);
  gap: var(--s-3);
  padding: var(--s-3) var(--s-5);
}

.iaf-stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
}

.iaf-preview-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-3);
}

.iaf-preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  cursor: default;
}

/* Analyzing / fixing / measuring all use the shared .aiw overlay
   (polish.css) - the stage only has to provide the positioning context. */

.iaf-panel {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
}

.iaf-score {
  display: flex;
  align-items: center;
  gap: 12px;
}

.iaf-score-num {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 750;
  color: #fff;
  background: var(--accent);
  flex-shrink: 0;
}

.iaf-score-num.iaf-verdict-good {
  background: #1f9d6a;
}

.iaf-score-num.iaf-verdict-weak {
  background: #c9851a;
}

.iaf-score-num.iaf-verdict-bad {
  background: #d64545;
}

.iaf-score-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  font-size: 13px;
  color: var(--text-2);
}

.iaf-score-meta strong {
  color: var(--text);
  font-size: 14px;
}

.iaf-issues {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.iaf-issue {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}

.iaf-issue--ok {
  color: var(--text-2);
}

.iaf-sev-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
}

.iaf-sev-high .iaf-sev-badge {
  background: rgba(214, 69, 69, 0.12);
  color: #d64545;
}

.iaf-sev-med .iaf-sev-badge {
  background: rgba(201, 133, 26, 0.14);
  color: #c9851a;
}

.iaf-toolbar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-5)
    max(var(--s-4), env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--divider);
  background: linear-gradient(
    180deg,
    rgba(238, 242, 247, 0.55) 0%,
    var(--surface) 40%
  );
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.iaf-controls {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-width: min-content;
  padding: 4px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.iaf-controls[hidden] {
  display: none;
}

/* The review row and the result row occupy the SAME cell, and a hidden row
   still holds it open. The toolbar is therefore exactly as tall in every
   stage - so entering "analyzing" cannot resize the stage and move the
   picture the user was just looking at. */
.iaf-controls-stack {
  display: grid;
}

.iaf-controls-stack > .iaf-controls {
  grid-area: 1 / 1;
}

.iaf-controls-stack > .iaf-controls[hidden] {
  display: flex;
  visibility: hidden;
  pointer-events: none;
}

.iaf-controls .btn {
  flex-shrink: 0;
  white-space: nowrap;
  min-height: 34px;
}

.iaf-model-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 2px 6px 2px 4px;
  border-radius: var(--r-md);
  background: var(--surface-pressed);
  border: 1px solid var(--border);
}

.iaf-model-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-3);
  white-space: nowrap;
  padding-inline-start: 4px;
}

.iaf-model-select .cselect-trigger {
  min-width: 148px;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.iaf-spacer {
  flex: 1 1 12px;
  min-width: 8px;
}

.iaf-hold.is-pressed {
  background: var(--accent-soft);
  color: var(--accent);
}

.iaf-fix-btn {
  font-weight: 700;
}

/* Colour check (image-color-check.js).
   The dialog wears `.iaf-modal .icc-modal` and reuses the auto-fix shell above
   - header, body, stage, panel, toolbar, score, issue rows - because it is the
   same dialog shape. Everything below is only what the colour report adds. */

.icc-issue-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.icc-issue-title {
  font-weight: 650;
  color: var(--text);
}

.icc-issue-detail {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-2);
}

.iaf-sev-info .iaf-sev-badge {
  background: var(--surface-pressed);
  color: var(--text-3);
}

.icc-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: var(--s-2);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.icc-metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
}

.icc-metric-label {
  color: var(--text-3);
  white-space: nowrap;
}

.icc-metric-value {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.icc-fix-note {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-2);
}

.icc-strength {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* Reserved from the start: this row appears the moment the measurement lands,
   and growing the toolbar then would slide the picture out from under the
   scan. It holds its space and only turns visible. */
.icc-strength[hidden] {
  visibility: hidden;
  pointer-events: none;
}

.icc-strength-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-3);
  white-space: nowrap;
}

.icc-strength-input {
  flex: 1;
  min-width: 90px;
  accent-color: var(--accent);
}

.icc-strength-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: end;
}

@media (max-width: 760px) {
  .icc-metrics {
    grid-template-columns: 1fr;
  }

  .iaf-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 1fr) minmax(160px, auto);
  }

  .iaf-toolbar {
    padding-inline: var(--s-3);
  }

  .iaf-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  .iaf-spacer {
    flex-basis: 100%;
    min-height: 0;
    height: 0;
    margin: 0;
  }

  .iaf-model-select {
    flex: 1 1 auto;
    justify-content: space-between;
  }

  .iaf-model-select .cselect-trigger {
    flex: 1;
    min-width: 0;
  }

  .iaf-controls .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

/* ── Premium image studio (image-premium.js) ────────────────────────────────
   Wears `.iaf-modal .ipx-modal`: same shell as the auto-fix and colour-check
   dialogs (header, stage, toolbar). Only the control column below is new,
   because this dialog is the one with real settings in it. */

.ipx-panel {
  gap: var(--s-3);
}

.ipx-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.ipx-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out);
}

.ipx-tab:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.ipx-tab.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.ipx-tab:disabled {
  opacity: 0.55;
  cursor: default;
}

.ipx-fields {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-height: 0;
  overflow-y: auto;
}

.ipx-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.ipx-row-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.ipx-row-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.ipx-row-hint {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-3);
}

.ipx-row .cselect-trigger {
  width: 100%;
}

.ipx-note {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-2);
}

.ipx-note .ui-icon {
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--text-3);
}

.ipx-note--warn {
  background: var(--ember-soft);
  border-color: rgba(232, 109, 47, 0.28);
  color: var(--text);
}

.ipx-note--warn .ui-icon {
  color: var(--orange);
}

.ipx-note-btn {
  margin-inline-start: auto;
  flex: 0 0 auto;
  padding-inline: 8px;
}

.ipx-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ipx-preset {
  padding: 6px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
}

.ipx-preset:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.ipx-preset.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.ipx-preset:disabled {
  opacity: 0.55;
  cursor: default;
}

.ipx-text {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.ipx-text:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

.ipx-engine-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.ipx-engine {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-align: start;
  font: inherit;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
}

.ipx-engine:hover:not(:disabled) {
  background: var(--surface-hover);
}

.ipx-engine.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ipx-engine:disabled {
  opacity: 0.55;
  cursor: default;
}

.ipx-engine-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.ipx-engine-hint {
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-3);
}

.ipx-seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 3px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.ipx-seg-btn {
  min-width: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 12px;
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.ipx-seg-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.ipx-seg-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.ipx-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
}

.ipx-check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.ipx-slider-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ipx-slider {
  flex: 1;
  min-width: 90px;
  accent-color: var(--accent);
}

.ipx-slider-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: end;
}

.ipx-cost {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.ipx-cost-usd {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.ipx-cost-note {
  font-size: 11px;
  color: var(--text-3);
}

/* The light stage is a canvas, not an <img>: it is the composite AND the place
   the lamp is dragged and the area is painted, so it has to be one surface.
   It inherits .iaf-preview-img for the fit, and only adds the interaction. */
.ipx-canvas {
  touch-action: none;
}

.ipx-canvas.is-paintable {
  cursor: crosshair;
}

.ipx-brush-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ipx-rerun {
  align-self: flex-start;
}

.iaf-status.is-error {
  color: var(--red);
}

@media (max-width: 760px) {
  .ipx-engine-row {
    grid-template-columns: 1fr;
  }
}

/* ── Scene sound cards ──────────────────────────────────────────────────────
   Scene-shaped, not sound-shaped: you close one room and move to the next,
   and the words are on screen and editable BEFORE anything is generated —
   generation costs money. Placement is worked out by scene-audio.js, so no
   lane and no time is ever asked for here. */
.auto-soundtrack-scenes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px 12px;
}

.auto-soundtrack-section-sub {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
  margin-inline-start: 8px;
}

.auto-soundtrack-scenes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: none;
  overflow: visible;
}

.auto-soundtrack-scene {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 12px 14px;
}

.auto-soundtrack-scene-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.ass-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ass-time {
  font-size: 11px;
  color: var(--text-3);
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.auto-soundtrack-scene-top .btn {
  margin-inline-start: auto;
  flex-shrink: 0;
}

/* The base rule above is later in the file than the phone layout, so it was
   winning on `display` and leaving the phone grid areas unused. */
@media (max-width: 768px) {
  .auto-soundtrack-scene-top {
    display: grid;
  }

  .auto-soundtrack-scene-need.is-status .asn-text {
    white-space: normal;
  }
}

.auto-soundtrack-scene-needs {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auto-soundtrack-scene-need {
  display: grid;
  grid-template-columns: 3.6em minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.asn-key {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-3);
}

.asn-text-input {
  font-size: 13px;
  padding: 7px 9px;
  min-width: 0;
}

.asn-text-input:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.asn-text {
  font-size: 13px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asn-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.asn-pill.is-done { color: var(--ok, #1f6b45); background: var(--ok-soft, #dff0e7); }
.asn-pill.is-todo { color: var(--warn, #9a6209); background: var(--warn-soft, #fbefdc); }

.auto-soundtrack-scene-need.is-status { opacity: 0.85; }

.auto-soundtrack-scenes-empty {
  font-size: 13.5px;
  color: var(--text-2);
  padding: 16px 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  line-height: 1.5;
  background: var(--surface);
}

.asn-undo {
  font-size: 10px;
  padding: 1px 7px;
  color: var(--text-3);
  flex-shrink: 0;
}
.asn-undo:hover { color: var(--text-2); }

/* Already inside the clip — the video model rendered it in sync with the
   action that causes it. Distinct from both "done" (we made it) and "missing"
   (nobody made it): this one is finished, by the take. */
.asn-pill.is-take {
  color: var(--accent);
  background: var(--accent-soft);
}
