:root {
  --bg: #0b0c0f;
  --bg-2: #111318;
  --panel: #15171d;
  --panel-2: #1b1e26;
  --line: #262a35;
  --line-2: #323745;
  --text: #eceef3;
  --muted: #9aa1b2;
  --faint: #6b7284;
  --accent: #ff6a3d;
  --accent-2: #ff9a5a;
  --accent-soft: rgba(255, 106, 61, .12);
  --ok: #3ccf91;
  --warn: #f5b942;
  --err: #ff5d6c;
  --info: #6aa7ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .35);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f5f2; --bg-2: #efede8; --panel: #ffffff; --panel-2: #f7f6f3; --line: #e5e2db; --line-2: #d6d2c9;
    --text: #16171b; --muted: #5d6270; --faint: #8b909c; --accent-soft: rgba(255, 106, 61, .1);
    --shadow: 0 10px 30px rgba(20, 20, 30, .08); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f6f5f2; --bg-2: #efede8; --panel: #ffffff; --panel-2: #f7f6f3; --line: #e5e2db; --line-2: #d6d2c9;
  --text: #16171b; --muted: #5d6270; --faint: #8b909c; --accent-soft: rgba(255, 106, 61, .1);
  --shadow: 0 10px 30px rgba(20, 20, 30, .08); color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
::selection { background: var(--accent); color: #fff; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 24px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; font-size: 17px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { padding: 7px 13px; border-radius: 8px; color: var(--muted); font-weight: 500; font-size: 14px; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a.active { color: var(--text); background: var(--panel-2); }
.topbar .spacer { flex: 1; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 32px 28px 80px; }

/* ---------- primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 15px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer;
  font-weight: 600; font-size: 14px; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff7b52; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.danger:hover { border-color: var(--err); color: var(--err); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn.icon { width: 34px; padding: 0; }
.btn.lg { height: 46px; padding: 0 22px; font-size: 15px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.input, .select, textarea.input { appearance: none; -webkit-appearance: none;
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--bg-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 90px; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: .01em; }
.hint { font-size: 12.5px; color: var(--faint); margin-top: 6px; }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
h1 { font-size: 30px; letter-spacing: -.03em; margin: 0 0 6px; line-height: 1.15; }
h2 { font-size: 19px; letter-spacing: -.02em; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0 0 10px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); } .badge.err { color: var(--err); } .badge.run { color: var(--warn); } .badge.queue { color: var(--info); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 36px; height: 20px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }

.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.25); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 70% -10%, rgba(255,106,61,.18), transparent 60%), var(--bg); }
.auth .card { width: 100%; max-width: 400px; padding: 34px; box-shadow: var(--shadow); }
.auth .brand { margin-bottom: 26px; }

/* ---------- home ---------- */
.hero { display: grid; grid-template-columns: 1.15fr 1fr; gap: 24px; margin-bottom: 40px; }
.hero-text { padding: 8px 4px; }
.hero-text p { color: var(--muted); max-width: 52ch; font-size: 16px; }
.feature-list { list-style: none; padding: 0; margin: 22px 0 0; display: grid; gap: 10px; }
.feature-list li { display: flex; gap: 10px; color: var(--muted); font-size: 14px; }
.feature-list li svg { width: 18px; height: 18px; color: var(--accent); flex: none; margin-top: 2px; }
.new-card { padding: 22px; box-shadow: var(--shadow); }
.dropzone { display: block;
  border: 1.5px dashed var(--line-2); border-radius: 12px; padding: 30px 18px; text-align: center; cursor: pointer;
  background: var(--bg-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { width: 34px; height: 34px; color: var(--accent); margin: 0 auto 10px; }
.dropzone strong { display: block; font-size: 15px; }
.dropzone .file-name { margin-top: 8px; font-family: var(--mono); font-size: 13px; color: var(--accent-2); word-break: break-all; }
.tabs-mini { display: flex; gap: 18px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs-mini button { background: none; border: 0; padding: 0 0 10px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs-mini button.on { color: var(--text); border-color: var(--accent); }
.opts { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.progress-upload { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 14px; }
.progress-upload > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.job-card { overflow: hidden; transition: border-color .15s, transform .15s; display: block; }
.job-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.job-thumb { aspect-ratio: 16/10; background: var(--bg-2); display: grid; place-items: center; overflow: hidden; position: relative; }
.job-thumb img { width: 100%; height: 100%; object-fit: cover; }
.job-thumb svg { width: 30px; height: 30px; color: var(--faint); }
.job-thumb .badge { position: absolute; top: 10px; left: 10px; background: rgba(10,10,12,.75); border-color: transparent; backdrop-filter: blur(6px); }
.job-body { padding: 12px 14px 14px; }
.job-body .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-body .meta { font-size: 12.5px; color: var(--faint); margin-top: 3px; }
.mini-bar { height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.mini-bar > div { height: 100%; background: var(--warn); }
.empty { padding: 48px 20px; text-align: center; color: var(--faint); border: 1px dashed var(--line-2); border-radius: var(--radius); }

/* ---------- job page ---------- */
.job-head { display: flex; gap: 20px; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; }
.job-head .title-edit { font-size: 28px; font-weight: 800; letter-spacing: -.03em; outline: none; border-radius: 6px; padding: 0 4px; margin-left: -4px; }
.job-head .title-edit:focus { background: var(--panel-2); }
.stats { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 6px; color: var(--muted); font-size: 13.5px; }
.stats b { color: var(--text); font-weight: 600; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.running-card { padding: 34px; text-align: center; max-width: 640px; margin: 40px auto; }
.running-card .big-bar { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin: 22px 0 12px; }
.running-card .big-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .5s; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .9s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { padding: 16px 18px; border: 1px solid color-mix(in srgb, var(--err) 45%, transparent); background: color-mix(in srgb, var(--err) 9%, transparent); border-radius: 12px; color: var(--text); text-align: left; margin: 18px 0; }

.job-layout { display: grid; grid-template-columns: 380px 1fr; gap: 24px; align-items: start; }
.side { position: sticky; top: 78px; display: grid; gap: 16px; }
.player { overflow: hidden; }
.player video { width: 100%; max-height: 62vh; background: #000; display: block; }
.player .now { padding: 10px 14px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.timeline { position: relative; height: 34px; margin: 0 14px 14px; border-radius: 6px; overflow: hidden; display: flex; background: var(--bg-2); cursor: pointer; }
.timeline .tl-seg { height: 100%; border-right: 1px solid var(--bg); background: var(--panel-2); transition: background .15s; position: relative; }
.timeline .tl-seg:nth-child(odd) { background: color-mix(in srgb, var(--panel-2) 70%, var(--line-2)); }
.timeline .tl-seg.on { background: var(--accent) !important; }
.timeline .tl-head { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; pointer-events: none; box-shadow: 0 0 6px rgba(0,0,0,.6); }
.side-block { padding: 16px 18px; }
.side-block p { margin: 0; color: var(--muted); font-size: 14px; }
.chars { display: grid; gap: 10px; }
.char { padding: 10px 12px; background: var(--bg-2); border-radius: 10px; border: 1px solid var(--line); font-size: 13.5px; }
.char b { display: block; margin-bottom: 2px; }
.char .v { color: var(--accent-2); font-size: 12.5px; margin-top: 4px; }

.main-tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.main-tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.main-tabs button.on { color: var(--text); border-color: var(--accent); }
.main-tabs .count { font-size: 11.5px; background: var(--panel-2); border-radius: 99px; padding: 1px 7px; margin-left: 4px; color: var(--muted); }

.synopsis-card { padding: 18px 20px; margin-bottom: 18px; }
.synopsis-card .style { color: var(--accent-2); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.synopsis-card .syn { outline: none; border-radius: 6px; }
.synopsis-card .syn:focus { background: var(--panel-2); }
.dialogue-list { margin-top: 14px; display: grid; gap: 6px; font-size: 14px; }
.dl { display: grid; grid-template-columns: 52px 1fr; gap: 10px; }
.dl .t { font-family: var(--mono); font-size: 12px; color: var(--faint); padding-top: 2px; }
.dl .sp { font-weight: 600; }
.dl .vo { color: var(--muted); font-style: italic; }

.shots { display: grid; gap: 16px; }
.shot { overflow: hidden; scroll-margin-top: 90px; transition: border-color .2s, box-shadow .2s; }
.shot.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.shot-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.shot-num { font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.shot-num span { color: var(--accent); }
.shot-time { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.shot-head .spacer { flex: 1; }
.filmstrip { display: flex; gap: 6px; padding: 12px 16px 0; overflow-x: auto; scrollbar-width: thin; }
.filmstrip button { padding: 0; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #000; cursor: pointer; flex: none; position: relative; }
.filmstrip img { height: 92px; width: auto; }
.filmstrip button span { position: absolute; bottom: 3px; right: 4px; font: 500 10.5px var(--mono); background: rgba(0,0,0,.7); color: #fff; padding: 0 4px; border-radius: 3px; }
.shot-body { padding: 14px 16px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; }
.f { min-width: 0; }
.f.full { grid-column: 1 / -1; }
.f .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); font-weight: 600; margin-bottom: 2px; }
.f .v { font-size: 14px; outline: none; border-radius: 5px; padding: 1px 4px; margin: 0 -4px; white-space: pre-wrap; word-wrap: break-word; }
.f .v[contenteditable="true"]:hover { background: var(--bg-2); }
.f .v[contenteditable="true"]:focus { background: var(--bg-2); box-shadow: 0 0 0 1px var(--line-2); }
.beats { display: grid; gap: 6px; }
.beat { display: grid; grid-template-columns: 86px 1fr; gap: 8px; font-size: 14px; }
.beat .t { font-family: var(--mono); font-size: 12px; color: var(--accent-2); padding-top: 2px; cursor: pointer; }
.beat .t:hover { text-decoration: underline; }
.dlg { display: grid; gap: 4px; font-size: 14px; }
.prompt-box { grid-column: 1 / -1; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; position: relative; }
.prompt-box .k { display: flex; align-items: center; justify-content: space-between; }
.prompt-box .v { font-size: 14px; }
.prompt-box .dl-in { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line-2); font-size: 13.5px; color: var(--muted); }

.raw { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; font: 13.5px/1.6 var(--mono); white-space: pre-wrap; word-wrap: break-word; max-height: none; }

/* ---------- settings ---------- */
.settings { max-width: 860px; }
.settings .card { padding: 24px; margin-bottom: 20px; }
.key-status { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 14px; }

/* ---------- menu ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 6px; box-shadow: var(--shadow); z-index: 40; display: none; }
.menu.open { display: block; }
.menu button { display: flex; width: 100%; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 10px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left; font-size: 14px; }
.menu button:hover { background: var(--panel-2); }
.menu button small { color: var(--faint); font-family: var(--mono); }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--ok); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; max-width: 380px; animation: tin .25s ease-out; }
.toast.err { border-left-color: var(--err); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .job-layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .player video { max-height: 50vh; }
}
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .opts { grid-template-columns: 1fr; }
  .shot-body { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .wrap { padding: 20px 16px 60px; }
  .topbar { padding: 12px 16px; gap: 10px; }
  .brand span.txt { display: none; }
  .nav a { padding: 7px 9px; }
  h1 { font-size: 24px; }
  .job-head .title-edit { font-size: 22px; }
  .filmstrip img { height: 70px; }
  .beat { grid-template-columns: 1fr; gap: 0; }
}
select.input { padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa1b2' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; text-overflow: ellipsis; }
.dropzone svg { display: block; }
.dropzone > span { display: block; }
