/* ── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 6px;
  --topbar: 56px;
  --jobs-w: 340px;

  /* light (paper) */
  --bg: #f3f0e9;
  --bg-2: #ebe7de;
  --panel: #faf8f3;
  --panel-2: #f1ede4;
  --line: #e2dcd0;
  --line-2: #cfc7b8;
  --ink: #1f1c18;
  --ink-dim: #5d564d;
  --ink-mute: #948b7f;
  --amber: #c9780f;
  --amber-2: #a86206;
  --amber-soft: rgba(201, 120, 15, 0.14);
  --amber-ink: #fff8ec;
  --teal: #1f8c73;
  --teal-dim: #9fd3c3;
  --blue: #2f6fd0;
  --red: #c4432c;
  --log-bg: #f6f3ec;
  --shadow: 0 10px 30px rgba(40, 30, 10, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12100e;
    --bg-2: #0d0b0a;
    --panel: #1a1714;
    --panel-2: #221e1a;
    --line: #2a2521;
    --line-2: #3a332c;
    --ink: #ebe4d8;
    --ink-dim: #a69c8f;
    --ink-mute: #6f665c;
    --amber: #e9a23a;
    --amber-2: #f6bd64;
    --amber-soft: rgba(233, 162, 58, 0.16);
    --amber-ink: #2a1a04;
    --teal: #4fcfae;
    --teal-dim: #2b6d60;
    --blue: #7ab6ff;
    --red: #e8634d;
    --log-bg: #0d0b0a;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}
/* Pinned themes also tell the browser which scrollbars, form controls and dialogs to draw. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12100e;
  --bg-2: #0d0b0a;
  --panel: #1a1714;
  --panel-2: #221e1a;
  --line: #2a2521;
  --line-2: #3a332c;
  --ink: #ebe4d8;
  --ink-dim: #a69c8f;
  --ink-mute: #6f665c;
  --amber: #e9a23a;
  --amber-2: #f6bd64;
  --amber-soft: rgba(233, 162, 58, 0.16);
  --amber-ink: #2a1a04;
  --teal: #4fcfae;
  --teal-dim: #2b6d60;
  --blue: #7ab6ff;
  --red: #e8634d;
  --log-bg: #0d0b0a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ── Base ────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--amber); color: var(--amber-ink); }
a { color: var(--amber-2); }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 600; font-size: 16px; }
.brand-sub { font-family: var(--mono); font-size: 11px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.14em; }
.tally {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--line-2);
  transition: background 0.3s;
}
.tally.on {
  background: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; margin-left: 6px;
  background: var(--amber); color: var(--amber-ink); font-size: 11px; font-weight: 600;
  display: inline-grid; place-content: center;
}
.badge:empty { display: none; }

/* ── Buttons & controls ──────────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink);
  padding: 7px 12px; border-radius: var(--radius); cursor: pointer;
  font-size: 13px; font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center;
}
.btn:hover { background: var(--panel-2); border-color: var(--ink-mute); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); font-weight: 600; }
.btn.primary:hover { background: var(--amber-2); border-color: var(--amber-2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.active { border-color: var(--amber); background: var(--amber-soft); }
.seg-ctl { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; }
.seg-ctl button {
  border: 0; background: transparent; color: var(--ink-dim); padding: 6px 10px; cursor: pointer;
  font-size: 12px; font-weight: 500; border-right: 1px solid var(--line-2); transition: background 0.15s, color 0.15s;
}
.seg-ctl button:last-child { border-right: 0; }
.seg-ctl button:hover { background: var(--panel-2); color: var(--ink); }
.seg-ctl button.on { background: var(--amber); color: var(--amber-ink); font-weight: 600; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-dim); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--amber); }
input[type="search"], input[type="text"], input:not([type]), input[type="password"], input[type="email"], select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 8px 10px; outline: none; transition: border-color 0.15s; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--amber); }
textarea { resize: vertical; }

/* ── Shell ───────────────────────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 0;
  height: calc(100vh - var(--topbar));
  transition: grid-template-columns 0.2s ease;
}
body.jobs-open .shell { grid-template-columns: 270px minmax(0, 1fr) var(--jobs-w); }
.index, .jobs { background: var(--panel); overflow: hidden; display: flex; flex-direction: column; }
.index { border-right: 1px solid var(--line); }
.jobs { border-left: 1px solid var(--line); visibility: hidden; }
body.jobs-open .jobs { visibility: visible; }
.stage { overflow-y: auto; padding: 28px 32px 80px; }

.index-head { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.count { font-family: var(--mono); font-size: 11px; color: var(--ink-mute); white-space: nowrap; }
.story-list, .job-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.story-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
  border-left: 2px solid transparent; transition: background 0.12s;
}
.story-item:hover { background: var(--panel-2); }
.story-item.active { background: var(--panel-2); border-left-color: var(--amber); }
.story-item .id { font-family: var(--mono); font-size: 11px; color: var(--ink-dim); letter-spacing: 0.04em; display: flex; align-items: center; gap: 6px; }
.story-item .topic { grid-column: 1 / -1; font-weight: 500; font-size: 14px; line-height: 1.3; color: var(--ink); }
.story-item .topic:empty::before { content: "Untitled"; color: var(--ink-mute); }
.bars { grid-column: 1 / -1; display: flex; gap: 4px; margin-top: 4px; }
.bar { flex: 1; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--teal); width: var(--w, 0%); transition: width 0.4s; }
.bar.img > i { background: var(--blue); }
.pill {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 2px 6px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--ink-dim);
}
.pill.hidden { border-style: dashed; color: var(--ink-mute); }
.status-ctl button.hidden.on { background: var(--ink-dim); color: var(--panel); }

/* Story list: one chip per status; on = stories with that status are listed */
.status-filter { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.status-filter:empty { display: none; }
.status-chip {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line-2); background: transparent; color: var(--ink-mute); cursor: pointer;
}
.status-chip .n { opacity: 0.7; }
.status-chip:hover { color: var(--ink); }
.status-chip.on { background: var(--panel-2); color: var(--ink); border-color: var(--ink-mute); }
.status-chip.picked.on { border-color: var(--teal); color: var(--teal); }
.status-chip.processed.on { border-color: var(--blue); color: var(--blue); }
.status-chip:not(.on) { text-decoration: line-through; }
.list-note { padding: 16px 12px; font-size: 13px; color: var(--ink-mute); }

.status-ctl button { text-transform: capitalize; padding: 6px 12px; }
.style-sel {
  width: auto; max-width: 240px; padding: 5px 26px 5px 10px; font-family: var(--sans); font-size: 12px; font-weight: 500;
  border: 1px solid var(--line-2); border-radius: var(--radius); background-color: var(--panel); color: var(--ink); cursor: pointer;
}
.style-sel:hover { border-color: var(--ink-mute); }
.style-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.style-row input { flex: 1; min-width: 220px; }
.char-note.shared { color: var(--amber-2); }
.status-ctl button.picked.on { background: var(--teal); color: #fff; }
.status-ctl button.processed.on { background: var(--blue); color: #fff; }
.status-ctl button.no.on { background: var(--ink-mute); color: #fff; }
.status-ctl button:disabled { cursor: wait; opacity: 0.7; }
.pill.picked { border-color: var(--teal-dim); color: var(--teal); }
.pill.processed { border-color: var(--blue); color: var(--blue); }
.pill.running { border-color: var(--amber); color: var(--amber); display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); animation: pulse 1.6s infinite; }

/* ── Stage: empty ────────────────────────────────────────────────────────── */
.empty { height: 100%; display: grid; place-content: center; text-align: center; color: var(--ink-mute); }
.empty-title { font-size: 22px; font-weight: 600; margin: 0 0 6px; color: var(--ink-dim); }
.empty-sub { margin: 0; }
.loading { color: var(--ink-mute); font-family: var(--mono); font-size: 12px; padding: 40px 0; }

/* ── Stage: story header ─────────────────────────────────────────────────── */
.story-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 24px; align-items: end; margin-bottom: 20px; }
.eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-family: var(--mono); font-size: 12px; color: var(--ink-dim); }
.story-title { font-size: clamp(22px, 2.4vw, 30px); line-height: 1.2; margin: 6px 0 0; }
.story-meta { grid-column: 1 / -1; margin: 0; color: var(--ink-dim); }
.source-text { grid-column: 1 / -1; font-size: 13px; color: var(--ink-dim); }
.source-text summary { cursor: pointer; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); }
.source-text p { margin: 8px 0 0; white-space: pre-wrap; padding: 10px 12px; border-left: 2px solid var(--amber); background: var(--panel); border-radius: 0 6px 6px 0; }
.story-meta b { color: var(--ink); font-weight: 600; }
.head-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.head-actions .row { display: flex; gap: 6px; }

/* ── Stage strip ─────────────────────────────────────────────────────────── */
.strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px;
  margin: 8px 0 28px;
}
.seg {
  min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  transition: border-color 0.2s;
}
.seg.done { border-color: var(--teal-dim); }
.seg.running { border-color: var(--amber); }
.seg-label { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-dim); display: flex; justify-content: space-between; }
.seg-label .n { color: var(--ink-mute); }
.seg-val { font-size: 24px; font-weight: 600; line-height: 1; }
.seg-val small { font-size: 13px; color: var(--ink-mute); font-family: var(--mono); font-weight: 400; margin-left: 4px; }
.seg.done .seg-val { color: var(--teal); }
.seg-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.seg-foot .hint { min-width: 0; font-size: 12px; color: var(--ink-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Sections ────────────────────────────────────────────────────────────── */
.section { margin-top: 30px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.section-head h3 { margin: 0; font-size: 16px; }
.section-head .sub { font-family: var(--mono); font-size: 11px; color: var(--ink-mute); }
.section-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-tools .seg-ctl button { padding: 4px 10px; }

/* ── Scene details list ──────────────────────────────────────────────────── */
.scene-list { display: grid; gap: 10px; }
.scene-row {
  display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 14px;
  padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
  opacity: 0; transform: translateY(6px); animation: reveal 0.35s ease-out forwards; animation-delay: calc(var(--i, 0) * 25ms);
  transition: border-color 0.15s;
}
.scene-row:hover { border-color: var(--amber); }
.scene-row-thumb { position: relative; aspect-ratio: 9 / 16; border-radius: 6px; overflow: hidden; background: var(--bg-2); border: 1px solid var(--line); }
.scene-row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scene-row-thumb .ph { position: absolute; inset: 0; display: grid; place-content: center; color: var(--ink-mute); font-family: var(--mono); font-size: 10px; text-align: center; }
.scene-row-thumb .play { position: absolute; inset: 0; display: grid; place-content: center; pointer-events: none; }
.scene-row-thumb .play span { width: 28px; height: 28px; border-radius: 50%; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.3); color: #fff; display: grid; place-content: center; font-size: 10px; padding-left: 2px; }
.scene-row-body { display: grid; gap: 8px; align-content: start; min-width: 0; }
.scene-row-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.scene-row-head .fr { font-size: 18px; font-weight: 600; line-height: 1; }
.scene-row-head .ts { font-size: 11px; color: var(--ink-dim); }
.scene-row-head .model { font-size: 11px; color: var(--ink-mute); margin-left: auto; }
.flags-inline { display: inline-flex; gap: 4px; }
.flags-inline .flag { background: var(--bg-2); color: var(--ink-mute); border: 1px solid var(--line); }
.flags-inline .flag.on { color: #fff; border-color: transparent; }
.scene-row-story { margin: 0; font-size: 15px; font-weight: 500; line-height: 1.4; }
.scene-row .kv { grid-template-columns: 96px 1fr; }

/* ── Scene grid ──────────────────────────────────────────────────────────── */
.scenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.scene {
  position: relative; aspect-ratio: 9 / 16; border-radius: 8px; overflow: hidden; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line);
  opacity: 0; transform: translateY(8px);
  animation: reveal 0.4s ease-out forwards;
  animation-delay: calc(var(--i, 0) * 35ms);
  transition: border-color 0.15s, transform 0.15s;
}
@keyframes reveal { to { opacity: 1; transform: none; } }
.scene:hover { border-color: var(--amber); transform: translateY(-2px); }
.scene[draggable="true"], .scene-row[draggable="true"] { cursor: grab; }
.scene.dragging, .scene-row.dragging { opacity: 0.4; }
.scene.drop-before { box-shadow: -4px 0 0 var(--amber); }
.scene.drop-after { box-shadow: 4px 0 0 var(--amber); }
.scene-row.drop-before { box-shadow: 0 -3px 0 var(--amber); }
.scene-row.drop-after { box-shadow: 0 3px 0 var(--amber); }
.scene img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scene .ph { position: absolute; inset: 0; display: grid; place-content: center; color: var(--ink-mute); font-family: var(--mono); font-size: 11px; text-align: center; padding: 12px; }
.scene .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 8px 8px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.8));
  display: flex; justify-content: space-between; align-items: flex-end; gap: 6px; color: #fff;
}
.scene .fr { font-size: 18px; font-weight: 600; line-height: 1; }
.scene .ts { font-family: var(--mono); font-size: 10px; color: rgba(255,255,255,0.75); }
.flags { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.flag { width: 18px; height: 18px; border-radius: 4px; display: grid; place-content: center; font-family: var(--mono); font-size: 10px; font-weight: 600; background: rgba(0,0,0,0.55); color: rgba(255,255,255,0.5); }
.flag.on { color: #0b0908; }
.flag.img.on { background: var(--blue); }
.flag.vid.on { background: var(--teal); }
.flag.vid.on.stale { background: var(--amber); }
.scene .play { position: absolute; inset: 0; display: grid; place-content: center; pointer-events: none; }
.scene .play span { width: 36px; height: 36px; border-radius: 50%; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.3); color: #fff; display: grid; place-content: center; font-size: 12px; padding-left: 3px; }

/* ── Narrative & characters ──────────────────────────────────────────────── */
.narr { display: grid; gap: 8px; }
.narr-row { display: grid; grid-template-columns: 76px 1fr 1fr; gap: 14px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.narr-row .t { font-family: var(--mono); font-size: 12px; color: var(--amber-2); }
.narr-row .zh { color: var(--ink-dim); }
.chars { display: flex; flex-wrap: wrap; gap: 10px; }
.char {
  display: flex; align-items: center; gap: 12px; padding: 6px 14px 6px 6px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--ink);
  transition: border-color 0.15s, transform 0.15s;
}
.char:hover { border-color: var(--amber); transform: translateY(-1px); }
.char img, .char-ph { width: 44px; height: 64px; border-radius: 6px; object-fit: cover; background: var(--bg-2); }
.char-ph { display: grid; place-content: center; color: var(--ink-mute); font-family: var(--mono); }
.char .nm { font-weight: 500; }
.char-note { margin: 0; color: var(--ink-dim); line-height: 1.55; }

/* ── Jobs ────────────────────────────────────────────────────────────────── */
.jobs-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-dim); }
.jobs-head .btn { text-transform: none; letter-spacing: 0; font-family: var(--sans); }
.job-list { max-height: 42%; border-bottom: 1px solid var(--line); }
.job-item { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 12px; border-left: 2px solid transparent; }
.job-item:hover { background: var(--panel-2); }
.job-item.active { background: var(--panel-2); border-left-color: var(--amber); }
.job-item .st { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-mute); }
.job-item .st.running { background: var(--amber); animation: pulse 1.6s infinite; box-shadow: 0 0 0 3px var(--amber-soft); }
.job-item .st.succeeded { background: var(--teal); }
.job-item .st.partial { background: var(--amber-2); }
.job-item .st.failed { background: var(--red); }
.job-item .st.stopped { background: transparent; border-radius: 2px; box-shadow: inset 0 0 0 2px var(--ink-mute); }
.job-item .stopping { color: var(--amber-2); font-family: var(--mono); font-size: 11px; font-weight: 400; }
.job-item .stage { color: var(--ink); font-weight: 500; }
.job-item .story { color: var(--ink-dim); grid-column: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 11px; }
.job-item .when { color: var(--ink-mute); text-align: right; font-family: var(--mono); font-size: 11px; }
.log { flex: 1; overflow: auto; padding: 12px 14px; font-family: var(--mono); font-size: 11.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; color: var(--ink-dim); background: var(--log-bg); }
.log-empty { color: var(--ink-mute); margin: 0; }
.log .ln { display: block; }
.log .ln.err { color: var(--red); }
.log .ln.warn { color: var(--amber-2); }
.log .ln b { color: var(--ink); font-weight: 500; }
.log .ln.job-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.log .ln.job-title .btn { font-family: var(--sans); white-space: nowrap; }
.log details.ln > summary { cursor: pointer; list-style: none; }
.log details.ln > summary::-webkit-details-marker { display: none; }
.log details.ln > summary::after { content: " ▸ details"; color: var(--ink-mute); font-size: 10.5px; }
.log details.ln[open] > summary::after { content: " ▾ details"; }
.log .ln-detail { margin: 4px 0 8px; padding: 8px 10px; max-height: 360px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; line-height: 1.5; color: var(--ink-dim); background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; }
.log .summary { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line-2); color: var(--ink); }

/* ── Dialogs ─────────────────────────────────────────────────────────────── */
/* The hidden attribute always wins over a component's own display (.btn, .seg-ctl, …). */
[hidden] { display: none !important; }

/* ── Sign-in ─────────────────────────────────────────────────────────────── */
body.signed-out > :not(#login):not(.toasts):not(script) { display: none !important; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 14px; padding: 28px 26px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow);
  border-top: 3px solid var(--amber);
}
.login-card .brand { display: flex; align-items: baseline; gap: 8px; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-dim); font-family: var(--mono); }
.login-card label input { font-family: var(--sans); font-size: 14px; }
.login-card .btn.primary { justify-content: center; padding: 9px 12px; }
.login-error { margin: 0; color: var(--red); font-size: 13px; }
.login-note { margin: 0; color: var(--ink-mute); font-size: 12px; }
.me { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dialog { border: 1px solid var(--line-2); border-radius: 10px; background: var(--panel); color: var(--ink); padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(20, 15, 5, 0.45); backdrop-filter: blur(2px); }
.dialog form, .dialog .scene-body { padding: 22px 24px; display: grid; gap: 12px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-head p { margin: 4px 0 0; color: var(--ink-dim); }
.dialog label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-dim); font-family: var(--mono); }
.dialog label input, .dialog label select, .dialog label textarea { font-family: var(--sans); font-size: 14px; }
.dialog label.toggle { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-family: var(--sans); font-size: 13px; }
.draft-box { display: grid; gap: 8px; padding: 12px; border: 1px dashed var(--line-2); border-radius: 8px; background: var(--amber-soft); }
.draft-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.draft-hint { font-size: 12px; color: var(--ink-dim); flex: 1 1 200px; }
.draft-buttons { display: flex; align-items: center; gap: 8px; }
.dialog label.inline-select { display: flex; align-items: center; gap: 6px; }
.dialog label.inline-select select { font-size: 13px; padding: 4px 6px; }

/* New idea dialog: "One video" vs "Series" */
.dialog-title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.dialog-title-row .seg-ctl button { padding: 4px 10px; }
.idea-form:not([data-mode="series"]) .series-only { display: none; }
.idea-form[data-mode="series"] .single-only { display: none; }
.single-fields { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 12px; }
#series-panel:empty { display: none; }
#series-panel { display: grid; gap: 10px; }
.series-head { display: grid; gap: 6px; }
.series-title { display: flex; align-items: baseline; gap: 8px; font-size: 16px; }
.series-key { font-family: var(--mono); font-size: 11px; color: var(--ink-mute); }
.series-reason { margin: 0; font-size: 13px; color: var(--ink-dim); }
.cast-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cast-chip { font-size: 12px; padding: 2px 8px; border: 1px solid var(--line-2); border-radius: 999px; color: var(--ink-dim); cursor: help; }
.episode-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.episode { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.episode.off { opacity: 0.45; }
.episode-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.episode-top label.toggle { white-space: nowrap; }
.episode-id { width: 9em; font-family: var(--mono); font-size: 12px; }
.episode input, .episode textarea { font-family: var(--sans); font-size: 14px; }
.episode-meta { margin: 0; font-size: 12px; color: var(--ink-mute); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.edit-dialog { width: min(760px, calc(100vw - 32px)); }

/* ── In-app confirmation ─────────────────────────────────────────────────── */
.ask-dialog {
  --tone: var(--amber);
  --tone-soft: var(--amber-soft);
  width: min(460px, calc(100vw - 32px));
  border-top: 3px solid var(--tone);
  overflow: hidden;
}
.ask-dialog[data-tone="danger"] { --tone: var(--red); --tone-soft: color-mix(in srgb, var(--red) 14%, transparent); }
.ask-dialog[open] { animation: ask-in 0.16s cubic-bezier(0.2, 0.8, 0.2, 1); }
.ask-dialog[open]::backdrop { animation: ask-fade 0.16s ease-out; }
@keyframes ask-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } }
@keyframes ask-fade { from { opacity: 0; } }
.ask-form { display: grid; gap: 0; }
.ask-main { padding: 20px 22px 16px; display: grid; gap: 10px; }
.ask-eyebrow {
  justify-self: start; font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--tone); background: var(--tone-soft); padding: 3px 8px; border-radius: 4px;
}
.ask-dialog h2 { margin: 0; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.ask-body p { margin: 0; color: var(--ink-dim); line-height: 1.55; }
.ask-body p + p { margin-top: 8px; }
.ask-facts {
  margin: 2px 0 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 14px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-2);
}
.ask-facts dt { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); padding-top: 1px; }
.ask-facts dd { margin: 0; font-family: var(--mono); font-size: 12px; color: var(--ink); overflow-wrap: anywhere; }
.ask-input { display: grid; gap: 4px; font-family: var(--mono); font-size: 12px; color: var(--ink-dim); }
.ask-check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--ink); line-height: 1.45; cursor: pointer; }
.ask-check input { margin-top: 3px; accent-color: var(--amber); }
.scene-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.stale-tag { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; padding: 1px 5px; border-radius: 4px; background: var(--amber-soft); color: var(--ink); }
.note-shared { margin: 0; font-size: 12.5px; color: var(--ink-dim); }
.shared-tag { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; padding: 1px 5px; border-radius: 4px; background: var(--amber-soft); color: var(--ink); margin-left: 6px; }
.shared-body { padding: 22px 24px; display: grid; gap: 14px; }
/* Earlier versions of a keyframe, clip, final video or sheet */
.versions-dialog { width: min(860px, calc(100vw - 32px)); }
.versions-body { padding: 22px 24px; display: grid; gap: 14px; }
.versions-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; max-height: 64vh; overflow-y: auto; }
.version { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line-2); border-radius: 8px; }
.version.current { border-color: var(--amber); }
.version img, .version video { width: 100%; aspect-ratio: 9 / 16; object-fit: cover; border-radius: 6px; background: var(--bg-2); }
.version-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-family: var(--mono); font-size: 11.5px; color: var(--ink-dim); }
.shared-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; max-height: 60vh; overflow-y: auto; }
.shared-item { display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--line-2); border-radius: 8px; }
.shared-item img, .shared-item .ph { width: 54px; height: 96px; object-fit: cover; border-radius: 6px; background: var(--bg-2); display: grid; place-content: center; font-size: 10px; }
.shared-text { display: grid; gap: 3px; min-width: 0; }
.shared-text .mono { font-size: 11.5px; color: var(--ink-dim); }
.shared-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn.danger-text { color: var(--red); }

/* ── Users ───────────────────────────────────────────────────────────────── */
.users-dialog { width: min(600px, calc(100vw - 32px)); }
.users-body { padding: 22px 24px; display: grid; gap: 16px; }
.users-body h3 { margin: 0; font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-dim); }
.user-list { list-style: none; margin: 0; padding: 0; display: grid; border: 1px solid var(--line-2); border-radius: 8px; max-height: 42vh; overflow-y: auto; }
.user-list .loading { padding: 16px; }
.user { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; padding: 10px 12px; }
.user + .user { border-top: 1px solid var(--line); }
.user-name { display: grid; gap: 2px; min-width: 0; }
.user-name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name .mono { font-size: 11.5px; color: var(--ink-mute); }
.user.off .user-name b { color: var(--ink-mute); text-decoration: line-through; text-decoration-color: var(--line-2); }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.you-tag { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; padding: 1px 5px; border-radius: 4px; background: var(--amber-soft); color: var(--ink); margin-left: 6px; font-weight: 500; }
.dialog form.user-pw { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; padding: 0; }
.user-pw input { flex: 1; min-width: 0; font-family: var(--sans); font-size: 14px; }
.dialog form.user-add { display: grid; gap: 10px; padding: 14px; border: 1px dashed var(--line-2); border-radius: 8px; background: var(--bg-2); }
.user-add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pw-field { display: flex; gap: 6px; }
.pw-field input { flex: 1; min-width: 0; font-family: var(--sans); font-size: 14px; }
.pw-field .btn { font-family: var(--sans); }
.user-add-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.user-confirm { padding-top: 12px; border-top: 1px solid var(--line); }
.user-confirm em { font-style: normal; color: var(--ink-mute); }
.users-status.err { color: var(--red); }
@media (max-width: 560px) { .user-add-row { grid-template-columns: 1fr; } .user { grid-template-columns: 1fr; } .user-actions { justify-content: flex-start; } }
.note-warn { margin: 0 0 10px; padding: 8px 12px; border-left: 3px solid var(--amber); background: var(--amber-soft); color: var(--ink); font-size: 13px; border-radius: 4px; }
.finals { display: flex; flex-wrap: wrap; gap: 16px; }
.final { margin: 0; display: grid; gap: 6px; width: min(240px, 100%); }
.final video { width: 100%; aspect-ratio: 9 / 16; background: #000; border-radius: 8px; border: 1px solid var(--line-2); }
.final figcaption { display: flex; justify-content: space-between; gap: 8px; font-family: var(--mono); font-size: 12px; color: var(--ink-dim); }
.final-links { display: flex; gap: 10px; }
.narr audio.voice { display: block; height: 28px; width: min(220px, 100%); margin-top: 6px; }
.seg-cost { display: block; font-family: var(--mono); font-size: 11px; color: var(--ink-mute); margin-top: 2px; }
.btn .cost { font-family: var(--mono); font-size: 11px; opacity: 0.75; margin-left: 4px; }
.ask-input input { font-family: var(--sans); font-size: 14px; }
.ask-count { justify-self: end; font-size: 11px; color: var(--ink-mute); }
.ask-error { margin: 0; font-size: 12.5px; color: var(--red); }
.ask-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px; border-top: 1px solid var(--line); background: var(--bg-2); }
.ask-dialog[data-tone="danger"] #ask-ok { background: var(--red); border-color: var(--red); color: #fff; }
.ask-dialog[data-tone="danger"] #ask-ok:hover { filter: brightness(1.08); }
.ask-dialog .btn:focus-visible { outline: 2px solid var(--tone); outline-offset: 2px; }
.models-body, .picker-body { padding: 22px 24px; display: grid; gap: 14px; }
.model-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.model-row .row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.model-label { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); }
.model-current { margin: 4px 0; overflow-wrap: anywhere; }
.model-current .mono { font-size: 12px; color: var(--ink-dim); }
.model-row .draft-hint { margin: 0; }
.picker-dialog { width: min(820px, calc(100vw - 32px)); }
.picker-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.picker-tools input { flex: 1; min-width: 200px; }
.picker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: min(60vh, 560px); overflow-y: auto; }
.picker-item button {
  width: 100%; display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; text-align: left;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); cursor: pointer;
}
.picker-item button:hover { border-color: var(--amber); }
.picker-item button:disabled { cursor: wait; opacity: 0.6; }
.picker-item.current button { border-color: var(--teal-dim); }
.picker-item img, .picker-thumb { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: var(--bg-2); display: block; }
.picker-text { display: grid; gap: 2px; min-width: 0; }
.picker-name { font-weight: 600; }
.picker-id { font-size: 11px; color: var(--ink-mute); overflow-wrap: anywhere; }
.picker-desc { font-size: 12px; color: var(--ink-dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.picker-price { font-family: var(--mono); font-size: 12px; color: var(--ink-dim); white-space: nowrap; }
@media (max-width: 560px) {
  .model-row { grid-template-columns: 1fr; }
  .model-row .row { justify-content: flex-start; }
  .picker-item button { grid-template-columns: 44px minmax(0, 1fr); }
  .picker-item img, .picker-thumb { width: 44px; height: 44px; }
  .picker-price { grid-column: 2; }
}
.edit-field textarea { font-size: 13px; line-height: 1.5; }
.edit-hint { color: var(--ink-mute); font-family: var(--sans); font-size: 11px; }
.req { color: var(--amber); }
.more summary { cursor: pointer; font-family: var(--mono); font-size: 12px; color: var(--ink-dim); margin-bottom: 8px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.scene-dialog { width: min(1040px, calc(100vw - 32px)); }
.scene-body { grid-template-columns: 300px minmax(0, 1fr); gap: 22px; }
.scene-media { aspect-ratio: 9 / 16; background: #000; border-radius: 8px; overflow: hidden; border: 1px solid var(--line-2); display: grid; place-content: center; }
.scene-media img, .scene-media video { width: 100%; height: 100%; object-fit: contain; display: block; outline: none; }
.scene-media .ph { color: var(--ink-mute); font-family: var(--mono); font-size: 12px; text-align: center; padding: 20px; }
.scene-info { display: grid; gap: 12px; align-content: start; }
.scene-info h2 { margin: 0; font-size: 20px; line-height: 1.3; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; margin: 0; }
.kv dt { font-family: var(--mono); font-size: 11px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.08em; padding-top: 2px; }
.kv dd { margin: 0; color: var(--ink-dim); }
.kv dd.prompt { font-size: 12.5px; line-height: 1.55; }
.kv dd .mono { color: var(--ink); font-size: 12px; }
.scene-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.icon-btn {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--panel);
  color: var(--ink-dim); font-size: 18px; line-height: 1; cursor: pointer; display: grid; place-content: center;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-mute); }
.scene-card { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.scene-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.scene-card-head .state { font-family: var(--mono); font-size: 11px; color: var(--ink-mute); }
.scene-card-head .state.done { color: var(--teal); }
.scene-card-model { font-size: 13px; overflow-wrap: anywhere; }
.scene-card-model .mono { font-size: 12px; color: var(--ink-dim); }
.scene-card-from { font-size: 11px; color: var(--ink-mute); margin-left: 6px; }
.scene-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.scene-prompts { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--line-2); border-left: 3px solid var(--amber); border-radius: 8px; background: var(--panel); }
.scene-prompts .scene-card-head { justify-content: flex-start; }
.scene-prompts .scene-card-head .btn { margin-left: auto; }
.scene-prompts .kv { margin: 0; }
.char-prompt { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--ink-dim); white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.char-facts { margin: 0; }
.char-base { font: inherit; font-size: 12px; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); max-width: 100%; }
.char-sheet { background: var(--bg-2); }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 1000; }
.toast { background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--amber); padding: 10px 14px; border-radius: 6px; font-size: 13px; box-shadow: var(--shadow); animation: reveal 0.25s ease-out; max-width: min(520px, calc(100vw - 32px)); }
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--teal); }
.toast.warn { border-left-color: var(--amber); }

/* ── Motion preference ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .scene { opacity: 1; transform: none; }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  body { overflow: auto; }
  .shell, body.jobs-open .shell { grid-template-columns: 1fr; height: auto; }
  .index { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .jobs { border-left: 0; border-top: 1px solid var(--line); min-height: 320px; display: none; }
  body.jobs-open .jobs { display: flex; }
  .job-list { max-height: 160px; }
  .stage { padding: 20px 16px 40px; }
  .strip { grid-template-columns: repeat(2, 1fr); }
  .story-head { grid-template-columns: 1fr; }
  .head-actions { align-items: flex-start; }
  .narr-row { grid-template-columns: 60px 1fr; }
  .narr-row .zh { grid-column: 2; }
  .scene-body { grid-template-columns: 1fr; }
  .scene-row { grid-template-columns: 72px minmax(0, 1fr); }
  .scene-row .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .scene-row .kv dd { margin-bottom: 6px; }
  .scene-media { max-width: 320px; margin: 0 auto; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { padding: 8px 12px; height: auto; min-height: var(--topbar); flex-wrap: wrap; }
  .topbar-actions { flex-wrap: wrap; }
  .brand-name { white-space: nowrap; }
  .brand-sub { display: none; }
}
@media (max-width: 480px) {
  .strip { grid-template-columns: 1fr; }
}
.note-warn.ref-warn { margin: 8px 0 0; }

/* Posting, under the final videos */
.posting { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-2); display: grid; gap: 8px; }
.post-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.post-head h4 { margin: 0; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-dim); }
.post-accts { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.post-acct { font-size: 12.5px; color: var(--ink-mute); }
.post-acct.on { color: var(--ink); }
.link-btn { background: none; border: 0; padding: 0; color: var(--ink-mute); text-decoration: underline; cursor: pointer; font: inherit; font-size: 12px; }
.post-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.post-lang { min-width: 70px; font-size: 13px; }
.post-history { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 3px; font-size: 12.5px; color: var(--ink-dim); }
.post-history .mono { font-size: 11.5px; color: var(--ink-mute); }
