:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --ink: #101828;
  --ink-soft: #475467;
  --ink-faint: #8A94A6;
  --line: #E1E5EB;
  --accent: #1F5EFF;
  --accent-strong: #1546D6;
  --accent-wash: #E8EEFF;
  --good: #12805C;
  --good-wash: #E3F5EE;
  --warn: #A15C07;
  --warn-wash: #FFF4E0;
  --bad: #C2341F;
  --bad-wash: #FDECEA;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent-strong); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.note { color: var(--ink-soft); font-size: 14px; margin: 4px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 999px; border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink-faint); }
.btn-danger { background: var(--surface); border-color: var(--line); color: var(--bad); }
.btn.small { padding: 6px 12px; font-size: 13.5px; }
.btn:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--ink-soft); }

/* Sign in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.signin-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 36px 32px; text-align: center; max-width: 380px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.signin-card h1 { font-size: 26px; }

/* Top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.project-pick { width: auto; min-width: 180px; max-width: 280px; }
.tabs { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.tab { font: inherit; font-weight: 600; font-size: 14px; padding: 7px 14px; border-radius: 999px; border: 0; background: none; color: var(--ink-soft); cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.tab[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent-strong); }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent); color: #fff; }
.status { margin: 0; padding: 0 20px; min-height: 0; color: var(--ink-soft); font-size: 14px; }
.status:not(:empty) { padding: 8px 20px; background: var(--warn-wash); color: var(--warn); }

main { padding: 20px; max-width: 1240px; margin: 0 auto; }
.panel { display: flex; flex-direction: column; gap: 16px; }
.panel-head { display: flex; flex-direction: column; gap: 2px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }

/* Characters */
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.char { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.char-portrait { aspect-ratio: 3 / 4; background: #EEF1F5; display: grid; place-items: center; color: var(--ink-faint); font-size: 14px; text-align: center; padding: 10px; }
.char-portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.char-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.add-card { max-width: 520px; }
.err { color: var(--bad); font-size: 13.5px; margin: 0; }

/* Scenes */
.scenes-layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.scene-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 70px; }
.scene-list ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.scene-list li button { width: 100%; text-align: left; font: inherit; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; color: var(--ink); }
.scene-list li button[aria-current="true"] { background: var(--accent-wash); }
.mini-form { display: flex; flex-direction: column; gap: 6px; }
.badge { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: #EEF1F5; color: var(--ink-soft); white-space: nowrap; }
.badge.queued, .badge.assembling { background: var(--accent-wash); color: var(--accent-strong); }
.badge.done { background: var(--good-wash); color: var(--good); }
.badge.failed { background: var(--bad-wash); color: var(--bad); }
.scene-detail { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.scene-head { display: grid; grid-template-columns: 90px 1fr 140px; gap: 10px; }
.progress { height: 8px; background: #EEF1F5; border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); }
.final video { width: 100%; max-height: 70vh; background: #000; border-radius: 8px; }
.shots { display: flex; flex-direction: column; gap: 12px; }
.shot { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; grid-template-columns: 40px 1fr 280px; gap: 14px; }
.shot-no { font-weight: 700; font-size: 18px; color: var(--ink-faint); }
.shot-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shot-form .wide { grid-column: 1 / -1; }
.who { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.who label { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.who input { width: auto; }
.shot-media { display: flex; flex-direction: column; gap: 6px; }
.shot-media img, .shot-media video { width: 100%; border-radius: 8px; background: #EEF1F5; display: block; }
.shot-media .placeholder { aspect-ratio: 16 / 9; border-radius: 8px; background: #EEF1F5; display: grid; place-items: center; color: var(--ink-faint); font-size: 13px; text-align: center; padding: 8px; }
.steps-done { display: flex; gap: 6px; flex-wrap: wrap; }
.step { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #EEF1F5; color: var(--ink-faint); }
.step.ok { background: var(--good-wash); color: var(--good); }

/* Queue */
.queue { display: flex; flex-direction: column; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat strong { display: block; font-size: 22px; }
.run { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.run pre { margin: 0; max-height: 260px; overflow: auto; background: #0F1729; color: #D7E0F4; border-radius: 8px; padding: 10px; font-size: 12.5px; white-space: pre-wrap; }
.steps { margin: 0; padding-left: 20px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 260px; width: auto; }

@media (max-width: 860px) {
  .scenes-layout { grid-template-columns: 1fr; }
  .scene-list { position: static; }
  .shot { grid-template-columns: 1fr; }
  .shot-form { grid-template-columns: 1fr; }
  .scene-head { grid-template-columns: 1fr; }
  .tabs { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
