/* studio-web shell — light theme per the studio redesign.
   M2 preview classes below; M3a studio-shell classes (composer/pcard/
   gallery/toast) at the end, adapted from static/index.html's palette. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #e3e6ea;
  --fg: #1c2127;
  --fg-dim: #6b7280;
  --faint: #9aa1ab;
  --accent: #4f46e5;
  --accent-soft: #ededfa;
  --ok: #3d8f5f;
  --err: #b91c1c;
  --warn: #b07d22;
  --panel: #f9fafb;
  --shadow: 0 1px 3px rgba(30, 28, 22, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.shell header h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.shell header p {
  margin: 0 0 20px;
  color: var(--fg-dim);
}

.fixtures {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.fixtures button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}

.fixtures button[data-active="true"] {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.status {
  margin: 0 0 12px;
  color: var(--fg-dim);
  min-height: 1.5em;
}

.status[data-kind="error"] {
  color: var(--err);
}

.player {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.viewport {
  position: relative;
  width: 100%;
  background: #101216;
  border-radius: 8px;
  overflow: hidden;
}

.viewport iframe {
  position: absolute;
  top: 0;
  left: 0;
  border: 0;
  transform-origin: top left;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.controls button {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  cursor: pointer;
  min-width: 72px;
}

.controls button:disabled {
  opacity: 0.5;
  cursor: default;
}

.controls input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.controls .readout {
  font-variant-numeric: tabular-nums;
  color: var(--fg-dim);
  min-width: 130px;
  text-align: right;
}

/* ── studio shell: header + composer ─────────────────────────────────────── */

/* App header: brand + the "New video" action on the left, the view-switcher
   tab strip on the right, separated from the page body by a hairline. */
.apphead {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.apphead .brand {
  margin-bottom: 0;
}

/* "New video" header ACTION (by the brand) — deliberately NOT tab-shaped:
   a filled accent button so it reads as "do something", not "go somewhere". */
.newvideo-btn {
  padding: 7px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease;
}

.newvideo-btn:hover,
.newvideo-btn:focus-visible {
  background: #4338ca;
  border-color: #4338ca;
  outline: none;
}

/* View switcher (Studio | Library | Settings): a compact segmented control —
   one shared track, the active view a raised white pill. Pushed to the right
   edge of the header. */
.topnav {
  margin-left: auto;
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.topnav button {
  padding: 5px 13px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--fg-dim);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.topnav button:hover:not([data-active="true"]) {
  color: var(--fg);
}

.topnav button[data-active="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.topnav button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* First-run hint now sits on its own line under the header (moved out of the
   nav row) — a small left-aligned notice, not nav clutter. */
.firstrun-hint {
  margin: 0 0 16px;
}

/* One-time first-visit hint pointing at the Settings TAB (settingsModal.js)
   — the handoff guide lives in that (inactive) tab; dismissed by its × or by
   activating Settings (localStorage vygent.firstRunHintSeen). */
.firstrun-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.firstrun-hint .firstrun-dismiss {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.brand b {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand span {
  font-size: 19px;
  color: var(--fg-dim);
}

p.sub {
  color: var(--fg-dim);
  margin: 0 0 16px;
  font-size: 13.5px;
  max-width: 600px;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
}

.composer textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  line-height: 1.55;
  padding: 2px;
  color: var(--fg);
}

.composer textarea::placeholder {
  color: var(--faint);
}

.composer .row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 11px;
}

/* R1 revision face: the collapsed "+ Add revision" row has no textarea above it. */
.composer .row.noline {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.composer .grow {
  flex: 1;
}

.composer .hint {
  color: var(--faint);
  font-size: 12.5px;
}

/* ── Brief-face control layout ─────────────────────────────────────────────
   A vertical stack instead of one ragged flex-wrap: a soft "options" panel of
   toggles, a uniform grid of setting selects (equal columns, stacked
   micro-labels), then a right-aligned action row. */
.composer .row.controls {
  flex-direction: column;
  align-items: stretch;
  gap: 13px;
}

.composer .opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 18px;
  padding: 9px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* dim a toggle whose input is disabled (e.g. a dependent axis / clips when
   images are off). */
.composer .opts label.toggle:has(input:disabled) {
  opacity: 0.45;
  cursor: default;
}

/* Speed preset slider [Fast · Balanced · Quality]. Greys to "custom" when the
   toggles no longer match a preset, but stays draggable to snap back. */
.composer .opts .speed {
  display: flex;
  align-items: center;
  gap: 8px;
}
.composer .opts .speed.custom {
  opacity: 0.5;
}
.composer .opts .speed .slabel {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.composer .opts .speed input[type="range"] {
  width: 108px;
  accent-color: var(--accent);
}
.composer .opts .speed .sticks {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--fg-dim);
}
.composer .opts .speed .sticks .on {
  font-weight: 700;
  color: var(--accent);
}

/* Three even columns → two tidy rows that also group by meaning: row 1 is
   look (Brand / Voice / Captions), row 2 is the model pickers (Image / Video /
   Voice model). Collapses to two columns on a narrow viewport. */
.composer .fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 16px;
}

@media (max-width: 620px) {
  .composer .fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Each field: an uppercase micro-label stacked over a full-width control, so
   every select lines up in a tidy column grid regardless of label length. */
.composer .fields label.select {
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
}

.composer .fields label.select select {
  width: 100%;
  max-width: none;
  padding: 7px 9px;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  color: var(--fg);
}

/* Brand picker button sits in the grid like the other field controls. */
.composer .fields label.brandwrap {
  position: relative;
}

.composer .fields label.brandwrap #brandBtn {
  width: 100%;
  justify-content: space-between;
  text-transform: none;
  letter-spacing: normal;
}

.composer .actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

#addRevision,
#discardDraft {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 20px;
  font: 600 13.5px/1.2 inherit;
  cursor: pointer;
}

#addRevision:disabled,
#discardDraft:disabled {
  opacity: 0.4;
  cursor: default;
}

#discardDraft {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
}

/* S3: force a full (non-incremental) render — a small link beside Generate. */
#goFull {
  background: none;
  border: none;
  padding: 9px 4px;
  font: 500 12.5px/1.2 inherit;
  color: var(--fg-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

#goFull:disabled {
  opacity: 0.4;
  cursor: default;
}

label.toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--fg-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

label.toggle input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
}

label.select {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--fg-dim);
  font-size: 13px;
}

label.select select {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  font: inherit;
  font-size: 12.5px;
  max-width: 220px;
}

#go {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 20px;
  font: 600 13.5px/1.2 inherit;
  cursor: pointer;
}

#go:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Stop face of the Generate button (danger styling while a run is watched). */
#go.stop {
  background: var(--err);
}

/* ── progress + player cards ─────────────────────────────────────────────── */

#status,
#player {
  margin-top: 20px;
}

.pcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
}

.progressrow {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar {
  flex: 1;
  height: 5px;
  background: #eae8e1;
  border-radius: 3px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s;
}

.bar i.done {
  background: var(--ok);
}

#stage {
  font-size: 12.5px;
  color: var(--fg-dim);
  font-weight: 500;
  white-space: nowrap;
}

#stage.ok {
  color: var(--ok);
  font-weight: 600;
}

#stage.err {
  color: var(--err);
  font-weight: 600;
  white-space: normal;
}

/* R0 error surfacing: a failed run's stage-error detail rendered prominently
   on the progress card (progress.js), plus the fal key/billing hint line. */
.stage-error-detail {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--err);
  border-radius: 8px;
  background: #fbeeee;
  color: var(--err);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.billing-hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--fg-dim);
}

.billing-hint a {
  color: var(--accent);
  font-weight: 600;
}

/* Fact-check report card (factCheckCard.js) — status-tinted left rail. */
.fc-card {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.fc-card.fc-ok {
  border-left-color: var(--ok);
  background: #eef7f1;
}
.fc-card.fc-warn {
  border-left-color: var(--warn);
  background: #fbf5e9;
}
.fc-card.fc-err {
  border-left-color: var(--err);
  background: #fbeeee;
}
.fc-card.fc-none {
  border-left-color: var(--fg-dim);
}
.fc-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.fc-icon {
  font-weight: 700;
}
.fc-ok .fc-icon {
  color: var(--ok);
}
.fc-warn .fc-icon {
  color: var(--warn);
}
.fc-err .fc-icon {
  color: var(--err);
}
.fc-title {
  font-weight: 600;
}
.fc-owner,
.fc-counts {
  color: var(--fg-dim);
}
.fc-counts {
  margin-top: 2px;
  font-size: 12px;
}
.fc-notes {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fc-note {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel);
}
.fc-badge {
  flex: none;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--accent-soft);
  color: var(--accent);
}
.fc-note-corrected .fc-badge {
  background: #fbf5e9;
  color: var(--warn);
}
.fc-note-contradicted .fc-badge {
  background: #fbeeee;
  color: var(--err);
}
.fc-claim {
  flex: 1 1 60%;
}
.fc-claim s {
  color: var(--fg-dim);
}
.fc-scene {
  margin-left: 6px;
  color: var(--fg-dim);
  font-size: 11px;
}
.fc-cite {
  flex-basis: 100%;
  color: var(--fg-dim);
  font-size: 12px;
  font-style: italic;
}

details.devfold {
  margin-top: 10px;
}

details.devfold > summary {
  list-style: none;
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

details.devfold > summary::-webkit-details-marker {
  display: none;
}

.fchev {
  display: inline-block;
  transition: transform 0.15s;
  font-size: 9px;
}

details.devfold[open] .fchev {
  transform: rotate(90deg);
}

#log {
  margin-top: 8px;
  max-height: 170px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font: 11.5px/1.75 var(--mono);
  color: var(--fg-dim);
}

#log .ok {
  color: var(--ok);
}

#log .err {
  color: var(--err);
}

#log .call {
  color: var(--accent);
}

#stats {
  margin-top: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}

#stats h2 {
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
}

#stats table {
  width: 100%;
  border-collapse: collapse;
  font: 11.5px/1.85 var(--mono);
}

#stats td {
  padding: 0 8px 0 0;
  color: var(--fg-dim);
}

#stats td.num {
  text-align: right;
  color: var(--fg);
  white-space: nowrap;
}

#stats tr.total td {
  border-top: 1px solid var(--line);
  padding-top: 4px;
  color: var(--fg);
  font-weight: 600;
}

#stats tr.running td:first-child::after {
  content: " ⏱";
}

/* Video-processing sub-rows under the render stage (setup / encode / mux). */
#stats tr.vsub td:first-child {
  padding-left: 14px;
  color: var(--faint);
}

/* Per-step diagnostic table: research / LLM / image / video (with model) + tokens. */
#stats table.steps {
  margin-top: 4px;
}
#stats table.steps th {
  text-align: left;
  color: var(--faint);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
#stats table.steps th.num {
  text-align: right;
}
#stats table.steps td.model {
  color: var(--accent);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#stats tr.step.scached td {
  opacity: 0.55;
}
#stats tr.step.serr td {
  color: var(--err);
}

#player video {
  width: 100%;
  border-radius: 10px;
  background: #000;
  display: block;
}

.vrow {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}

a.dl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
}

#renders {
  font-size: 12px;
  color: var(--fg-dim);
}

#renders a {
  color: var(--accent);
  text-decoration: none;
  margin-right: 6px;
}

/* ── job gallery (the Library nav tab) ───────────────────────────────────── */

#gallery {
  margin-top: 20px;
}

.galleryempty {
  color: var(--faint);
  font-size: 13px;
}

#gallery h2 {
  margin: 0 0 14px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
}

#galleryGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.tile:hover,
.tile:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.tile.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.tile .shot {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #000;
}

.tile .shot.empty {
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  font-size: 11.5px;
}

.tile .meta {
  padding: 10px 12px 12px;
}

.tile .tprompt {
  font-size: 12.5px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 36px;
}

.tile .trow {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--fg-dim);
}

.tile .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.tile .dot.done {
  background: var(--ok);
}

.tile .dot.error {
  background: var(--err);
}

.tile .dot.running,
.tile .dot.queued {
  background: var(--warn);
}

/* ── document editor (M3b, adapted from static/index.html :85-156) ───────── */

@keyframes vypulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.9;
  }
}

#doc {
  margin-top: 28px;
}

#doc textarea,
#doc input[type="text"],
#doc input[type="number"] {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  width: 100%;
}

#doc textarea:focus,
#doc input:focus,
#doc select:focus {
  outline: none;
  border-color: var(--accent);
}

#doc select {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  font: inherit;
  font-size: 12.5px;
}

#doc button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 20px;
  font: 600 13.5px/1.2 inherit;
  cursor: pointer;
}

#doc button:disabled {
  opacity: 0.4;
  cursor: default;
}

#doc button.ghost {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
}

#doc button.small {
  padding: 7px 14px;
  font-size: 12.5px;
}

.docbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(246, 247, 249, 0.94);
  backdrop-filter: blur(8px);
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.docbar label.select {
  font-size: 12px;
  color: var(--fg-dim);
  gap: 6px;
}

.docbar select {
  padding: 4px 7px;
  font-size: 12px;
}

.docbar .grow {
  flex: 1;
}

/* R2 revision picker: ‹ › nav, render thumb, meta, read-only affordances. */
.docbar .revnav {
  padding: 2px 9px;
  font-size: 14px;
  line-height: 1.4;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg-dim);
  cursor: pointer;
}

.docbar .revnav:disabled {
  opacity: 0.4;
  cursor: default;
}

.docbar .revthumb {
  width: 64px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #000;
  pointer-events: none;
}

.docbar .revmeta {
  font-size: 12px;
  color: var(--fg-dim);
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.docbar .robadge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 999px;
  padding: 3px 10px;
}

/* Read-only wrapper around the scene cards (a disabled fieldset kills every
   input/textarea/select/button inside natively) — visually a no-op frame. */
.scenesfs {
  border: 0;
  padding: 0;
  margin: 0;
  min-inline-size: auto;
}

.scenesfs:disabled #scenes {
  opacity: 0.75;
}

/* Player caption when a picked revision's render is showing (R2). */
.renderlabel {
  font-size: 12.5px;
  color: var(--fg-dim);
  padding: 8px 12px 0;
}

#diag {
  margin: 12px 0 0;
  background: #fdf1f0;
  border: 1px solid #e5a9a4;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 12.5px;
  color: var(--err);
  white-space: pre-wrap;
  line-height: 1.6;
}

#docwarn {
  margin: 12px 0 0;
  color: var(--warn);
  font-size: 12.5px;
  background: #fcf6e8;
  border: 1px solid #ebd9ae;
  border-radius: 10px;
  padding: 10px 14px;
}

/* ── scene cards (collapsible) ────────────────────────────────────────────── */

details.scene {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  margin-top: 12px;
}

details.scene > summary {
  list-style: none;
}

details.scene > summary::-webkit-details-marker {
  display: none;
}

details.scene[open] .snip {
  display: none;
}

details.scene[open] .mthumb {
  display: none;
}

details.scene[open] .chev {
  transform: rotate(90deg);
}

.shead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.chev {
  display: inline-block;
  transition: transform 0.15s;
  font-size: 9px;
  color: var(--faint);
}

.num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg-dim);
  font: 600 11px var(--mono);
  flex: none;
}

.kind {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.mthumb {
  width: 50px;
  height: 28px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--line);
}

/* S3 per-scene dirty + render-lifecycle badge (summary chip). */
.sbadge {
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: none;
}

.sbadge[data-state="dirty"] {
  background: #f7efdd;
  color: var(--warn);
}

.sbadge[data-state="queued"] {
  background: var(--panel);
  color: var(--fg-dim);
  border: 1px solid var(--line);
}

.sbadge[data-state="committing"],
.sbadge[data-state="rendering"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* S3 [Regenerate scene] bar at the top of a dirty scene's body. */
.scenebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin: 8px 0 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.scenebar .dirtynote {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--fg-dim);
}

.snip {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  color: var(--fg-dim);
}

.shead .sync {
  margin-left: auto;
  color: var(--faint);
  font: 11px var(--mono);
}

.shead .sid {
  color: var(--faint);
  font: 11px var(--mono);
}

.sbody {
  padding: 2px 16px 16px;
}

.srow {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.thumbcol {
  flex: 0 0 400px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumb {
  width: 400px;
  max-width: 100%;
  height: 225px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #000;
  cursor: zoom-in;
  display: block;
}

.thumb.pattern {
  border: 1px dashed var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  font: 11.5px var(--mono);
  cursor: default;
}

.imgpanel {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* S1 layout: version chips + the image-prompt field share ONE row, inline
   beside the hero thumbnail (the imgpanel already sits next to .thumbcol). */
.imgrow {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.imgrow .chips {
  flex: 0 1 auto;
  max-width: 40%;
}

.imgrow .fld {
  flex: 1;
  min-width: 200px;
}

.imgpanel .motion textarea {
  min-height: 48px;
}

.inline {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inline textarea {
  min-height: 84px;
  max-height: 150px;
  resize: vertical;
  background: var(--panel);
  color: var(--fg-dim);
  border-color: var(--line);
  font-size: 12px;
  line-height: 1.5;
}

.inline button {
  align-self: flex-start;
}

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

.chip {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  cursor: pointer;
  background: var(--surface);
}

.chip img {
  width: 54px;
  height: 30px;
  object-fit: cover;
  border-radius: 5px;
  display: block;
}

.chip.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.chip .cv {
  display: block;
  text-align: center;
  font-size: 9.5px;
  color: var(--faint);
  padding: 1px 0;
}

.chip.active .cv {
  color: var(--accent);
  font-weight: 600;
}

.chip .cv.warn {
  color: var(--warn);
}

.chip .clipbadge {
  color: var(--accent);
  font-style: normal;
  margin-left: 3px;
}

.scol {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fld label {
  display: block;
  font-size: 10px;
  font-weight: 650;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 4px;
}

.fld label em {
  font-style: normal;
  font-family: var(--mono);
  font-weight: 400;
  color: var(--faint);
  text-transform: none;
  letter-spacing: 0;
}

.fld.dirty label::after {
  content: " ●";
  color: var(--warn);
}

.fld.dirty textarea,
.fld.dirty input,
.fld.dirty select {
  background: #fffdf5;
  border-color: #e4ce96;
}

.fld textarea {
  min-height: 34px;
  resize: vertical;
  line-height: 1.4;
}

.narr {
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}

.narr textarea {
  min-height: 44px;
  font-size: 14px;
  line-height: 1.5;
}

.selrow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.selrow .fld.f-sel {
  flex: 0 0 170px;
}

.selrow .fld.f-num {
  flex: 0 0 90px;
}

.selrow .fld.f-txt {
  flex: 1 1 200px;
  max-width: 340px;
}

.selrow .fld.f-ta {
  flex: 1 1 260px;
}

.selrow .fld.f-wide {
  flex: 1 1 100%;
}

.f-wide textarea {
  min-height: 56px;
  line-height: 1.5;
}

/* skeleton cards while generating */

.scene.skeleton {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 12px;
  animation: vypulse 2.2s ease-in-out infinite;
}

.scene.skeleton .skhead {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.scene.skeleton .kind {
  background: var(--panel);
  color: var(--fg-dim);
}

.scene.skeleton .sid {
  margin-left: auto;
  color: var(--faint);
  font: 11px var(--mono);
}

.scene.skeleton .narr {
  border-left-color: var(--line);
  margin-bottom: 8px;
}

.scene.skeleton .sktext {
  font-size: 13px;
  color: var(--fg-dim);
  line-height: 1.5;
}

.scene.skeleton .skvisual {
  font-size: 12.5px;
  color: var(--faint);
  line-height: 1.5;
}

/* gallery tile actions + sync chip + error card (U0) */

.tile .syncchip {
  font: 600 10px/1.4 inherit;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--faint);
  white-space: nowrap;
}

.tile .syncchip .cloudicon {
  font-weight: 700;
}

/* U2: LIVE chip states — the icon + colour track the SyncEngine record and
   the transition animates as the background queue drains. */
.tile .syncchip[data-state="synced"] {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 40%, var(--line));
}

.tile .syncchip[data-state="dirty"],
.tile .syncchip[data-state="queued"] {
  color: var(--warn, #a6791f);
  border-color: color-mix(in srgb, var(--warn, #a6791f) 35%, var(--line));
}

.tile .syncchip[data-state="syncing"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  animation: syncpulse 1.1s ease-in-out infinite;
}

.tile .syncchip[data-state="error"] {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 45%, var(--line));
}

.tile .syncchip[data-state="paused"] {
  color: var(--faint);
  border-style: dashed;
}

@keyframes syncpulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.tile .tileactions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.tile .tileactions button {
  background: var(--surface);
  color: var(--fg-dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 7px;
  font: 600 11px/1 inherit;
  cursor: pointer;
}

.tile .tileactions button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.tile .tileactions button.del:hover:not(:disabled) {
  border-color: var(--err);
  color: var(--err);
}

.tile .tileactions button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* failed / interrupted tiles: unmistakable — NOT a healthy-looking placeholder */
.tile.broken {
  border-color: color-mix(in srgb, var(--err) 55%, var(--line));
}

.tile .errbadge {
  background: var(--err);
  color: #fff;
  font: 650 10.5px/1.3 inherit;
  padding: 4px 10px;
  text-align: center;
}

.tile .shot.empty.err {
  color: var(--err);
  background: color-mix(in srgb, var(--err) 8%, var(--panel));
  font-weight: 650;
}

.tile .errcard {
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--err) 40%, var(--line));
  background: color-mix(in srgb, var(--err) 6%, var(--surface));
  cursor: default;
}

.tile .errcard .errmsg {
  margin: 0 0 8px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--fg);
}

.tile .errcard .erractions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tile .errcard .erractions button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font: 600 11px/1.3 inherit;
  cursor: pointer;
}

.tile .errcard .erractions button.rerender {
  background: var(--surface);
  color: var(--accent);
}

.tile .errcard .erractions button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Library asset browser: toolbar + media tiles + tags + preview ─────────── */

.libloading,
.libwarn {
  font-size: 11px;
  color: var(--faint);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  margin-left: 8px;
}
.libwarn {
  display: block;
  margin: -6px 0 12px;
  color: var(--warn, #b5761f);
}

.libtoolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.libchips,
.libtags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.typechip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg-dim);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.typechip:hover {
  border-color: var(--accent);
}
.typechip[data-active="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.typechip .cnt {
  opacity: 0.6;
  font-variant-numeric: tabular-nums;
  margin-left: 3px;
}
.typechip[data-active="true"] .cnt {
  opacity: 0.85;
}

.libcontrols {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.libsearch {
  flex: 1 1 220px;
  min-width: 180px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 13px;
}
.libsearch:focus {
  outline: none;
  border-color: var(--accent);
}
.libsort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--faint);
}
.libsort select {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12.5px;
}
.librefresh {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg-dim);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.librefresh:hover:not(:disabled) {
  border-color: var(--accent);
}
.librefresh:disabled {
  opacity: 0.55;
  cursor: default;
}

/* tag chips — filter bar (toolbar) and per-tile editor share the pill look */
.tagchip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg-dim);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  cursor: pointer;
  max-width: 100%;
}
.tagchip.filter.auto {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 10.5px;
}
.tagchip.filter.user {
  font-weight: 600;
}
.tagchip.filter:hover {
  border-color: var(--accent);
}
.tagchip.filter[data-active="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.tagclear {
  border: none;
  background: none;
  color: var(--faint);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
}

/* per-tile custom-tag row */
.tile .tagrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-top: 9px;
}
.tile .tagrow .tagchip.user {
  cursor: default;
  font-weight: 600;
}
.tagchip .tagx {
  border: none;
  background: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}
.tagchip .tagx:hover {
  opacity: 1;
}
.tagadd {
  border: 1px dashed var(--line);
  background: none;
  color: var(--faint);
  border-radius: 999px;
  width: 20px;
  height: 20px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.tagadd:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.tagadd-input {
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--fg);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  width: 90px;
}
.tagadd-input:focus {
  outline: none;
}

/* media tiles — type badge + play affordance over the existing .tile look */
.tile .kindbadge {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 2;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  padding: 1px 5px;
  line-height: 1.5;
}
.tile .playbadge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  color: #fff;
  font-size: 26px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.tile {
  position: relative;
}
.tile.media .shot.empty.voice {
  font-size: 26px;
}
.tile .asrc {
  font-variant-numeric: tabular-nums;
}

.libcount {
  margin-top: 14px;
  font-size: 11px;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 12px;
}
.libmore {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg-dim);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 12px;
  cursor: pointer;
}
.libmore:hover {
  border-color: var(--accent);
}

/* preview overlay (media lightbox) */
.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 18, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.preview-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  max-width: min(880px, 92vw);
  max-height: 88vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.pv-close {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.pv-media {
  display: block;
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  background: #000;
  border-radius: 14px 14px 0 0;
}
audio.pv-media {
  background: var(--panel);
  padding: 24px;
  height: auto;
}
.pv-loading {
  padding: 60px;
  text-align: center;
  color: var(--faint);
}
.pv-meta {
  padding: 14px 16px 16px;
}
.pv-title {
  font-size: 13.5px;
  line-height: 1.5;
}
.pv-sub {
  font-size: 11px;
  color: var(--faint);
  margin-top: 4px;
}
.pv-actions {
  margin-top: 12px;
}
.pv-open {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
}

/* ── toasts ──────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  z-index: 20;
  box-shadow: 0 6px 20px rgba(30, 28, 22, 0.25);
}

/* ── settings tab panel (page section behind the Settings tab) ──────────── */

.settings-panel {
  max-width: 640px;
}

.settings-panel > h2 {
  margin: 8px 0 12px;
  font-size: 15px;
  font-weight: 650;
}

/* ── engine bar + key gate + import bridge (M6) ─────────────────────────── */

.enginebar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
  flex-wrap: wrap;
}

/* U0: the engine switcher is the Settings tab's "Rendering" section — a full
   width heading over the (wrapping) Browser/Server control row. */
#rendering h2 {
  flex-basis: 100%;
  font-size: 15px;
  margin: 0 0 4px;
}

.importjob {
  font-size: 12px;
  color: var(--faint);
  cursor: pointer;
}

.importjob input[type="file"] {
  font-size: 11px;
  max-width: 220px;
}

.keygate {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 12.5px;
}

.keygate p {
  margin: 0 0 8px;
  color: var(--faint);
  line-height: 1.5;
}

.keygate .row {
  display: flex;
  gap: 8px;
}

.keygate input[type="password"] {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
}

.keygate .keyproblem {
  color: #b3261e;
  margin: 6px 0 0;
}

.keychip {
  font: 600 12px/1.4 ui-monospace, monospace;
}

.keygate[data-state="stored"] {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
}

.linkish {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  padding: 0;
}

/* ── models section (task #4, L2) — the Settings tab's "Models" section ──── */

#models {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

#models h2 {
  font-size: 15px;
  margin: 0 0 8px;
}

.models-section .hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--faint);
  line-height: 1.5;
}

.modelrow {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  align-items: center;
  gap: 6px 12px;
  margin: 0 0 12px;
}

.modelrow .modellabel {
  font-size: 12.5px;
  font-weight: 600;
}

.modelrow .modelselect {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12.5px;
  background: var(--surface);
  color: var(--fg);
}

.modelrow .modelnote {
  grid-column: 2;
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.4;
}

/* ── storage panel (M8) — the Settings tab's "Storage" section ──────────── */

#storage {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

#storage h2 {
  font-size: 15px;
  margin: 0 0 8px;
}

/* U0: Storage splits into a Local (browser/disk) card and a Remote (fal.ai)
   card. The M8 sync toggle, restore row and per-project rows live under
   Remote; OPFS usage + the (U3) linked-folder placeholder live under Local. */
.storagecard {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 12px;
  background: var(--surface);
}

.storagecard h3 {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  margin: 0 0 10px;
}

/* U3: per-project FSA linked-folder mirror rows (Local card, Chromium only). */
.linkedfolders {
  font-size: 12px;
  color: var(--fg-dim);
}

.linkedfolders .lf-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 4px 0 6px;
}

.linkedfolders .lf-label {
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  color: var(--faint);
}

.linkedfolders .lf-hint {
  color: var(--faint);
}

.linkedfolders .lf-empty {
  color: var(--faint);
  margin: 2px 0;
}

.lf-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid #eae8e1;
}

.lf-row .lf-jid {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lf-row .lf-state {
  white-space: nowrap;
  color: var(--fg-dim);
}

.lf-row .lf-state[data-state="unlinked"] {
  color: var(--faint);
  font-style: italic;
}

.lf-row .lf-state[data-state="linked"] {
  color: var(--ok);
}

.lf-row .lf-state[data-state="lapsed"] {
  color: var(--err);
  font-weight: 650;
}

.lf-row .lf-media {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--faint);
  white-space: nowrap;
}

.lf-row button {
  font-size: 11px;
  padding: 3px 8px;
}

.lf-row button.lf-grant {
  border-color: var(--err);
  color: var(--err);
}

.storagemeter {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--faint);
  margin: 4px 0 10px;
}

.storagemeter .bar {
  max-width: 220px;
}

.storagemeter .persist[data-persisted="false"] {
  color: #b3261e;
}

.syncrow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  margin: 0 0 8px;
}

.syncrow .syncnote {
  color: var(--faint);
}

.restorerow {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  margin: 0 0 10px;
}

.restorerow .pull {
  display: flex;
  gap: 6px;
  align-items: center;
}

.restorerow .pull input[type="text"] {
  width: 260px;
  font-size: 12px;
  padding: 4px 8px;
}

.jobrow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid #eae8e1;
  font-size: 12px;
}

.jobrow .jid {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jobrow .syncstate {
  color: var(--faint);
  white-space: nowrap;
}

.jobrow .syncstate[data-state="synced"] {
  color: var(--ok);
}

.jobrow .syncstate[data-state="error"] {
  color: #b3261e;
}

.jobrow .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.jobrow .actions button {
  font-size: 11px;
  padding: 3px 8px;
}

.storageempty {
  color: var(--faint);
  font-size: 12px;
}

/* ── M9 hardening: quota banner, cancel, feature gate, help panel ─────────── */

.quotabanner {
  margin: 0 0 8px;
  padding: 8px 12px;
  border: 1px solid #e8d9b0;
  border-radius: 8px;
  background: #fdf6e3;
  color: var(--warn);
  font-size: 12.5px;
}

#cancelJob {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--err);
  font: 600 12px/1.4 inherit;
  padding: 4px 12px;
  cursor: pointer;
  margin-left: 10px;
}

#cancelJob:hover {
  border-color: var(--err);
}

.gatefail {
  max-width: 640px;
  margin: 12vh auto 0;
  padding: 24px 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.gatefail h1 {
  font-size: 18px;
  margin: 0 0 10px;
}

.gatefail ul {
  color: var(--err);
  font-size: 13.5px;
}

.gatefail-note {
  color: var(--faint);
  font-size: 12.5px;
}

.helpcard {
  margin: 0 0 12px;
}

.helpcard details {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px 14px;
}

.helpcard summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--fg-dim);
}

.helpcard summary .linkish {
  margin-left: 8px;
}

.helpbody {
  font: 12px/1.55 var(--mono);
  white-space: pre-wrap;
  color: var(--fg);
  max-height: 340px;
  overflow: auto;
  margin: 10px 0 4px;
}

.helpbody.err {
  color: var(--err);
}

/* ── D4 document/image drop zone + chips + brand confirm card ─────────────── */
.dropzone-wrap {
  margin: 8px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dropzone {
  border: 1px dashed var(--line, #cbd2dc);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
  cursor: pointer;
  color: var(--muted, #5b6472);
  font-size: 13px;
  background: var(--panel, #f7f9fc);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.over,
.dropzone:hover {
  border-color: var(--accent, #3b6cff);
  background: var(--panel-hi, #eef3ff);
}
.dropzone-error {
  color: var(--err, #c0392b);
  font-size: 12px;
  margin: 0;
}
.docchips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.docchip {
  border: 1px solid var(--line, #cbd2dc);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  max-width: 280px;
  background: var(--card, #fff);
}
.docchip-head {
  display: flex;
  align-items: center;
  gap: 6px;
}
.docchip-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  flex: 0 0 auto;
}
.docchip-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 5px;
  border-radius: 4px;
  background: var(--panel-hi, #eef3ff);
  color: var(--accent, #3b6cff);
  flex: 0 0 auto;
}
.docchip-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}
.docchip-meta {
  font-size: 11px;
  color: var(--muted, #5b6472);
  flex: 0 0 auto;
}
.docchip-x {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--muted, #5b6472);
  padding: 0 2px;
}
.docchip-x:hover {
  color: var(--err, #c0392b);
}
.docchip-instr {
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--line, #cbd2dc);
  border-radius: 5px;
  width: 100%;
  box-sizing: border-box;
}
.docchip-more {
  border: 1px dashed var(--line, #cbd2dc);
  border-radius: 8px;
  background: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted, #5b6472);
  padding: 0 10px;
}
.brandsuggest-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brandcard {
  border: 1px solid var(--line, #cbd2dc);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card, #fff);
  max-width: 380px;
}
.brandcard-title {
  font-weight: 600;
  font-size: 13px;
}
.brandcard-swatches {
  display: flex;
  gap: 4px;
}
.brand-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}
.brand-logo {
  max-width: 160px;
  max-height: 60px;
  object-fit: contain;
  border: 1px solid var(--line, #cbd2dc);
  border-radius: 4px;
  background: #fff;
}
.brand-nologo {
  font-size: 12px;
  color: var(--muted, #5b6472);
}
.brandcard-attrs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  font-size: 12px;
}
.brandcard-attrs > div {
  display: flex;
  gap: 6px;
}
.brandcard-attrs dt {
  color: var(--muted, #5b6472);
  margin: 0;
}
.brandcard-attrs dd {
  margin: 0;
  font-weight: 600;
}
.brandcard-actions {
  display: flex;
  gap: 6px;
}

/* ── brand kit picker (popover) + New-brand dialog (D6) ──────────────────────
 * Ported from static/index.html with the legacy tokens remapped to studio-web's
 * light theme (--card→--surface, --text→--fg, --dim→--fg-dim, --dim2→--faint). */
.brandwrap {
  position: relative;
}
#brandBtn {
  display: flex;
  align-items: center;
  gap: 8px;
}
#brandBtn .ramp {
  display: flex;
  gap: 2px;
}
.ramp i {
  width: 10px;
  height: 14px;
  border-radius: 2px;
  display: block;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
#brandPop {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(30, 28, 22, 0.14);
  padding: 8px;
}
.bcard {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
}
.bcard:hover {
  background: var(--panel);
}
.bcard.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.bcard .ramp i {
  width: 14px;
  height: 20px;
}
.bcard .meta {
  flex: 1;
  min-width: 0;
}
.bcard .meta b {
  display: block;
  font-size: 13px;
}
.bcard .meta span {
  display: block;
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bcard .bcap {
  display: flex;
  gap: 2px;
}
.bcard .bcap i {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  font-size: 9px;
  font-style: normal;
  line-height: 18px;
  text-align: center;
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
}
.bcard img.blogo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}
.bcard .del {
  color: var(--err);
  font-size: 11px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
}
.bcard .edit {
  color: var(--accent);
  font-size: 11px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
}
#brandDialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  width: 420px;
  max-width: 92vw;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
}
#brandDialog::backdrop {
  background: rgba(30, 28, 22, 0.35);
}
#brandDialog h3 {
  margin: 0 0 12px;
  font-size: 15px;
}
#brandDialog .fld {
  margin-top: 10px;
}
#brandDialog .fld label {
  display: block;
  font-size: 11px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}
#brandDialog .fld input[type="text"],
#brandDialog .fld select {
  width: 100%;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
}
#brandDialog .hueRow {
  display: flex;
  gap: 10px;
  align-items: center;
}
#brandDialog .hueRow .bcaplabel {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--fg-dim);
  text-transform: none;
  letter-spacing: 0;
}
#hueSlider {
  flex: 1;
  appearance: none;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    hsl(0, 80%, 55%),
    hsl(60, 80%, 55%),
    hsl(120, 80%, 55%),
    hsl(180, 80%, 55%),
    hsl(240, 80%, 55%),
    hsl(300, 80%, 55%),
    hsl(360, 80%, 55%)
  );
}
#hueSlider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--fg);
}
#brandPreview {
  display: flex;
  gap: 3px;
  margin-top: 12px;
}
#brandPreview i {
  flex: 1;
  height: 26px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
#brandDialog .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ── Cast tab (reusable dialogue characters) ─────────────────────────────── */
.castpanel {
  max-width: 900px;
}
.castpanel h2 {
  margin: 0 0 4px;
}
.cast-form {
  display: grid;
  gap: 10px;
  max-width: 520px;
  margin: 16px 0 26px;
}
.cast-form label {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--fg-dim);
}
.cast-form input,
.cast-form textarea,
.cast-form select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
}
.cast-form textarea {
  resize: vertical;
}
/* Placeholders must read as faint HINTS, not filled-in values — the fields are
   empty until you type, so a dark/heavy placeholder makes the form look
   pre-populated (and Create then "does nothing" on an empty required field). */
.cast-form input::placeholder,
.cast-form textarea::placeholder,
.cast-editor .fld input::placeholder,
.cast-editor .fld textarea::placeholder {
  color: var(--faint);
  font-weight: 400;
  font-style: normal;
  opacity: 1; /* Firefox dims placeholders by default; pin it to --faint */
}
.cast-form > button {
  justify-self: start;
  padding: 8px 16px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
}
.cast-form > button[disabled] {
  opacity: 0.6;
  cursor: default;
}
.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.cast-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.cast-thumb {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: var(--panel);
}
.cast-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cast-noimg {
  color: var(--fg-dim);
  font-size: 12px;
}
.cast-meta {
  padding: 8px 10px;
  display: grid;
  gap: 2px;
}
.cast-meta .sub {
  font-size: 12px;
}
.cast-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.cast-actions button {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.cast-actions button.danger {
  color: var(--err);
}
.cast-actions button[disabled] {
  opacity: 0.6;
  cursor: default;
}

/* Hover-info affordance beside section/panel headings (see ui/infoDot.js).
   A real <button> (keyboard-focusable, screen-reader-named) styled down to a
   bare glyph; the visible bubble is the native `title` on mouse-hover. */
.info {
  cursor: help;
  margin-left: 0.35em;
  color: var(--faint);
  font-size: 0.85em;
  font-style: normal;
  font-weight: 400;
  line-height: 1;
  background: none;
  border: 0;
  padding: 0;
  user-select: none;
  vertical-align: middle;
}
.info:hover {
  color: var(--accent);
}
.info:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
  color: var(--accent);
}

/* ── cast picker (composer) — mirrors the brand picker popover ─────────────── */
.composer .fields label.castwrap {
  position: relative;
}
.composer .fields label.castwrap > button {
  width: 100%;
  justify-content: space-between;
  text-transform: none;
  letter-spacing: normal;
}
#castPop {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(30, 28, 22, 0.14);
  padding: 8px;
}
.ccard {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--fg);
  font-size: 13px;
}
.ccard:hover {
  background: var(--panel);
}
.ccard.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.ccard.empty {
  cursor: default;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.4;
}
.ccard .cthumb {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 7px;
  overflow: hidden;
  background: var(--panel);
  display: grid;
  place-items: center;
}
.ccard .cthumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ccard .cnoimg {
  font-weight: 700;
  color: var(--fg-dim);
}
.ccard .meta {
  flex: 1;
  min-width: 0;
}
.ccard .meta b {
  display: block;
  font-size: 13px;
}
.ccard .meta span {
  display: block;
  font-size: 11px;
  color: var(--fg-dim);
}
.ccard .ccheck {
  color: var(--accent);
  font-weight: 700;
  width: 14px;
  text-align: center;
}

/* ── knowledge-base panel (character + brand editors) ─────────────────────── */
.kb {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.kb-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}
.kb-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
}
.kb-sub {
  font-size: 12px;
  color: var(--fg-dim);
}
.kb-count {
  font-size: 11px;
  color: var(--fg-dim);
}
.kb-count.full {
  color: var(--warn, #b8860b);
  font-weight: 600;
}
.kb-drop.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
a.kb-name {
  color: var(--accent);
  text-decoration: none;
}
a.kb-name:hover {
  text-decoration: underline;
}
.kb-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  border: 1px dashed var(--line);
  border-radius: 9px;
  padding: 14px;
  font-size: 12px;
  color: var(--fg-dim);
  cursor: pointer;
  text-align: center;
}
.kb-drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.kb-drop.busy {
  opacity: 0.6;
}
.kb-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.kb-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kb-doc {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
}
.kb-fmt {
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-dim);
  background: var(--panel);
  border-radius: 4px;
  padding: 2px 5px;
}
.kb-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-size {
  color: var(--fg-dim);
}
.kb-x {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 13px;
}
.kb-x:hover {
  color: var(--err);
}
.kb-empty {
  font-size: 12px;
  color: var(--fg-dim);
  margin: 8px 0 0;
}

/* ── character detail editor ───────────────────────────────────────────────── */
/* ── Virtual Expert: "+ Create" CTA + unified create/edit editor ─────────────── */
.expert-new {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 620px;
  text-align: left;
  padding: 13px 16px;
  margin: 0 0 20px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  transition:
    border-color 0.12s ease,
    background 0.12s ease;
}
.expert-new:hover,
.expert-new:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.expert-new-plus {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}
.expert-new > span:last-child {
  display: grid;
  gap: 1px;
}
.expert-new b {
  font-size: 14px;
}
.expert-new > span:last-child > span {
  font-size: 12px;
  color: var(--fg-dim);
}

.expert-editor {
  max-width: 620px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px 16px;
  margin: 0 0 22px;
  background: var(--surface);
  box-shadow: 0 10px 32px rgba(30, 28, 22, 0.1);
}
.expert-editor-head {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 13px;
  margin-bottom: 15px;
}
.expert-portrait {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  display: grid;
  place-items: center;
  color: var(--fg-dim);
  font-size: 20px;
  font-weight: 600;
}
.expert-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Portrait control (portraitStudio.js): webcam · upload · generate · edit. */
.portrait-studio {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 168px;
}
.portrait-studio .expert-portrait {
  width: 168px;
  height: 168px;
  flex: 0 0 168px;
}
.portrait-studio .expert-portrait video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.portrait-busy {
  opacity: 0.6;
}
.portrait-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.portrait-actions button,
.portrait-upload {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}
.portrait-actions button:disabled {
  opacity: 0.5;
  cursor: default;
}
.portrait-upload {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
}
.portrait-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.portrait-edit {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.portrait-edit textarea {
  width: 100%;
  resize: vertical;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
}
.portrait-ref {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  font-size: 12px;
  color: var(--fg-dim);
  cursor: pointer;
}
.portrait-ref input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.portrait-err {
  font-size: 12px;
  margin: 0;
}

/* Voice-clone control (voiceClone.js): record mic → f5-tts cloned dialogue. */
.voiceclone {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.vc-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.vc-hint {
  margin: 0;
  font-size: 12px;
  color: var(--fg-dim);
}
.vc-sentence {
  margin: 0;
  font-size: 13px;
  font-style: italic;
  color: var(--fg);
  line-height: 1.4;
}
.vc-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.vc-timer {
  font-size: 13px;
  color: var(--err);
  font-variant-numeric: tabular-nums;
}
.vc-audio {
  width: 100%;
  height: 34px;
}
.vc-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.vc-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}
.vc-err {
  font-size: 12px;
  margin: 0;
}
.expert-editor-title {
  flex: 1;
  min-width: 0;
}
.expert-editor-title h3 {
  margin: 0 0 2px;
  font-size: 16px;
}
.expert-editor-title p {
  margin: 0;
  font-size: 12.5px;
  color: var(--fg-dim);
}
.expert-close {
  align-self: flex-start;
}
.expert-fields {
  display: grid;
  gap: 13px;
}
.expert-field {
  display: grid;
  gap: 5px;
}
.expert-field > span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
}
.expert-field input,
.expert-field textarea,
.expert-field select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-family: inherit; /* UI font — NOT the monospace the old editor inherited */
  font-size: 14px;
  line-height: 1.45;
}
.expert-field textarea {
  resize: vertical;
}
.expert-field input:focus,
.expert-field textarea:focus,
.expert-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.expert-field input::placeholder,
.expert-field textarea::placeholder {
  color: var(--faint);
  font-weight: 400;
  opacity: 1;
}
.expert-field small {
  font-size: 11.5px;
  color: var(--fg-dim);
}
.expert-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.expert-progress {
  margin-right: auto;
  font-size: 12px;
  color: var(--fg-dim);
}
.expert-actions button {
  font: inherit;
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
  padding: 8px 14px;
}
.expert-actions button.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg-dim);
}
.expert-actions button:last-child {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.expert-actions button:last-child[disabled] {
  opacity: 0.6;
  cursor: default;
}

/* staged-but-not-yet-uploaded KB rows (create flow) */
.kb-doc.pending {
  border-style: dashed;
}
.kb-pending {
  font-size: 11px;
  font-style: italic;
  color: var(--fg-dim);
}

/* ── Brand tab (page) — reuses .castpanel/.cast-grid/.cast-card + .expert-editor ─
   The brand card thumbnail is a logo (or first reference image), so `contain`
   with padding reads better than the cast portrait's `cover` crop; a kit-less
   thumbnail falls back to a colour ramp. */
.brandpanel .cast-thumb img {
  object-fit: contain;
  padding: 14px;
}
/* Logo preview in the editor header — scale to fit, never crop a wide/tall logo. */
.brandpanel-editor .expert-portrait img {
  object-fit: contain;
  padding: 6px;
}
/* "Guide generated visuals" opt-out toggle under the image panel. */
.brandpanel-editor .brand-toggle {
  margin-top: 10px;
  font-size: 12px;
  color: var(--fg-dim);
}
.brandcard-ramp {
  display: flex;
  gap: 0;
  width: 70%;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
}
.brandcard-ramp i {
  flex: 1;
}

/* Compound editor rows (brand color / watermark / captions) inside .expert-field */
.brandpanel-editor .brow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.brandpanel-editor .brow input[type="range"] {
  flex: 1;
  min-width: 120px;
}
.brandpanel-editor .brow .bcaplabel {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-dim);
}

/* ── reference-image panel (imagePanel.js) — thumbnail-grid twin of .kb ──────── */
.imgset {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.imgset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.imgset-tile {
  position: relative;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}
.imgset-tile.pending {
  border-style: dashed;
}
.imgset-tile > img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain; /* preserve aspect — a wide/tall reference is scaled, not cropped */
  padding: 4px;
  background: var(--panel);
}
.imgset-noimg {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  font-size: 11px;
  font-weight: 700;
  color: var(--fg-dim);
}
.imgset-tile figcaption {
  display: grid;
  gap: 1px;
  padding: 4px 6px;
  font-size: 10px;
}
.imgset-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.imgset-size {
  color: var(--fg-dim);
}
.imgset-x {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.imgset-x:hover {
  color: var(--err);
  background: var(--surface);
}

/* ── live scene media: unified image/clip thumbnail + overlay + playback ────
   The hero thumbnail wraps its media so the Generate/Regenerate-clip button can
   sit OVER it — telling you at a glance whether a scene has no image (dashed
   placeholder), a still (click to enlarge), or a playable clip. */
.thumbwrap {
  position: relative;
  width: 400px;
  max-width: 100%;
}

/* Live still that fades in only once it has actually loaded — a not-yet-ready
   or failed image leaves the "generating…"/"loading…" placeholder showing
   behind it instead of a broken-image glyph (skeleton, waiting for assets). */
.thumb.overlay-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.thumb.clip {
  cursor: default;
}

.thumb.placeholder {
  border: 1px dashed var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  font: 11.5px var(--mono);
  cursor: default;
}

/* Generate/Regenerate-clip control overlaid on the thumbnail — top-right so it
   clears a playing video's control bar. */
/* #doc-scoped to beat the generic `#doc button` accent-pill rule (specificity). */
#doc .clip-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 5px 10px;
  border: 0;
  border-radius: 7px;
  background: rgba(17, 18, 22, 0.72);
  color: #fff;
  font: 600 12px/1.2 inherit;
  cursor: pointer;
  backdrop-filter: blur(2px);
  transition: background 0.12s ease;
}
#doc .clip-overlay:hover:not(:disabled) {
  background: rgba(17, 18, 22, 0.9);
}
#doc .clip-overlay:disabled {
  opacity: 0.7;
  cursor: default;
}
#doc .clip-overlay.has-clip {
  background: rgba(17, 18, 22, 0.55);
  font-size: 11.5px;
}
#doc .clip-overlay:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

/* ▶ play button on a narration line (appears once its TTS audio has landed). */
/* #doc-scoped to beat the generic `#doc button` accent-pill rule (specificity). */
#doc .playline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 0 0 0 1px; /* optical: the ▶ triangle sits slightly left of centre */
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font: 8px/1 inherit;
  cursor: pointer;
  vertical-align: middle;
}
#doc .playline:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
#doc .playline:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Skeleton (during generation): live thumbnail beside the narration. */
.skrow {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.skcol {
  flex: 1;
  min-width: 240px;
}
.scene.skeleton.haslive {
  border-style: solid;
  animation: none; /* asset landed — stop the waiting pulse so it reads as "ready", not dimmed */
}

/* Image lightbox (ui/lightbox.js) — click a still to see it full size. */
.lightbox {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
}
.lightbox::backdrop {
  background: rgba(10, 11, 14, 0.85);
}
.lightbox img {
  display: block;
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}
.lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ── per-scene WYSIWYG mini-player (ui/scenePreviewPlayer.js + scenePreviewMount.js) ──
   Opt-in per scene: the ▶ Preview toggle swaps the still/clip thumbnail for a
   live, scrubbable render of the actual composition (captions/headings/effects).
   The compiled doc is 1280×720; the player scales it (inline transform) into the
   400px thumb column and clips it here. */
/* #doc-scoped to beat the generic `#doc button` accent-pill rule (specificity). */
#doc .preview-toggle {
  align-self: flex-start;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--fg-dim);
  font: 600 12px/1.2 inherit;
  cursor: pointer;
}
#doc .preview-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
#doc .preview-toggle.on {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.scenepreview {
  width: 400px;
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #000;
}
.spv-view {
  position: relative;
  overflow: hidden;
  background: #000;
  height: 214px;
}
.spv-frame {
  border: 0;
  display: block;
}
.spv-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
#doc .spv-play {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.spv-scrub {
  flex: 1;
  accent-color: var(--accent);
}
.spv-readout {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--fg-dim);
  min-width: 68px;
  text-align: right;
}
.spv-loading,
.spv-empty {
  height: 214px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  font: 12px var(--mono);
  background: var(--panel);
}

/* ── original-brief panel (ui/briefPanel.js) — read-only, collapsible ──────
   Shows the prompt + options a job was generated from, at the top of the
   studio view when a job is open. */
.briefpanel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  margin-bottom: 12px;
  overflow: hidden;
}
.briefpanel > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.briefpanel > summary::-webkit-details-marker {
  display: none;
}
.briefpanel .bp-chev {
  font-size: 9px;
  color: var(--faint);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}
.briefpanel[open] .bp-chev {
  transform: rotate(90deg);
}
.briefpanel .bp-label {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--fg-dim);
  flex: 0 0 auto;
}
.briefpanel .bp-preview {
  color: var(--faint);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}
.briefpanel[open] .bp-preview {
  display: none;
}
.briefpanel .bp-body {
  padding: 4px 16px 14px;
  border-top: 1px solid var(--line);
}
.briefpanel .bp-field {
  margin: 10px 0;
}
.briefpanel .bp-field label {
  display: block;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--fg-dim);
  margin-bottom: 4px;
}
.briefpanel .bp-prompt {
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--fg);
  white-space: pre-wrap;
}
.briefpanel .bp-opts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px 18px;
  margin: 12px 0 0;
}
.briefpanel .bp-opts > div {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.briefpanel .bp-opts dt {
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
}
.briefpanel .bp-opts dd {
  margin: 0;
  font-size: 13.5px;
  color: var(--fg);
}
.briefpanel .bp-loading {
  color: var(--faint);
  font: 12px var(--mono);
  margin-top: 10px;
}
.briefpanel .bp-note {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--faint);
}
