:root {
  --ink: #17233c;
  --muted: #667085;
  --line: #e4e8f0;
  --blue: #2957e8;
  --blue-soft: #eef3ff;
  --green: #0f9f6e;
  --green-soft: #e9f8f2;
  --amber: #b76e00;
  --amber-soft: #fff5df;
  --surface: #ffffff;
  --canvas: #f5f7fb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 84px;
  padding: 18px max(24px, calc((100vw - 1480px) / 2));
  background: #101a31;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.topbar h1 { margin: 2px 0 0; font-size: 22px; }
.eyebrow, .section-kicker { font-size: 12px; letter-spacing: .08em; font-weight: 700; text-transform: uppercase; }
.eyebrow { color: #92a9e8; }
.section-kicker { color: var(--blue); }
.connection { font-size: 13px; padding: 8px 12px; border-radius: 999px; background: rgba(255,255,255,.1); color: #dce5ff; }
.connection.live { background: rgba(15,159,110,.2); color: #91ebca; }
.connection.mock { background: rgba(255,183,77,.15); color: #ffd28a; }
.connection.blocked { background: rgba(239,68,68,.16); color: #ffb1b1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.key-change-button { padding: 7px 10px; border: 1px solid rgba(255,255,255,.22); border-radius: 8px; background: transparent; color: #dce5ff; font-size: 12px; }
.key-change-button:hover { background: rgba(255,255,255,.08); }

.key-gate { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; background: rgba(9,18,38,.72); backdrop-filter: blur(5px); }
.key-gate-card { width: min(440px, 100%); padding: 28px; border-radius: 18px; background: white; box-shadow: 0 24px 80px rgba(5,14,34,.28); }
.key-gate-card h2 { margin: 7px 0 8px; font-size: 24px; }
.key-gate-card > p { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.key-gate-card .field { margin-top: 4px; }
.key-gate-error { margin: 9px 0 0 !important; color: #c03945 !important; }
.key-gate-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

main { max-width: 1480px; margin: 0 auto; padding: 24px; }
.panel, .sidebar { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }

.module-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 18px 0; }
.module-tab { min-height: 72px; border: 1px solid var(--line); border-radius: 14px; background: white; padding: 14px 18px; display: grid; gap: 4px; text-align: left; color: var(--muted); }
.module-tab b { color: var(--ink); font-size: 16px; }
.module-tab span { font-size: 12px; }
.module-tab.active { border-color: var(--blue); background: var(--blue-soft); box-shadow: 0 0 0 2px rgba(41,87,232,.06); }
.module-tab.active b { color: var(--blue); }
body[data-active-module="library"] .production-only,
body[data-active-module="production"] .library-only { display: none !important; }
body[data-active-module="library"] .asset-library-title { margin-top: 0; }

.shot-overview { margin: -2px 0 18px; padding: 14px 16px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.shot-overview-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.shot-overview-head > div { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.shot-overview-head strong { font-size: 13px; }
.shot-overview-head span { color: var(--muted); font-size: 11px; }
.shot-progress { height: 3px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: #e9edf5; }
.shot-progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), #6c86f4); transition: width .25s ease; }
.shot-list.shot-overview-list { display: flex; gap: 9px; margin-top: 10px; padding: 1px 1px 4px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
.shot-overview-list .shot-card { flex: 0 0 215px; }

.workspace { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.sidebar { padding: 18px; position: sticky; top: 18px; }
.sidebar-title { display: flex; align-items: center; justify-content: space-between; font-weight: 750; margin-bottom: 14px; }
.asset-library-title { margin-top: 18px; margin-bottom: 10px; }
.scene-roles { display: grid; gap: 8px; }
.role-card { width: 100%; display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 9px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: white; text-align: left; }
.role-card.active { border-color: var(--blue); background: var(--blue-soft); }
.role-select { grid-column: 1 / 3; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 9px; align-items: center; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; }
.role-letter { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: #eef1f6; color: var(--muted); font-size: 12px; font-weight: 800; }
.role-card.active .role-letter { background: var(--blue); color: white; }
.role-copy { min-width: 0; display: grid; gap: 3px; }
.role-copy strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.role-copy small { color: var(--muted); font-size: 10px; }
.role-remove { border: 0; background: transparent; color: #98a1b2; padding: 4px; font-size: 15px; }
.link-button { border: 0; padding: 0; background: transparent; color: var(--blue); font-size: 13px; }
.secondary { border: 1px solid #cfd6e3; border-radius: 9px; background: white; color: var(--ink); padding: 9px 12px; font-weight: 700; }
.full-button { width: 100%; margin: 10px 0 14px; color: var(--blue); border-style: dashed; }
.compact-button { min-height: 36px; padding: 8px 12px; }
.character-list { display: grid; gap: 9px; }
.character-card { border: 1px solid var(--line); border-radius: 12px; background: #fafbfe; padding: 10px; }
.character-card.selected { border-color: var(--blue); background: var(--blue-soft); }
.character-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.character-head strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.character-head span { color: var(--muted); font-size: 10px; white-space: nowrap; }
.character-thumbs { display: flex; gap: 5px; margin: 9px 0; overflow: hidden; }
.character-thumbs img, .character-thumb-placeholder { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 7px; background: #e9edf5; object-fit: cover; }
.character-actions { display: flex; gap: 7px; }
.character-actions button { flex: 1; border: 1px solid #ccd5e6; border-radius: 7px; background: white; padding: 6px; color: var(--blue); font-size: 11px; }
.character-actions .danger-link { flex: 0 0 auto; color: #b43a48; }
.character-editor { margin: 0 0 14px; padding: 12px; border: 1px solid var(--blue); border-radius: 12px; background: var(--blue-soft); }
.character-editor p { margin: 9px 0; color: var(--muted); font-size: 11px; }
.asset-pick-list { display: grid; gap: 6px; max-height: 260px; overflow: auto; }
.asset-pick { display: grid; grid-template-columns: 18px 38px minmax(0, 1fr); gap: 7px; align-items: center; padding: 6px; border-radius: 8px; background: white; font-size: 11px; }
.asset-pick input { width: auto; }
.asset-pick img { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; background: #eef1f6; }
.asset-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 10px; }
.history-assets { margin-top: 4px; }
.history-assets summary { cursor: pointer; color: var(--ink); font-size: 12px; font-weight: 800; }
.history-assets summary span { color: var(--muted); font-weight: 500; }
.asset-list { display: grid; gap: 9px; }
.selection-help { margin: 0 0 10px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.review-tracker { margin-bottom: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfe; }
.tracker-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.tracker-head strong { font-size: 12px; }
.tracker-head span { color: var(--muted); font-size: 11px; }
.tracker-row { display: grid; grid-template-columns: 38px 58px minmax(0, 1fr); gap: 7px; align-items: center; min-height: 30px; border-top: 1px solid #edf0f5; font-size: 11px; }
.tracker-row > span { color: var(--muted); }
.tracker-row b { font-weight: 750; color: #7b8497; }
.tracker-row small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.tracker-row.processing b { color: var(--amber); }
.tracker-row.success b { color: var(--green); }
.tracker-row.error b, .tracker-row.error small { color: #c03945; }
.asset-item { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 12px; text-align: left; display: grid; gap: 4px; }
.asset-card { grid-template-columns: 56px minmax(0, 1fr); gap: 10px; align-items: center; padding: 8px; }
.asset-card { position: relative; }
.asset-card.selected::after { content: attr(data-order); position: absolute; top: 6px; right: 6px; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 10px; display: grid; place-items: center; background: var(--blue); color: white; font-size: 10px; font-weight: 800; }
.role-reference-title { margin-top: 5px; color: #286a58; font-size: 12px; font-weight: 800; }
.asset-card img { width: 56px; height: 56px; border-radius: 8px; background: #eef1f6; object-fit: cover; }
.asset-card img.image-error { opacity: .22; }
.asset-info { min-width: 0; display: grid; gap: 5px; }
.asset-item:hover, .asset-item.selected { border-color: var(--blue); background: var(--blue-soft); }
.asset-item strong { font-size: 13px; }
.asset-item span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-small { color: var(--muted); font-size: 13px; padding: 18px 10px; text-align: center; border: 1px dashed #ccd3df; border-radius: 10px; }
.rule-box { margin-top: 18px; padding: 14px; border-radius: 12px; background: #f7f9fd; font-size: 12px; }
.rule-box ul { padding-left: 18px; margin: 8px 0 0; color: var(--muted); line-height: 1.7; }

.panel { padding: 24px; }
.storyboard { margin: 0 0 20px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: #f7f9fd; }
.version-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.shot-list { display: grid; gap: 8px; }
.shot-card { width: 100%; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: white; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px; align-items: center; }
.shot-card.active { border-color: var(--blue); background: var(--blue-soft); }
.shot-card-select { min-width: 0; padding: 6px; border: 0; background: transparent; display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 9px; align-items: center; text-align: left; }
.shot-number { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: #eef1f6; color: var(--muted); font-size: 11px; font-weight: 800; }
.shot-card.active .shot-number { background: var(--blue); color: white; }
.shot-card-copy { min-width: 0; display: grid; gap: 3px; }
.shot-card-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.shot-card-copy small { color: var(--muted); font-size: 10px; }
.shot-state { width: 8px; height: 8px; border-radius: 50%; background: #c5ccda; }
.shot-state.ready { background: var(--green); }
.shot-state.running { background: var(--amber); }
.shot-state.failed { background: #c03945; }
.shot-delete-button { width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; color: #9aa3b2; font-size: 18px; line-height: 1; }
.shot-delete-button:hover, .shot-delete-button:focus-visible { background: #fff0f1; color: #c03945; }
.continuity-choice { max-width: 420px; }
.production-panel-header { margin-top: 22px; }
.panel-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.panel-header.compact { margin-top: 24px; }
.panel-header h2 { font-size: 20px; margin: 6px 0 0; }
.status-badge { font-size: 12px; padding: 6px 10px; border-radius: 999px; font-weight: 700; }
.status-badge.neutral { color: #667085; background: #f0f2f5; }
.status-badge.processing { color: var(--amber); background: var(--amber-soft); }
.status-badge.success { color: var(--green); background: var(--green-soft); }
.status-badge.error { color: #c03945; background: #fff0f1; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 15px; }
.form-grid > .wide { grid-column: 1 / -1; }
.view-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.view-grid.wide { grid-column: 1 / -1; }
.view-field { display: flex; flex-direction: column; gap: 7px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfe; }
.view-field > span { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 750; }
.view-field > span b { color: var(--blue); font-size: 11px; letter-spacing: .08em; }
.view-field small { color: var(--muted); font-size: 12px; }
.mock-hint { grid-column: 1 / -1; margin: -5px 0 0; color: var(--muted); font-size: 11px; }
.mock-hint code { padding: 2px 5px; border-radius: 4px; background: #f0f2f5; color: var(--ink); }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 13px; font-weight: 700; }
.field small { color: var(--muted); font-size: 12px; }
input, select, textarea { width: 100%; border: 1px solid #cfd6e3; border-radius: 9px; padding: 10px 12px; color: var(--ink); background: white; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(41,87,232,.1); }
textarea { resize: vertical; min-height: 132px; line-height: 1.65; }
.multimodal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.media-field { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfe; }
.media-field-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.media-field-head > span { font-weight: 700; }
.media-add-button { border: 0; background: transparent; color: var(--blue); padding: 2px 0; font-size: 12px; font-weight: 700; cursor: pointer; }
.media-add-button:disabled { color: var(--muted); cursor: not-allowed; }
.media-url-list { display: grid; gap: 8px; }
.media-url-row { display: grid; grid-template-columns: minmax(0, 1fr) 30px; gap: 8px; align-items: center; }
.media-url-row input { min-width: 0; background: white; font-size: 12px; }
.media-remove-button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--muted); cursor: pointer; line-height: 1; }
.media-remove-button:hover { border-color: #f3b6b6; color: var(--danger); background: #fff6f6; }
.input-quota { padding: 10px 12px; border-radius: 9px; background: #f0f3f8; color: var(--muted); font-size: 12px; }
.input-quota.valid { color: var(--green); background: var(--green-soft); }
.input-quota.invalid { color: #c03945; background: #fff0f1; }
.action-field { justify-content: end; }
.primary { border: 0; border-radius: 9px; background: var(--blue); color: white; font-weight: 750; padding: 11px 18px; min-height: 42px; }
.primary:hover { background: #2048c7; }
.primary:disabled { background: #aab4cc; cursor: not-allowed; }
.video-button { min-width: 210px; }
.toggle-row { display: flex; gap: 9px; align-items: center; font-size: 13px; padding-top: 25px; }
.toggle-row input { width: auto; }
.disabled-section { opacity: .48; pointer-events: none; }

.result-card { margin-top: 18px; padding: 15px; border-radius: 12px; background: var(--green-soft); display: flex; gap: 13px; align-items: flex-start; }
.result-icon { width: 32px; height: 32px; border-radius: 50%; background: var(--green); color: white; display: grid; place-items: center; font-weight: 900; }
.result-card p { margin: 5px 0 8px; color: #41645a; font-size: 13px; }
.result-card code { display: inline-block; padding: 5px 8px; border-radius: 6px; background: white; color: var(--green); font-size: 12px; }
.reference-list { display: grid; gap: 6px; margin-top: 8px; }
.reference-row { display: flex; align-items: center; gap: 8px; }
.reference-row span { min-width: 34px; color: #41645a; font-size: 12px; font-weight: 700; }
hr { border: 0; border-top: 1px solid var(--line); margin: 26px 0 0; }

.generation { margin-top: 22px; padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: #fafbfe; }
.video-stage { aspect-ratio: 16 / 8; max-height: 430px; background: #111827; border-radius: 11px; overflow: hidden; display: grid; place-items: center; color: white; }
.video-stage.has-video { aspect-ratio: auto; min-height: 320px; max-height: none; padding: 12px; }
.video-stage.has-video video { display: block; width: auto; max-width: 100%; height: auto; max-height: min(72vh, 760px); margin: auto; object-fit: contain; background: #111827; }
.generation-error { max-width: 620px; padding: 24px; text-align: center; }
.generation-error strong { display: block; color: #ffb8bd; font-size: 18px; }
.generation-error p { margin: 10px 0 0; color: #d7deed; font-size: 13px; line-height: 1.65; }
.mock-frame { text-align: center; color: #d6dceb; }
.mock-person { width: 88px; height: 120px; margin: 0 auto 15px; border-radius: 42px 42px 20px 20px; background: linear-gradient(145deg, #7e9cff, #d8a7e5); box-shadow: 0 0 50px rgba(108,132,255,.4); animation: pulse 1.6s infinite ease-in-out; }
@keyframes pulse { 50% { transform: scale(1.04); filter: brightness(1.16); } }
.progress-meta { margin-top: 13px; display: flex; justify-content: space-between; gap: 16px; }
.progress-meta strong, .progress-meta span { display: block; }
.progress-meta div span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.progress-meta .generation-detail { display: inline-block; margin-right: 12px; }
.progress-track { height: 7px; margin-top: 10px; background: #e3e7ef; border-radius: 99px; overflow: hidden; }
.progress-track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), #7f5ce8); transition: width .4s; }
.version-section, .assembly-panel { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.version-head h3 { margin: 5px 0 0; font-size: 16px; }
.version-head > span { color: var(--muted); font-size: 11px; }
.version-list, .assembly-list { display: grid; gap: 10px; margin-top: 12px; }
.version-card { display: grid; grid-template-columns: max-content minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfe; }
.version-card.selected { border-color: var(--green); background: var(--green-soft); }
.version-preview { width: 150px; aspect-ratio: var(--preview-ratio, 16 / 9); border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: #111827; color: #d6dceb; font-size: 10px; }
.version-preview.portrait { width: 84px; }
.version-preview.square { width: 108px; }
.version-preview video { width: 100%; height: 100%; object-fit: contain; background: #111827; }
.version-copy { min-width: 0; display: grid; gap: 4px; }
.version-copy strong { font-size: 13px; }
.version-copy span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.version-actions { display: grid; grid-template-columns: repeat(2, auto); gap: 6px; justify-content: end; }
.version-card button, .version-card a { border: 1px solid #cbd4e5; border-radius: 8px; background: white; padding: 7px 10px; color: var(--blue); font-size: 11px; text-align: center; text-decoration: none; cursor: pointer; }
.version-card button:disabled { color: var(--muted); cursor: not-allowed; }
.version-actions .select-version-button { grid-column: 1 / -1; }
.version-card.selected .select-version-button { color: var(--green); }
.assembly-row { display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfe; }
.assembly-row b { color: var(--blue); font-size: 11px; }
.assembly-row strong { font-size: 12px; }
.assembly-row span { color: var(--muted); font-size: 11px; }
.assembly-panel > p { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 420px; background: #16213b; color: white; padding: 12px 15px; border-radius: 10px; box-shadow: 0 12px 34px rgba(15,23,42,.22); font-size: 13px; z-index: 30; }
.toast.error { background: #a52f3a; }
.hidden { display: none !important; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

@media (max-width: 680px) {
  .topbar { align-items: flex-start; padding: 16px; }
  .topbar-actions { align-items: flex-end; flex-direction: column-reverse; }
  .key-change-button { white-space: nowrap; }
  main { padding: 14px; }
  .panel { padding: 18px; }
  .module-tabs { grid-template-columns: 1fr; }
  .shot-overview-head { align-items: flex-start; }
  .shot-overview-head > div { align-items: flex-start; flex-direction: column; gap: 3px; }
  .shot-overview-list .shot-card { flex-basis: 190px; }
  .version-card { grid-template-columns: max-content minmax(0, 1fr); }
  .version-actions { grid-column: 1 / -1; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .view-grid { grid-template-columns: 1fr; }
  .multimodal-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
}
