:root {
  color-scheme: dark;
  --ink: #0d1010;
  --surface: #121818;
  --surface-raised: #182020;
  --surface-hover: #202929;
  --line: #2c3735;
  --line-soft: #202927;
  --text: #edf3ed;
  --muted: #8a9590;
  --accent: #d5f05c;
  --accent-ink: #172000;
  --danger: #ff8b72;
  --warm: #eeb15f;
  --shadow: 0 16px 44px rgb(0 0 0 / 28%);
  font-family: "Manrope", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 1180px; min-height: 100dvh; margin: 0; color: var(--text); background: var(--ink); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app-shell { display: grid; grid-template-columns: 344px minmax(590px, 1fr) 324px; gap: 12px; min-height: 100dvh; padding: 12px; }
.control-panel, .canvas-panel, .history-panel { min-height: 0; border: 1px solid var(--line); background: rgb(18 24 24 / 93%); box-shadow: var(--shadow); }
.control-panel { display: flex; flex-direction: column; padding: 24px; }
.brand-row, .canvas-header, .history-header, .section-heading, .prompt-foot, .result-meta, .dialog-heading, .dialog-actions, .connection-status, .history-item, .task-status-line { display: flex; align-items: center; }
.brand-row { gap: 12px; margin-bottom: 24px; }
.brand-mark { display: grid; grid-template-columns: repeat(3, 5px); gap: 3px; width: 36px; height: 36px; padding: 7px; border: 1px solid #5c6963; background: #202929; }
.brand-mark span { background: var(--accent); }
.brand-mark span:nth-child(1) { align-self: end; height: 9px; }
.brand-mark span:nth-child(2) { align-self: center; height: 18px; }
.brand-mark span:nth-child(3) { height: 26px; }
.brand-kicker, .eyebrow { margin: 0 0 3px; color: var(--muted); font: 500 10px/1 "DM Mono", monospace; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 21px; line-height: 1; }
h2 { margin: 0; font-size: 18px; }

.connection-status { width: 100%; gap: 9px; padding: 12px 13px; margin-bottom: 22px; border: 1px solid var(--line); color: var(--muted); text-align: left; background: transparent; }
.connection-status i { width: 16px; margin-left: auto; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.connection-status.is-connected { color: var(--text); border-color: #586951; }
.connection-status.is-connected .status-dot { background: var(--accent); }

.form-section { padding: 18px 0; border-top: 1px solid var(--line-soft); }
.section-heading { justify-content: space-between; margin-bottom: 11px; color: var(--muted); font-size: 12px; }
.section-heading label { color: var(--text); }
textarea, input { width: 100%; border: 1px solid var(--line); border-radius: 0; color: var(--text); background: #101515; }
textarea { min-height: 132px; padding: 13px; resize: vertical; line-height: 1.55; }
textarea::placeholder, input::placeholder { color: #69736f; }
.prompt-foot { justify-content: space-between; margin-top: 8px; }
.mono { font-family: "DM Mono", monospace; font-size: 11px; }
.muted { color: var(--muted); }
.text-button, .icon-button, .secondary-button, .primary-button { border: 0; color: inherit; background: transparent; }
.text-button { color: var(--accent); font-size: 11px; }
.icon-button { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--line); }
.icon-button:hover, .secondary-button:hover { background: var(--surface-hover); }
.icon-button i { width: 16px; height: 16px; }
.icon-button.subtle { width: 26px; height: 26px; border-color: transparent; color: var(--muted); }

.reference-note { margin: -3px 0 11px; color: var(--muted); font-size: 10px; line-height: 1.55; }
.reference-board { display: grid; gap: 12px; }
.reference-group { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 9px; align-items: start; }
.reference-group-heading { display: grid; gap: 5px; padding-top: 6px; color: #b7c1b9; font-size: 11px; }
.reference-group-heading .mono { color: var(--muted); }
.reference-assets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.reference-card, .reference-add { position: relative; min-width: 0; min-height: 76px; overflow: hidden; border: 1px solid var(--line); background: #101515; }
.reference-card img { display: block; width: 100%; height: 76px; object-fit: cover; }
.reference-name { position: absolute; right: 0; bottom: 0; left: 0; width: 100%; height: 26px; padding: 5px 4px; overflow: hidden; border: 0; border-top: 1px solid rgb(255 255 255 / 10%); border-radius: 0; color: #edf3ed; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; background: rgb(10 13 13 / 80%); }
.reference-name:focus { overflow: visible; color: var(--text); outline: 1px solid var(--accent); outline-offset: -1px; background: #18201d; }
.reference-remove { position: absolute; top: 3px; right: 3px; display: grid; width: 20px; height: 20px; place-items: center; padding: 0; border: 0; color: var(--text); background: rgb(10 13 13 / 80%); }
.reference-remove i { width: 13px; }
.reference-add { display: grid; gap: 4px; place-content: center; border-style: dashed; border-color: #506057; color: var(--muted); font-size: 10px; }
.reference-add:hover { border-color: var(--accent); color: var(--accent); }
.reference-add:disabled { cursor: not-allowed; opacity: .45; }
.reference-add i { width: 18px; justify-self: center; }

.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.controls-grid label, .settings-card label { display: grid; gap: 7px; color: var(--muted); font-size: 11px; }
.wide-control { grid-column: 1 / -1; }
input { height: 40px; padding: 0 11px; }
.duration-field { display: flex; align-items: center; border: 1px solid var(--line); background: #101515; }
.duration-field:focus-within { border-color: #6a796e; background: #151b1a; }
.duration-field input { min-width: 0; border: 0; background: transparent; }
.duration-field span { padding: 0 11px 0 3px; color: var(--muted); font-size: 12px; }
.select-control { position: relative; width: 100%; }
.native-select.is-enhanced { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.select-trigger { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 40px; padding: 0 11px; border: 1px solid var(--line); color: var(--text); text-align: left; background: #101515; }
.select-trigger:hover, .select-control.is-open .select-trigger { border-color: #6a796e; background: #151b1a; }
.select-trigger i { width: 16px; color: var(--muted); transition: transform 160ms ease-out; }
.select-control.is-open .select-trigger i { transform: rotate(180deg); color: var(--accent); }
.select-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-menu { position: absolute; z-index: 20; top: calc(100% + 6px); right: 0; left: 0; display: none; max-height: 286px; padding: 5px; overflow: auto; border: 1px solid #59655e; box-shadow: 0 18px 34px rgb(0 0 0 / 38%); background: #151b1a; }
.select-control.is-open .select-menu { display: grid; gap: 2px; }
.select-option { width: 100%; min-height: 34px; padding: 7px 9px; border: 0; color: #dbe2dc; text-align: left; background: transparent; }
.select-option:hover, .select-option:focus-visible { color: var(--accent-ink); outline: 0; background: var(--accent); }
.select-option.is-selected { color: var(--accent); background: #25301b; }
.select-option::before { display: inline-block; width: 17px; content: ""; }
.select-option.is-selected::before { content: "✓"; }
.select-option:disabled { cursor: not-allowed; color: #5f6963; }
.field-note { min-height: 16px; margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.generate-button { display: flex; align-items: center; justify-content: center; gap: 9px; width: 100%; min-height: 50px; margin-top: 9px; border: 0; color: var(--accent-ink); font-weight: 800; background: var(--accent); }
.generate-button:hover { background: #e2fa6c; }
.generate-button:disabled { cursor: wait; color: #65703d; background: #a1ae63; }
.generate-button i { width: 18px; }
kbd { margin-left: auto; padding: 2px 5px; border: 1px solid #acbf4e; color: #66722e; font: 10px "DM Mono", monospace; }
.form-error, .dialog-error { min-height: 17px; margin: 9px 0 0; color: var(--danger); font-size: 11px; }
.request-diagnostics { margin-top: 10px; border: 1px solid #5b4038; background: #1b1716; }
.request-diagnostics summary { padding: 9px 10px; color: var(--warm); font-size: 11px; cursor: pointer; }
.request-diagnostics pre { max-height: 180px; margin: 0; padding: 0 10px 10px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #c9b7af; font: 10px/1.55 "DM Mono", monospace; }
.privacy-note { display: flex; gap: 8px; align-items: center; margin-top: auto; padding-top: 20px; color: var(--muted); font-size: 10px; }
.privacy-note i { width: 15px; color: var(--accent); }

.canvas-panel { display: flex; flex-direction: column; padding: 20px; }
.canvas-header, .history-header { justify-content: space-between; padding-bottom: 17px; border-bottom: 1px solid var(--line-soft); }
.canvas-actions { display: flex; gap: 7px; }
.empty-stage, .loading-stage, .result-stage { flex: 1; min-height: 0; margin-top: 20px; border: 1px dashed #3b4742; }
.empty-stage, .loading-stage { display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.stage-symbol { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 15px; border: 1px solid #526259; color: var(--accent); background: #19221f; }
.stage-symbol i { width: 26px; height: 26px; }
.empty-stage h3, .loading-stage h3 { margin-bottom: 7px; font-size: 18px; }
.empty-stage p, .loading-stage p { max-width: 300px; margin-bottom: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.loading-stage { gap: 0; min-width: 0; }
.task-status-line { justify-content: center; gap: 8px; margin-bottom: 14px; color: var(--accent); }
.task-status-line #task-progress { color: var(--muted); }
.status-pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.loading-track { width: min(300px, 80vw); height: 5px; overflow: hidden; background: #29342f; }
.loading-track span { display: block; width: 100%; height: 100%; transform: scaleX(.03); transform-origin: left center; background: var(--accent); transition: transform 180ms ease-out; }
.loading-stage h3 { margin-top: 20px; }
.loading-stage .text-button { margin-top: 16px; }
.result-stage { position: relative; display: grid; place-items: center; overflow: hidden; background: #080b0b; }
.result-stage video { display: block; max-width: 100%; max-height: calc(100dvh - 105px); background: #080b0b; }
.result-meta { position: absolute; right: 10px; bottom: 10px; gap: 8px; padding: 8px 9px; color: #c7d0c9; font-size: 10px; background: rgb(9 12 12 / 87%); }

.history-panel { display: flex; flex-direction: column; padding: 20px; }
.history-list { display: grid; gap: 9px; padding-top: 16px; overflow: auto; }
.history-empty { padding: 30px 8px; color: var(--muted); font-size: 12px; line-height: 1.6; text-align: center; }
.history-item { gap: 9px; min-width: 0; padding: 8px; border: 1px solid var(--line-soft); background: #141a19; }
.history-item:hover { border-color: #4b5952; }
.history-preview { display: grid; flex: 0 0 54px; width: 54px; height: 54px; place-items: center; padding: 0; border: 0; color: var(--accent); background: #202923; }
.history-preview i { width: 19px; }
.history-copy { min-width: 0; flex: 1; }
.history-copy p { display: -webkit-box; margin: 0 0 6px; overflow: hidden; color: #dfe7e0; font-size: 10px; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.history-copy span { color: var(--muted); }
.history-state { align-self: flex-start; color: var(--warm); font-size: 9px; }
.history-state.is-complete { color: var(--accent); }

dialog { width: min(450px, calc(100vw - 32px)); padding: 0; border: 1px solid #4f5e56; color: var(--text); background: #141a19; box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 65%); }
.settings-card { display: grid; gap: 16px; padding: 22px; }
.secret-field { display: flex; border: 1px solid var(--line); background: #101515; }
.secret-field input { border: 0; }
.dialog-actions { justify-content: flex-end; gap: 8px; padding-top: 5px; }
.secondary-button, .primary-button { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); font-size: 12px; }
.primary-button { border-color: var(--accent); color: var(--accent-ink); font-weight: 800; background: var(--accent); }
.settings-hint { margin: -4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.settings-hint code { color: var(--accent); font-family: "DM Mono", monospace; }

@media (max-width: 1240px) {
  body { min-width: 0; }
  .app-shell { grid-template-columns: 306px minmax(460px, 1fr); }
  .history-panel { grid-column: 1 / -1; max-height: 240px; }
  .history-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app-shell { display: flex; flex-direction: column; min-height: 100dvh; padding: 9px; }
  .control-panel { order: 2; }
  .canvas-panel { order: 1; min-height: 62dvh; }
  .history-panel { order: 3; }
  .result-stage video { max-height: 55dvh; }
  .history-list { grid-template-columns: 1fr; max-height: 330px; }
}

@media (prefers-reduced-motion: reduce) {
  .select-trigger i, .loading-track span { transition: none; }
}
