:root {
  --bg: #0e0f13; --panel: #15171d; --raised: #1c1f27; --line: #2a2e39; --ink: #eceef3; --mute: #9299a8; --faint: #636a79;
  --accent: #e6ad45; --accent-ink: #1a1405; --good: #5cc98b; --bad: #f0706a; --warn: #e6ad45;
  --radius: 10px; --font: -apple-system, "SF Pro Text", "Inter", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
#app { display: grid; grid-template-columns: 250px minmax(0, 1fr) 360px; height: 100vh; }

/* ---- sidebar ---- */
#side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #c9772e); display: inline-block; }
.label { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); margin-top: 12px; }
#projects { overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.proj { padding: 9px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.proj:hover { background: var(--raised); }
.proj.on { background: var(--raised); border-color: var(--line); }
.proj .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj .meta { font-size: 12px; color: var(--mute); display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.live { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.done { background: var(--good); }
@keyframes pulse { 50% { opacity: .3; } }
.foot { font-size: 12px; color: var(--faint); }

/* ---- buttons, fields ---- */
.btn { border: 1px solid var(--line); background: var(--raised); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: var(--faint); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
a.btn { color: inherit; }
a.btn.wide { display: block; text-align: center; text-decoration: none; }
a.btn.primary, .btn.primary small { color: var(--accent-ink) !important; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
input[type=text], textarea, select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; outline: none; }
input[type=text]:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.45; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--mute); }

/* ---- main ---- */
#main { min-width: 0; overflow: auto; }
.head { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: 16px 28px 0; }
.head h1 { font-size: 20px; margin: 0 0 2px; letter-spacing: -.01em; }
.head .sub { color: var(--mute); font-size: 13px; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 9px 14px; cursor: pointer; color: var(--mute); border-bottom: 2px solid transparent; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); border-color: var(--accent); }
.tab .n { font-size: 11px; width: 18px; height: 18px; border-radius: 50%; background: var(--raised); display: grid; place-items: center; color: var(--mute); }
.tab.ready .n { background: var(--good); color: #06210f; }
.body { padding: 24px 28px 80px; max-width: 1180px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hint { color: var(--mute); font-size: 13px; }
.warn { color: var(--warn); font-size: 13px; }
.empty { text-align: center; color: var(--mute); padding: 70px 20px; }
.empty .big { font-size: 17px; color: var(--ink); font-weight: 600; margin-bottom: 6px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -4px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* new video */
.new { max-width: 720px; margin: 7vh auto; padding: 0 28px; }
.new h1 { font-size: 30px; letter-spacing: -.02em; margin: 0 0 6px; }
.new p.lede { color: var(--mute); margin: 0 0 24px; font-size: 15px; }
.new .grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.new form { display: flex; flex-direction: column; gap: 14px; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; background: var(--bg); }
.choice b { display: block; }
.choice small { color: var(--mute); }
.choice.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--bg)); }

/* markdown */
.md { line-height: 1.6; font-size: 15px; }
.md h1 { font-size: 24px; margin: 0 0 14px; letter-spacing: -.01em; }
.md h2 { font-size: 13px; margin: 24px 0 6px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.md h3 { font-size: 15px; margin: 16px 0 4px; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code { background: var(--raised); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 8px 0 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--raised); white-space: nowrap; }
.md a { color: var(--accent); }
.outline-edit { min-height: 520px; font: 14px/1.55 ui-monospace, "SF Mono", Menlo, monospace; }

/* storyboard */
.stage { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(240px, 1fr); gap: 18px; margin-bottom: 22px; }
video { width: 100%; border-radius: var(--radius); background: #000; display: block; aspect-ratio: 16/9; }
.facts-mini { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.facts-mini div { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.facts-mini b { display: block; font-size: 18px; }
.facts-mini span { color: var(--mute); font-size: 12px; }
.beat { display: grid; grid-template-columns: 34px 200px minmax(0, 1.25fr) minmax(0, 1fr) 30px; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); align-items: start; }
.beat .num { color: var(--faint); font-variant-numeric: tabular-nums; padding-top: 4px; text-align: right; }
.beat .thumb { aspect-ratio: 16/9; background: var(--raised); border-radius: 6px; overflow: hidden; cursor: pointer; position: relative; border: 1px solid var(--line); }
.beat .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.beat .thumb .none { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 12px; }
.beat .time { font-size: 11px; color: var(--mute); margin-top: 4px; display: flex; justify-content: space-between; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 2px 7px; border-radius: 5px; background: var(--raised); color: var(--mute); border: 1px solid var(--line); }
.beat textarea { min-height: 76px; font-size: 14px; }
.beat .shot { display: flex; flex-direction: column; gap: 6px; }
.beat .shot label { display: grid; grid-template-columns: 74px 1fr; gap: 8px; align-items: center; font-size: 12px; color: var(--mute); }
.beat .shot input { padding: 5px 8px; font-size: 13px; }
.beat .tools { display: flex; flex-direction: column; gap: 4px; }
.icon { width: 28px; height: 26px; border-radius: 6px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--mute); font-size: 13px; }
.icon:hover { background: var(--raised); color: var(--ink); border-color: var(--line); }
.savebar { position: sticky; bottom: 16px; margin-top: 18px; background: var(--raised); border: 1px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 10px; align-items: center; box-shadow: 0 12px 40px rgba(0,0,0,.5); }

/* export */
.exp { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr); gap: 18px; }
.dl { display: flex; flex-direction: column; gap: 8px; }
.dl a { text-decoration: none; display: flex; justify-content: space-between; }
.dl a small { color: var(--mute); font-weight: 500; }
.thumbimg { width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; }
.desc { min-height: 260px; font-size: 13px; }
.credit { font-size: 13px; padding: 8px 0; border-top: 1px solid var(--line); }
.credit small { color: var(--mute); display: block; }
.yt { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.yt a, .sheet a { color: var(--accent); }
.yt .hint { margin-top: 4px; overflow-wrap: anywhere; }

/* ---- assistant panel ---- */
#panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
#progress { padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--mute); }
#progress .bar { height: 5px; background: var(--raised); border-radius: 3px; overflow: hidden; margin-bottom: 5px; }
#progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
#feed { flex: 1; overflow: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.ev { font-size: 13px; }
.ev.assistant { background: var(--raised); border: 1px solid var(--line); border-radius: 10px 10px 10px 3px; padding: 9px 12px; }
.ev.assistant .md { font-size: 13px; line-height: 1.5; }
.ev.assistant .md h1, .ev.assistant .md h2, .ev.assistant .md h3 { font-size: 13px; margin: 8px 0 3px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.ev.assistant .md p:last-child { margin: 0; }
.ev.user { align-self: flex-end; background: color-mix(in srgb, var(--accent) 18%, var(--raised)); border-radius: 10px 10px 3px 10px; padding: 8px 12px; max-width: 90%; white-space: pre-wrap; }
.ev.tool { color: var(--mute); display: flex; gap: 8px; align-items: baseline; padding-left: 2px; }
.ev.tool::before { content: "›"; color: var(--faint); }
.ev.tool span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev.note { color: var(--accent); font-weight: 600; margin-top: 6px; }
.ev.log { color: var(--faint); font: 12px/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap; }
.ev.done { color: var(--good); font-weight: 600; }
.ev.done small { color: var(--faint); font-weight: 400; margin-left: 6px; }
.ev.error { color: var(--bad); white-space: pre-wrap; }
.ev.working { color: var(--mute); }
#chat { border-top: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#chat textarea { resize: none; font-size: 13px; }
#chat .btn { align-self: flex-end; }

/* modal, toast */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; }
#modal[hidden], #toast[hidden], #progress[hidden], #stopBtn[hidden] { display: none; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(680px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.sheet h3 { margin: 0; }
.sheet textarea { min-height: 300px; font: 13px/1.5 ui-monospace, Menlo, monospace; }
.sheet.pub { max-height: 92vh; overflow: auto; }
.sheet.pub textarea { min-height: 170px; font: 13px/1.5 var(--font); }
.sheet.pub .field i { font-style: normal; font-weight: 400; color: var(--faint); margin-left: 6px; }
.sheet.pub .field i.over { color: var(--bad); }
.sheet.pub .knobs { grid-template-columns: 1fr 1fr; }
#toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-weight: 600; z-index: 30; }

@media (max-width: 1180px) {
  #app { grid-template-columns: 210px minmax(0, 1fr) 300px; }
  .beat { grid-template-columns: 26px 150px minmax(0, 1fr) 30px; }
  .beat .shot { grid-column: 3; }
  .stage, .exp { grid-template-columns: 1fr; }
}

/* knobs */
.knobs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; align-items: start; }
.knobs .wide { grid-column: 1 / -1; }
.knobs .check { display: flex; gap: 8px; align-items: center; cursor: pointer; padding-top: 4px; }
.knobs input[type=number] { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; outline: none; }
.knobs input[type=range] { width: 100%; accent-color: var(--accent); }
.knobs input[type=color] { width: 44px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.knobs input[type=checkbox], .settings input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
.knobs .field span b { color: var(--ink); margin-left: 6px; }
.more { border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; background: var(--panel); }
.more summary { cursor: pointer; font-weight: 600; padding: 12px 0; }
.more[open] { padding-bottom: 14px; }
.settings { display: flex; flex-direction: column; gap: 18px; max-width: 900px; }
.new { max-width: 820px; margin-top: 4vh; padding-bottom: 60px; }

/* Portrait creation and previews */
.format-choices { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:28px; }
.format-choices .choice { text-align:left; padding:16px; }
.concepts { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:14px; }
.portrait video { aspect-ratio:9/16; max-height:650px; width:auto; max-width:100%; margin:0 auto; }
.portrait .beat .thumb { aspect-ratio:9/16; width:95px; margin:auto; }
.portrait .thumbimg { max-width:220px; margin:auto; }
