:root {
  --bg: #0b0e1a; --panel: #121627; --panel2: #181d33; --line: #262c47; --line2: #343b5e;
  --text: #e8ebf7; --dim: #9aa3c4; --faint: #6b7396;
  --accent: #4d7dff; --accent2: #7c5cff; --ok: #3ecf8e; --warn: #f5b942; --err: #ff6b6b;
  --r: 10px;
  --well: #0005; --sunk: #0003; --hover: #ffffff0a; --codebg: #05060d;
  color-scheme: dark;
}
/* 浅色主题。视频框保持深色：成片要在暗底上看才准 */
:root[data-theme="light"] {
  --bg: #f4f5f8; --panel: #ffffff; --panel2: #f1f3f8; --line: #e3e6ee; --line2: #cfd4e1;
  --text: #1c2030; --dim: #5b6480; --faint: #8a92aa;
  --accent: #2f62f0; --accent2: #6a48e8; --ok: #17995f; --warn: #b7791f; --err: #d64545;
  --well: #1c203010; --sunk: #1c203008; --hover: #1c20300d; --codebg: #f1f3f8;
  color-scheme: light;
}
:root[data-theme="light"] .stagebox .state, :root[data-theme="light"] .thumb { color: #9aa3c4; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.6 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; display: flex; flex-direction: column; }
button, select, input, textarea { font: inherit; color: inherit; }
.spacer { flex: 1; }

.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand small { font-weight: 400; color: var(--faint); font-size: 12px; }
.mark { width: 18px; height: 18px; border-radius: 5px; background: conic-gradient(from 210deg, var(--accent), var(--accent2), #ff5ea8, var(--accent)); }
select, input[type=text], input[type=password], textarea { background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 6px 10px; outline: none; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
#projectSelect { max-width: 260px; }
.btn { background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
a.btn { color: var(--text); text-decoration: none; display: inline-block; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger:hover:not(:disabled) { border-color: var(--err); color: var(--err); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line2); color: var(--dim); white-space: nowrap; }
.pill::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--faint); }
.pill.ok::before { background: var(--ok); } .pill.warn::before { background: var(--warn); } .pill.err::before { background: var(--err); }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 30%) 1fr; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 94%; padding: 10px 13px; border-radius: 12px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: stretch; max-width: 100%; padding: 2px 2px; display: flex; flex-direction: column; gap: 8px; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 4px 0 6px; padding-left: 20px; }
.msg code { background: var(--well); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.msg table { border-collapse: collapse; margin: 6px 0; font-size: 12.5px; display: block; overflow-x: auto; }
.msg th, .msg td { border: 1px solid var(--line2); padding: 3px 8px; text-align: left; white-space: nowrap; }
.msg th { color: var(--dim); font-weight: 600; }
.typing > :last-child::after { content: "▍"; animation: blink 1s steps(2) var(--sync, 0s) infinite; color: var(--accent); }
/* 步骤行：图标 + 名称 + 一行灰字 + 状态。多步折成一行，点开列出每一步 */
.steps { border: 1px solid var(--line); border-radius: 10px; background: var(--sunk); overflow: hidden; }
.step { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; background: none; border: 0; text-align: left; font-size: 13px; cursor: pointer; }
.step:hover:not(:disabled) { background: var(--hover); }
.step:disabled { cursor: default; }
.step .ico { flex: none; width: 18px; text-align: center; font-size: 13px; }
.step b { flex: none; font-weight: 600; }
.step .detail { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--faint); font-size: 12px; }
.step .cnt { flex: none; font-size: 11px; color: var(--dim); border: 1px solid var(--line2); border-radius: 999px; padding: 0 7px; }
.step .st { flex: none; width: 16px; text-align: center; font-weight: 700; font-size: 12px; }
.step.ok .st { color: var(--ok); } .step.bad .st { color: var(--warn); } .step.bad .detail { color: var(--warn); }
.step .spin { width: 12px; height: 12px; margin: 0; animation-delay: var(--sync, 0s); }
.step .chev { flex: none; color: var(--faint); transition: transform .15s; }
.steps.open > .sum .chev { transform: rotate(90deg); }
.sub { border-top: 1px solid var(--line); padding: 2px 0 2px 12px; }
.btn.stop { border-color: var(--err); color: var(--err); }
.drawer { position: fixed; inset: 0; background: #0008; z-index: 9; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-box { width: min(620px, 100%); height: 100%; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line2); padding: 18px 20px; box-shadow: -12px 0 40px #0008; }
.drawer-head { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.drawer-sub { color: var(--dim); margin: 6px 0 4px; overflow-wrap: anywhere; }
.drawer-box h4 { margin: 16px 0 6px; font-size: 12px; color: var(--dim); font-weight: 600; }
.drawer-box pre { margin: 0; background: var(--well); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.badge { font-size: 11px; border-radius: 999px; padding: 1px 8px; border: 1px solid var(--line2); }
.badge.ok { color: var(--ok); border-color: var(--ok); } .badge.bad { color: var(--warn); border-color: var(--warn); }
.thinking { color: var(--dim); font-size: 13px; padding: 2px 0; }
.thinking > .spin { width: 12px; height: 12px; margin-right: 8px; animation-delay: var(--sync, 0s); }
/* 只露出最后两行，从右下往上顶，像滚动字幕 */
.thought { margin-top: 4px; font-size: 12px; line-height: 1.5; height: 3em; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; color: var(--faint); border-left: 2px solid var(--line2); padding-left: 8px; }

@keyframes blink { 50% { opacity: 0; } }
.welcome { color: var(--dim); padding: 8px 4px; }
.welcome h3 { color: var(--text); margin: 0 0 6px; font-size: 16px; }
.suggest { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.suggest button { text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer; color: var(--text); }
.suggest button:hover { border-color: var(--accent); }
.composer { border-top: 1px solid var(--line); padding: 12px; }
.composer textarea { width: 100%; resize: none; display: block; }
.composer-row { display: flex; align-items: center; margin-top: 8px; }
.hint { color: var(--faint); font-size: 12px; flex: 1; }

.work { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.tabs { display: flex; align-items: center; gap: 6px; padding: 10px 16px 0; border-bottom: 1px solid var(--line); }
.tabs > button[data-tab] { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 14px; cursor: pointer; color: var(--dim); font-weight: 600; }
.tabs > button[data-tab].on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .btn { margin-bottom: 8px; }
.summary { padding: 12px 16px 0; display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.summary h2 { margin: 0; font-size: 18px; }
.summary .meta { color: var(--dim); font-size: 13px; }
.summary .brief { flex-basis: 100%; color: var(--dim); margin: 0; }
.panel { flex: 1; overflow-y: auto; padding: 16px; }
.empty { border: 1px dashed var(--line2); border-radius: var(--r); padding: 48px 24px; text-align: center; color: var(--dim); }
.empty h3 { color: var(--text); margin: 0 0 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; }
.card.dirty { border-color: #f5b94266; }
.stagebox { aspect-ratio: 16 / 9; background: #05060d; position: relative; display: flex; align-items: center; justify-content: center; }
.stagebox video, .stagebox img { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.stagebox .beam { position: absolute; inset: 0; opacity: .5; background: radial-gradient(ellipse 45% 95% at 50% 0%, var(--c, #2b6cff), transparent 70%); }
.stagebox .state { position: relative; color: var(--dim); font-size: 13px; text-align: center; padding: 0 16px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { display: flex; align-items: baseline; gap: 8px; }
.card-title .n { color: var(--faint); font-variant-numeric: tabular-nums; font-weight: 700; }
.card-title b { flex: 1; }
.card-title .dur { color: var(--dim); font-size: 12px; white-space: nowrap; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.chip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.chip.seg { color: var(--text); border-color: var(--line2); }
.action { color: var(--dim); font-size: 13px; margin: 0; flex: 1; }
.err { color: var(--err); font-size: 12px; margin: 0; overflow-wrap: anywhere; }
.note { color: var(--warn); font-size: 12px; margin: 0; }
.card-foot { display: flex; gap: 6px; flex-wrap: wrap; }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.block h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.block h3 small { color: var(--faint); font-weight: 400; }
.block p { margin: 0 0 8px; color: var(--dim); }
.block .en { font-size: 12px; color: var(--faint); font-family: ui-monospace, Menlo, monospace; }
.refrow { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.refrow:first-of-type { border-top: none; }
.thumb { width: 120px; flex: none; aspect-ratio: 16/9; background: #05060d; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 12px; text-align: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.thumb.big { width: 100%; }
.lib { display: grid; gap: 6px; }
.lib div { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.lib .used { color: var(--accent); font-size: 12px; white-space: nowrap; }
.lib span.d { color: var(--faint); font-size: 12px; }
.finalbox { max-width: 960px; margin: 0 auto; }
.finalbox video { width: 100%; border-radius: var(--r); background: #000; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }

.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 10; padding: 24px; }
.modal[hidden], .toast[hidden] { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; padding: 20px; width: min(760px, 100%); max-height: 100%; overflow-y: auto; }
.modal-box h3 { margin: 0 0 14px; }
.modal-box img.full { width: 100%; border-radius: 8px; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { color: var(--dim); font-size: 13px; }
.field input, .field select { width: 100%; }
.field small { color: var(--faint); }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 14px; padding: 12px 14px 2px; }
legend { color: var(--dim); padding: 0 6px; }
pre { background: var(--codebg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; max-height: 320px; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); border-radius: 10px; padding: 10px 16px; z-index: 20; max-width: 80vw; }
.toast.bad { border-color: var(--err); }

.stagebox .state .bar { height: 4px; width: 160px; max-width: 80%; margin: 10px auto 0; background: var(--line2); border-radius: 2px; overflow: hidden; }
.stagebox .state .bar i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.grip { cursor: grab; color: var(--faint); user-select: none; padding: 0 2px; }
.grip:hover { color: var(--text); }
.card.dragging { opacity: .4; }
.card.drop-before { box-shadow: -3px 0 0 var(--accent); }
.card.drop-after { box-shadow: 3px 0 0 var(--accent); }
button.chip { cursor: pointer; font: inherit; font-size: 12px; }
button.chip.take:hover:not(:disabled):not(.on) { border-color: var(--accent); color: var(--text); }
button.chip.take.on { background: var(--accent); border-color: var(--accent); color: #fff; cursor: default; }
button.chip:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger:not(.ghost) { color: var(--err); border-color: #ff6b6b66; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field textarea { width: 100%; resize: vertical; }
.field input[type=number] { background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 6px 10px; outline: none; }
.field label { display: flex; align-items: center; gap: 8px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.checks { display: flex; gap: 6px 14px; flex-wrap: wrap; }
.checks label { display: flex; align-items: center; gap: 5px; color: var(--text); cursor: pointer; white-space: nowrap; }
.checks input { width: auto; margin: 0; }
.block h3 .btn { font-weight: 400; }
.summary .btn { align-self: center; }
small.hint { display: block; }
.thumb span { padding: 0 6px; }

@media (max-width: 900px) {
  .two { grid-template-columns: 1fr; }
  main { grid-template-columns: 1fr; grid-template-rows: 46vh 1fr; }
  .chat { border-right: none; border-bottom: 1px solid var(--line); }
  .brand small { display: none; }
}
