:root {
  --bg: #111318;
  --bg2: #16181f;
  --panel: #1e212b;
  --surface-2: #272b38;
  --field: #16181f;
  --line: #343848;
  --ink: #f2f3f5;
  --muted: #9aa0ae;
  --paper: #16181f;
  --paper-ink: #f2f3f5;
  --accent: #8ba4ff;
  --accent-ink: #12141c;
  --accent2: #8ba4ff;
  --ok: #7dcea0;
  --warn: #e0c36b;
  --bad: #e06b73;
  --queued: #8ba4ff;
  --gen: #6ee0d6;
  --live: #6ee0d6;
  --shadow: 0 18px 50px rgba(0, 0, 0, .4);
  --sans: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); }
button, input, textarea, select { font-family: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1100px 480px at 50% -8%, #2a3358 0%, transparent 58%),
    var(--bg);
}
.login-card {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
}
.brand { padding: 0 8px 18px; }
.brand .mark { font-size: 26px; letter-spacing: .06em; padding: 0; margin: 0; }
.brand-sub {
  font-size: 11px;
  letter-spacing: .16em;
  color: var(--muted);
  margin-top: 2px;
}
.mark {
  font-size: 36px;
  font-weight: 600;
  letter-spacing: .04em;
  margin: 0 0 6px;
}
.sub { color: var(--muted); margin: 0 0 28px; font-size: 13px; letter-spacing: .08em; }
.auth-switch { margin: 16px 0 0; text-align: center; font-size: 13px; color: var(--muted); }
.auth-switch a { color: var(--accent); text-decoration: none; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
input, textarea, select {
  width: 100%;
  background: var(--field);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.paper {
  background: var(--paper);
  color: var(--paper-ink);
  border-color: var(--line);
  min-height: 380px;
  font-size: 15px;
}
.btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ok { background: var(--accent); color: var(--accent-ink); }
.btn.bad { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
label.btn { display: inline-flex; align-items: center; justify-content: center; }
.err { color: var(--bad); min-height: 1.2em; font-size: 13px; margin: 8px 0; }

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.side {
  background: var(--bg2);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.side .mark { font-size: 26px; letter-spacing: .06em; padding: 0 8px 0; }
.nav {
  display: block;
  color: var(--muted);
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 999px;
}
.nav:hover { color: var(--ink); background: var(--surface-2); }
.nav.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--ink); }
.side .who { margin-top: auto; padding: 12px 8px 0; font-size: 12px; color: var(--muted); }
.main { padding: 18px 32px 48px; overflow: auto; }
.chrome {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
}
.chrome .btn { padding: 8px 14px; }
.top {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px;
}
h1 { font-weight: 600; font-size: 28px; margin: 0; }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: inherit;
  display: block;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card h3 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--field); color: var(--muted); }
.pill.queued { color: var(--queued); }
.pill.generating { color: var(--gen); }
.pill.done { color: var(--ok); }
.pill.failed { color: var(--bad); }
.pill.draft { color: var(--muted); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; }
  .cols, .cols-3 { grid-template-columns: 1fr; }
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.elapsed { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar {
  height: 6px; background: var(--field); border-radius: 99px; overflow: hidden; min-width: 80px;
}
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; }
.log {
  background: var(--field); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; height: 220px; overflow: auto; font-size: 12px; color: var(--muted);
}
.engine { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--ok); }
.modal {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 40;
}
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.55);
}
.modal .box {
  width: min(520px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; position: relative; z-index: 1;
}
video { width: 100%; border-radius: 12px; background: #000; max-height: 360px; }
.player {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center;
}
.player[hidden] { display: none !important; }
.player-mask { position: absolute; inset: 0; background: rgba(0,0,0,.72); }
.player-box {
  position: relative; z-index: 1; width: min(960px, 94vw);
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 18px; box-shadow: var(--shadow);
}
.player-bar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 10px; color: var(--muted); font-size: 13px;
}
.player-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-box video { max-height: min(72vh, 640px); background: #000; }
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 60; display: none; max-width: min(640px, 90vw);
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 18px; box-shadow: var(--shadow); font-size: 14px;
}
#toast.on { display: block; }
#toast.bad { border-color: var(--bad); color: #f0c8c0; }
.format-hint {
  background: var(--field); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin: 0 0 16px; font-size: 13px; color: var(--muted); line-height: 1.55;
}
.format-hint code { color: var(--accent); }
.still-box {
  margin: 12px 0 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.still-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.still-title { font-size: 16px; font-weight: 600; }
.still-roles { margin: 10px 0 4px; }
#still-prompt { min-height: 110px; }
.still-current { margin-top: 12px; }
.still-current img, .still-card img {
  width: 100%; max-height: 180px; object-fit: cover; border-radius: 10px; background: var(--field);
}
.still-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; margin-top: 12px;
}
.still-card { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.still-card.on { border-color: var(--ok); }
.write-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.write-box #write-brief { min-height: 90px; }
.cast-list { display: grid; gap: 8px; }
.cast-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.cast-card select { width: auto; min-width: 88px; }
.cast-card input { min-width: 0; flex: 1; }
.cast-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.cast-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--field);
  display: grid;
  place-items: center;
}
.cast-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cast-empty { color: var(--muted); font-size: 12px; }
.cast-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.cast-actions .btn { padding: 8px 10px; }
.cast-body { margin-top: 8px; }
.cast-body textarea { min-height: 72px; }
.cast-still { margin-top: 8px; }
.cast-still img {
  width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; background: var(--field);
}
.show-tabs {
  display: flex;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--field);
  padding: 4px;
  gap: 0;
}
.show-tabs button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 18px;
  font-weight: 600;
  border-radius: 999px;
}
.show-tabs button.on { background: var(--accent); color: var(--accent-ink); }
.show-deck { overflow: hidden; touch-action: pan-y; }
.show-track {
  display: flex;
  width: 200%;
  transition: transform .28s ease;
}
.show-track.story { transform: translateX(-50%); }
.show-pane { width: 50%; min-width: 0; padding-right: 8px; }
.show-pane + .show-pane { padding-right: 0; padding-left: 8px; }
.ep-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  flex-wrap: wrap;
}
.ep-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}
.ep-chips button {
  background: var(--field);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 600;
}
.ep-chips button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.show-pane #style, .show-pane #world { min-height: 88px; }
.fold { margin-top: 12px; }
.fold summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.first-frame {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 12px;
  align-items: start;
  margin-top: 8px;
}
.first-preview {
  background: var(--field);
  border-radius: 10px;
  min-height: 94px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
}
.first-preview img { width: 100%; height: 94px; object-fit: cover; display: block; }
#first-prompt { min-height: 94px; }
.still-grid.compact { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.still-grid.compact img { max-height: 64px; }
@media (max-width: 720px) {
  .cast-row { grid-template-columns: 48px 1fr; }
  .cast-actions { grid-column: 1 / -1; }
  .first-frame { grid-template-columns: 1fr; }
}
