:root {
  --bg: #0f0e13;
  --bg-2: #15131b;
  --panel: #1b1922;
  --panel-2: #221f2b;
  --line: #2e2a38;
  --line-2: #3a3547;
  --fg: #f1eef6;
  --muted: #a39dae;
  --faint: #6f697b;
  --accent: #f06a90;
  --accent-2: #ff8fae;
  --accent-ink: #1c0a11;
  --accent-soft: rgba(240, 106, 144, 0.14);
  --good: #5bd48a;
  --warn: #f2b35e;
  --bad: #ff8a80;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 32px rgba(0, 0, 0, 0.35);
  --checker: #1d1b24;
  color-scheme: dark;
  scrollbar-color: var(--line-2) transparent;
}
* { scrollbar-width: thin; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f3f8;
    --bg-2: #efecf3;
    --panel: #ffffff;
    --panel-2: #f7f5fa;
    --line: #e4e0ea;
    --line-2: #d6d1de;
    --fg: #1d1a23;
    --muted: #625c6e;
    --faint: #9a94a5;
    --accent: #d9416b;
    --accent-2: #e75a82;
    --accent-ink: #ffffff;
    --accent-soft: rgba(217, 65, 107, 0.1);
    --good: #1b8a4b;
    --warn: #b76b0b;
    --bad: #b3261e;
    --shadow: 0 1px 2px rgba(20, 10, 30, 0.05), 0 10px 28px rgba(20, 10, 30, 0.07);
    --checker: #ece8f1;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f3f8; --bg-2: #efecf3; --panel: #ffffff; --panel-2: #f7f5fa; --line: #e4e0ea; --line-2: #d6d1de;
  --fg: #1d1a23; --muted: #625c6e; --faint: #9a94a5; --accent: #d9416b; --accent-2: #e75a82; --accent-ink: #ffffff;
  --accent-soft: rgba(217, 65, 107, 0.1); --good: #1b8a4b; --warn: #b76b0b; --bad: #b3261e; --checker: #ece8f1;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, var(--accent-soft), transparent 60%), var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent-2); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------------ layout: one screen */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr);
  gap: 0 18px;
  padding: 0 18px 18px;
}
.bar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; }
.rail {
  /* the gutter is always reserved so the controls don't narrow when the scrollbar appears;
     the right padding is smaller by about its width */
  display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 16px 8px 16px 16px;
  scrollbar-gutter: stable;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stage {
  display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; padding: 10px; container-type: inline-size;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ------------------------------------------------------------------ header */
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--accent-ink); font-weight: 800;
}
.name { font-size: 16px; letter-spacing: -0.01em; }
.name b { font-weight: 700; color: var(--accent-2); }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; min-width: 0; }
.status span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent); }
.dot.busy { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.dot.err { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.35; } }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip {
  font-size: 12px; color: var(--muted); padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); white-space: nowrap;
}
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
}
.icon-btn:hover:not(:disabled) { color: var(--fg); border-color: var(--line-2); }
.icon-btn.soft { background: var(--panel-2); }

/* ------------------------------------------------------------------ shared controls */
.label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.help { margin: 0; font-size: 12px; color: var(--faint); }
.help.center { text-align: center; }
.muted { color: var(--faint); font-style: normal; font-weight: 400; }
.help code { font-size: 11px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; user-select: all; overflow-wrap: anywhere; }
#backendHelp { line-height: 1.6; }
.link { background: none; border: 0; padding: 0; color: var(--accent-2); font-size: 12px; }
.link:hover { text-decoration: underline; }
.small-link { font-size: 12px; cursor: pointer; }

textarea, input, select {
  font: inherit; color: inherit; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; width: 100%;
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { flex: 1 1 auto; min-height: 110px; resize: none; line-height: 1.5; }
textarea.neg { flex: none; min-height: 0; height: 64px; resize: vertical; font-size: 13px; }
select {
  -webkit-appearance: none; appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a39dae' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 14px;
}
select option { background: var(--panel); color: var(--fg); }
/* styled picker where the browser supports it (Chrome 135+); elsewhere the native one */
@supports (appearance: base-select) {
  select, ::picker(select) { appearance: base-select; }
  select { display: flex; align-items: center; gap: 8px; background-image: none; padding-right: 12px; }
  select::picker-icon {
    content: ""; width: 14px; height: 14px; margin-left: auto; transition: rotate 0.15s;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a39dae' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") center / 14px no-repeat;
  }
  select:open::picker-icon { rotate: 180deg; }
  select:open { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  ::picker(select) {
    margin-block: 6px; padding: 5px; border: 1px solid var(--line-2); border-radius: 12px;
    background: var(--panel); color: var(--fg); box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
    max-height: min(440px, 70dvh); overflow-y: auto;
  }
  optgroup {
    padding: 8px 10px 2px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--faint);
  }
  optgroup + optgroup { margin-top: 4px; border-top: 1px solid var(--line); }
  option {
    display: flex; align-items: center; gap: 8px; margin: 1px 0; padding: 7px 10px; border-radius: 8px;
    font-size: 13px; font-weight: 400; letter-spacing: normal; text-transform: none; color: var(--fg);
    background: transparent; cursor: pointer;
  }
  optgroup option { margin-inline: -10px; }
  option:hover, option:focus-visible { background: var(--panel-2); outline: none; }
  option:checked { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
  option::checkmark { order: 1; margin-left: auto; content: "✓"; color: var(--accent-2); }
  option:disabled { color: var(--faint); cursor: default; background: transparent; }
  .batch { width: 64px; padding: 0 8px 0 12px; gap: 4px; }
  .batch::picker-icon { width: 12px; height: 12px; background-size: 12px; }
  .batch::picker(select) { min-width: 72px; }
  .batch option { justify-content: center; }
  .batch option::checkmark { display: none; }
}

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; padding: 0; background: transparent; border: 0; }
input[type="range"]:focus { box-shadow: none; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 99px; background: var(--line-2); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 99px; background: var(--line-2); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 13px 16px; border: 0; border-radius: 12px; font-weight: 700; font-size: 15px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--accent-ink);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 0.08s, filter 0.15s;
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary:active:not(:disabled) { transform: translateY(1px); }
.primary.wide { width: auto; min-width: 240px; align-self: center; }
.primary.slim { width: auto; padding: 10px 18px; font-size: 14px; }
.ghost { background: transparent; border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 14px; color: var(--fg); }
.ghost.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

/* segmented control */
.seg { display: flex; padding: 3px; gap: 3px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.seg button {
  flex: 1 1 0; min-width: 0; padding: 4px 2px; border: 0; border-radius: 7px; background: transparent; color: var(--muted);
  font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg button[aria-checked="true"] { background: var(--panel-2); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); font-weight: 600; }
.seg button:hover:not([aria-checked="true"]) { color: var(--fg); }

/* pill toggles (Boost, new seed each time) */
.pill {
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-2);
  background: transparent; color: var(--faint); letter-spacing: 0.01em; white-space: nowrap;
}
.pill[aria-pressed="true"] { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--accent-soft); }
.pill:hover { color: var(--fg); }

.url-row { display: flex; gap: 8px; }
.url-row .ghost { flex: none; }

/* ------------------------------------------------------------------ rail: two views (main / LoRAs) */
.view { display: flex; flex-direction: column; gap: 12px; flex: 1 0 auto; }
.view.enter { animation: slideIn 0.18s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateX(12px); } }
.view-head { display: flex; align-items: center; gap: 10px; }
.view-head h2 { margin: 0; font-size: 16px; flex: 1; }
.view-foot { display: flex; justify-content: space-between; gap: 8px; padding-top: 2px; }

.group { display: flex; flex-direction: column; gap: 8px; }
.group.grow { flex: 1 1 auto; min-height: 170px; }
.head-actions { display: flex; align-items: center; gap: 10px; }

/* LoRA entry row */
.lora-entry {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg-2); text-align: left; flex: none;
}
.lora-entry:hover { border-color: var(--line-2); }
.lora-entry .label { flex: none; }
.lora-entry .stack { display: flex; }
.lora-entry .stack img, .lora-entry .stack i {
  width: 22px; height: 22px; border-radius: 6px; object-fit: cover; border: 2px solid var(--bg-2); margin-left: -6px; background: var(--panel-2);
}
.lora-entry .stack :first-child { margin-left: 0; }
.lora-sum { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.chev { width: 16px; height: 16px; color: var(--faint); flex: none; }

/* canvas: aspect ratios and sizes | width and height sliders */
.canvas-grid { display: grid; grid-template-columns: 184px minmax(0, 1fr); gap: 8px 10px; align-items: center; }
.canvas-grid .seg button { padding: 5px 0; }
.shapes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.shape {
  display: flex; align-items: center; justify-content: center; height: 32px; padding: 0;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg-2); color: var(--muted);
}
.shape i { display: block; border: 1.5px solid currentColor; border-radius: 3px; }
.shape[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--fg); }
.shape:hover { border-color: var(--line-2); }
.slider { display: grid; grid-template-columns: 12px minmax(0, 1fr) 34px; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.slider > span { text-align: center; }
.slider output { font-variant-numeric: tabular-nums; text-align: right; color: var(--fg); font-size: 12px; }

/* sampling */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button {
  font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px dashed var(--line-2); background: transparent; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chips button:hover, .chips button[aria-expanded="true"] { color: var(--fg); border-style: solid; border-color: var(--accent); }
.chips button b { color: var(--fg); font-weight: 600; }

.popover {
  position: fixed; z-index: 20; width: 240px; padding: 12px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--line-2); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45); display: flex; flex-direction: column; gap: 8px;
}
.popover .row { display: grid; grid-template-columns: minmax(0, 1fr) 42px; gap: 8px; align-items: center; }
.popover output { text-align: right; font-variant-numeric: tabular-nums; }
.popover .opts { display: flex; flex-direction: column; gap: 4px; }
.popover .opts button { text-align: left; padding: 6px 8px; border-radius: 8px; border: 1px solid transparent; background: transparent; font-size: 13px; }
.popover .opts button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.popover .opts button small { display: block; color: var(--faint); font-size: 11px; }

/* seed */
.seed-row { display: flex; align-items: center; gap: 6px; }
.seed-row input { padding: 6px 10px; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.seed-row .icon-btn { width: 32px; height: 32px; flex: none; }

/* generate row */
.go-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; margin-top: auto; flex: none; }
.go-row .primary { height: 46px; gap: 8px; padding: 0 14px; }
.go-sub { font-size: 12px; font-weight: 500; opacity: 0.75; }
.go-sub::before { content: "· "; }
.go-sub:empty { display: none; }
.batch { width: 58px; height: 46px; padding: 0 22px 0 10px; font-weight: 600; text-align: center; background-position: right 6px center; background-size: 12px; }
.stop { width: 46px; height: 46px; color: var(--bad); }
.stop svg { width: 14px; height: 14px; }

/* ------------------------------------------------------------------ LoRA view */
.lora-card {
  display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 12px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-2);
}
.lora-card img, .lora-card .noimg { width: 56px; height: 74px; border-radius: 8px; object-fit: cover; background: var(--panel-2); }
.lora-card h3 { margin: 0 0 2px; font-size: 15px; }
.lora-card .meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.badge { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.words { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.words span { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--panel-2); color: var(--fg); }
.card-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.dl { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.dl .bar-progress { max-width: none; }
.dl-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.loras { display: flex; flex-direction: column; gap: 6px; flex: 1 1 auto; min-height: 60px; overflow-y: auto; scrollbar-width: thin; }
.loras:empty::after { content: "No LoRAs yet."; font-size: 12px; color: var(--faint); }
.lora {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 7px 8px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line);
}
.lora.off { opacity: 0.55; }
.lora.bad { border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.lora .thumb {
  width: 40px; height: 40px; border-radius: 7px; background: var(--panel-2); border: 0; padding: 0;
  display: grid; place-items: center; font-size: 11px; color: var(--faint); overflow: hidden;
}
.lora .thumb img { width: 100%; height: 100%; object-fit: cover; }
.lora .mid { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lora.pending .mid { gap: 5px; }
.lora .title { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lora .title small { color: var(--faint); }
.lora .str { display: grid; grid-template-columns: minmax(0, 1fr) 30px; gap: 6px; align-items: center; }
.lora .str output { font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.lora .bar-progress { max-width: none; height: 4px; }
.lora .msg { font-size: 11px; color: var(--bad); }
.lora .btns { display: flex; gap: 2px; }
.lora .btns a, .lora .btns button {
  width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; border: 0; background: transparent; color: var(--muted);
}
.lora .btns a:hover, .lora .btns button:hover { color: var(--fg); background: var(--panel-2); }
.lora .btns svg { width: 14px; height: 14px; }

/* ------------------------------------------------------------------ stage: viewer */
.canvas-box {
  position: relative; flex: 1 1 auto; min-height: 0; display: grid; place-items: center; overflow: hidden;
  background: var(--bg-2); border-radius: var(--radius-sm);
}
canvas {
  position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px); display: block;
  object-fit: contain; filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.35));
}
.panel-center {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 32px; text-align: center; overflow-y: auto;
}
.panel-center h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.panel-center h2 { margin: 0; font-size: 18px; }
.lead { margin: 0; max-width: 520px; color: var(--muted); }
.welcome-version { width: 100%; max-width: 640px; text-align: left; }
.empty-art { width: 132px; height: 104px; color: var(--accent-2); }
.empty-art svg { width: 100%; height: 100%; stroke-width: 1.6; }
.empty-art .frame { stroke: var(--line-2); }
.empty-art .hill { fill: var(--accent-soft); stroke: color-mix(in srgb, var(--accent) 60%, transparent); }
.empty-art .spark { stroke: var(--accent-2); }

.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 640px; }
.preset {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2);
}
.preset:hover { border-color: var(--line-2); }
.preset[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.preset b { font-size: 14px; }
.preset .size { font-size: 13px; font-variant-numeric: tabular-nums; }
.preset .desc { font-size: 12px; color: var(--muted); }
.preset .tag { position: absolute; top: 10px; right: 10px; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.preset .saved { font-size: 11px; color: var(--good); }

.welcome-token { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.welcome-token .label em { font-style: normal; font-weight: 400; color: var(--faint); margin-left: 4px; }
.welcome-token .ghost { flex: none; display: inline-flex; align-items: center; text-decoration: none; font-size: 13px; white-space: nowrap; }
.welcome-token .help.ok { color: var(--good); }
.welcome-token .help.err { color: var(--bad); }

.spinner {
  width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar-progress { width: 100%; max-width: 420px; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar-progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.25s; }

.progress-card {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); width: min(420px, calc(100% - 40px));
  display: flex; flex-direction: column; gap: 8px; padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 85%, transparent); backdrop-filter: blur(10px);
  border: 1px solid var(--line); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.progress-card .bar-progress { max-width: none; }
.error-card {
  position: absolute; left: 50%; top: 20px; transform: translateX(-50%); max-width: calc(100% - 40px);
  padding: 10px 14px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--bad) 50%, transparent);
  background: var(--panel); color: var(--bad); font-size: 13px;
}

/* all images of the session, covering the viewer */
.gallery {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: var(--bg-2);
}
.gallery-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.gallery-head .help { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-head .icon-btn { width: 32px; height: 32px; }
.gallery-grid {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: thin;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); grid-auto-rows: max-content; gap: 10px; align-content: start;
}
.gallery-grid .tile { height: auto; width: 100%; font-size: 12px; }
.gallery-grid .tile .ring { width: 40px; height: 40px; }

/* ------------------------------------------------------------------ stage: info line + image strip */
/* Fixed heights, so the viewer never changes size as info or thumbnails come and go. */
.stage-foot { flex: none; display: flex; flex-direction: column; gap: 8px; }
.info {
  display: flex; align-items: center; gap: 12px; height: 32px; min-width: 0; padding: 0 2px 0 4px;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.info .meta { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info .meta b { font-weight: 600; color: var(--fg); }
.info .meta .sep { color: var(--faint); margin: 0 6px; }
.info .meta .note { color: var(--warn); }
.info .actions { flex: none; display: flex; gap: 6px; }
.info .actions button, .info .actions a {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--fg); font-size: 12px; text-decoration: none; white-space: nowrap;
}
.info .actions button:hover, .info .actions a:hover { border-color: var(--line-2); }
.info .actions svg { width: 14px; height: 14px; }
@container (max-width: 640px) { .info .actions span { display: none; } .info .actions button, .info .actions a { padding: 0 8px; } }

.strip-row { display: flex; gap: 8px; height: 64px; }
.strip { flex: 1 1 auto; min-width: 0; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.strip:empty::before { content: "Your images will show up here."; align-self: center; padding-left: 4px; font-size: 12px; color: var(--faint); }
.all-btn {
  flex: none; width: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums;
}
.all-btn:hover:not(:disabled) { color: var(--fg); border-color: var(--line-2); }
.all-btn[aria-pressed="true"] { color: var(--fg); background: var(--accent-soft); border-color: var(--accent); }

/* one tile: a finished image, the one being made (live preview), or a queued job */
.tile {
  position: relative; flex: none; height: 64px; aspect-ratio: 1; padding: 0; border-radius: 10px; overflow: hidden;
  border: 2px solid transparent; background: var(--bg-2); display: grid; place-items: center; color: var(--muted); font-size: 11px;
}
.tile img, .tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.tile[aria-current="true"] { border-color: var(--accent); }
.tile:hover:not([aria-current="true"]) { border-color: var(--line-2); }
.tile.queued { border: 1.5px dashed var(--line-2); cursor: default; }
.tile.queued .x {
  position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: var(--panel-2);
  color: var(--muted); display: none; place-items: center; font-size: 12px; line-height: 1; padding: 0;
}
.tile.queued:hover .x, .tile.queued:focus-within .x { display: grid; }
.tile.running canvas { filter: saturate(0.85); }
.tile .ring { width: 30px; height: 30px; }
.tile .ring circle { fill: none; stroke-width: 3; }
.tile .ring .bg { stroke: var(--line-2); }
.tile .ring .fg { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 0.3s; }
.tile.has-preview .ring { display: none; }
.tile .tile-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: color-mix(in srgb, var(--bg) 60%, transparent); }
.tile .tile-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

/* ------------------------------------------------------------------ settings dialog */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--panel); color: var(--fg);
  width: min(720px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
dialog::backdrop { background: rgba(8, 6, 12, 0.6); backdrop-filter: blur(3px); }
.dialog { display: flex; flex-direction: column; gap: 14px; padding: 20px 22px 22px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog .presets { max-width: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.advanced { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.advanced summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.advanced[open] summary { margin-bottom: 10px; }
.adv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.storage { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.storage p { margin-top: 2px; }
.storage-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.fatal {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); color: var(--bad);
  white-space: pre-wrap; text-align: center; font-size: 15px;
}

/* ------------------------------------------------------------------ small screens: stack and scroll */
@media (max-width: 900px) {
  .app { height: auto; min-height: 100dvh; grid-template-columns: 1fr; grid-template-rows: 56px auto auto; gap: 12px; padding: 0 12px 16px; }
  .bar { gap: 10px; order: -2; }
  .status { display: none; }
  .stage { order: -1; }
  .canvas-box { min-height: 60vh; }
  .rail { overflow: visible; }
  .group.grow { min-height: 0; }
  .presets { grid-template-columns: 1fr; }
  .adv-grid { grid-template-columns: 1fr; }
}
@media (max-height: 700px) and (min-width: 901px) {
  .rail { padding: 12px 4px 12px 12px; }
  .view { gap: 8px; }
}
