/* YumUp Studio
   One system: warm neutral grounds, one accent (YumUp rose, from the Y of the logo),
   the logo's rainbow only as a brand band (generation progress). Radius 8 / 12 / 20.
   Motion: 150ms in, 120ms out, 90ms press, one ease-out; transform and opacity only. */

:root,
:root[data-theme="light"] {
  --bg: #F6F5F3;
  --surface: #FFFFFF;
  --surface-2: #F5F4F1;
  --surface-3: #ECEAE6;
  --line: #E6E3DE;
  --line-2: #D2CEC7;
  --ink: #1C1917;
  --muted: #5E5852;
  --faint: #8C857E;
  --action: #E0245E;
  --action-hover: #C51F53;
  --action-ink: #FFFFFF;
  --action-text: #C41C51;
  --action-soft: rgba(224, 36, 94, .08);
  --action-line: rgba(224, 36, 94, .45);
  --base: #0B7A96;
  --base-soft: rgba(11, 122, 150, .10);
  --turbo: #A85A00;
  --turbo-soft: rgba(245, 158, 11, .14);
  --ok: #15803D;
  --warn: #A85A00;
  --danger: #C62828;
  --danger-soft: rgba(198, 40, 40, .08);
  --stage: #EDEBE7;
  --checker: #E1DED9;
  --shadow-pop: 0 12px 32px rgba(28, 25, 23, .14), 0 1px 3px rgba(28, 25, 23, .08);
  --scrim: rgba(28, 25, 23, .45);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0F0F10;
  --surface: #18181A;
  --surface-2: #1F1F22;
  --surface-3: #2A2A2E;
  --line: #2B2B2F;
  --line-2: #3B3B41;
  --ink: #F3F1EE;
  --muted: #ADA7A1;
  --faint: #7B7670;
  --action: #E0245E;
  --action-hover: #F0396F;
  --action-ink: #FFFFFF;
  --action-text: #FF7FA3;
  --action-soft: rgba(255, 79, 139, .12);
  --action-line: rgba(255, 110, 155, .55);
  --base: #4CC9E6;
  --base-soft: rgba(76, 201, 230, .13);
  --turbo: #FBBF24;
  --turbo-soft: rgba(251, 191, 36, .13);
  --ok: #4ADE80;
  --warn: #FBBF24;
  --danger: #FF6B6B;
  --danger-soft: rgba(255, 107, 107, .12);
  --stage: #121214;
  --checker: #1E1E21;
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, .55), 0 1px 3px rgba(0, 0, 0, .4);
  --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}
:root {
  --brand-grad: linear-gradient(90deg, #FF7EB3 0%, #FF2D55 20%, #FF8A00 42%, #FFD60A 60%, #34C759 80%, #0AA5D8 100%);
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 20px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --m-in: 150ms;
  --m-out: 120ms;
  --m-press: 90ms;
  --top: 64px;
  --font: "Be Vietnam Pro", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .f { fill: currentColor; stroke: none; }
code { font-family: "Cascadia Code", Consolas, monospace; font-size: 12.5px; background: var(--surface-3); padding: 1px 6px; border-radius: 6px; overflow-wrap: anywhere; }
kbd { font: 600 12px/1 var(--font); padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line-2); border-bottom-width: 2px; background: var(--surface); color: var(--ink); white-space: nowrap; }
b { font-weight: 600; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

:focus-visible { outline: 2px solid var(--action-text); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

.skip-link { position: fixed; left: 12px; top: 10px; z-index: 100; padding: 10px 14px; border-radius: var(--r-sm); background: var(--ink); color: var(--bg); font-weight: 600; text-decoration: none; transform: translateY(-160%); }
.skip-link:focus { transform: none; }

/* ---------- buttons (one system) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  border: 1px solid transparent;
  transition: background-color var(--m-out) var(--ease), border-color var(--m-out) var(--ease), color var(--m-out) var(--ease), transform var(--m-out) var(--ease);
}
.btn--primary { background: var(--action); color: var(--action-ink); }
.btn--primary svg { fill: currentColor; stroke: none; }
.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn--sm { height: 34px; padding: 0 12px; font-size: 13px; gap: 6px; }
.btn--sm svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--danger); }
.btn.on { color: var(--action-text); border-color: var(--action-line); background: var(--action-soft); }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { transform: translateY(-1px); transition-duration: var(--m-in); }
  .btn--primary:hover:not(:disabled) { background: var(--action-hover); }
  .btn--secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--faint); }
  .btn.danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(.985); transition-duration: var(--m-press); }

.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-sm); display: inline-grid; place-items: center;
  background: transparent; border: 1px solid transparent; color: var(--muted); text-decoration: none;
  transition: color var(--m-out) var(--ease), background-color var(--m-out) var(--ease), border-color var(--m-out) var(--ease);
}
.icon-btn:hover { color: var(--ink); background: var(--surface-2); border-color: var(--line); transition-duration: var(--m-in); }
.icon-btn:active { transform: scale(.96); }
:root[data-theme="dark"] .i-sun, :root[data-theme="light"] .i-moon { display: none; }

.link-btn { border: 0; background: none; padding: 4px 0; color: var(--action-text); font-weight: 600; font-size: 13px; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; transition: text-decoration-color var(--m-out) var(--ease); }
.link-btn:hover { text-decoration-color: currentColor; }

/* ---------- brand band + top bar ---------- */
.brand-band { position: fixed; left: 0; right: 0; top: 0; height: 3px; z-index: 30; background: var(--brand-grad); background-size: 200% 100%; opacity: 0; transition: opacity 300ms var(--ease); pointer-events: none; }
body.busy .brand-band { opacity: 1; animation: band 3.2s linear infinite; }
@keyframes band { to { background-position: -200% 0; } }

.topbar {
  height: var(--top); flex: none; position: relative; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; border-radius: var(--r-sm); }
.logo { width: 36px; height: 36px; display: block; border-radius: 10px; box-shadow: 0 0 0 1px var(--line); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 16px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-text small { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

.status { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; height: 32px; padding: 0 12px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--ok); }
.dot.busy { background: var(--action); box-shadow: 0 0 0 3px var(--action-soft); }
.dot.off { background: var(--danger); }

.vram-wrap { position: relative; }
.vram {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px 0 12px;
  border-radius: 99px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: border-color var(--m-out) var(--ease), color var(--m-out) var(--ease);
}
.vram:hover, .vram[aria-expanded="true"] { border-color: var(--line-2); color: var(--ink); }
.vram svg { width: 16px; height: 16px; }
.vram-bar { width: 56px; height: 6px; border-radius: 9px; background: var(--surface-3); overflow: hidden; }
.vram-bar span { display: block; height: 100%; width: 0; background: var(--base); border-radius: 9px; transition: width .6s var(--ease); }
.vram-text { font-variant-numeric: tabular-nums; color: var(--ink); }
.pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: 340px; max-width: calc(100vw - 24px);
  padding: 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow-pop);
  font-size: 13.5px; animation: drop 200ms var(--ease);
}
.pop h3 { margin: 0 0 4px; font-size: 15px; }
.pop p { margin: 0 0 10px; }
.pop .pop-num { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pop .pop-num b { font-size: 22px; color: var(--ink); font-weight: 700; margin-right: 2px; }
.pop .btn { width: 100%; margin-top: 4px; }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } }

.top-actions { display: flex; align-items: center; gap: 2px; }
/* Add-on slot in the top bar (ext-lora.js: admin "Train LoRA"). .top-pill matches the VRAM pill; its .top-pill-label
   is hidden on phones (icon only). .top-pill-dot marks something running. */
.topbar-slot { display: flex; align-items: center; gap: 6px; }
.topbar-slot:empty { display: none; }
.top-pill {
  position: relative; display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px;
  border-radius: 99px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  font-size: 13px; font-weight: 500; white-space: nowrap; text-decoration: none;
  transition: border-color var(--m-out) var(--ease), color var(--m-out) var(--ease);
}
.top-pill:hover, .top-pill[aria-expanded="true"] { border-color: var(--line-2); color: var(--ink); }
.top-pill svg { width: 16px; height: 16px; }
.top-pill-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--action); box-shadow: 0 0 0 3px var(--action-soft); flex: none; }

/* ---------- layout ---------- */
.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 384px minmax(0, 1fr) 328px;
  gap: 12px; padding: 12px;
}
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  min-height: 0; display: flex; flex-direction: column; overflow: hidden;
}

/* ---------- controls ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.panel-title { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.mode-switch { flex: none; }
.mode-switch button { padding: 0 12px; }

.controls-scroll { flex: 1; overflow-y: auto; padding: 0 16px 16px; scrollbar-gutter: stable; }
.block { padding: 16px 0; border-bottom: 1px solid var(--line); }
.block:last-of-type { border-bottom: 0; }
.block-title {
  font-size: 13px; font-weight: 600; color: var(--ink);
  margin: 0 0 10px; display: flex; align-items: center; gap: 8px;
}
.block-title label { cursor: pointer; }
.tag { font-size: 12px; font-weight: 500; color: var(--muted); padding: 1px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); }
.hint { margin-left: auto; font-weight: 500; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.hint kbd { font-size: 11px; padding: 2px 5px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

:root[data-mode="simple"] .adv-only { display: none !important; }
:root[data-mode="pro"] .simple-only { display: none !important; }

textarea, input[type="number"], input[type="search"] {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 10px 12px; outline: none;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease), background-color 140ms var(--ease);
}
textarea { resize: vertical; min-height: 64px; line-height: 1.55; }
textarea::placeholder, input::placeholder { color: var(--faint); }
textarea:hover, input[type="number"]:hover, input[type="search"]:hover { border-color: var(--line-2); }
textarea:focus, input:focus { border-color: var(--action); box-shadow: 0 0 0 3px var(--action-soft); background: var(--surface); }
textarea:focus-visible, input:focus-visible { outline: none; }
textarea:disabled, input:disabled { opacity: .5; cursor: not-allowed; }
#prompt { font-size: 15px; min-height: 120px; }
.mini-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mini-actions .chip-btn { white-space: nowrap; }
.controls .row-between:has(> .mini-actions) { align-items: flex-end; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--r-sm); font-size: 13px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink);
  transition: background-color var(--m-out) var(--ease), border-color var(--m-out) var(--ease);
}
.chip-btn svg { width: 15px; height: 15px; color: var(--action-text); }
.chip-btn:hover { background: var(--surface-2); border-color: var(--faint); }
.chip-btn:active { transform: scale(.97); }
.counter { margin-top: 8px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* reference images */
#refBlock { border-radius: var(--r-md); transition: background-color var(--m-out) var(--ease); }
#refBlock.drop { background: var(--action-soft); outline: 2px dashed var(--action); outline-offset: -2px; padding-left: 10px; padding-right: 10px; }
/* one row per reference: thumbnail (click inserts <imageN>), tag + role, remove */
.refs { display: flex; flex-direction: column; gap: 6px; }
.ref { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2); }
.ref-thumb { position: relative; flex: none; width: 56px; height: 56px; padding: 0; border: 0; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-3); }
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 400ms var(--ease); }
.ref-thumb:hover img { transform: scale(1.03); }
.ref.uploading img, .edit-src-img.uploading img { opacity: .4; filter: blur(2px); }
.ref-idx { position: absolute; left: 4px; top: 4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 6px; font-size: 12px; font-weight: 700; display: grid; place-items: center; color: #fff; background: rgba(20, 18, 17, .72); }
.ref-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ref-main code { align-self: flex-start; }
.ref-role { height: 34px; font-size: 13px; }
.ref-x { flex: none; width: 34px; height: 34px; border-radius: var(--r-sm); border: 0; display: grid; place-items: center; font-size: 13px; color: var(--muted); background: transparent; }
.ref-x:hover { color: var(--danger); background: var(--danger-soft); }
.ref-add { display: flex; align-items: center; justify-content: center; gap: 6px; height: 44px; border-radius: var(--r-md); border: 1.5px dashed var(--line-2); background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; transition: color var(--m-out) var(--ease), border-color var(--m-out) var(--ease), background-color var(--m-out) var(--ease); }
.ref-add:hover { color: var(--action-text); border-color: var(--action); background: var(--action-soft); }
.ref-add:focus-within { outline: 2px solid var(--action-text); outline-offset: 2px; }
.ref-add svg { width: 18px; height: 18px; }

/* generation paused by a dispatch gate (e.g. LoRA training) */
.held-banner { margin: 0 0 10px; padding: 8px 10px; border-radius: var(--r-sm); background: var(--turbo-soft); color: var(--ink); font-size: 12.5px; line-height: 1.45; }
#loraSlot:empty { display: none; }

/* speed modes */
.speed-opts { display: flex; flex-direction: column; gap: 6px; }
.speed-opt { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--surface); transition: border-color var(--m-out) var(--ease), background-color var(--m-out) var(--ease); }
.speed-opt:hover { border-color: var(--faint); }
.speed-opt.active { border-color: var(--action); background: var(--action-soft); box-shadow: inset 0 0 0 1px var(--action); }
.so-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.so-head b { font-size: 14px; }
.so-eta { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.speed-opt.active .so-eta { color: var(--action-text); font-weight: 600; }
.so-desc { font-size: 12.5px; color: var(--muted); }
.speed-custom { margin-top: 10px; padding: 4px 12px 12px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.speed-custom .toggle-row { margin-top: 8px; }
.speed-custom .slider-row { margin-top: 10px; }
.mchip.speed-exact { color: var(--base); border-color: color-mix(in srgb, var(--base) 35%, transparent); background: var(--base-soft); }
.settings-break { flex-basis: 100%; height: 0; }
.settings-select { width: auto; min-width: 190px; }

/* tasks: Tạo ảnh / Chỉnh sửa ảnh */
:root[data-task="edit"] .create-only, :root:not([data-task="edit"]) .edit-only { display: none !important; }
.task-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 10px 12px 0; }
.task-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; border: 1px solid transparent; border-radius: var(--r-md); background: var(--surface-2); color: var(--muted); font-size: 14.5px; font-weight: 600; transition: background-color var(--m-out) var(--ease), color var(--m-out) var(--ease), border-color var(--m-out) var(--ease); }
.task-tabs button:hover { color: var(--ink); background: var(--surface-3); }
.task-tabs button.active { color: var(--action-text); background: var(--action-soft); border-color: var(--action); }
.task-tabs svg { width: 18px; height: 18px; }
.task-tabs button.active svg { fill: none; }
.panel-head { border-bottom: 0; padding-bottom: 4px; }
.task-intro { margin: 0; padding: 0 16px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.edit-src { display: flex; flex-direction: column; gap: 8px; }
.edit-src-img { position: relative; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line); background: var(--stage); display: grid; place-items: center; max-height: 240px; }
.edit-src-img img { max-width: 100%; max-height: 240px; object-fit: contain; display: block; }
.edit-src-actions { display: flex; gap: 6px; }
.edit-drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 16px; border-radius: var(--r-md); border: 1.5px dashed var(--line-2); background: transparent; color: var(--muted); text-align: center; font-size: 13px; transition: color var(--m-out) var(--ease), border-color var(--m-out) var(--ease), background-color var(--m-out) var(--ease); }
.edit-drop b { color: var(--ink); font-size: 14.5px; }
.edit-drop svg { width: 30px; height: 30px; color: var(--action-text); }
.edit-drop:hover { border-color: var(--action); background: var(--action-soft); }
.edit-chips { margin-bottom: 10px; }
.edit-chips .chip { height: 30px; font-size: 12.5px; }
.warn-note { margin: 10px 0 0; padding: 8px 10px; border-radius: var(--r-sm); background: var(--turbo-soft); color: var(--ink); font-size: 12.5px; line-height: 1.45; }
.soon { margin-left: 4px; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 99px; background: var(--surface-3); color: var(--muted); }
.chip-btn:disabled { opacity: .6; cursor: not-allowed; }
.layout-form summary { cursor: pointer; list-style: none; font-size: 13px; font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-height: 32px; }
.layout-form summary::-webkit-details-marker { display: none; }
.layout-form summary::after { content: ""; width: 8px; height: 8px; margin: 0 6px 0 auto; border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted); transform: rotate(45deg); transition: transform 200ms var(--ease); }
.layout-form[open] summary::after { transform: rotate(225deg); }
.layout-form .lbl { margin-top: 10px; font-size: 13px; }
.layout-form .warn-note { margin-top: 6px; }
.ly-keep { display: flex; align-items: flex-end; padding-bottom: 8px; }
.ly-preview { margin: 10px 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.mchip.edit { color: var(--action-text); border-color: var(--action-line); background: var(--action-soft); font-weight: 600; }
.gbadges { position: absolute; left: 6px; top: 6px; display: flex; gap: 4px; }
.gbadges .gbadge { position: static; }
.gbadge.edit { background: #B0174B; }
.ref-help { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.ref-help kbd { font-size: 11px; padding: 2px 5px; }
.ref-options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.ref-sub { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.meta-refs { display: flex; align-items: center; gap: 6px; margin: -2px 0 10px; font-size: 12.5px; color: var(--muted); }
.meta-refs img { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; border: 1px solid var(--line); }

/* chips, ratios, segmented */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 99px; font-size: 13px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink);
  transition: background-color var(--m-out) var(--ease), border-color var(--m-out) var(--ease), color var(--m-out) var(--ease);
}
.chip:hover { background: var(--surface-2); border-color: var(--faint); }
.chip:active { transform: scale(.97); }
.chip.active { color: var(--action-text); background: var(--action-soft); border-color: var(--action); font-weight: 600; }

.ratios { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 10px; }
.ratio {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px;
  height: 64px; padding: 8px 2px 6px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--line-2); color: var(--muted); font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: background-color var(--m-out) var(--ease), border-color var(--m-out) var(--ease), color var(--m-out) var(--ease);
}
.ratio:hover { color: var(--ink); border-color: var(--faint); }
.ratio .shape { border: 1.6px solid currentColor; border-radius: 3px; }
.ratio.active { color: var(--action-text); border-color: var(--action); background: var(--action-soft); font-weight: 600; }
.ratio.active .shape { background: color-mix(in srgb, var(--action) 22%, transparent); }
.ratios.disabled { opacity: .45; pointer-events: none; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button { flex: 1; height: 32px; border-radius: 6px; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; transition: background-color var(--m-out) var(--ease), color var(--m-out) var(--ease); }
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line-2), 0 1px 2px rgba(28, 25, 23, .08); }
:root[data-theme="dark"] .seg button.active { background: var(--surface-3); box-shadow: 0 0 0 1px var(--line-2); }
.seg.small button { height: 30px; font-size: 12.5px; padding: 0 8px; }

.custom-size { display: flex; align-items: flex-end; gap: 8px; margin-top: 10px; }
.custom-size label { flex: 1; font-size: 12.5px; font-weight: 500; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.custom-size > span { padding-bottom: 10px; color: var(--faint); }
.size-readout { margin-top: 8px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* model */
.model-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.model-card {
  text-align: left; padding: 12px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line-2);
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color var(--m-out) var(--ease), background-color var(--m-out) var(--ease), transform var(--m-out) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .model-card:hover { border-color: var(--faint); transform: translateY(-2px); transition-duration: 180ms; }
}
.model-card:active { transform: translateY(0) scale(.985); transition-duration: var(--m-press); }
.model-card.active { border-color: var(--action); background: var(--action-soft); box-shadow: inset 0 0 0 1px var(--action); }
.mc-row { display: flex; align-items: center; justify-content: space-between; gap: 4px 6px; flex-wrap: wrap; }
.mc-name { font-weight: 700; font-size: 15px; white-space: nowrap; }
.mc-badge { font-size: 12px; padding: 1px 8px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.mc-badge.q { color: var(--base); background: var(--base-soft); }
.mc-badge.f { color: var(--turbo); background: var(--turbo-soft); }
.mc-meta { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.model-cards.disabled .model-card { opacity: .5; pointer-events: none; }
.model-help { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

.toggle-row { position: relative; display: flex; align-items: center; gap: 10px; margin-top: 12px; cursor: pointer; font-size: 13.5px; user-select: none; min-height: 32px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 36px; height: 22px; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--line-2); position: relative; flex: none; transition: background-color 180ms var(--ease), border-color 180ms var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform 180ms var(--ease); }
.toggle-row input:checked + .switch { background: var(--action); border-color: var(--action); }
.toggle-row input:checked + .switch::after { transform: translateX(14px); background: #fff; }
.toggle-row input:focus-visible + .switch { outline: 2px solid var(--action-text); outline-offset: 2px; }

/* count + seed */
.grid2 { display: grid; grid-template-columns: 1fr 1.3fr; gap: 16px; }
:root[data-mode="simple"] .grid2 { grid-template-columns: 1fr; }
:root[data-mode="simple"] .grid2 .stepper { max-width: 160px; }
.stepper { display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); height: 40px; }
.stepper button { width: 40px; height: 100%; border: 0; background: transparent; color: var(--muted); font-size: 18px; border-radius: var(--r-md); }
.stepper button:hover { color: var(--ink); background: var(--surface-3); }
.stepper input { border: 0; background: transparent; text-align: center; padding: 0; height: 100%; box-shadow: none !important; -moz-appearance: textfield; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper input::-webkit-inner-spin-button, .seed-row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.seed-row { display: flex; gap: 6px; }
.seed-row input { height: 40px; font-variant-numeric: tabular-nums; font-size: 13.5px; padding: 0 10px; }
.seed-row .icon-btn { border-color: var(--line-2); background: var(--surface); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--muted); cursor: pointer; min-height: 24px; }
.check input { accent-color: var(--action); width: 16px; height: 16px; margin: 0; }

/* advanced */
.adv { border-bottom: 0; }
.adv summary { cursor: pointer; list-style: none; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; min-height: 32px; border-radius: var(--r-sm); }
.adv summary::-webkit-details-marker { display: none; }
.adv summary::after { content: ""; width: 8px; height: 8px; margin: 0 6px 0 auto; border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted); transform: rotate(45deg); transition: transform 200ms var(--ease); }
.adv[open] summary::after { transform: rotate(225deg); }
.adv-body { display: flex; flex-direction: column; gap: 18px; padding-top: 14px; }
.slider-row { display: flex; flex-direction: column; gap: 6px; }
.slider-row label, .lbl { font-size: 13.5px; font-weight: 500; }
.lbl { display: block; margin-bottom: 6px; }
.slider-row output { font-variant-numeric: tabular-nums; color: var(--action-text); font-weight: 700; }
.slider-row small { font-size: 12.5px; line-height: 1.45; }
.slider-row.disabled { opacity: .45; }
input[type="range"] { width: 100%; accent-color: var(--action); margin: 4px 0; }
.adv .toggle-row { margin-top: 0; }

.adv-summary { margin-top: 12px; padding: 12px; border-radius: var(--r-md); background: var(--turbo-soft); border: 1px solid color-mix(in srgb, var(--turbo) 35%, transparent); font-size: 13px; }
.adv-summary p { margin: 0 0 4px; }
.adv-summary-actions { display: flex; gap: 16px; }

/* generate */
.generate-bar { padding: 14px 16px 16px; border-top: 1px solid var(--line); background: var(--surface); }
#generateBtn { width: 100%; height: 48px; font-size: 15.5px; border-radius: var(--r-md); }
.gen-sub { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 8px; font-variant-numeric: tabular-nums; }

/* ---------- stage ---------- */
.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.stage-canvas {
  position: relative; flex: 1; min-height: 0;
  border-radius: var(--r-lg); border: 1px solid var(--line); overflow: hidden;
  background: var(--stage);
  display: grid; place-items: center;
}
.stage-canvas.checker {
  background-image: conic-gradient(var(--checker) 25%, transparent 0 50%, var(--checker) 0 75%, transparent 0);
  background-size: 22px 22px;
}
#stageImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; animation: settle 400ms var(--ease); transition: filter 250ms var(--ease); }
#stageImg.loading { filter: blur(8px) brightness(.95); }
@keyframes settle { from { opacity: 0; transform: scale(1.01); } }

.empty { text-align: center; width: min(560px, 100%); padding: 28px 24px; overflow-y: auto; max-height: 100%; }
.empty-logo { display: block; margin: 0 auto 14px; border-radius: 16px; box-shadow: 0 0 0 1px var(--line); }
.empty h2 { margin: 0 0 18px; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.steps li { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; line-height: 1.5; }
.step-n { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--action-ink); background: var(--action); margin-top: -1px; }
.empty .steps { padding: 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); }
.ex-title { margin: 22px 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); text-align: left; }
.ex-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ex-card {
  text-align: left; padding: 12px 14px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; gap: 2px;
  transition: transform 180ms var(--ease), border-color var(--m-out) var(--ease);
}
.ex-card b { font-size: 14px; }
.ex-card span { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@media (hover: hover) and (pointer: fine) { .ex-card:hover { transform: translateY(-2px); border-color: var(--line-2); } }
.ex-card:active { transform: scale(.985); }

.progress-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--stage) 70%, transparent); }
#livePreviewImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.progress-card {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; padding: 12px 12px 12px 12px;
  width: min(440px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  animation: rise 300ms var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
.ring { position: relative; width: 52px; height: 52px; flex: none; }
.ring svg { width: 52px; height: 52px; transform: rotate(-90deg); stroke-width: 5; }
.ring .trk { stroke: var(--surface-3); }
.ring .val { stroke: url(#ringGrad); stroke-dasharray: 163.4; stroke-dashoffset: 163.4; transition: stroke-dashoffset .35s var(--ease); }
.ring.spin svg { animation: spin 1s linear infinite; }
.ring.spin .val { stroke-dashoffset: 120; }
@keyframes spin { to { transform: rotate(270deg); } }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pc-text { flex: 1; min-width: 0; }
.pc-stage { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-sub { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.nav-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 56px; border-radius: var(--r-md); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); display: grid; place-items: center;
  opacity: 0; transition: opacity var(--m-out) var(--ease), background-color var(--m-out) var(--ease);
}
.nav-btn svg { width: 22px; height: 22px; stroke-width: 2.2; }
.stage-canvas:hover .nav-btn, .nav-btn:focus-visible { opacity: .95; }
.nav-btn:hover { background: var(--surface-2); }
.nav-btn.prev { left: 12px; } .nav-btn.next { right: 12px; }
@media (hover: none) { .nav-btn { opacity: .85; } }

.compare { position: absolute; inset: 0; display: grid; place-items: center; }
.cmp-box { position: relative; width: 100%; height: 100%; --pos: 50%; }
.cmp-box img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.cmp-top { clip-path: inset(0 0 0 var(--pos)); }
.cmp-line { position: absolute; top: 0; bottom: 0; left: var(--pos); width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); pointer-events: none; }
.cmp-knob { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 40px; height: 40px; border-radius: 50%; background: #fff; color: #1C1917; display: grid; place-items: center; box-shadow: 0 2px 10px rgba(0, 0, 0, .35); }
.cmp-knob svg { width: 20px; height: 20px; stroke-width: 2.2; }
#cmpRange { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.cmp-label { position: absolute; top: 12px; padding: 5px 10px; border-radius: var(--r-sm); font-size: 12.5px; font-weight: 600; color: #fff; background: rgba(20, 18, 17, .72); pointer-events: none; }
.cmp-label.left { left: 12px; } .cmp-label.right { right: 12px; }

.stage-info { flex: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; }
.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mchip b { color: var(--ink); font-weight: 600; }
.mchip.base { color: var(--base); border-color: color-mix(in srgb, var(--base) 35%, transparent); background: var(--base-soft); font-weight: 600; }
.mchip.turbo { color: var(--turbo); border-color: color-mix(in srgb, var(--turbo) 35%, transparent); background: var(--turbo-soft); font-weight: 600; }
.mchip.copyable { cursor: pointer; }
.mchip.copyable:hover { border-color: var(--line-2); color: var(--ink); }
.meta-prompt { margin: 10px 0 12px; font-size: 14px; line-height: 1.55; color: var(--ink); max-height: 3.2em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; cursor: pointer; }
.meta-prompt.open { max-height: none; -webkit-line-clamp: unset; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.act-gap { flex: 1; min-width: 0; }
.act {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  text-decoration: none; font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background-color var(--m-out) var(--ease), border-color var(--m-out) var(--ease), color var(--m-out) var(--ease), transform var(--m-out) var(--ease);
}
.act svg { width: 16px; height: 16px; color: var(--muted); }
.act--icon { width: 36px; padding: 0; justify-content: center; }
.act--main { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
.act--main svg { color: currentColor; }
.act:disabled { opacity: .45; cursor: not-allowed; }
@media (hover: hover) and (pointer: fine) {
  .act:hover:not(:disabled) { background: var(--surface-2); border-color: var(--faint); transform: translateY(-1px); transition-duration: var(--m-in); }
  .act--main:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 86%, var(--bg)); border-color: var(--ink); }
  .act.danger:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
  .act.danger:hover svg { color: var(--danger); }
}
.act:active:not(:disabled) { transform: translateY(1px) scale(.985); transition-duration: var(--m-press); }

/* ---------- side ---------- */
.side { padding: 14px 14px 0; gap: 14px; }
.side-title { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-3); color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.pill:empty { display: none; }
.queue-wrap { flex: none; }
.queue { display: flex; flex-direction: column; gap: 6px; max-height: 230px; overflow-y: auto; }
.qitem { padding: 10px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center; cursor: pointer; transition: opacity .4s var(--ease), border-color var(--m-out) var(--ease); }
.qitem:hover { border-color: var(--line-2); }
.qitem.running { border-color: var(--action-line); background: var(--action-soft); }
.qitem.done { opacity: .75; }
.qitem.fading { animation: qfade 600ms var(--ease) forwards; pointer-events: none; }
@keyframes qfade { to { opacity: 0; transform: translateY(-4px); } }
.q-empty { margin: 0; font-size: 12.5px; color: var(--muted); }
.qitem.error { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.q-top { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; }
.q-model { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 5px; flex: none; }
.q-model.base { color: var(--base); background: var(--base-soft); }
.q-model.turbo { color: var(--turbo); background: var(--turbo-soft); }
.q-prompt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.q-x { width: 32px; height: 32px; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--muted); font-size: 14px; grid-row: span 2; }
.q-x:hover { color: var(--danger); background: var(--danger-soft); }
.q-bottom { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.q-bar { flex: 1; height: 4px; border-radius: 9px; background: var(--surface-3); overflow: hidden; }
.q-bar span { display: block; height: 100%; width: 0; background: var(--brand-grad); background-size: 300px 100%; transition: width .3s var(--ease); }
.qitem.error .q-bottom { color: var(--danger); }

.gallery-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.gallery-wrap .block-title { margin-bottom: 0; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); pointer-events: none; }
input.search { height: 38px; padding: 0 12px 0 34px; font-size: 13.5px; }
.cmp-hint { font-size: 13px; padding: 8px 10px 8px 12px; border-radius: var(--r-md); background: var(--turbo-soft); border: 1px solid color-mix(in srgb, var(--turbo) 35%, transparent); color: var(--ink); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cmp-hint button { border: 0; background: transparent; color: var(--action-text); font-weight: 600; font-size: 13px; padding: 4px 6px; }
#galFilter [data-f="trash"] { flex: none; padding: 0 10px; }
#galFilter svg { width: 15px; height: 15px; }
#trashCount:empty { display: none; }
#trashCount { font-size: 12px; font-variant-numeric: tabular-nums; }
.selbar { padding: 10px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--action-line); display: flex; flex-direction: column; gap: 8px; animation: drop 200ms var(--ease); }
.sel-count { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.selbar .row-between { flex-wrap: wrap; gap: 4px 10px; }
.sel-links { display: flex; gap: 12px; }
.sel-links button { border: 0; background: none; padding: 2px 0; color: var(--action-text); font-size: 13px; font-weight: 500; white-space: nowrap; }
.sel-links button:hover { text-decoration: underline; text-underline-offset: 3px; }
.sel-actions { display: flex; gap: 6px; }
.sel-act { flex: 1; height: 34px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); font-size: 13px; font-weight: 600; white-space: nowrap; padding: 0 8px; transition: background-color var(--m-out) var(--ease), border-color var(--m-out) var(--ease); }
.sel-act:hover:not(:disabled) { border-color: var(--faint); background: var(--surface-2); }
.sel-act.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
:root[data-theme="dark"] .sel-act.danger { color: #1C1917; }
.sel-act.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 88%, var(--ink)); border-color: var(--danger); }
.sel-act:active:not(:disabled) { transform: scale(.985); }
.sel-act:disabled { opacity: .45; cursor: not-allowed; }
.trash-note { font-size: 13px; color: var(--muted); padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); }
.trash-note button { display: block; margin-top: 6px; border: 0; background: none; padding: 2px 0; color: var(--danger); font-weight: 600; font-size: 13px; }
.trash-note button:hover { text-decoration: underline; text-underline-offset: 3px; }

.gallery:empty { display: none; }
/* max-content rows: the square tiles clip their overflow, so auto rows would shrink to fit the panel height. */
.gallery { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(2, 1fr); grid-auto-rows: max-content; gap: 8px; align-content: start; padding: 2px 2px 8px; margin: -2px; }
.gitem { position: relative; aspect-ratio: 1; border-radius: var(--r-md); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; padding: 0; transition: border-color var(--m-out) var(--ease), box-shadow var(--m-out) var(--ease); }
.gitem img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 400ms var(--ease), border-radius 200ms var(--ease); }
@media (hover: hover) and (pointer: fine) { .gitem:hover img { transform: scale(1.03); transition-duration: 600ms; } }
.gitem.active { border-color: var(--action); box-shadow: 0 0 0 2px var(--action); }
.gitem.picked { border-color: var(--turbo); box-shadow: 0 0 0 2px var(--turbo); }
.gbadge { position: absolute; left: 6px; top: 6px; font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; color: #fff; background: rgba(20, 18, 17, .72); }
.gbadge.base { background: #0A6A82; }
.gbadge.turbo { background: #9A5200; }
.gcmp { position: absolute; right: 6px; top: 6px; width: 30px; height: 30px; border-radius: var(--r-sm); border: 0; display: grid; place-items: center; color: #fff; background: rgba(20, 18, 17, .72); opacity: 0; transition: opacity var(--m-out) var(--ease), background-color var(--m-out) var(--ease); }
.gcmp:hover { background: rgba(20, 18, 17, .9); }
.gcmp svg { width: 16px; height: 16px; }
.gitem:hover .gcmp, .gitem:focus-visible .gcmp, .gitem.picked .gcmp { opacity: 1; }
@media (hover: none) { .gcmp { opacity: .9; } }
.gtime { position: absolute; right: 6px; bottom: 6px; font-size: 11.5px; padding: 1px 6px; border-radius: 6px; color: #fff; background: rgba(20, 18, 17, .66); font-variant-numeric: tabular-nums; }
.gcheck { position: absolute; right: 6px; top: 6px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: rgba(20, 18, 17, .35); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); display: grid; place-items: center; }
.gcheck svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; opacity: 0; }
.selecting .gcmp { display: none; }
.gitem.selected { border-color: var(--action); box-shadow: 0 0 0 2px var(--action); }
.gitem.selected img { transform: scale(.9); border-radius: var(--r-sm); }
.gitem.selected .gcheck { background: var(--action); border-color: var(--action); }
.gitem.selected .gcheck svg { opacity: 1; }
.selecting .gitem:hover img { transform: none; }
.selecting .gitem.selected:hover img { transform: scale(.9); }
.gal-empty { color: var(--muted); text-align: center; padding: 30px 12px; font-size: 13.5px; }
.gal-tip { flex: none; margin: 0 -14px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.gal-tip svg { width: 15px; height: 15px; }
.gal-tip kbd { font-size: 11px; padding: 2px 5px; }

/* ---------- lightbox, dialog, toasts ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(10, 9, 9, .95); display: grid; place-items: center; overflow: auto; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; cursor: zoom-in; }
.lightbox.actual { place-items: start; }
.lightbox.actual img { max-width: none; max-height: none; cursor: zoom-out; }
.lb-close { position: fixed; top: 14px; right: 14px; width: 44px; height: 44px; border-radius: var(--r-md); border: 1px solid rgba(255, 255, 255, .2); background: rgba(24, 24, 26, .8); color: #fff; display: grid; place-items: center; }
.lb-close:hover { background: rgba(48, 48, 52, .9); }
.lb-hint { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); color: rgba(255, 255, 255, .8); font-size: 13px; background: rgba(24, 24, 26, .75); padding: 6px 12px; border-radius: 99px; pointer-events: none; white-space: nowrap; }

.help { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line-2); border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
.help[open] { display: flex; flex-direction: column; animation: drop 200ms var(--ease); }
.help::backdrop { background: var(--scrim); }
.help-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.help-head img { border-radius: 10px; box-shadow: 0 0 0 1px var(--line); flex: none; }
.help-head > div { flex: 1; min-width: 0; }
.help-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.help-head p { margin: 2px 0 0; font-size: 13.5px; }
.help-body { overflow-y: auto; padding: 4px 18px 8px; }
.help-body section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.help-body section:last-child { border-bottom: 0; }
.help-body h3 { margin: 0 0 10px; font-size: 14px; font-weight: 700; }
.tips { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 14px; align-items: center; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
.help-foot { padding: 12px 18px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }

.toasts { position: fixed; top: calc(var(--top) + 10px); right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; min-width: 260px; max-width: 400px; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow-pop); font-size: 13.5px; display: flex; gap: 10px; align-items: center; animation: toastin 200ms var(--ease); }
.toast > div { flex: 1; }
.toast::before { content: ""; width: 4px; align-self: stretch; border-radius: 4px; background: var(--faint); flex: none; }
.toast.ok::before { background: var(--ok); }
.toast.warn::before { background: var(--warn); }
.toast.err::before { background: var(--danger); }
.toast.out { opacity: 0; transform: translateX(10px); transition: opacity 200ms var(--ease), transform 200ms var(--ease); }
@keyframes toastin { from { opacity: 0; transform: translateX(12px); } }
.toast .t-act { flex: none; height: 32px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink); font-weight: 700; font-size: 13px; white-space: nowrap; }
.toast .t-act:hover { border-color: var(--faint); }
.toast { padding-right: 6px; }
.toast.out { pointer-events: none; }
.toast .t-x { flex: none; width: 28px; height: 28px; margin: -4px 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: 12px; display: grid; place-items: center; }
.toast .t-x:hover { color: var(--ink); background: var(--surface-2); }
.toast.bump { animation: toastbump 260ms var(--ease); }
@keyframes toastbump { 40% { transform: scale(1.03); } }

* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }

/* ---------- accounts (gateway) ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:root:not([data-role="admin"]) .admin-only { display: none !important; }
:root[data-role="admin"] .user-only { display: none !important; }
input[type="text"], input[type="password"], .select {
  width: 100%; height: 40px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 0 12px; outline: none; font-size: 14px;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease), background-color 140ms var(--ease);
}
.select { cursor: pointer; padding-right: 8px; }
input[type="text"]:hover, input[type="password"]:hover, .select:hover { border-color: var(--line-2); }
.select:focus { border-color: var(--action); box-shadow: 0 0 0 3px var(--action-soft); background: var(--surface); }

.user-wrap { position: relative; margin-left: 4px; }
.user-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px 0 4px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: 13.5px; font-weight: 600; max-width: 200px; transition: border-color var(--m-out) var(--ease); }
.user-btn:hover, .user-btn[aria-expanded="true"] { border-color: var(--line-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 12px; font-weight: 700; color: #fff; background: var(--ink); }
:root[data-theme="dark"] .avatar { color: var(--bg); }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-pop { width: 260px; padding: 8px; }
.user-pop-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.user-pop-head .muted { font-size: 12.5px; }
.menu-item { display: block; width: 100%; text-align: left; padding: 10px; border: 0; border-radius: var(--r-sm); background: transparent; font-size: 14px; font-weight: 500; }
.menu-item:hover { background: var(--surface-2); }
a.menu-item { color: inherit; text-decoration: none; }

.lib-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.q-user { flex: none; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 5px; background: var(--surface-3); color: var(--ink); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-user.me { background: var(--action-soft); color: var(--action-text); }
.qitem.watched { outline: 2px solid var(--action); outline-offset: 1px; }
.gal-user .select { height: 36px; font-size: 13.5px; }
.gowner { position: absolute; left: 6px; bottom: 6px; max-width: calc(100% - 12px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 6px; color: #fff; background: rgba(20, 18, 17, .72); }
.mchip.owner { color: var(--ink); font-weight: 600; background: var(--surface-3); }

/* dialogs: prompt library, prompt form, admin */
.lib { width: min(980px, calc(100vw - 24px)); height: min(820px, calc(100vh - 48px)); }
.lib-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 18px 0; }
.lib-tools .seg { flex: none; }
.lib-tools .seg button { padding: 0 12px; }
.lib-search { flex: 1; min-width: 200px; }
.lib-tags { padding: 10px 18px 0; }
.lib-tags:empty { display: none; }
.lib-body { flex: 1; padding-top: 14px; padding-bottom: 18px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.pcard { display: flex; gap: 12px; padding: 12px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); }
.pcard-thumb { flex: none; width: 88px; height: 88px; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); display: grid; place-items: center; font-size: 28px; font-weight: 700; color: var(--faint); }
.pcard-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.pcard-head { display: flex; align-items: flex-start; gap: 6px; }
.pcard-head h3 { margin: 0; flex: 1; font-size: 14.5px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.fav { flex: none; width: 32px; height: 32px; margin: -6px -6px 0 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: 18px; line-height: 1; }
.fav:hover { background: var(--surface-2); }
.fav.on { color: var(--turbo); }
.pcard-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 12.5px; color: var(--muted); }
.vis { font-weight: 600; padding: 0 7px; border-radius: 5px; background: var(--surface-3); color: var(--ink); }
.vis.team { background: var(--base-soft); color: var(--base); }
.vis.pending { background: var(--turbo-soft); color: var(--turbo); }
.pcard-note { margin: 0; font-size: 12.5px; color: var(--danger); }
.pcard-prompt { margin: 0; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pcard-tags { display: flex; flex-wrap: wrap; gap: 4px; font-size: 12.5px; color: var(--action-text); }
.pcard-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 4px; }

.pdlg { width: min(860px, calc(100vw - 24px)); }
.pdlg form { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 48px); }
.pform { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 20px; padding-top: 14px; }
.pform-main { display: flex; flex-direction: column; }
.pform-main .lbl { margin-top: 12px; }
.pform-main .lbl:first-child { margin-top: 0; }
.pform-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 12px; }
.pform-grid .lbl { margin-top: 12px; }
.pform-side { display: flex; flex-direction: column; gap: 10px; }
.pf-thumb { aspect-ratio: 1; border-radius: var(--r-md); border: 1px dashed var(--line-2); background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.pf-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pf-share { color: var(--ink); align-items: flex-start; }
.pf-note { margin: 0; font-size: 12.5px; }
.pf-error { margin: 0 18px 4px; }
.small-dlg { width: min(440px, calc(100vw - 24px)); }
.small-dlg form { display: flex; flex-direction: column; }
.small-dlg .help-body { padding-top: 14px; padding-bottom: 14px; }
.admin-dlg { width: min(980px, calc(100vw - 24px)); }
.table-wrap { overflow-x: auto; }
.utable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.utable th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.utable td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.utable tr.inactive td { color: var(--muted); }
.utable .select { height: 34px; min-width: 120px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn + .btn { margin-left: 6px; }
.new-user { align-items: end; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.new-user .seed-row input { min-width: 120px; }
.new-user .seed-row .btn { flex: none; height: 40px; }
.new-user-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; grid-column: 1 / -1; }
.new-user-foot .login-error { margin: 0; }
.settings-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 14px; }
.settings-row input { width: 80px; height: 40px; }

/* ---------- lettering: "Chữ trong ảnh", prompt warnings, "Sửa chữ", brand ---------- */
.text-lines { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.text-line { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) 34px; gap: 6px; align-items: center; }
.text-line input { height: 40px; min-width: 0; }
.text-foot { margin-top: 10px; flex-wrap: wrap; gap: 8px; }
.text-foot .check { margin-top: 0; }
.text-form .tag.on { color: var(--action-text); border-color: var(--action-line); background: var(--action-soft); }
.text-form .ref-help { margin: 8px 0 0; }
.info-note { margin: 10px 0 0; padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font-size: 12.5px; line-height: 1.45; }
.info-note .link-btn { padding: 0; font-size: 12.5px; }
.text-notes:empty { display: none; }
.style-tip { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.prompt-warn { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.pw-item { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 6px 8px; padding: 8px 10px; border-radius: var(--r-sm); background: var(--turbo-soft); color: var(--ink); font-size: 12.5px; line-height: 1.45; }
.pw-item > svg { width: 16px; height: 16px; margin-top: 1px; color: var(--warn); stroke-width: 2; }
.pw-acts { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; }
.pw-acts .chip-btn { height: 30px; font-size: 12.5px; }
.chip.chip--tool { border-color: var(--action-line); color: var(--action-text); }
#refLogoBtn { margin-top: 8px; }
.fix-dlg .pform-main { display: flex; flex-direction: column; }
.fix-dlg .text-line { align-items: end; }
.fix-dlg .text-line .lbl { margin-top: 0; }
.fix-dlg #fixAdd { margin-top: 8px; align-self: flex-start; }
.fix-dlg .text-notes { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.fix-dlg .pf-thumb img { object-fit: contain; }
.fix-logo { width: 22px; height: 22px; border-radius: 5px; object-fit: contain; vertical-align: middle; margin-left: 4px; background: var(--surface-2); }
.check.disabled { opacity: .6; cursor: not-allowed; }
.brand-form { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 16px; align-items: start; }
.brand-logo img { width: 96px; height: 96px; object-fit: contain; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2); display: block; }
.brand-logo p { font-size: 12px; margin: 6px 0 0; line-height: 1.4; }
.brand-fields { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.brand-fields .lbl { margin-top: 0; }
.brand-fields p { margin: 0; font-size: 12.5px; line-height: 1.45; }
@media (max-width: 520px) {
  .brand-form { grid-template-columns: 1fr; }
  .text-line { grid-template-columns: minmax(0, 1fr) 34px; }
  .text-line > :nth-child(2) { grid-column: 1; }
  .text-line > :nth-child(3) { grid-row: 1; grid-column: 2; }
}

/* login page */
.login-page { overflow: auto; }
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; padding: 28px 24px 24px; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--surface); }
.login-logo { border-radius: 14px; box-shadow: 0 0 0 1px var(--line); margin-bottom: 16px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.login-card > .muted { margin: 0 0 18px; }
.login-card .lbl { margin-top: 12px; }
.login-card input { height: 44px; font-size: 15px; }
.login-card .btn { height: 46px; margin-top: 18px; font-size: 15px; }
.login-error { margin: 12px 0 0; padding: 10px 12px; border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger); font-size: 13.5px; font-weight: 500; }
.login-note { margin: 16px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1360px) {
  .layout { grid-template-columns: 356px minmax(0, 1fr) 288px; }
  .vram-label { display: none; }
}
@media (max-width: 1100px) {
  body { overflow: auto; }
  .layout { flex: none; grid-template-columns: 356px minmax(0, 1fr); grid-template-rows: minmax(600px, calc(100vh - var(--top) - 24px)) auto; }
  .side { grid-column: 1 / -1; padding-bottom: 0; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); overflow: visible; }
  .brand-text small { display: none; }
}
@media (max-width: 760px) {
  :root { --top: 56px; }
  .topbar { padding: 0 8px 0 12px; gap: 8px; }
  .logo { width: 32px; height: 32px; }
  .brand-text strong { font-size: 15px; }
  .status { padding: 0 10px; height: 30px; }
  #connText { font-size: 12.5px; }
  .vram { padding: 0 8px; height: 30px; }
  .vram-bar, .comfy-link { display: none; }
  .top-pill { padding: 0 9px; height: 30px; }
  .top-pill-label { display: none; }
  .pop { position: fixed; left: 12px; right: 12px; top: calc(var(--top) + 8px); width: auto; max-width: none; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; padding: 8px; gap: 8px; }
  .controls { overflow: visible; }
  .controls-scroll { overflow: visible; padding: 0 14px 12px; }
  .panel-head { padding: 12px 14px; }
  .generate-bar { position: sticky; bottom: 0; z-index: 5; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); border-radius: 0 0 var(--r-lg) var(--r-lg); box-shadow: 0 -8px 20px rgba(0, 0, 0, .08); }
  .stage-canvas { flex: none; height: min(72vh, 120vw); min-height: 340px; }
  .empty { padding: 20px 16px; }
  .empty h2 { font-size: 20px; }
  .ex-grid { grid-template-columns: 1fr; }
  .side { overflow: visible; }
  .ratios { grid-template-columns: repeat(4, 1fr); }
  .progress-card { bottom: 10px; gap: 10px; padding: 10px; }
  .act-gap { display: none; }
  .actions .act:not(.act--icon) { flex: 1 1 calc(50% - 6px); justify-content: center; }
  .actions .act--icon { flex: 1 1 0; }
  .toasts { left: 12px; right: 12px; top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; }
  .gal-tip, .kbd-hint { display: none; }
  .user-name { display: none; }
  .user-btn { padding: 0 4px; height: 44px; }
  .pform { grid-template-columns: 1fr; }
  .pf-thumb { width: 160px; }
  .lib-tools .seg { width: 100%; overflow-x: auto; }
  .lib-grid { grid-template-columns: 1fr; }
  .menu-item { min-height: 44px; }
  /* 44px targets on touch */
  .chip, .chip-btn, .seg button, .sel-act, .btn--sm, .act { min-height: 44px; }
  .ratio { height: 68px; }
  .stepper, .seed-row input, .seed-row .icon-btn, input.search { height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .keys { grid-template-columns: 1fr; gap: 2px 0; }
  .keys dd { margin-bottom: 8px; }
}
@media (max-width: 760px) {
  .brand, .logo { flex: none; }
  .topbar { gap: 6px; }
}
@media (max-width: 420px) {
  #connText { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .status { padding: 0 11px; }
  .top-actions { gap: 0; }
  /* room for the add-on pill (#topbarSlot) */
  .vram svg { display: none; }
  .top-pill { gap: 5px; padding: 0 8px; }
}
@media (max-width: 380px) {
  .topbar { gap: 3px; padding: 0 6px 0 10px; }
}
@media (max-width: 400px) {
  .brand-text { display: none; }
  .mode-switch button { padding: 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .ring.spin svg { animation: spin 1s linear infinite !important; }
}
