:root {
  --bg: #0f0e13;
  --bg-2: #15131b;
  --panel: #1b1922;
  --panel-2: #221f2b;
  --line: #2e2a38;
  --line-2: #3a3547;
  --fg: #f1eef6;
  --muted: #a39dae;
  --faint: #6f697b;
  --accent: #7382ff;
  --accent-2: #a2acff;
  --accent-ink: #0b0d22;
  --accent-soft: rgba(115, 130, 255, 0.15);
  --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;
}
@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: #4655e0;
    --accent-2: #5a68ee;
    --accent-ink: #ffffff;
    --accent-soft: rgba(70, 85, 224, 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: #4655e0; --accent-2: #5a68ee; --accent-ink: #ffffff;
  --accent-soft: rgba(70, 85, 224, 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 {
  display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  scrollbar-width: thin;
}
.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; }
.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; }
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); }

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 (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 */
.view { display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto; min-height: 0; }
.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; }

/* quality and guidance: a segmented preset row above a slider with its value */
.param { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 4px 10px; align-items: center; }
.param .seg { grid-column: 1 / -1; }
.param output { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--fg); }
.neg textarea { min-height: 58px; flex: none; }
.neg summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); list-style: none; display: flex; align-items: center; gap: 6px; }
.neg summary::-webkit-details-marker { display: none; }
.neg summary::before { content: "+"; width: 14px; text-align: center; color: var(--faint); }
.neg[open] summary::before { content: "−"; }
.neg[open] summary { margin-bottom: 8px; }
.neg summary em { font-style: normal; font-weight: 400; color: var(--faint); }

/* first-run download card */
.dl-card { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); text-align: left; }
.dl-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); padding: 3px 0; }
.dl-row b { color: var(--fg); font-weight: 600; }
.dl-row span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dl-row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 7px; color: var(--fg); }
.dl-row .saved { color: var(--good); }

/* 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; }

/* ------------------------------------------------------------------ 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));
}
.canvas-box.pixel canvas { image-rendering: pixelated; }
.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); }
.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); }

.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; }
.field { display: flex; flex-direction: column; gap: 6px; }
.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; gap: 8px; }

.fatal {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: var(--bg);
  text-align: center; font-size: 15px; overflow-y: auto;
}
.fatal > div { width: min(520px, 100%); display: flex; flex-direction: column; gap: 12px; }
.fatal h2 { margin: 0; font-size: 20px; color: var(--fg); }
.fatal p { margin: 0; color: var(--muted); line-height: 1.55; }
.fatal .detail { font-size: 12px; color: var(--faint); }

/* ------------------------------------------------------------------ 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; }
}
@media (max-height: 700px) and (min-width: 901px) {
  .rail { padding: 12px; }
  .view { gap: 8px; }
}
