:root {
  color-scheme: dark;
  --bg: #0c0e12;
  --surface: #14171d;
  --surface-raised: #1b1f27;
  --border: #2b303a;
  --text: #f2f4f8;
  --muted: #9da5b3;
  --accent: #b7f36b;
  --accent-strong: #94d645;
  --danger: #ff8c8c;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: radial-gradient(ellipse at 50% -20%, #202731 0, var(--bg) 42rem); color: var(--text); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea, summary { outline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); }
.site-header { display: flex; justify-content: space-between; align-items: center; max-width: 1120px; margin: auto; padding: 20px 24px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 750; letter-spacing: -.03em; }
.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; color: #14190c; background: var(--accent); font-weight: 900; }
nav { display: flex; gap: 8px; }
nav a { padding: 8px 12px; color: var(--muted); border-radius: 8px; font-size: 13px; }
nav a:hover, nav a[aria-current="page"] { color: var(--text); background: rgba(255,255,255,.07); }
.page-shell { max-width: 980px; min-height: calc(100vh - 138px); margin: auto; padding: 46px 24px 70px; }
.page-heading { margin: 0 auto 30px; max-width: 820px; }
.page-heading h1 { margin: 4px 0 8px; font-size: clamp(30px, 5vw, 46px); line-height: 1.1; letter-spacing: -.045em; }
.page-heading p { margin: 6px 0; }
.compact-heading { margin-bottom: 22px; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .15em; }
.muted, .label-hint { color: var(--muted); }
.label-hint { margin-left: 6px; font-size: 12px; font-weight: 400; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); background: rgba(20,23,29,.92); box-shadow: 0 16px 48px rgba(0,0,0,.12); }
.stack-form { display: grid; gap: 16px; }
.form-section, .progress-panel, .finished-panel, .provider-list { padding: clamp(18px, 3vw, 28px); }
.section-title { display: flex; align-items: flex-start; gap: 13px; margin: 0 0 23px; }
.section-title h2, .section-title p { margin: 0; }
.section-title h2 { font-size: 18px; letter-spacing: -.02em; }
.section-title p { margin-top: 4px; color: var(--muted); font-size: 13px; }
.section-number { display: grid; flex: 0 0 34px; min-height: 34px; place-items: center; border: 1px solid #39433a; border-radius: 10px; color: var(--accent); background: rgba(183,243,107,.07); font-size: 10px; font-weight: 800; letter-spacing: .06em; }
label, legend { display: block; margin: 16px 0 7px; color: #e7eaf0; font-size: 13px; font-weight: 650; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { width: 100%; padding: 11px 12px; border: 1px solid #343a45; border-radius: 10px; color: var(--text); background: #101318; }
textarea { resize: vertical; min-height: 44px; }
input::placeholder, textarea::placeholder { color: #737c8a; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-grid > div { min-width: 0; }
.range-caption { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.range-caption strong { color: var(--text); }
.inline-controls { display: flex; gap: 8px; }
.inline-controls select { flex: 1; min-width: 0; }
.style-fieldset { padding: 0; border: 0; }
.style-fieldset legend { margin-bottom: 9px; }
.style-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.style-card { position: relative; display: flex; flex-direction: column; min-height: 112px; margin: 0; padding: 10px; border: 1px solid #343a45; border-radius: 11px; cursor: pointer; background: #101318; }
.style-card:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.style-card input { position: absolute; top: 8px; right: 8px; accent-color: var(--accent); }
.style-card strong { padding-right: 18px; font-size: 12px; }
.style-card small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.style-swatch { display: grid; width: 100%; height: 45px; margin-bottom: 8px; place-items: center; border-radius: 7px; color: #e8d2a3; background: linear-gradient(135deg, #34312c, #12161a 55%, #3b4142); font-family: Georgia, serif; font-size: 12px; letter-spacing: .08em; }
.toggle-row { display: flex; gap: 11px; align-items: flex-start; padding: 13px 0; margin: 0; border-bottom: 1px solid rgba(255,255,255,.06); cursor: pointer; }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row input { margin-top: 5px; accent-color: var(--accent); }
.toggle-row span { display: grid; gap: 2px; }
.toggle-row strong { font-size: 13px; }
.toggle-row small { color: var(--muted); font-size: 12px; font-weight: 400; }
.form-actions, .heading-row, .library-title-row, .copy-heading, .finished-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.form-actions { margin-top: 3px; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 9px; padding: 9px 16px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-weight: 720; font-size: 13px; transition: background .15s, transform .15s; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button-primary { color: #17200f; background: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }
.button-secondary { border-color: #3b424d; color: var(--text); background: var(--surface-raised); }
.button-secondary:hover:not(:disabled) { background: #252b35; }
.button-small { min-height: 34px; padding: 6px 10px; font-size: 11px; }
.button:disabled { opacity: .48; cursor: not-allowed; }
.spinner { display: none; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.is-loading .spinner, .htmx-request .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.field-error { display: block; margin: 5px 0; color: var(--danger); font-size: 12px; }
.notice { margin: 0 0 18px; padding: 14px 16px; border-radius: 11px; }
.notice-error { border: 1px solid #693e43; color: #ffd5d5; background: rgba(115,38,47,.22); }
.back-link, .text-link { color: var(--accent); font-size: 12px; font-weight: 650; }
.back-link { display: inline-block; margin-bottom: 12px; }
.status-pill { display: inline-block; padding: 4px 8px; border-radius: 999px; color: #d3dae4; background: #2a3039; font-size: 10px; font-weight: 750; white-space: nowrap; }
.status-rendered { color: #d5f8ae; background: #273923; }
.status-failed, .status-interrupted, .status-cancelled { color: #ffd0d0; background: #4a2b31; }
.status-awaiting-review { color: #f8dfa7; background: #443923; }
.stepper { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 6px; padding: 0; margin: 0 0 24px; list-style: none; }
.step { display: flex; flex-direction: column; align-items: center; gap: 7px; color: #858e9b; text-align: center; font-size: 10px; }
.step-dot { display: grid; width: 27px; height: 27px; place-items: center; border: 1px solid #3b424d; border-radius: 50%; color: #abb2bd; font-size: 10px; font-weight: 700; }
.step.is-active { color: var(--text); }
.step.is-active .step-dot, .step.is-complete .step-dot { border-color: var(--accent); color: #18210f; background: var(--accent); }
.progress-meta { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 12px; }
progress { display: block; width: 100%; height: 7px; border: 0; border-radius: 10px; overflow: hidden; accent-color: var(--accent); }
progress::-webkit-progress-bar { background: #2a3039; }
progress::-webkit-progress-value { border-radius: 10px; background: var(--accent); transition: width .4s; }
.log-details { margin-top: 18px; color: var(--muted); font-size: 12px; }
.log-details summary { display: flex; justify-content: space-between; cursor: pointer; }
.log-details pre { max-height: 190px; overflow: auto; padding: 12px; border-radius: 9px; color: #c0c8d3; background: #0c0e12; font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
.repair-note { margin-top: 16px; padding: 12px 14px; border: 1px solid #43513a; border-radius: 10px; color: #d7e5cd; background: rgba(91,126,60,.12); }
.repair-note h2 { margin: 0 0 8px; color: #c7e9ae; font-size: 13px; }
.repair-note ul { display: grid; gap: 5px; margin: 0; padding-left: 18px; font-size: 12px; }
.review-panel { margin-top: 20px; }
.review-panel > .section-title, .review-panel > .form-actions { padding: 0 2px; }
.scene-grid, .library-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.scene-card { padding: 16px; }
.scene-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.scene-index { color: var(--accent); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.scene-card label { margin-top: 12px; }
.scene-image { width: 100%; max-height: 270px; object-fit: cover; border-radius: 9px; background: #0c0e12; }
.scene-card .button { margin-top: 12px; }
.finished-panel { margin-top: 20px; }
.video-player-wrap { display: flex; justify-content: center; padding: 6px; border-radius: 12px; background: #090a0d; }
.video-player-wrap video { width: min(100%, 360px); max-height: 80vh; aspect-ratio: 9 / 16; object-fit: contain; background: #000; }
.finished-actions { justify-content: flex-start; margin: 18px 0 24px; }
.metadata-list { display: grid; gap: 8px; margin-bottom: 18px; }
.metadata-list > div { padding: 13px; border: 1px solid var(--border); border-radius: 10px; }
.metadata-list h3 { margin: 0; font-size: 13px; }
.metadata-list p { margin: 6px 0 0; color: var(--muted); font-size: 12px; white-space: pre-wrap; }
.copy-heading { align-items: flex-start; }
.copy-button, .text-button { padding: 4px 8px; border: 0; color: var(--accent); background: none; cursor: pointer; font-size: 11px; }
.recovery-panel { margin-top: 20px; padding: 22px; }
.recovery-panel h2 { margin: 0; font-size: 18px; }
.recovery-panel p { margin: 8px 0 16px; }
.manual-script-editor { display: grid; gap: 8px; margin-top: 18px; }
.heading-row h1 { margin-bottom: 4px; }
.filter-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.filter-bar label { margin: 0; }
.filter-bar select { width: auto; min-width: 180px; }
.library-card { display: grid; grid-template-columns: 90px minmax(0,1fr); overflow: hidden; }
.thumbnail-link { display: grid; min-height: 132px; place-items: center; background: #101318; }
.thumbnail-link img { width: 90px; height: 100%; max-height: 160px; object-fit: cover; }
.thumbnail-placeholder { color: #717a87; font-size: 11px; }
.library-card-body { min-width: 0; padding: 12px; }
.library-title-row { align-items: flex-start; gap: 8px; }
.library-title-row h2 { overflow: hidden; margin: 0; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.library-card-body p { margin: 7px 0; font-size: 11px; }
.library-card-actions { display: flex; justify-content: space-between; align-items: center; }
.empty-state { padding: 48px 20px; text-align: center; }
.empty-state h2 { margin: 8px 0 4px; }
.empty-state p { margin: 4px 0 18px; }
.empty-icon { color: var(--accent); font-size: 30px; }
.provider-row { display: grid; grid-template-columns: 1fr 140px auto minmax(150px,1fr); gap: 12px; align-items: center; padding: 15px 0; border-top: 1px solid var(--border); }
.provider-row > div { display: grid; gap: 2px; }
.provider-row > div strong { font-size: 13px; }
.provider-row > div span, .provider-result { font-size: 11px; }
.provider-state { font-size: 11px; font-weight: 700; }
.is-configured { color: var(--accent); }
.is-missing { color: #f0bf77; }
.fine-print { margin: 14px 0 0; font-size: 11px; }
.platform-fieldset { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 0; border: 0; }
.platform-fieldset legend { flex-basis: 100%; }
.inline-choice { display: inline-flex; align-items: center; gap: 7px; margin: 0; font-weight: 500; }
.inline-choice input { accent-color: var(--accent); }
.length-controls { display: flex; align-items: center; gap: 10px; }
.length-controls input[type="range"] { flex: 1; min-width: 90px; }
.length-controls input[type="number"] { width: 82px !important; }
.length-readout { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 9px 0; font-size: 12px; }
.length-status { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.length-status.is-ok { color: #d7f5bf; background: #273923; }
.length-status.is-tight { color: #ffe3a7; background: #443923; }
.length-status.is-too-long { color: #ffd0d0; background: #4a2b31; }
.over-limit-actions { margin-top: 8px; padding: 12px; border: 1px solid #624148; border-radius: 10px; }
.over-limit-actions > p { margin: 0 0 8px; color: #ffd0d0; font-size: 12px; }
.trim-preview { margin-top: 14px; }
.trim-preview h3 { font-size: 14px; }
.diff-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.diff-grid > div { min-width: 0; }
.diff-grid pre { max-height: 220px; overflow: auto; padding: 12px; border-radius: 8px; color: var(--text); background: #101318; white-space: pre-wrap; }
.scene-duration-warning { color: #ffe3a7 !important; font-size: 11px; }
.length-settings { margin-top: 18px; padding: clamp(18px, 3vw, 28px); }
.length-settings dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; margin: 0; }
.length-settings dl > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.length-settings dt { color: var(--muted); font-size: 12px; }
.length-settings dd { margin: 0; font-size: 12px; font-weight: 700; text-align: right; }
.site-footer { max-width: 1120px; margin: auto; padding: 16px 24px 24px; border-top: 1px solid rgba(255,255,255,.06); color: #707987; font-size: 11px; text-align: center; }
.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; }

@media (max-width: 680px) {
  .site-header { padding: 14px 16px; }
  nav { gap: 0; }
  nav a { padding: 8px; font-size: 12px; }
  .page-shell { padding: 32px 16px 48px; }
  .field-grid, .scene-grid, .library-grid { grid-template-columns: 1fr; }
  .style-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stepper { gap: 2px; }
  .step { font-size: 9px; }
  .step-dot { width: 24px; height: 24px; }
  .form-actions, .heading-row { align-items: stretch; flex-direction: column; }
  .form-actions .button, .heading-row .button { width: 100%; }
  .provider-row { grid-template-columns: 1fr auto; }
  .provider-state { grid-column: 1; }
  .provider-test { grid-column: 2; grid-row: 1 / span 2; }
  .provider-result { grid-column: 1 / -1; }
  .inline-controls { flex-direction: column; }
  .length-controls { flex-wrap: wrap; }
  .length-controls input[type="range"] { flex-basis: 100%; }
  .diff-grid, .length-settings dl { grid-template-columns: 1fr; }
}
