:root {
  color-scheme: dark;
  --bg: #090a0d;
  --surface: #111318;
  --surface-2: #171a20;
  --surface-3: #20242c;
  --line: #292d36;
  --line-strong: #3a404b;
  --text: #f4f5f7;
  --muted: #979eaa;
  --accent: #d9ff43;
  --accent-hover: #e4ff72;
  --accent-soft: rgba(217, 255, 67, .12);
  --danger: #ff6b76;
  --success: #72e6a4;
  --text-soft: #c8cdd5;
  --topbar-bg: rgba(9, 10, 13, .9);
  --status-bg: #0e1014;
  --preview-start: #1a1d23;
  --preview-end: #101216;
  --button-hover: #292e37;
  --on-accent: #11140b;
  --radius: 16px;
  --shadow: 0 24px 70px rgba(0, 0, 0, .28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f8f8f5;
  --surface-3: #ecece7;
  --line: #deded8;
  --line-strong: #c8c8c0;
  --text: #11120f;
  --muted: #6f746c;
  --accent: #20240f;
  --accent-hover: #353b1b;
  --accent-soft: rgba(32, 36, 15, .08);
  --danger: #c43d49;
  --success: #197647;
  --text-soft: #454a43;
  --topbar-bg: rgba(244, 244, 241, .9);
  --status-bg: #f8f8f5;
  --preview-start: #efefe9;
  --preview-end: #e3e3dc;
  --button-hover: #e4e4de;
  --on-accent: #ffffff;
  --shadow: 0 24px 65px rgba(31, 33, 25, .1);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); transition: background-color .32s ease, color .32s ease; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 70px; padding: 0 4vw;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  border-bottom: 1px solid var(--line); background: var(--topbar-bg); backdrop-filter: blur(18px);
}
.brand { display: inline-flex; width: max-content; gap: 10px; align-items: center; color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #0b0c0e; font-weight: 900; transform: rotate(-4deg);
}
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
:root[data-theme="light"] .brand-mark { color: #ffffff; }
.project-switcher { display: flex; align-items: center; gap: 8px; }
.project-switcher select { min-width: 220px; }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 4px; }
.token-button, .theme-button { display: flex; align-items: center; gap: 9px; background: transparent; color: var(--muted); border: 0; padding: 9px 12px; border-radius: 10px; }
.token-button:hover, .theme-button:hover { color: var(--text); background: var(--surface-2); }
.theme-icon { display: inline-grid; place-items: center; width: 18px; height: 18px; transition: transform .4s ease; }
.theme-button:hover .theme-icon { transform: rotate(45deg); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 4px rgba(255,107,118,.1); }
.status-dot.connected { background: var(--success); box-shadow: 0 0 0 4px rgba(114,230,164,.1); }

main { width: min(1180px, 92vw); margin: 0 auto; padding: 48px 0 96px; }
#workspaceView:not([hidden]) > section { animation: section-in .42s both; }
#workspaceView:not([hidden]) > section:nth-child(2) { animation-delay: .05s; }
#workspaceView:not([hidden]) > section:nth-child(3) { animation-delay: .1s; }
#workspaceView:not([hidden]) > section:nth-child(4) { animation-delay: .15s; }
.project-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.editable-title { display: flex; align-items: center; gap: 10px; }
.editable-title input {
  width: min(680px, 70vw); padding: 0; border: 0; background: transparent;
  color: var(--text); font-size: clamp(34px, 5vw, 62px); font-weight: 760; letter-spacing: -.055em;
}
.editable-title span { color: var(--muted); }
.project-meta { margin: 12px 0 0; color: var(--muted); }

.settings-strip, .assets-section, .storyboard-section { border-top: 1px solid var(--line); padding: 30px 0 42px; }
.settings-strip { display: grid; grid-template-columns: minmax(220px, .8fr) 2fr; gap: 40px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; }
.section-heading.compact { align-items: start; margin: 0; display: block; }
.section-heading h2 { margin: 0; font-size: 25px; letter-spacing: -.03em; }
.section-heading p:last-child { color: var(--muted); font-size: 13px; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
label { display: grid; gap: 8px; color: var(--text-soft); font-size: 12px; font-weight: 650; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--text); padding: 11px 13px; transition: border-color .15s, background .15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
textarea { resize: vertical; min-height: 112px; line-height: 1.55; }
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23c8cdd5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 34px;
}

:root[data-theme="light"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f746c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
button { border: 0; transition: transform .16s ease, background-color .2s ease, color .2s ease, border-color .2s ease, box-shadow .2s ease; }
button:active { transform: scale(.97); }
.primary-button, .secondary-button, .ghost-button {
  min-height: 40px; padding: 10px 16px; border-radius: 10px; font-weight: 750;
}
.primary-button { background: var(--accent); color: var(--on-accent); }
.primary-button:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 8px 24px var(--accent-soft); }
.primary-button:disabled { cursor: not-allowed; opacity: .45; }
.secondary-button { background: var(--surface-3); color: var(--text); border: 1px solid var(--line-strong); }
.secondary-button:hover, .ghost-button:hover { background: var(--button-hover); }
.ghost-button { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.ghost-button.danger:hover { border-color: var(--danger); color: var(--danger); background: rgba(255,107,118,.06); }
.icon-button { display: grid; place-items: center; min-width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--text); font-size: 20px; }

.asset-filters { display: flex; gap: 8px; margin-bottom: 18px; }
.filter-chip { border: 1px solid var(--line); padding: 7px 12px; border-radius: 99px; background: transparent; color: var(--muted); font-size: 12px; }
.filter-chip:hover, .filter-chip.active { color: var(--text); border-color: var(--line-strong); background: var(--surface-2); }
.filter-chip.active { color: var(--accent); }
.asset-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; min-height: 80px; }
.asset-card { position: relative; min-width: 0; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: var(--surface); transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease; }
.asset-card:hover { transform: translateY(-4px); border-color: var(--line-strong); box-shadow: var(--shadow); }
.asset-preview { display: grid; place-items: center; aspect-ratio: 1.25; background: linear-gradient(135deg, var(--preview-start), var(--preview-end)); color: var(--muted); font-size: 24px; overflow: hidden; }
.asset-preview img, .asset-preview video { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.asset-card:hover .asset-preview img { transform: scale(1.045); }
.audio-play-button { display: grid; place-items: center; gap: 7px; width: 100%; height: 100%; background: transparent; color: var(--text); }
.audio-play-button > span { display: grid; place-items: center; width: 42px; height: 42px; padding-left: 2px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: 15px; box-shadow: 0 0 0 8px var(--accent-soft); transition: transform .2s ease, box-shadow .2s ease; }
.audio-play-button:hover > span { transform: scale(1.08); box-shadow: 0 0 0 12px var(--accent-soft); }
.audio-play-button.is-playing > span { padding-left: 0; animation: audio-pulse 1.2s ease-in-out infinite; }
.audio-play-button small { color: var(--muted); font-size: 9px; }
.selected-asset-preview video, .picker-asset-preview video { width: 100%; height: 100%; object-fit: cover; }
.asset-info { padding: 9px; }
.asset-info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.asset-info small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.asset-remove { position: absolute; top: 6px; right: 6px; width: 25px; height: 25px; border-radius: 50%; background: rgba(5,6,8,.78); color: white; opacity: 0; transition: opacity .15s; }
.asset-card:hover .asset-remove, .asset-remove:focus-visible { opacity: 1; }
.empty-state { grid-column: 1 / -1; display: grid; place-items: center; min-height: 120px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); font-size: 13px; text-align: center; }

.shot-list { display: grid; gap: 16px; }
.shot-card { display: grid; grid-template-columns: 70px minmax(0, 1fr) 340px; align-items: stretch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: var(--shadow); transition: border-color .22s ease, box-shadow .22s ease; }
.shot-card:hover { border-color: var(--line-strong); }
.shot-index { display: flex; flex-direction: column; align-items: center; padding: 22px 10px; border-right: 1px solid var(--line); color: var(--muted); }
.shot-index strong { color: var(--text); font-size: 25px; }
.shot-main { padding: 22px; min-width: 0; }
.shot-toolbar { display: flex; justify-content: space-between; gap: 16px; align-items: start; margin-bottom: 15px; }
.shot-title-input { width: min(420px, 75%); padding: 5px 8px; border-color: transparent; background: transparent; font-size: 16px; font-weight: 750; }
.shot-title-input:hover, .shot-title-input:focus { border-color: var(--line-strong); background: var(--surface-2); }
.shot-toolbar button { background: none; color: var(--muted); font-size: 12px; }
.shot-toolbar button:hover { color: var(--danger); }
.shot-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.shot-prompt-input { min-height: 210px; }
.duration-field { min-width: 0; margin: 0; padding: 0; border: 0; }
.duration-field legend { margin-bottom: 8px; color: var(--text-soft); font-size: 12px; font-weight: 650; }
.duration-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; padding: 5px; border-radius: 11px; background: var(--surface-3); }
.duration-option { position: relative; display: block; }
.duration-option input { position: absolute; opacity: 0; pointer-events: none; }
.duration-option span { display: grid; place-items: center; min-height: 34px; border-radius: 8px; color: var(--muted); font-size: 11px; cursor: pointer; }
.duration-option input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.duration-option input:focus-visible + span { outline: 2px solid var(--accent); }
.shot-assets { margin-top: 16px; }
.shot-assets-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.shot-assets-heading p { margin: 0; color: var(--text-soft); font-size: 12px; font-weight: 700; }
.shot-assets-heading small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.no-assets { color: var(--muted); font-size: 11px; }
.selected-assets-title { margin-top: 14px !important; }
.selected-assets-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.selected-asset-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.selected-asset-preview { display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; color: var(--muted); }
.selected-asset-preview img { width: 100%; height: 100%; object-fit: cover; }
.selected-asset-card > span { display: block; padding: 6px 7px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.asset-picker-dialog { width: min(920px, calc(100vw - 30px)); }
.asset-picker-tools { display: grid; grid-template-columns: minmax(0, 1fr) 180px; gap: 12px; }
.asset-picker-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; max-height: 55vh; min-height: 180px; padding: 2px; overflow-y: auto; }
.picker-asset { position: relative; display: block; min-width: 0; cursor: pointer; }
.picker-asset > input { position: absolute; z-index: 1; top: 8px; right: 8px; width: 18px; height: 18px; accent-color: var(--accent); }
.picker-asset-body { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.picker-asset > input:checked + .picker-asset-body { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.picker-asset-preview { display: grid; place-items: center; aspect-ratio: 4 / 3; overflow: hidden; color: var(--muted); font-size: 25px; }
.picker-asset-preview img { width: 100%; height: 100%; object-fit: cover; }
.picker-asset-body strong, .picker-asset-body small { display: block; overflow: hidden; padding: 0 8px; text-overflow: ellipsis; white-space: nowrap; }
.picker-asset-body strong { padding-top: 8px; font-size: 11px; }
.picker-asset-body small { padding-top: 3px; padding-bottom: 8px; color: var(--muted); font-size: 10px; }
.shot-status { display: flex; flex-direction: column; gap: 18px; width: 100%; height: 100%; min-height: 0; overflow: hidden; padding: 22px; border-left: 1px solid var(--line); background: var(--status-bg); }
.task-history-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.task-history-heading strong { font-size: 13px; }
.task-history-heading span { color: var(--muted); font-size: 10px; }
.task-history { display: grid; flex: 1 1 auto; align-content: start; gap: 10px; min-height: 0; overflow-y: auto; padding-right: 3px; }
.task-card { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.task-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.task-card-heading time { color: var(--muted); font-size: 9px; }
.task-id { margin-top: 7px; overflow: hidden; color: #656d79; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.task-action { width: 100%; min-height: 32px; margin-top: 10px; padding: 6px 9px; font-size: 10px; }
.generate-button { width: 100%; flex: 0 0 auto; margin-top: auto; }
.empty-task-history { display: grid; place-items: center; min-height: 100px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 11px; text-align: center; }
.status-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 750; }
.status-label::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-label.running::before { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: pulse 1.5s infinite; }
.status-label.succeeded::before { background: var(--success); }
.status-label.failed::before { background: var(--danger); }
.progress-track { height: 5px; margin-top: 12px; border-radius: 9px; overflow: hidden; background: var(--surface-3); }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-hover), var(--accent)); background-size: 200% 100%; transition: width .25s; animation: progress-flow 1.8s linear infinite; }
.status-detail { min-height: 34px; margin: 10px 0 0; color: var(--muted); font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.result-list { display: grid; gap: 8px; margin-top: 12px; }
.result-list video, .result-list img, .result-list audio { width: 100%; max-height: 170px; border-radius: 8px; background: #000; }
.result-link { color: var(--accent); font-size: 11px; }

.welcome { min-height: calc(100vh - 180px); display: grid; justify-items: center; align-content: center; text-align: center; }
.welcome-art { display: grid; place-items: center; width: 120px; height: 120px; margin-bottom: 28px; border: 1px solid var(--line); border-radius: 32px; background: radial-gradient(circle at 35% 30%, var(--accent-soft), transparent 55%), var(--surface); transform: rotate(-5deg); }
.welcome-art span { color: var(--accent); font-size: 45px; }
.welcome h1 { margin: 0; font-size: clamp(38px, 6vw, 68px); letter-spacing: -.06em; }
.welcome > p:not(.eyebrow) { max-width: 460px; color: var(--muted); line-height: 1.7; }
.welcome .primary-button { margin-top: 16px; }

dialog { width: min(500px, calc(100vw - 30px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 18px; background: var(--surface-2); color: var(--text); box-shadow: var(--shadow); }
dialog[open] { animation: dialog-in .22s ease-out; }
dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(4px); }
dialog form { display: grid; gap: 20px; padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; }
.dialog-heading h2 { margin: 0; font-size: 25px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.token-dialog-actions { align-items: center; flex-wrap: wrap; }
.token-dialog-brand { margin-right: auto; color: var(--muted); font-size: 11px; }
.asset-type-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0; border: 0; }
.asset-type-options label { position: relative; display: grid; place-items: center; gap: 4px; padding: 16px 8px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.asset-type-options input { position: absolute; opacity: 0; }
.asset-type-options label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.asset-type-options span { font-size: 24px; }
.asset-type-options small, .file-note { color: var(--muted); font-size: 10px; line-height: 1.5; }
.check-row { display: flex; grid-template-columns: auto 1fr; align-items: center; }
.check-row input { width: auto; }
.toast-region { position: fixed; z-index: 50; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 12px 15px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface-3); box-shadow: var(--shadow); font-size: 12px; animation: toast-in .2s ease-out; }
.toast.error { border-color: rgba(255,107,118,.5); }

@keyframes pulse { 50% { opacity: .45; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes section-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes progress-flow { to { background-position: -200% 0; } }
@keyframes audio-pulse { 50% { transform: scale(.92); box-shadow: 0 0 0 14px var(--accent-soft); } }

@media (max-width: 900px) {
  .asset-grid { grid-template-columns: repeat(3, 1fr); }
  .shot-card { grid-template-columns: 55px 1fr; }
  .shot-status { grid-column: 1 / -1; height: auto; max-height: 620px; border-left: 0; border-top: 1px solid var(--line); }
  .task-history { flex: 1 1 auto; min-height: 0; max-height: 460px; overflow-y: auto; }
  .settings-strip { grid-template-columns: 1fr; gap: 22px; }
}
@media (max-width: 640px) {
  .topbar { height: auto; min-height: 66px; padding: 10px 4vw; grid-template-columns: 1fr auto; gap: 10px; }
  .project-switcher { grid-row: 2; grid-column: 1 / -1; }
  .project-switcher select { flex: 1; min-width: 0; }
  .token-button span:last-child, .theme-button span:last-child, .brand small { display: none; }
  main { padding-top: 30px; }
  .project-hero { gap: 12px; }
  .project-hero > div:first-child { min-width: 0; flex: 1 1 auto; }
  .editable-title { min-width: 0; }
  .editable-title input { flex: 1 1 auto; min-width: 0; width: auto; }
  .editable-title span { flex: none; }
  .hero-actions { flex: none; }
  .settings-grid { grid-template-columns: 1fr; }
  .asset-grid { grid-template-columns: repeat(2, 1fr); }
  .shot-card { grid-template-columns: 1fr; }
  .shot-index { flex-direction: row; justify-content: space-between; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .shot-fields { grid-template-columns: 1fr; }
  .asset-picker-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .asset-picker-tools { grid-template-columns: 1fr; }
  .section-heading { align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
