/* ==========================================================================
   H3 Studio — stylesheet
   Dark-first, no external assets, no fonts fetched over the network.
   Theme resolution: <html data-theme="dark|light"> is always written by app.js
   (from localStorage, falling back to prefers-color-scheme), so the CSS only
   ever has to read the attribute.
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 22px; --sp-6: 30px; --sp-7: 44px;

  --ease: cubic-bezier(.22, .61, .36, 1);
  --dur: 180ms;

  --maxw: 1560px;
}

/* dark (default) */
:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0b0a10;
  --bg-grad:       radial-gradient(1200px 620px at 12% -10%, #1d1733 0%, transparent 62%),
                   radial-gradient(900px 520px at 92% 4%, #0e2430 0%, transparent 58%);
  --surface:       #131220;
  --surface-2:     #1a1929;
  --surface-3:     #222034;
  --line:          #2a2840;
  --line-soft:     #211f33;

  --text:          #eceaf5;
  --text-2:        #a9a5c0;
  --text-3:        #75718c;

  --accent:        #a78bfa;
  --accent-2:      #7c5cf5;
  --accent-ink:    #12091f;
  --accent-soft:   rgba(167, 139, 250, .14);

  --teal:          #4fd1c5;
  --ok:            #3ddc97;
  --warn:          #f5b544;
  --danger:        #ff6b81;

  --shadow-1: 0 1px 2px rgba(0,0,0,.5);
  --shadow-2: 0 10px 34px -12px rgba(0,0,0,.75), 0 2px 8px rgba(0,0,0,.35);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* light */
[data-theme="light"] {
  color-scheme: light;
  --bg:            #f6f5fa;
  --bg-grad:       radial-gradient(1100px 560px at 10% -12%, #e8e2ff 0%, transparent 60%),
                   radial-gradient(820px 460px at 94% 0%, #dff2f4 0%, transparent 56%);
  --surface:       #ffffff;
  --surface-2:     #f3f2f9;
  --surface-3:     #e9e7f4;
  --line:          #ddd9ec;
  --line-soft:     #eae7f4;

  --text:          #191627;
  --text-2:        #57536e;
  --text-3:        #85809b;

  --accent:        #6d43e8;
  --accent-2:      #5a2fd6;
  --accent-ink:    #ffffff;
  --accent-soft:   rgba(109, 67, 232, .10);

  --teal:          #0e9188;
  --ok:            #14915f;
  --warn:          #b7791f;
  --danger:        #d13b52;

  --shadow-1: 0 1px 2px rgba(30,25,60,.08);
  --shadow-2: 0 14px 36px -18px rgba(40,30,90,.35), 0 2px 6px rgba(40,30,90,.06);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
/* Several containers below set `display`, which would otherwise beat the UA's
   [hidden] rule and leave hidden overlays swallowing clicks. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.012em; line-height: 1.25; }
p { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }
code { font-family: var(--font-mono); font-size: .88em;
  background: var(--surface-3); padding: .1em .38em; border-radius: var(--r-sm); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
em { font-style: italic; color: var(--text); }

:where(button, input, select, textarea, a, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-sm);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--surface-3);
  --btn-fg: var(--text);
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  border: 1px solid var(--line);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit; font-weight: 560;
  padding: 9px 15px;
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }

.btn-primary {
  --btn-bg: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  --btn-fg: var(--accent-ink);
  border-color: transparent;
  box-shadow: var(--shadow-1);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); border-color: transparent; }
.btn-ghost { --btn-bg: transparent; --btn-fg: var(--text-2); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { --btn-fg: var(--text); background: var(--surface-2); }
.btn-danger { --btn-bg: transparent; --btn-fg: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }

.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text-2); width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: var(--r-md); cursor: pointer; display: grid; place-items: center;
  font-size: 16px; line-height: 1;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- boot + login ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; color: var(--text-2); }
.boot-inner { display: flex; align-items: center; gap: var(--sp-3); font-size: 14px; }
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-5); }
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  box-shadow: var(--shadow-2);
  text-align: center;
}
.login-mark {
  width: 52px; height: 52px; margin: 0 auto var(--sp-4);
  display: grid; place-items: center;
  border-radius: 15px;
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-2) 100%);
  color: var(--accent-ink); font-family: var(--font-mono); font-weight: 700; font-size: 19px;
  box-shadow: var(--shadow-1);
}
.login-title { font-size: 25px; }
.login-sub { color: var(--text-2); font-size: 14px; margin: var(--sp-2) 0 var(--sp-5); }
.login-card .field { text-align: left; margin-bottom: var(--sp-4); }
.login-error {
  color: var(--danger); font-size: 13.5px; margin: 0 0 var(--sp-3);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3);
}

/* ---------- app shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-brand { display: flex; align-items: center; gap: var(--sp-3); flex: 0 0 auto; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px;
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-2) 100%);
  color: var(--accent-ink); font-family: var(--font-mono); font-weight: 700; font-size: 13px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; }
.brand-text small { font-size: 11.5px; color: var(--text-3); }
.topbar-actions { margin-left: auto; flex: 0 0 auto; }
.theme-icon::before { content: "☀"; }
[data-theme="light"] .theme-icon::before { content: "☾"; }

/* status bar — fixed min widths so a poll never reflows the header */
.statusbar {
  display: flex; align-items: center; gap: var(--sp-4);
  flex: 1 1 auto; min-width: 0;
  padding: 6px var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  font-size: 12.5px;
  overflow-x: auto; scrollbar-width: none;
}
.statusbar::-webkit-scrollbar { display: none; }
.stat { display: flex; align-items: center; gap: var(--sp-2); white-space: nowrap; flex: 0 0 auto; }
.stat-key { color: var(--text-3); }
.stat-value { color: var(--text-2); }
.stat-online .stat-value { min-width: 5.2ch; }
.stat-gpu .stat-key { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }
.stat + .stat { padding-left: var(--sp-4); border-left: 1px solid var(--line-soft); }

.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-3);
  flex: 0 0 8px; transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.dot[data-state="online"]  { background: var(--ok);     box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot[data-state="offline"] { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
.dot[data-state="unknown"] { background: var(--text-3); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.vram { display: flex; align-items: center; gap: var(--sp-2); }
.vram-track { width: 68px; height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; flex: 0 0 68px; }
.vram-fill { display: block; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--teal), var(--accent));
  transition: width 400ms var(--ease); }
#vram-text { min-width: 11ch; }
#queue-text { min-width: 6ch; }
#deadline-text { min-width: 8ch; }
.stat-deadline[data-level="warn"]   .stat-value { color: var(--warn); font-weight: 600; }
.stat-deadline[data-level="warn"]   .stat-key   { color: var(--warn); }
.stat-deadline[data-level="danger"] .stat-value { color: var(--danger); font-weight: 700; }
.stat-deadline[data-level="danger"] .stat-key   { color: var(--danger); }
.stat-deadline[data-level="danger"] { animation: blink 2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .6; } }

/* banners */
.banner {
  margin: var(--sp-4) var(--sp-5) 0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: 13.5px;
  display: flex; gap: var(--sp-2); flex-wrap: wrap;
}
.banner-offline {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--text);
}
.banner-offline strong { color: var(--danger); }

/* ---------- layout ---------- */
.layout {
  flex: 1 1 auto;
  width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding: var(--sp-5);
  display: grid; gap: var(--sp-5);
  grid-template-columns: minmax(0, 430px) minmax(0, 1fr);
  align-items: start;
}
@media (max-width: 1080px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.panel { min-width: 0; display: flex; flex-direction: column; gap: var(--sp-4); }
.controls { position: sticky; top: 76px; }
@media (max-width: 1080px) { .controls { position: static; } }

.block {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-1);
}
.block-tight { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.block-title { font-size: 13px; font-weight: 640; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); }
.counter { font-size: 12px; color: var(--text-3); }

/* ---------- tabs ---------- */
.tabs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 3px;
}
.tab {
  appearance: none; border: 0; background: transparent; color: var(--text-3);
  font: inherit; font-size: 13px; font-weight: 560;
  padding: 9px 8px; border-radius: 7px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover:not([aria-disabled="true"]) { color: var(--text); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.tab[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }

.pane { animation: fade var(--dur) var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(-3px); } }
.hint { font-size: 13px; color: var(--text-2); margin-bottom: var(--sp-3); }
.note { font-size: 12.2px; color: var(--text-3); line-height: 1.5; margin: var(--sp-2) 0 0; }
.note-warn { color: var(--warn); }

/* ---------- drop zones ---------- */
.dropzones { display: grid; gap: var(--sp-3); }
.dropzones.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 420px) { .dropzones.two { grid-template-columns: 1fr; } }

.dz {
  position: relative;
  border: 1.5px dashed var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: var(--sp-4);
  min-height: 118px;
  display: flex; flex-direction: column; justify-content: center; gap: var(--sp-3);
  cursor: pointer; text-align: center;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dz:hover { border-color: var(--accent); }
.dz.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.dz.has-items { text-align: left; }
.dz.has-items .dz-body { display: none; }
/* the browse affordance is a real <button> so keyboard + screen readers get it
   for free, and so the per-thumbnail remove buttons are never nested inside it */
.dz-body {
  appearance: none; border: 0; background: transparent; color: inherit; font: inherit;
  width: 100%; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.dz-icon { font-size: 19px; color: var(--accent); line-height: 1; }
.dz-title { font-size: 13.5px; font-weight: 570; }
.dz-sub { font-size: 11.5px; color: var(--text-3); }

.dz-items { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.dz:not(.has-items) .dz-items { display: none; }

.thumb {
  position: relative; width: 78px; height: 78px; flex: 0 0 78px;
  border-radius: var(--r-sm); overflow: hidden;
  background: var(--surface-3); border: 1px solid var(--line);
  display: grid; place-items: center;
}
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-add {
  appearance: none; font: inherit; cursor: pointer;
  border-style: dashed; color: var(--text-3);
}
.thumb-add:hover { border-color: var(--accent); color: var(--accent); }
.thumb .thumb-kind {
  font-size: 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em;
  padding: 0 4px; text-align: center; word-break: break-all;
}
.thumb-remove {
  position: absolute; top: 2px; right: 2px; width: 19px; height: 19px;
  border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0,0,0,.72); color: #fff; font-size: 12px; line-height: 1;
  display: grid; place-items: center; padding: 0;
}
.thumb-remove:hover { background: var(--danger); }
.thumb.is-uploading::after {
  content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.55);
}
.thumb-progress {
  position: absolute; left: 6px; right: 6px; bottom: 8px; height: 4px; z-index: 2;
  border-radius: 2px; background: rgba(255,255,255,.25); overflow: hidden;
}
.thumb-progress > span { display: block; height: 100%; background: var(--accent); width: 0; transition: width 120ms linear; }
.thumb.is-error { border-color: var(--danger); }

/* ---------- fields ---------- */
.field { display: block; margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }
.field-inline { margin-top: var(--sp-3); }
.field-label { display: block; font-size: 12.5px; font-weight: 560; color: var(--text-2); margin-bottom: 5px; }
.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: 5px; }
.field-row .field-label { margin: 0; }
.field-out { font-size: 12.5px; color: var(--accent); font-weight: 600; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 9px 11px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  padding-right: 34px;
}
textarea { resize: vertical; }
.prompt { min-height: 190px; line-height: 1.6; font-size: 14px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 24px; background: transparent; cursor: pointer; display: block;
}
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: var(--surface-3); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--surface-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 17px; height: 17px; margin-top: -6px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--bg);
  box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease);
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg); box-shadow: var(--shadow-1);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.16); }

.seed-row { display: flex; gap: var(--sp-2); align-items: center; }
.seed-row input { flex: 1 1 auto; min-width: 0; }

.adv { margin-bottom: var(--sp-4); border-top: 1px solid var(--line-soft); }
.adv > summary {
  cursor: pointer; font-size: 12.5px; color: var(--text-3); padding: var(--sp-2) 0;
  list-style: none; user-select: none;
}
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before { content: "▸"; display: inline-block; width: 1.1em; }
.adv[open] > summary::before { content: "▾"; }
.adv > summary:hover { color: var(--text); }
.adv-body { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); padding-bottom: var(--sp-2); }
.adv-body .note { grid-column: 1 / -1; margin-top: 0; }

/* ---------- prompt tools ---------- */
.prompt-tools { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-3); }
.disclosure {
  margin-top: var(--sp-3); padding: var(--sp-4);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); font-size: 13px; color: var(--text-2);
  animation: fade var(--dur) var(--ease);
}
.structure-list { margin: 0 0 var(--sp-3); padding-left: 1.15em; display: grid; gap: 7px; }
.structure-list strong { color: var(--text); }

.examples { margin-top: var(--sp-4); }
.examples-label { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: var(--sp-2); }
.example-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  appearance: none; cursor: pointer; font: inherit; font-size: 12.5px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2);
  transition: all var(--dur) var(--ease);
}
.chip:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- estimate ---------- */
.estimate {
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
}
.estimate-main { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.estimate-key { font-size: 12.5px; color: var(--text-2); }
.estimate-val { font-size: 19px; font-weight: 640; color: var(--text); letter-spacing: -.01em; }
.estimate-sub { font-size: 12.2px; color: var(--text-3); margin-top: 2px; }

.btn-generate { padding: 13px 18px; font-size: 15px; border-radius: var(--r-md); }
.blocked-reason {
  font-size: 12.5px; color: var(--warn); text-align: center; margin: 0;
}

/* ---------- progress ---------- */
.progress-card {
  background: var(--surface); border: 1px solid var(--accent-soft);
  border-radius: var(--r-lg); padding: var(--sp-4); box-shadow: var(--shadow-1);
}
.progress-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.progress-stage { font-size: 14px; font-weight: 600; }
.progress-track {
  height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; position: relative;
}
.progress-fill {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--teal), var(--accent));
  transition: width 400ms var(--ease);
}
/* indeterminate = VAE decode + mux, which reports no step counter */
.progress-track.indeterminate .progress-fill {
  width: 38% !important;
  animation: slide 1.5s var(--ease) infinite;
}
@keyframes slide { 0% { transform: translateX(-105%); } 100% { transform: translateX(300%); } }
.progress-meta { display: flex; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-2); font-size: 12.5px; color: var(--text-3); }

/* ---------- result ---------- */
.result {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: var(--sp-4); box-shadow: var(--shadow-1);
  animation: fade 260ms var(--ease);
}
.video-wrap { position: relative; border-radius: var(--r-md); overflow: hidden; background: #000; line-height: 0; }
.video-wrap video { width: 100%; height: auto; display: block; max-height: 66vh; background: #000; }

.unmute {
  position: absolute; left: var(--sp-3); right: var(--sp-3); bottom: 56px;
  display: flex; align-items: center; gap: var(--sp-3); text-align: left;
  padding: 10px 14px; border-radius: var(--r-md); cursor: pointer;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(14, 10, 26, .82);
  backdrop-filter: blur(8px);
  color: #fff; font: inherit; font-size: 12.8px; line-height: 1.45;
  animation: rise 500ms var(--ease);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.unmute:hover { background: rgba(24, 16, 44, .94); border-color: var(--accent); }
.unmute[hidden] { display: none; }
.unmute-icon { font-size: 20px; flex: 0 0 auto; }
.unmute-text strong { display: inline; color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 520px) { .unmute { bottom: 48px; font-size: 12px; padding: 8px 10px; } }

.result-meta {
  display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3);
  margin-top: var(--sp-3); font-size: 12.5px;
}
.meta-item { display: inline-flex; gap: 5px; align-items: baseline;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  padding: 3px 9px; border-radius: 999px; }
.meta-k { color: var(--text-3); }
.meta-v { color: var(--text); font-variant-numeric: tabular-nums; }

.result-prompt {
  margin-top: var(--sp-3); font-size: 13px; color: var(--text-2);
  white-space: pre-wrap; max-height: 8.5em; overflow: auto;
  border-left: 2px solid var(--line); padding-left: var(--sp-3);
}
.result-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-4); }

/* ---------- placeholder / error ---------- */
.placeholder {
  background: var(--surface); border: 1px dashed var(--line);
  border-radius: var(--r-lg); padding: var(--sp-7) var(--sp-5);
  text-align: center; color: var(--text-2);
}
.placeholder-icon { font-size: 30px; color: var(--accent); display: block; margin-bottom: var(--sp-3); }
.placeholder h2 { font-size: 17px; color: var(--text); margin-bottom: var(--sp-2); }
.placeholder p { font-size: 13.5px; max-width: 52ch; margin: 0 auto; }

.errorbox {
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 42%, transparent);
  border-radius: var(--r-lg); padding: var(--sp-4);
}
.errorbox-head { font-weight: 620; color: var(--danger); margin-bottom: var(--sp-2); }
.errorbox-msg {
  font-family: var(--font-mono); font-size: 12.2px; color: var(--text);
  white-space: pre-wrap; word-break: break-word; margin: 0 0 var(--sp-3);
  max-height: 220px; overflow: auto;
}

/* ---------- gallery ---------- */
.gallery-block {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: var(--sp-4);
}
.gallery {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.gallery-empty { font-size: 13px; color: var(--text-3); margin: 0; }

.card {
  position: relative; border-radius: var(--r-md); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  cursor: pointer; text-align: left; padding: 0; font: inherit; color: inherit;
  appearance: none;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
  display: flex; flex-direction: column;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card-thumb { aspect-ratio: 16 / 9; background: var(--surface-3); position: relative; overflow: hidden; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-thumb .card-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
}
.card-badge {
  position: absolute; left: 6px; bottom: 6px;
  font-size: 10.5px; padding: 2px 7px; border-radius: 999px;
  background: rgba(0,0,0,.66); color: #fff; font-variant-numeric: tabular-nums;
}
.card-state {
  position: absolute; right: 6px; top: 6px;
  font-size: 10px; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .05em;
  background: rgba(0,0,0,.66); color: #fff;
}
.card-state[data-state="error"] { background: var(--danger); }
.card-state[data-state="running"], .card-state[data-state="queued"], .card-state[data-state="decoding"] { background: var(--accent); color: var(--accent-ink); }
.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.card-prompt {
  font-size: 12px; color: var(--text-2); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-prompt.is-open { -webkit-line-clamp: unset; line-clamp: unset; display: block; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); font-size: 10.5px; color: var(--text-3); }
.card-foot > span:first-child { white-space: nowrap; }
.card-actions { display: flex; gap: 4px; }
.mini-btn {
  appearance: none; border: 1px solid var(--line); background: transparent; color: var(--text-3);
  font: inherit; font-size: 10.5px; padding: 1px 6px; border-radius: var(--r-sm); cursor: pointer;
}
.mini-btn:hover { color: var(--text); border-color: var(--text-3); }
.mini-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- footer ---------- */
.footer {
  max-width: var(--maxw); margin: 0 auto; width: 100%;
  padding: var(--sp-5); display: flex; flex-wrap: wrap; gap: var(--sp-2);
  font-size: 12px; color: var(--text-3); border-top: 1px solid var(--line-soft);
}
.footer-sep { opacity: .5; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: 90;
  display: flex; flex-direction: column; gap: var(--sp-2);
  max-width: min(380px, calc(100vw - 2 * var(--sp-4)));
}
.toast {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md); padding: 10px 13px;
  box-shadow: var(--shadow-2); font-size: 13px; color: var(--text);
  animation: toast-in 220ms var(--ease);
}
.toast[data-kind="error"] { border-left-color: var(--danger); }
.toast[data-kind="warn"]  { border-left-color: var(--warn); }
.toast[data-kind="ok"]    { border-left-color: var(--ok); }
.toast.is-out { animation: toast-out 200ms var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(14px); } }

/* ---------- narrow screens ---------- */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); gap: var(--sp-3); }
  .statusbar {
    order: 3; flex-basis: 100%; border-radius: var(--r-md);
    flex-wrap: wrap; overflow: visible; gap: var(--sp-2) var(--sp-3); padding: var(--sp-2) var(--sp-3);
  }
  .stat + .stat { padding-left: var(--sp-3); }
  .stat-gpu .stat-key { max-width: 16ch; }
  .layout { padding: var(--sp-4); gap: var(--sp-4); }
  .banner { margin: var(--sp-3) var(--sp-4) 0; }
  .footer { padding: var(--sp-4); }
}
@media (max-width: 400px) {
  body { font-size: 14.5px; }
  .block { padding: var(--sp-3); }
  .brand-text small { display: none; }
  .adv-body { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .result-actions .btn { flex: 1 1 auto; }
}

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

/* ── LoRA picker ────────────────────────────────────────────────────── */
.lora-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.lora-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-2) var(--sp-3);
  align-items: center;
  padding: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.lora-row[data-on="true"] { border-color: var(--accent); background: var(--accent-soft); }

.lora-check { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; grid-column: 1 / -1; }
.lora-check input { flex: none; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.lora-name {
  font-family: var(--font-mono); font-size: .8125rem; line-height: 1.3;
  overflow-wrap: anywhere; min-width: 0;
}

/* strength only matters once the LoRA is on, so it collapses away when off */
.lora-strength {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2);
  align-items: center;
}
.lora-row[data-on="false"] .lora-strength { display: none; }
.lora-strength input[type="range"] { width: 100%; }
.lora-strength .num { font-size: .8125rem; min-width: 2.75rem; text-align: right; }

/* ── Shared-secret gate ───────────────────────────────────────────────
   The password field is type="text" (see index.html for why) and masked in CSS.
   Where the browser supports neither text-security property, app.js falls back to
   a real password input — an unmasked secret on screen is worse than the
   cross-app autofill this avoids. */
.pw-wrap { position: relative; display: block; }
#login-password.masked {
  -webkit-text-security: disc;
  text-security: disc;
  letter-spacing: .12em;
}
.pw-reveal {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  background: none; border: 0; cursor: pointer; padding: .25rem .4rem;
  font: inherit; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted, #9b96b0); border-radius: 6px;
}
.pw-reveal:hover { color: var(--fg, #eee); background: rgba(255,255,255,.06); }
.login-note { margin: .4rem 0 0; font-size: .8rem; color: var(--muted, #9b96b0); text-align: center; }

/* ── Workspace switch: single clip vs story ─────────────────────────── */
.viewswitch {
  display: flex; gap: .4rem; padding: .75rem 1.25rem 0;
  max-width: 1600px; margin: 0 auto; width: 100%;
}
.vtab {
  appearance: none; border: 1px solid var(--line, #2a2440);
  background: var(--panel, #17142433); color: var(--muted, #9b96b0);
  padding: .5rem 1.1rem; border-radius: 10px 10px 0 0;
  font: inherit; font-weight: 600; cursor: pointer; border-bottom-color: transparent;
}
.vtab[aria-selected="true"] {
  background: var(--panel-solid, #1b1729); color: var(--fg, #eee);
  border-color: var(--accent, #a78bfa);
}
.vtab:focus-visible { outline: 2px solid var(--accent, #a78bfa); outline-offset: 2px; }

/* ── Story panel ─────────────────────────────────────────────────────── */
.story-seg { margin: .6rem 0; }
.story-seg > summary {
  display: flex; align-items: center; gap: .6rem; cursor: pointer;
  padding: .5rem .2rem; font-weight: 600;
}
.story-seg-n {
  display: inline-grid; place-items: center;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--accent-dim, #2c2450); color: var(--accent, #a78bfa);
  font-size: .8rem; font-variant-numeric: tabular-nums;
}
.story-seg-state {
  margin-left: auto; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  padding: .15rem .5rem; border-radius: 999px;
  background: rgba(255,255,255,.06); color: var(--muted, #9b96b0);
}
.story-seg-state[data-state="running"] { background: #3b2f14; color: #f0c674; }
.story-seg-state[data-state="done"]    { background: #14321f; color: #7ee2a8; }
.story-seg-state[data-state="error"]   { background: #3a1a1a; color: #f08a8a; }
.story-seg textarea.prompt { width: 100%; margin-top: .4rem; }
.story-seg video { margin-top: .6rem; width: 100%; border-radius: 10px; }

#story-status[data-kind="error"] { color: #f08a8a; }
#story-status[data-kind="warn"]  { color: #f0c674; }
#story-status[data-kind="ok"]    { color: #7ee2a8; }

/* ── Work bar: workspace tabs on the left, the GPU pod on the right ──── */
.workbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  max-width: 1600px; margin: 0 auto; width: 100%;
  padding: .75rem 1.25rem 0;
}
.workbar .viewswitch { padding: 0; margin: 0; width: auto; }

.podbar { display: flex; align-items: center; padding-bottom: .35rem; }
.pod-idle, .pod-live { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.pod-label { font-size: .82rem; color: var(--muted, #9b96b0); }
.pod-hours { display: flex; align-items: center; gap: .35rem; font-size: .78rem;
             color: var(--muted, #9b96b0); }
.pod-hours input { width: 4.5rem; }

.pod-dot { width: .6rem; height: .6rem; border-radius: 50%; background: #f0c674; flex: none; }
.pod-dot[data-state="running"] { background: #7ee2a8; }
.pod-dot[data-state="error"]   { background: #f08a8a; }
/* Provisioning takes ~12 minutes, so the pulse is what says "still working, not stuck". */
.pod-dot[data-state="provisioning"] { animation: pod-pulse 1.6s ease-in-out infinite; }
@keyframes pod-pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

.pod-phase { font-size: .82rem; font-weight: 600; }
.pod-metric { font-size: .82rem; color: var(--muted, #9b96b0); }
.pod-metric[data-level="warn"]   { color: #f0c674; }
.pod-metric[data-level="danger"] { color: #f08a8a; font-weight: 700; }
.pod-danger:hover { color: #f08a8a; }

.pod-note {
  max-width: 1600px; margin: .4rem auto 0; width: 100%;
  padding: 0 1.25rem; font-size: .82rem; color: var(--muted, #9b96b0);
}
.pod-note[data-kind="error"] { color: #f08a8a; }
.pod-note[data-kind="ok"]    { color: #7ee2a8; }

@media (max-width: 760px) {
  .workbar { flex-direction: column; align-items: stretch; }
  .podbar { justify-content: flex-start; }
}

/* ── Storyboard keyframes ────────────────────────────────────────────── */
.sub-title { margin: 1.2rem 0 .5rem; font-size: .95rem; }
.kf-grid {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.kf-card {
  border: 1px solid var(--line, #2a2440); border-radius: 12px;
  padding: .7rem; display: flex; flex-direction: column; gap: .45rem;
  background: var(--panel, rgba(255,255,255,.02));
}
.kf-head { display: flex; align-items: center; gap: .5rem; }
.kf-title { font-weight: 600; font-size: .88rem; }
.kf-head .story-seg-state { margin-left: auto; }
.kf-img { width: 100%; border-radius: 8px; display: block; aspect-ratio: 16/9; object-fit: cover; }
.kf-placeholder {
  aspect-ratio: 16/9; border-radius: 8px; display: grid; place-items: center;
  padding: .8rem; text-align: center; font-size: .78rem; line-height: 1.35;
  color: var(--muted, #9b96b0); background: rgba(255,255,255,.03);
  border: 1px dashed var(--line, #2a2440);
}
.kf-prompt { font-size: .78rem; }
.kf-neg, .kf-note { width: 100%; font-size: .76rem; }
.kf-actions { display: flex; gap: .3rem; flex-wrap: wrap; }
.kf-actions .btn { padding: .28rem .55rem; font-size: .74rem; }

#board-status[data-kind="error"] { color: #f08a8a; }
#board-status[data-kind="warn"]  { color: #f0c674; }
#board-status[data-kind="ok"]    { color: #7ee2a8; }
