/* ── Hatsu UI: the component layer ───────────────────────────────────────────
   Loaded AFTER the page's own stylesheet, so it also retunes the older classes
   (.hz-btn, .ps-*, .tl-*) rather than requiring every renderer to be rewritten.
   Presentation changes here; domain logic stays where it is.

   Read the file in this order: shell → primitives → editor surfaces → states. */

/* ═══ Base ══════════════════════════════════════════════════════════════════ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
	background: var(--surface-canvas);
	color: var(--text-primary);
	font-family: var(--font);
	font-size: var(--t-body);
	line-height: var(--lh-body);
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }

/* product.css set `label { text-transform: uppercase }` globally, which shouted
   through every label-wrapped control — including the upload panel, whose heading
   and paragraph came out in capitals. Labels are sentence case; the few genuinely
   uppercase elements ask for it by name. */
label, label * { text-transform: none; letter-spacing: normal; }
label { font-size: var(--t-label); color: var(--text-secondary); margin-bottom: var(--s-1); }
.btn, .hz-btn, .btn-primary, .insp-tab, .seg > button { text-transform: none; letter-spacing: normal; }
::selection { background: var(--text-primary); color: var(--text-inverse); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: var(--r-pill); border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ═══ Application shell ═════════════════════════════════════════════════════ */
.app {
	display: grid;
	grid-template-columns: var(--rail-w) 1fr;
	min-height: 100vh;
}
.app[data-rail="collapsed"] { grid-template-columns: var(--rail-w-collapsed) 1fr; }

/* ── Navigation rail ─────────────────────────────────────────────────────── */
.rail {
	position: sticky; top: 0; align-self: start;
	height: 100vh;
	display: flex; flex-direction: column;
	gap: var(--s-1);
	padding: var(--s-4) var(--s-3);
	background: var(--surface-1);
	border-right: 1px solid var(--line-faint);
}
.rail-mark {
	display: flex; align-items: center; gap: var(--s-2);
	padding: var(--s-2) var(--s-2) var(--s-5);
	font-size: var(--t-display); font-weight: 700; letter-spacing: -.02em;
	color: var(--text-primary);
}
.rail-mark small {
	font-size: var(--t-micro); font-weight: 600; letter-spacing: .14em;
	text-transform: uppercase; color: var(--text-muted); padding-top: 7px;
}
.rail-group { display: flex; flex-direction: column; gap: 2px; }
.rail-heading {
	font-size: var(--t-micro); font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
	color: var(--text-muted); padding: var(--s-4) var(--s-2) var(--s-2);
}
.rail a, .rail button.rail-item {
	display: flex; align-items: center; gap: var(--s-3);
	height: var(--control-h-lg); padding: 0 var(--s-3);
	border: 1px solid transparent; border-radius: var(--r-md);
	background: none; font: inherit; font-size: var(--t-label); font-weight: 500;
	color: var(--text-secondary); text-decoration: none; cursor: pointer;
	transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.rail a:hover, .rail button.rail-item:hover { background: var(--surface-2); color: var(--text-primary); }
.rail a[aria-current="page"] {
	background: var(--surface-3); color: var(--text-primary); font-weight: 600;
	border-color: var(--line);
}
.rail a[aria-current="page"] .rail-ico { color: var(--text-primary); }
.rail-ico { flex: 0 0 var(--icon); width: var(--icon); height: var(--icon); color: var(--text-muted); }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.app[data-rail="collapsed"] .rail-label,
.app[data-rail="collapsed"] .rail-heading,
.app[data-rail="collapsed"] .rail-mark small { display: none; }
.app[data-rail="collapsed"] .rail { padding: var(--s-4) var(--s-2); align-items: center; }
.app[data-rail="collapsed"] .rail a { justify-content: center; padding: 0; width: var(--control-h-lg); }

.app-main { min-width: 0; display: flex; flex-direction: column; }

/* ── Top project bar ─────────────────────────────────────────────────────── */
.topbar {
	position: sticky; top: 0; z-index: 30;
	display: flex; align-items: center; gap: var(--s-3);
	height: var(--topbar-h); padding: 0 var(--s-5);
	background: var(--surface-canvas);
	border-bottom: 1px solid var(--line-faint);
}
.topbar-title { display: flex; align-items: baseline; gap: var(--s-3); min-width: 0; }
.topbar-title h1 {
	margin: 0; font-size: var(--t-title); font-weight: 600; letter-spacing: -.01em;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-kind { font-size: var(--t-micro); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }
.topbar-sep { width: 1px; height: 20px; background: var(--line); }

/* ═══ Primitives ════════════════════════════════════════════════════════════ */

/* ── Buttons. One system: primary is white-on-black and there is ONE per view ── */
.btn, .hz-btn {
	display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
	height: var(--control-h); padding: 0 var(--s-3);
	font: inherit; font-size: var(--t-label); font-weight: 550; line-height: 1;
	color: var(--text-primary); background: var(--surface-2);
	border: 1px solid var(--line); border-radius: var(--r-md);
	cursor: pointer; white-space: nowrap;
	transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.btn:hover, .hz-btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.btn:active, .hz-btn:active { background: var(--surface-2); }
.btn-primary, .hz-btn-primary {
	color: var(--text-inverse); background: var(--text-primary);
	border-color: var(--text-primary); font-weight: 600;
}
.btn-primary:hover, .hz-btn-primary:hover { background: #FFFFFF; border-color: #FFFFFF; color: var(--text-inverse); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); border-color: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger-line); background: var(--danger-bg); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-sm, .hz-btn-sm { height: var(--control-h-sm); padding: 0 var(--s-2); font-size: var(--t-small); }
.btn-lg { height: var(--control-h-lg); padding: 0 var(--s-4); }
.btn-block { width: 100%; }
.btn[disabled], .hz-btn[disabled], .btn[aria-disabled="true"] {
	opacity: 1; color: var(--text-muted); background: var(--surface-1);
	border-color: var(--line-faint); cursor: not-allowed;
}
.btn-icon {
	display: inline-flex; align-items: center; justify-content: center;
	width: var(--control-h); height: var(--control-h); padding: 0;
	color: var(--text-secondary); background: transparent;
	border: 1px solid transparent; border-radius: var(--r-md); cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text-primary); }
.btn svg, .btn-icon svg, .hz-btn svg { width: var(--icon); height: var(--icon); flex: none; }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
.input, .hz-input, select.hz-input, textarea.hz-input {
	width: 100%; height: var(--control-h); padding: 0 var(--s-3);
	font: inherit; font-size: var(--t-label); color: var(--text-primary);
	background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md);
	transition: border-color var(--fast) var(--ease);
}
textarea.hz-input, textarea.input { height: auto; padding: var(--s-2) var(--s-3); line-height: var(--lh-body); }
.input:hover, .hz-input:hover { border-color: var(--line-strong); }
.input::placeholder, .hz-input::placeholder { color: var(--text-muted); }
select.hz-input, select.input {
	appearance: none; padding-right: var(--s-6);
	background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
	background-position: calc(100% - 18px) 15px, calc(100% - 13px) 15px;
	background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--text-primary); width: 15px; height: 15px; }
input[type="range"] { accent-color: var(--text-primary); height: 18px; }

/* ── Segmented control (platform, preview mode, density) ─────────────────── */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.seg > button, .hz-plats { font: inherit; }
.seg > button {
	flex: 1; height: var(--control-h-sm); padding: 0 var(--s-3);
	font-size: var(--t-small); font-weight: 550; color: var(--text-secondary);
	background: transparent; border: 0; border-radius: var(--r-sm); cursor: pointer;
	transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.seg > button:hover { color: var(--text-primary); }
.seg > button[aria-pressed="true"], .seg > button.active {
	background: var(--surface-3); color: var(--text-primary); box-shadow: var(--shadow-1);
}
/* the editor's platform buttons, retuned into the same control */
.hz-plats { display: flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); }
.hz-plat {
	flex: 1; height: var(--control-h-sm); min-width: 0; padding: 0 var(--s-2);
	font-size: var(--t-small); font-weight: 550; color: var(--text-secondary);
	background: transparent; border: 0; border-radius: var(--r-sm); cursor: pointer;
}
.hz-plat:hover { color: var(--text-primary); }
.hz-plat.active { background: var(--surface-3); color: var(--text-primary); box-shadow: var(--shadow-1); }

/* ── Badges. Status is a word first, a colour second ─────────────────────── */
.badge, .ps-badge {
	display: inline-flex; align-items: center; gap: 5px;
	height: 20px; padding: 0 var(--s-2);
	font-size: var(--t-micro); font-weight: 600; letter-spacing: .01em; line-height: 1;
	color: var(--text-secondary); background: var(--info-bg);
	border: 1px solid var(--info-line); border-radius: var(--r-pill);
	white-space: nowrap;
}
.badge-ok, .ps-badge-ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.badge-warn, .ps-badge-warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.badge-danger { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-line); }
.badge-quiet, .ps-badge-soon { color: var(--text-muted); background: transparent; border-color: var(--line); }
.badge-accent { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; }

/* ── Panels + section headings ───────────────────────────────────────────── */
.panel, .pane {
	background: var(--surface-1); border: 1px solid var(--line-faint);
	border-radius: var(--r-lg); padding: var(--s-4);
}
.panel-flush { padding: 0; overflow: hidden; }
.section-h, .ps-h {
	display: flex; align-items: center; gap: var(--s-2);
	margin: 0 0 var(--s-3);
	font-size: var(--t-section); font-weight: 600; letter-spacing: -.005em;
	color: var(--text-primary); text-transform: none;
}
.section-h .badge, .ps-h .badge, .ps-h .ps-badge { margin-left: auto; }
.hint, .ps-meta, .ps-note {
	margin-top: var(--s-2);
	font-size: var(--t-small); line-height: 1.5; color: var(--text-muted);
	word-break: normal;
}
.divider { height: 1px; background: var(--line-faint); margin: var(--s-4) 0; border: 0; }

/* ── Advanced disclosure: diagnostics stay, they just stop shouting ──────── */
.adv { margin-top: var(--s-3); border-top: 1px solid var(--line-faint); padding-top: var(--s-3); }
.adv > summary {
	display: flex; align-items: center; gap: var(--s-2);
	font-size: var(--t-small); font-weight: 550; color: var(--text-muted);
	cursor: pointer; list-style: none; user-select: none;
}
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before { content: "+"; font-size: 13px; line-height: 1; width: 10px; }
.adv[open] > summary::before { content: "–"; }
.adv > summary:hover { color: var(--text-primary); }
.adv-body { margin-top: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); }
.kv { display: flex; gap: var(--s-3); font-size: var(--t-micro); color: var(--text-muted); }
.kv dt { min-width: 116px; color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-secondary); font-family: var(--font-mono); word-break: break-all; }

/* ═══ Editor workspace ══════════════════════════════════════════════════════ */
/* The editor fills the viewport: the stage and the inspector scroll inside
   themselves, so the timeline is ALWAYS on screen. A timeline you have to
   scroll to is a report, not a timeline. */
.workspace {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 400px;
	grid-template-rows: minmax(0, 1fr) auto;
	grid-template-areas: "stage inspector" "timeline inspector";
	gap: var(--s-4);
	padding: var(--s-4) var(--s-5) var(--s-4);
	height: calc(100vh - var(--topbar-h));
	min-height: 0;
}
#preview-pane { grid-area: stage; min-height: 0; overflow: auto; }
#project-pane { grid-area: inspector; min-height: 0; overflow: auto; }
#timeline-pane { grid-area: timeline; min-height: 0; max-height: var(--timeline-h); overflow: auto; }

/* ── Studio start: the upload-first state ────────────────────────────────── */
.start { display: flex; flex-direction: column; gap: var(--s-5); max-width: 640px; margin: auto; padding: var(--s-5) 0; }
.start-drop {
	display: flex; flex-direction: column; align-items: center; gap: var(--s-3);
	padding: var(--s-7) var(--s-5); text-align: center; cursor: pointer;
	background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--r-lg);
	transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.start-drop:hover, .start-drop.is-dropping { border-color: var(--text-secondary); background: var(--surface-3); }
.start-drop:focus-within { box-shadow: var(--focus-ring); }
.start-drop h2 { margin: 0; font-size: var(--t-title); font-weight: 600; letter-spacing: -.01em; }
.start-drop p { margin: 0; max-width: 44ch; font-size: var(--t-label); color: var(--text-secondary); }
.start-next-h { font-size: var(--t-micro); font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--s-3); }
.start-steps { margin: 0; padding-left: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); }
.start-steps li { font-size: var(--t-label); color: var(--text-secondary); }
.start-steps li::marker { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.start-alts { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.hz-stage.is-dropping { border-color: var(--text-secondary); }

/* the preview is the centre of the room: it gets the height, not the form */
#preview-pane { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); }
.hz-stage-wrap { width: 100%; display: flex; justify-content: center; }
.hz-stage {
	width: auto; height: min(52vh, 560px); max-width: 100%;
	aspect-ratio: 9 / 16; background: #000;
	border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden;
	box-shadow: var(--shadow-2);
}
.hz-preview-controls { display: flex; gap: var(--s-2); flex-wrap: wrap; justify-content: center; }
.hz-dropzone { gap: var(--s-2); color: var(--text-muted); font-size: var(--t-label); }
.hz-dz-emoji { font-size: 26px; opacity: .5; }
.hz-dz-sub { font-size: var(--t-micro); opacity: .8; }

/* ── Preview modes: clean · safe · debug ──────────────────────────────────
   The guides were shouting louder than the work. Clean shows nothing, Safe
   shows quiet regions, Debug keeps every label and coordinate for developers. */
.mask-zone { background: rgba(212,115,110,.10); border: 1px solid rgba(212,115,110,.28); }
.mask-zone span { font-size: 8px; color: #fff; opacity: .55; }
.mask-margin { border: 1px dashed rgba(255,255,255,.28); }
.mask-tag { font-size: var(--t-micro); background: rgba(0,0,0,.6); color: var(--text-secondary); }
body[data-preview="clean"] .mask-layer,
body[data-preview="clean"] [data-exclude-from-export="true"] { display: none !important; }
body[data-preview="safe"] .mask-zone span,
body[data-preview="safe"] .mask-tag { display: none; }
body[data-preview="debug"] .mask-zone { background: rgba(212,115,110,.20); border-color: rgba(212,115,110,.7); }
body[data-preview="debug"] .mask-zone span { opacity: 1; font-size: 8.5px; }

/* ── Inspector tabs ──────────────────────────────────────────────────────── */
.insp-tabs {
	position: sticky; top: 0; z-index: 2;
	display: flex; gap: 2px; padding: 0 0 var(--s-3);
	margin: 0 0 var(--s-3); overflow-x: auto;
	background: var(--surface-1); border-bottom: 1px solid var(--line-faint);
}
.insp-tab {
	height: var(--control-h-sm); padding: 0 var(--s-3);
	font: inherit; font-size: var(--t-small); font-weight: 550; color: var(--text-muted);
	background: transparent; border: 0; border-radius: var(--r-sm); cursor: pointer; white-space: nowrap;
}
.insp-tab:hover { color: var(--text-primary); background: var(--surface-2); }
.insp-tab[aria-selected="true"] { color: var(--text-primary); background: var(--surface-3); }
.insp-tab .badge-dot { margin-left: 6px; background: var(--warn); }
[role="tabpanel"][hidden] { display: none; }
.ps-block { margin: 0 0 var(--s-5); }
.ps-block:last-child { margin-bottom: 0; }
.ps-row { display: flex; gap: var(--s-2); margin-top: var(--s-2); }
.ps-status { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-3); font-size: var(--t-small); color: var(--text-secondary); }
.ps-dot { width: 6px; height: 6px; background: var(--line-strong); }
.ps-dot.busy { background: var(--text-primary); }
.ps-prog { height: 3px; background: var(--surface-2); border-radius: var(--r-pill); margin-top: var(--s-2); }
.ps-prog-fill { background: var(--text-primary); }
.ps-empty {
	padding: var(--s-4); font-size: var(--t-small); color: var(--text-secondary);
	background: var(--surface-2); border: 1px solid var(--line-faint); border-radius: var(--r-md);
	opacity: 1;
}
.ps-transcript { background: var(--surface-inset); border-color: var(--line-faint); border-radius: var(--r-md); font-size: var(--t-label); }
.ps-warn {
	font-size: var(--t-small); color: var(--danger);
	background: var(--danger-bg); border: 1px solid var(--danger-line); border-radius: var(--r-md);
	padding: var(--s-3);
}
.ps-warn-demo { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.ps-w:hover { border-bottom-color: var(--text-muted); }
.ps-w-low { color: var(--warn); border-bottom-color: var(--warn); }

/* stage checklist: where the project actually is, in five lines */
.stage-list { display: flex; flex-direction: column; gap: var(--s-1); }
.stage-row {
	display: flex; align-items: center; gap: var(--s-3);
	padding: var(--s-2) 0; border-bottom: 1px solid var(--line-faint);
}
.stage-row:last-child { border-bottom: 0; }
.stage-name { font-size: var(--t-label); color: var(--text-secondary); }
.stage-row .badge { margin-left: auto; }
.ce-chk { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--t-label); color: var(--text-secondary); cursor: pointer; }

/* ── Timeline: docked to the stage, not a card at the end of a page ──────── */
#timeline-pane { padding: var(--s-3) var(--s-4) var(--s-4); }
.tl-head { margin-bottom: var(--s-3); }
.tl-title { font-size: var(--t-section); font-weight: 600; color: var(--text-primary); }
.tl-dur { font-size: var(--t-small); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tl-ruler { border-bottom: 1px solid var(--line-faint); }
.tl-tick { font-size: var(--t-micro); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tl-playhead { background: var(--accent); width: 1.5px; }
.tl-tracks { gap: var(--s-1); }
.tl-label { width: 132px; font-size: var(--t-small); font-weight: 550; color: var(--text-secondary); }
.tl-lane {
	min-height: 38px; background: var(--surface-inset);
	border: 1px solid var(--line-faint); border-radius: var(--r-md);
}
.tl-empty { font-size: var(--t-small); color: var(--text-muted); }
.tl-item { border-radius: var(--r-sm); font-size: var(--t-micro); font-weight: 550; box-shadow: none; }
.tl-cap { background: #3A3A3A; color: var(--text-primary); }
.tl-mo  { background: #4A4A4A; color: var(--text-primary); }
.tl-so  { background: #5A5A5A; color: var(--text-primary); }
.tl-cap.tl-sel { outline: 2px solid var(--text-primary); outline-offset: 1px; }
.tl-mini { border-color: var(--line); border-radius: var(--r-sm); font-size: var(--t-micro); }
.tl-mini:hover { background: var(--surface-3); }

/* ═══ States ════════════════════════════════════════════════════════════════ */
.empty-state {
	display: flex; flex-direction: column; align-items: center; justify-content: center;
	gap: var(--s-3); padding: var(--s-7) var(--s-5); text-align: center;
}
.empty-state h2 { margin: 0; font-size: var(--t-title); font-weight: 600; letter-spacing: -.01em; }
.empty-state p { margin: 0; max-width: 46ch; font-size: var(--t-label); color: var(--text-secondary); }
.empty-state .empty-actions { display: flex; gap: var(--s-2); margin-top: var(--s-2); }
.empty-icon { width: 40px; height: 40px; color: var(--text-muted); }

/* ── Product pages (Projects, Carousel, AI Video, Settings) ──────────────── */
.p-main { padding: var(--s-5) var(--s-5) var(--s-7); max-width: 1400px; }
.p-h1 { font-size: var(--t-title); font-weight: 600; letter-spacing: -.01em; margin: 0 0 var(--s-2); }
.p-sub { font-size: var(--t-label); color: var(--text-secondary); margin: 0 0 var(--s-5); max-width: 76ch; }
.p-card {
	background: var(--surface-1); border: 1px solid var(--line-faint); border-radius: var(--r-lg);
	padding: var(--s-5); margin-bottom: var(--s-4);
}
.p-card > h2 {
	font-size: var(--t-section); font-weight: 600; letter-spacing: -.005em;
	text-transform: none; color: var(--text-primary); margin: 0 0 var(--s-4);
}
.p-note { font-size: var(--t-small); color: var(--text-muted); margin-top: var(--s-4); }
.p-btn {
	display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
	height: var(--control-h); padding: 0 var(--s-3);
	font: inherit; font-size: var(--t-label); font-weight: 550; text-transform: none; letter-spacing: normal;
	color: var(--text-primary); background: var(--surface-2);
	border: 1px solid var(--line); border-radius: var(--r-md); cursor: pointer;
}
.p-btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.p-btn.primary { color: var(--text-inverse); background: var(--text-primary); border-color: var(--text-primary); font-weight: 600; }
.p-row { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }

/* ── Carousel Studio: a design workspace, not a stack of cards ───────────── */
/* Slide rail · canvas · inspector, from the markup the editor already writes. */
.p-main:has(#carousel-host) {
	max-width: none; display: grid; grid-template-columns: minmax(0, 1fr) 340px;
	grid-template-areas: "head side" "sub side" "editor side";
	grid-template-rows: auto auto minmax(0, 1fr);
	gap: 0 var(--s-4); align-content: start;
}
.p-main:has(#carousel-host) > .p-h1 { grid-area: head; }
.p-main:has(#carousel-host) > .p-sub { grid-area: sub; }
/* The brief and the export panel share one scrolling side column: two separate
   grid rows put them on different tracks, which left a hole beside the canvas. */
#brief-card, #export-card { grid-area: side; align-self: start; }
#export-card { align-self: end; }
#editor-card { grid-area: editor; }
/* Slide rail · canvas · inspector. The children are matched by what they ARE,
   not by their position: the editor appends more than three, and nth-child
   mapping silently created extra columns that crushed the inspector to 50px. */
/* The editor writes: [ .car-rail , .car-cols[ canvas , panels ] ]. So the rail
   is one column and .car-cols carries canvas + inspector — measured in the
   browser, after a first guess at nth-child put the inspector in a 45px strip. */
.car-editor { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: var(--s-4); align-items: start; }
.car-cols { grid-template-columns: minmax(320px, 1fr) minmax(300px, 360px); gap: var(--s-4); }
.car-cols > .p-card { padding: var(--s-4); }
.car-cols > .p-card > h2 { font-size: var(--t-label); }
.car-rail {
	display: flex; flex-direction: column; gap: var(--s-2);
	max-height: 62vh; overflow-y: auto; padding-right: var(--s-1);
}
.car-rail > button {
	display: grid; grid-template-columns: 20px 1fr; align-items: center; gap: var(--s-2);
	padding: var(--s-2); text-align: left; cursor: pointer;
	background: var(--surface-2); border: 1px solid var(--line-faint); border-radius: var(--r-sm);
	color: var(--text-secondary); font: inherit; font-size: var(--t-micro);
}
.car-rail > button:hover { border-color: var(--line); background: var(--surface-3); }
.car-rail > button[aria-current="true"], .car-rail > button.is-selected { border-color: var(--text-secondary); color: var(--text-primary); }
.car-thumb-n { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.car-thumb-svg { display: block; overflow: hidden; border-radius: 3px; }
.car-thumb-svg svg { width: 100%; height: auto; display: block; }
.car-thumb-lay { grid-column: 1 / -1; color: var(--text-muted); }
.car-canvas { border-color: var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-2); }
.car-canvas-note { font-size: var(--t-micro); color: var(--text-muted); margin-top: var(--s-2); }
.car-field { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.car-field input, .car-field select, .car-field textarea {
	width: 100%; min-height: var(--control-h); padding: var(--s-2) var(--s-3);
	font: inherit; font-size: var(--t-label); color: var(--text-primary);
	background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md);
}

/* ── AI Video Studio: scenes across, work below ──────────────────────────── */
.p-main:has(#aivideo-host) { max-width: none; display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "head head" "scenes preview" "scenes script" "scenes export"; gap: 0 var(--s-4); align-content: start; }
.p-main:has(#aivideo-host) > .p-h1 { grid-area: head; }
.p-main:has(#aivideo-host) > .p-sub { grid-area: sub; }
#v-editor-card { grid-area: scenes; }
.av-side { grid-area: side; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: var(--s-3); padding-right: var(--s-1); }
.av-side > .p-card { margin-bottom: 0; }
/* once a project exists the setup form is a header you have already used */
#v-setup-card.is-done > .car-brief, #v-setup-card.is-done > .p-row { display: none; }
#v-setup-card.is-done { padding: var(--s-3) var(--s-4); }
#v-preview-card { grid-area: preview; }
#v-script-card { grid-area: script; }
#v-export-card { grid-area: export; }
.av-timeline { display: flex; gap: var(--s-2); overflow-x: auto; padding-bottom: var(--s-2); }
.av-timeline > * { flex: 0 0 auto; }
.av-mocklabel {
	background: var(--surface-3); color: var(--text-primary); text-transform: none;
	letter-spacing: normal; font-size: var(--t-micro); font-weight: 550;
	border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 3px 8px;
}

@media (max-width: 1240px) {
	.p-main:has(#carousel-host), .p-main:has(#aivideo-host) { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }
	.car-editor { grid-template-columns: 120px minmax(0, 1fr); grid-template-areas: "rail canvas" "props props"; }
}

/* ── Cards: providers, export routes ─────────────────────────────────────── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s-3); }
.pcard {
	display: flex; flex-direction: column; gap: var(--s-3);
	padding: var(--s-4); background: var(--surface-2);
	border: 1px solid var(--line-faint); border-radius: var(--r-md);
}
.pcard-h { display: flex; align-items: center; gap: var(--s-3); }
.pcard-h h3 { margin: 0; font-size: var(--t-body); font-weight: 600; }
.pcard-h .badge { margin-left: auto; }
.pcard p { margin: 0; font-size: var(--t-label); line-height: 1.55; color: var(--text-secondary); }
.pcard-state { font-size: var(--t-small); color: var(--text-muted); }
.pcard .btn { align-self: flex-start; }
.pcard .adv { margin-top: 0; }

/* developer section */
.dev-list { display: flex; flex-direction: column; gap: var(--s-2); }
.dev-row {
	display: grid; grid-template-columns: 220px auto 1fr; align-items: center; gap: var(--s-2) var(--s-3);
	padding: var(--s-2) 0; border-bottom: 1px solid var(--line-faint);
}
.dev-row .hint { grid-column: 1 / -1; margin: 0; }
.dev-name { font-size: var(--t-label); font-weight: 550; color: var(--text-primary); }
#s-dev-body { margin-top: var(--s-4); }

/* ── Project library ─────────────────────────────────────────────────────── */
.proj {
	display: flex; align-items: center; gap: var(--s-4);
	padding: var(--s-3) var(--s-4);
	background: var(--surface-1); border: 1px solid var(--line-faint);
	border-radius: var(--r-md); margin-bottom: var(--s-2);
	transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.proj:hover { border-color: var(--line); background: var(--surface-2); }
.proj-thumb {
	display: flex; align-items: center; justify-content: center; flex: none;
	width: 52px; height: 52px; color: var(--text-secondary);
	background: var(--surface-inset); border: 1px solid var(--line-faint); border-radius: var(--r-sm);
}
.proj-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.proj-name { font-size: var(--t-body); font-weight: 550; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-meta { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; font-size: var(--t-small); color: var(--text-muted); }
.proj-acts { display: flex; align-items: center; gap: var(--s-1); flex: none; }

/* rail environment note: present, quiet, and only when this is not the live site */
.rail-env {
	display: block; padding: var(--s-2) var(--s-3); margin-bottom: var(--s-2);
	font-size: var(--t-micro); color: var(--text-muted);
	border: 1px dashed var(--line); border-radius: var(--r-sm); text-align: center;
}
.app[data-rail="collapsed"] .rail-env { display: none; }
/* the verification strip only renders in developer mode; keep it compact there */
.rail .p-status { display: flex; flex-direction: column; gap: 3px; margin-bottom: var(--s-2); }
.rail .p-badge { font-size: 10px; padding: 2px 6px; border-radius: var(--r-sm); }

/* toast */
#hz-toast {
	left: auto; right: var(--s-5); bottom: var(--s-5); transform: translateY(12px);
	max-width: 380px; text-align: left;
	background: var(--surface-3); color: var(--text-primary);
	border: 1px solid var(--line); border-radius: var(--r-md);
	box-shadow: var(--shadow-2); font-size: var(--t-label); font-weight: 500;
	padding: var(--s-3) var(--s-4);
}
#hz-toast.show { transform: translateY(0); }

/* the inspector tab row must always fit: it scrolls rather than clipping */
.insp-tabs { scrollbar-width: none; }
.insp-tabs::-webkit-scrollbar { display: none; }
@media (max-width: 1500px) { .insp-tab { padding: 0 var(--s-2); font-size: var(--t-micro); } }

/* ═══ Responsive ════════════════════════════════════════════════════════════ */
@media (max-width: 1500px) { .workspace { grid-template-columns: minmax(0, 1fr) 360px; } }
@media (max-width: 1240px) {
	.app { grid-template-columns: var(--rail-w-collapsed) 1fr; }
	.app .rail-label, .app .rail-heading, .app .rail-mark small { display: none; }
	.app .rail { padding: var(--s-4) var(--s-2); align-items: center; }
	.app .rail a { justify-content: center; padding: 0; width: var(--control-h-lg); }
	.workspace { grid-template-columns: minmax(0, 1fr) 340px; padding: var(--s-3) var(--s-4) var(--s-4); }
	.hz-stage { height: min(52vh, 520px); }
}
@media (max-width: 980px) {
	.workspace {
		grid-template-columns: minmax(0, 1fr);
		grid-template-areas: "stage" "inspector" "timeline";
	}
	#project-pane { position: static; max-height: none; }
	.hz-stage { height: min(60vh, 560px); }
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.app[data-rail="collapsed"] ~ * .toasts, .app[data-rail="collapsed"] .toasts { left: calc(var(--rail-w-collapsed) + var(--s-5)); }
.toasts {
	/* Anchored to the WORK column, not the window: bottom-right would sit on top
	   of the inspector, which is where the controls are. */
	position: fixed; left: calc(var(--rail-w) + var(--s-5)); bottom: var(--s-4); z-index: 60;
	display: flex; flex-direction: column; gap: var(--s-2);
	max-width: min(380px, calc(100vw - var(--s-6))); pointer-events: none;
}
.toast {
	display: flex; align-items: center; gap: var(--s-3);
	padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
	background: var(--surface-3); color: var(--text-primary);
	border: 1px solid var(--line); border-left: 2px solid var(--line-strong);
	border-radius: var(--r-md); box-shadow: var(--shadow-2);
	font-size: var(--t-label); line-height: 1.45;
	opacity: 0; transform: translateY(8px); pointer-events: auto;
	transition: opacity var(--base) var(--ease), transform var(--base) var(--ease);
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--ok); }
.toast-warning { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--danger); }
.toast-text { flex: 1; min-width: 0; }
.toast-action {
	flex: none; height: var(--control-h-sm); padding: 0 var(--s-3);
	font: inherit; font-size: var(--t-small); font-weight: 600;
	color: var(--text-inverse); background: var(--text-primary);
	border: 0; border-radius: var(--r-sm); cursor: pointer;
}
.toast-close {
	flex: none; width: 24px; height: 24px; padding: 0;
	font-size: 16px; line-height: 1; color: var(--text-muted);
	background: transparent; border: 0; border-radius: var(--r-sm); cursor: pointer;
}
.toast-close:hover { color: var(--text-primary); background: var(--surface-2); }

/* short viewports: the timeline dock gives ground before the stage does */
@media (max-height: 820px) { :root { --timeline-h: 186px; } .hz-stage { height: min(46vh, 460px); } }
@media (max-width: 1240px) { .toasts { left: calc(var(--rail-w-collapsed) + var(--s-5)); } }

/* ═══ Studio-class workspaces: Carousel and AI Video ════════════════════════
   Both were laid out correctly but still grew past one screen, so editing a
   deck or a scene list meant scrolling the page. They now use the same rule as
   Studio: the workspace owns the remaining viewport height, and every region
   scrolls inside itself. Adding slides or scenes lengthens a rail, never the
   page. */
.p-main:has(#carousel-host), .p-main:has(#aivideo-host) {
	height: 100vh; padding: var(--s-4) var(--s-5); overflow: hidden;
	grid-template-rows: auto auto minmax(0, 1fr);
}
.p-main:has(#carousel-host) { grid-template-areas: "head side" "sub side" "editor side"; }
.p-main:has(#aivideo-host) { grid-template-areas: "head head" "sub sub" "scenes side"; }
.p-main:has(#carousel-host) > .p-h1, .p-main:has(#aivideo-host) > .p-h1 { margin-bottom: 0; }
.p-main:has(#carousel-host) > .p-sub, .p-main:has(#aivideo-host) > .p-sub { margin-bottom: var(--s-3); }
#editor-card, #v-editor-card { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
#editor-card > div, #v-editor-card > div { min-height: 0; }
#brief-card, #export-card { min-height: 0; overflow: auto; }
/* the right-hand column shares one scroll region across its cards */
.p-main:has(#carousel-host) > #brief-card { margin-bottom: var(--s-3); max-height: 55vh; }
.p-main:has(#carousel-host) > #export-card { max-height: 38vh; }

/* Carousel: rail scrolls, canvas fits the height it is given, inspector scrolls */
.car-editor { min-height: 0; height: 100%; align-items: stretch; }
.car-rail { max-height: none; height: 100%; min-height: 0; }
.car-cols { min-height: 0; height: 100%; align-items: stretch; }
.car-cols > div:first-child { min-height: 0; overflow: hidden; display: flex; flex-direction: column; align-items: center; }
.car-canvas { height: min(100%, 58vh); width: auto; max-width: 100%; }
.car-canvas svg { width: 100%; height: 100%; }
.car-cols > .p-card { min-height: 0; overflow: auto; }

/* AI Video: scene rail scrolls, preview fits, inspector tabs stay put */
#v-editor-card { grid-area: scenes; }
.av-editor, .av-cols { min-height: 0; height: 100%; }
.av-cols { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(280px, 340px); gap: var(--s-4); align-items: stretch; }
.av-rail, .av-centre, .av-inspector { min-height: 0; overflow: auto; }
.av-rail { padding-right: var(--s-1); }
.av-scenes { display: flex; flex-direction: column; gap: var(--s-2); }
.av-scene {
	display: grid; grid-template-columns: 22px 1fr; gap: var(--s-1) var(--s-2);
	padding: var(--s-2) var(--s-3); text-align: left; cursor: pointer;
	background: var(--surface-2); border: 1px solid var(--line-faint); border-radius: var(--r-md);
	color: var(--text-secondary); font: inherit; font-size: var(--t-small);
}
.av-scene:hover { border-color: var(--line); background: var(--surface-3); }
.av-scene.is-selected { border-color: var(--text-secondary); color: var(--text-primary); }
.av-scene-n { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.av-scene-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.av-scene-body b { font-weight: 600; color: var(--text-primary); }
.av-scene-body span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.av-scene .sfx-chip { grid-column: 2; justify-self: start; }
.av-centre { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); }
.av-stage { position: relative; height: min(100%, 62vh); aspect-ratio: 9 / 16; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: #000; }
.av-stage svg { width: 100%; height: 100%; display: block; }
.av-tabs { font-size: var(--t-micro); position: sticky; top: 0; z-index: 2; display: flex; gap: 2px; flex-wrap: wrap; padding-bottom: var(--s-3); margin-bottom: var(--s-3); background: var(--surface-1); border-bottom: 1px solid var(--line-faint); }
.av-panel[hidden] { display: none; }
.av-source { display: flex; flex-direction: column; gap: var(--s-3); }
.av-source p { margin: 0; font-size: var(--t-label); color: var(--text-secondary); line-height: 1.55; }
.sfx-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: center; }

@media (max-width: 1240px) {
	.av-cols { grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) minmax(260px, 300px); }
	.car-editor { grid-template-columns: 120px minmax(0, 1fr); }
}
@media (max-width: 980px) {
	.p-main:has(#carousel-host), .p-main:has(#aivideo-host) { height: auto; overflow: visible; grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }
	.av-cols { grid-template-columns: minmax(0, 1fr); }
}

.av-tabs .insp-tab { padding: 0 var(--s-2); font-size: var(--t-micro); }
@media (max-width: 1440px) { .av-tabs .insp-tab { padding: 0 6px; } }

/* The scene workspace is three columns INSIDE a two-column page, so at 1366 the
   centre was being squeezed to a sliver. The side column and the rail give way
   first; the preview is what the screen is for. */
@media (max-width: 1500px) {
	.p-main:has(#aivideo-host) { grid-template-columns: minmax(0, 1fr) 300px; }
	.av-cols { grid-template-columns: minmax(180px, 210px) minmax(0, 1fr) minmax(240px, 270px); gap: var(--s-3); }
	.av-scene { font-size: var(--t-micro); padding: var(--s-2); }
}
@media (max-width: 1400px) {
	.p-main:has(#aivideo-host) { grid-template-columns: minmax(0, 1fr) 280px; }
	.av-cols { grid-template-columns: 170px minmax(0, 1fr) 240px; }
	.av-stage { height: min(100%, 46vh); }
}

/* ═══ Production polish ═════════════════════════════════════════════════════ */

/* Seven tabs wrapped to two lines at 1366. A tab row that reflows is a tab row
   you have to re-find, so it is now one line that scrolls, with the selected tab
   scrolled into view by the editor. */
.av-tabs {
	flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
	scroll-snap-type: x proximity;
}
.av-tabs::-webkit-scrollbar { display: none; }
.av-tabs .insp-tab { flex: 0 0 auto; scroll-snap-align: start; font-size: var(--t-small); padding: 0 var(--s-2); }
@media (max-width: 1500px) { .av-tabs .insp-tab { font-size: var(--t-micro); padding: 0 7px; } }

/* The canvas note was wider than the canvas and centred, so both ends clipped. */
.car-cols > div:first-child { width: 100%; }
.car-canvas-note {
	width: 100%; max-width: 100%; text-align: center;
	overflow-wrap: anywhere; line-height: 1.45; padding: 0 var(--s-2);
}

/* ── Project previews ────────────────────────────────────────────────────── */
.proj-thumb { width: 64px; height: 64px; padding: 0; overflow: hidden; background: var(--surface-inset); }
.proj-thumb svg { width: 100%; height: 100%; display: block; }
.proj-thumb.is-fallback { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.proj-thumb.is-fallback svg { width: 22px; height: 22px; }

/* ── Quick start: the first-use checklist ────────────────────────────────── */
.quickstart {
	background: var(--surface-2); border: 1px solid var(--line);
	border-radius: var(--r-md); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-5);
}
.quickstart-h { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-3); }
.quickstart-h h3 { margin: 0; font-size: var(--t-label); font-weight: 600; }
.quickstart-h .btn-icon { margin-left: auto; width: 24px; height: 24px; }
.quickstart ol { margin: 0; padding-left: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); }
.quickstart li { font-size: var(--t-small); color: var(--text-secondary); }
.quickstart li.is-done { color: var(--text-muted); }
.quickstart li.is-done::marker { content: '✓  '; }
.quickstart li button {
	font: inherit; font-size: var(--t-small); color: var(--text-primary);
	background: none; border: 0; border-bottom: 1px solid var(--line-strong);
	padding: 0; cursor: pointer;
}
.quickstart li button:hover { border-bottom-color: var(--text-primary); }

/* ── Help ────────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: rgba(0,0,0,.6); padding: var(--s-5); }
.modal { width: min(640px, 100%); max-height: min(80vh, 680px); overflow: auto; background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-2); }
.modal-h { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); }
.modal-h h2 { margin: 0; font-size: var(--t-title); font-weight: 600; letter-spacing: -.01em; }
.modal-h .btn-icon { margin-left: auto; }
.modal h3 { margin: var(--s-4) 0 var(--s-2); font-size: var(--t-label); font-weight: 600; color: var(--text-primary); }
.modal p, .modal li { font-size: var(--t-label); color: var(--text-secondary); line-height: 1.55; }
.modal ul { margin: 0; padding-left: var(--s-5); display: flex; flex-direction: column; gap: var(--s-1); }

/* Six tabs at 400px: "Export" was clipping even at 1920. The row still scrolls,
   but it should not need to — the tabs simply fit now. */
.insp-tab { padding: 0 var(--s-2); font-size: var(--t-small); }
@media (max-width: 1500px) { .insp-tab { padding: 0 7px; font-size: var(--t-micro); } }
