/* Promptomy: a minimal, neutral productivity theme. Themes (html[data-theme]: light, bright, dark; "System" is
   resolved to light or dark by js/theme.js) only redefine color tokens; the accent (html[data-accent]) is one base
   color, and everything accent-tinted is mixed from it, so each accent works in every theme.
   Everything below uses these tokens; don't add raw colors, sizes or spacing further down. */
:root {
  /* Surfaces */
  --bg: #f7f7f8;
  --canvas: #eeeef0;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #ebebed;
  --field-bg: #f4f4f5;
  --field-hover: #ededef;
  --border: #e6e6e9;
  --border-strong: #d4d4d8;

  /* Text */
  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #6b6b74;
  --faint: #a1a1aa;

  /* Accent: --accent is the base color (white text on it passes AA); the rest is derived. */
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-text-mix: 84%; /* how much accent is in accent-colored text; the rest is --text */
  --accent-soft-mix: 9%;
  --accent-border-mix: 34%;
  --accent-hover: color-mix(in srgb, var(--accent) 86%, var(--text));
  --accent-text: color-mix(in srgb, var(--accent) var(--accent-text-mix), var(--text));
  --accent-soft: color-mix(in srgb, var(--accent) var(--accent-soft-mix), var(--surface));
  --accent-border: color-mix(in srgb, var(--accent) var(--accent-border-mix), var(--surface));
  --focus: color-mix(in srgb, var(--accent) 24%, transparent);
  --topbar-accent: transparent;

  /* Color accents: hues for templates, editor sections and badges. Used through --tint (see "Color accents"). */
  --c-blue: #3b82f6;
  --c-violet: #8b5cf6;
  --c-rose: #f43f5e;
  --c-orange: #f97316;
  --c-amber: #f59e0b;
  --c-teal: #14b8a6;
  --c-green: #22c55e;
  --c-slate: #64748b;
  --tint-soft-mix: 12%;
  --tint-text-mix: 78%;

  /* States */
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --ok-border: #bbf7d0;
  --warn: #a16207;
  --warn-soft: #fefce8;
  --warn-border: #fde68a;
  --mock: #7c3aed;

  /* Overlays */
  --overlay: rgba(255, 255, 255, 0.72);
  --scan-overlay: rgba(255, 255, 255, 0.24);
  --backdrop: rgba(24, 24, 27, 0.32);
  --checker-a: #e7e7ea;
  --checker-b: #efeff1;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.06);
  --shadow-md: 0 4px 16px rgba(24, 24, 27, 0.08), 0 1px 3px rgba(24, 24, 27, 0.06);
  --shadow-lg: 0 16px 48px rgba(24, 24, 27, 0.16), 0 2px 6px rgba(24, 24, 27, 0.06);

  /* JSON syntax */
  --j-key: var(--accent-text);
  --j-str: #15803d;
  --j-num: #b45309;
  --j-bool: #7c3aed;

  /* Type */
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --fs-2xs: 10.5px;
  --fs-xs: 11.5px;
  --fs-sm: 12.5px;
  --fs-md: 13px;
  --fs-lg: 15px;
  --fs-xl: 20px;
  --fs-2xl: 24px;

  /* Space (4px scale) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;

  /* Radius */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 12px;

  /* Controls and layout */
  --h-xs: 22px;
  --h-sm: 28px;
  --h-md: 32px;
  --h-lg: 40px;
  --topbar-h: 48px;
  --panel-head-h: 48px;
  --rail-w: 96px;
  --inspector-w: clamp(380px, 32vw, 520px);
  --label-w: 34%;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: light;
}

/* Bright: pure white surfaces, crisper text and borders, livelier tints and an accent line along the top. */
:root[data-theme="bright"] {
  --bg: #ffffff;
  --canvas: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #e9edf2;
  --field-bg: #f4f6f9;
  --field-hover: #ebeff4;
  --border: #e3e7ed;
  --border-strong: #cdd3dc;
  --text: #0b0d12;
  --text-2: #323846;
  --muted: #5a6272;
  --faint: #99a1ae;
  --accent-soft-mix: 12%;
  --accent-border-mix: 40%;
  --tint-soft-mix: 16%;
  --tint-text-mix: 82%;
  --topbar-accent: var(--accent);
  --checker-a: #e8ecf1;
  --checker-b: #f3f5f8;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.05);
}

:root[data-theme="dark"] {
  --bg: #0f0f11;
  --canvas: #0b0b0d;
  --surface: #161618;
  --surface-2: #1d1d20;
  --surface-3: #26262a;
  --field-bg: #1d1d20;
  --field-hover: #232327;
  --border: #26262b;
  --border-strong: #37373d;
  --text: #ededf0;
  --text-2: #b8b8c0;
  --muted: #8b8b94;
  --faint: #55555c;
  --accent-text-mix: 60%;
  --accent-soft-mix: 16%;
  --accent-border-mix: 48%;
  --accent-hover: color-mix(in srgb, var(--accent) 84%, var(--text));
  --tint-soft-mix: 18%;
  --tint-text-mix: 62%;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.1);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.08);
  --ok-border: rgba(74, 222, 128, 0.3);
  --warn: #facc15;
  --warn-soft: rgba(250, 204, 21, 0.08);
  --warn-border: rgba(250, 204, 21, 0.3);
  --mock: #a78bfa;
  --overlay: rgba(15, 15, 17, 0.72);
  --scan-overlay: rgba(15, 15, 17, 0.28);
  --backdrop: rgba(0, 0, 0, 0.55);
  --checker-a: #121215;
  --checker-b: #0b0b0d;
  --shadow-sm: none;
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --j-str: #86efac;
  --j-num: #fdba74;
  --j-bool: #c4b5fd;
  color-scheme: dark;
}

/* Accent colors. Each keeps white text on it at 4.5:1 or better. Keep in sync with ACCENTS in js/theme.js. */
:root[data-accent="violet"] {
  --accent: #7c3aed;
}
:root[data-accent="teal"] {
  --accent: #0f766e;
}
:root[data-accent="green"] {
  --accent: #15803d;
}
:root[data-accent="orange"] {
  --accent: #c2410c;
}
:root[data-accent="rose"] {
  --accent: #e11d48;
}

/* ── Base ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-md) / 1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.9em;
}
code {
  padding: 1px 5px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.muted {
  color: var(--muted);
}

.i {
  flex: none;
  display: block;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: var(--s-2);
  left: var(--s-2);
  z-index: 100;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: none;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--faint);
}
::-webkit-scrollbar-track {
  background: transparent;
}

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

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--h-md);
  padding: 0 var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.btn:hover:not(:disabled) {
  background: var(--surface-2);
}
.btn:active:not(:disabled) {
  background: var(--surface-3);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled),
.btn-primary:active:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
.btn-ghost.active,
.btn-ghost[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.btn-danger {
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}
/* A pressed toggle, e.g. "Editing" on the image being edited. */
.btn-toggle.is-on {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  box-shadow: none;
  color: var(--accent-text);
}
.btn-toggle.is-on:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.btn-sm {
  height: var(--h-sm);
  padding: 0 10px;
  font-size: var(--fs-sm);
  gap: 5px;
}
.btn-lg {
  height: var(--h-lg);
  padding: 0 var(--s-5);
  font-size: var(--fs-md);
}
.btn-kbd {
  margin-left: var(--s-1);
  padding: 0 5px;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.18);
  font: 500 var(--fs-2xs) / 18px var(--font);
  letter-spacing: 0.01em;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--h-md);
  height: var(--h-md);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover:not(:disabled),
.icon-btn.is-open,
.icon-btn.active {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn.active {
  color: var(--accent-text);
  background: var(--accent-soft);
}
.icon-btn:disabled {
  color: var(--faint);
  cursor: not-allowed;
}

.mini-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--h-xs);
  height: var(--h-xs);
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.mini-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}
.mini-btn.remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-size: inherit;
  font-weight: 500;
  cursor: pointer;
}
.link-btn:hover:not(:disabled) {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:disabled {
  color: var(--faint);
  cursor: not-allowed;
}

.spinner {
  display: inline-block;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
.spinner.sm {
  width: 14px;
  height: 14px;
}
.btn-primary .spinner,
.spinner.dark {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
}
.btn:not(.btn-primary) .spinner.dark {
  border-color: var(--border-strong);
  border-top-color: var(--text);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.count-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
.count-badge:empty {
  display: none;
}

/* ── Form controls ─────────────────────────────────────── */
.text-input {
  width: 100%;
  height: var(--h-md);
  padding: 0 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: var(--fs-md);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.select-wrap {
  position: relative;
  display: inline-flex;
  min-width: 0;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  color: var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.select-wrap select {
  appearance: none;
  min-width: 0;
  max-width: 100%;
  height: var(--h-md);
  padding: 0 28px 0 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: var(--fs-md);
  text-overflow: ellipsis;
  cursor: pointer;
}
.select-wrap select:hover:not(:disabled) {
  background: var(--surface-2);
}
.select-wrap select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.select-sm select {
  height: var(--h-sm);
  padding: 0 24px 0 8px;
  font-size: var(--fs-sm);
}
.select-sm::after {
  right: 9px;
}
/* A borderless select that reads like text until hovered (inspector meta row, composer). */
.select-plain select,
.dock .select-wrap select {
  field-sizing: content; /* as wide as the chosen option, not the longest one */
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
}
.select-plain select:hover:not(:disabled),
.dock .select-wrap select:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
.select-wrap.is-custom select {
  color: var(--accent-text);
}

.seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 24px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.seg-btn:hover:not(:disabled) {
  color: var(--text);
}
.seg-btn[aria-selected="true"],
.seg-btn[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
}
.seg-btn:disabled {
  color: var(--faint);
  cursor: not-allowed;
}

.search-field {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: var(--h-md);
  padding: 0 var(--s-1) 0 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--field-bg);
  cursor: text;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.search-field:hover {
  border-color: var(--border-strong);
}
.search-field:focus-within {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--focus);
}
.search-icon {
  color: var(--muted);
}
.search-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: var(--fs-md);
}
.search-field input::placeholder {
  color: var(--muted);
}
.search-field input::-webkit-search-cancel-button {
  cursor: pointer;
}
.search-count {
  flex: none;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}
.search-count:empty {
  display: none;
}
.search-kbd {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 2px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font: 500 var(--fs-2xs) / 1 var(--font);
}
.search-sm {
  flex: none;
  width: min(240px, 100%);
  height: var(--h-sm);
}

.notice {
  padding: 10px var(--s-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.notice:empty {
  display: none;
}
.notice-ok {
  border-color: var(--ok-border);
  background: var(--ok-soft);
  color: var(--ok);
}
.notice-warn {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}
.notice-info {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
}
.pill-error {
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}
.pill-error .dot {
  background: var(--danger);
}
.pill-warn {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}
.pill-warn .dot {
  background: var(--warn);
}
.pill-mock {
  color: var(--mock);
  border-color: color-mix(in srgb, var(--mock) 35%, transparent);
  background: color-mix(in srgb, var(--mock) 8%, transparent);
}
.pill-mock .dot {
  background: var(--mock);
}

/* ── Menus and popovers ────────────────────────────────── */
.menu-wrap {
  position: relative;
  display: inline-flex;
  min-width: 0;
}
.menu,
.popover {
  position: absolute;
  top: calc(100% + var(--s-1));
  left: 0;
  z-index: 40;
  min-width: 220px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.12s var(--ease);
}
.menu {
  display: flex;
  flex-direction: column;
  padding: var(--s-1);
}
.menu-right {
  left: auto;
  right: 0;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  height: var(--h-md);
  padding: 0 var(--s-2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-md);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.menu-item .i {
  color: var(--muted);
}
.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  background: var(--surface-2);
  outline: none;
}
.menu-item:disabled {
  color: var(--faint);
  cursor: not-allowed;
}
.menu-item:disabled .i {
  color: var(--faint);
}
.menu-item.is-danger,
.menu-item.is-danger .i {
  color: var(--danger);
}
.menu-item.is-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}
.menu-item.is-suggested::after {
  content: "Suggested";
  margin-left: auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 18px;
}
.menu-sep {
  height: 1px;
  margin: var(--s-1) calc(-1 * var(--s-1));
  background: var(--border);
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

/* ── Top bar ───────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  height: var(--topbar-h);
  padding: 0 var(--s-3) 0 var(--s-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: inset 0 2px 0 var(--topbar-accent);
}
.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: var(--h-md);
  padding: 0 var(--s-2) 0 var(--s-1);
  margin-left: calc(-1 * var(--s-1));
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand:hover {
  background: var(--surface-2);
}
.brand-mark {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 2px solid var(--accent);
}
.brand-mark::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--accent);
}
body[data-view="workspace"] .brand-text {
  display: none;
}
.crumb {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.crumb-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--h-sm);
  padding: 0 var(--s-2);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
}
.crumb-link:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
.crumb-link:disabled {
  cursor: not-allowed;
}
.crumb-link .i {
  display: none; /* phones show the arrow instead of "Projects" */
}
.crumb-sep {
  color: var(--faint);
}
.crumb-name {
  min-width: 60px;
  width: clamp(120px, 28vw, 360px);
  height: var(--h-sm);
  padding: 0 var(--s-2);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: transparent;
  font-size: var(--fs-md);
  font-weight: 600;
  text-overflow: ellipsis;
  transition: border-color 0.12s, background 0.12s;
}
.crumb-name:hover {
  background: var(--surface-2);
}
.crumb-name:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--focus);
}
.save-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  height: 24px;
  padding: 0 var(--s-2);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}
.save-status:disabled {
  cursor: default;
}
.save-status.is-saved .i {
  color: var(--ok);
}
.save-status.is-error {
  background: var(--danger-soft);
  color: var(--danger);
  cursor: pointer;
}

/* ── Home ──────────────────────────────────────────────── */
.home {
  padding: var(--s-8) var(--s-6) var(--s-12);
}
.home-inner {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  max-width: 1160px;
  margin: 0 auto;
}
.home-head h1 {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.home-head p {
  max-width: 64ch;
  margin-top: var(--s-1);
  color: var(--muted);
}

.new-card {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.new-media {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4);
  border-right: 1px solid var(--border);
  background: var(--surface-2);
}
.new-options {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  min-width: 0;
  padding: var(--s-5) var(--s-5) 0;
}
.opt-block {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.opt-label,
.opt-label-row .opt-label {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.opt-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  font-size: var(--fs-sm);
}
.optional {
  color: var(--muted);
  font-weight: 400;
}
.help {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.dropzone {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 340px;
  border-radius: var(--r-lg);
  border: 1.5px dashed var(--border-strong);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover,
.dropzone.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone:focus-visible {
  outline-offset: 3px;
}
.dz-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-1);
  padding: var(--s-6);
  text-align: center;
}
.dz-empty strong {
  margin-top: var(--s-2);
  font-size: var(--fs-md);
  font-weight: 600;
}
.dz-empty > span {
  color: var(--muted);
  font-size: var(--fs-sm);
}
/* Copy that depends on the input: drag, drop and paste with a mouse; tapping on a touch screen. */
.when-touch {
  display: none;
}
@media (hover: none) and (pointer: coarse) {
  .when-pointer {
    display: none;
  }
  .when-touch {
    display: revert;
  }
}
.dz-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.dropzone:hover .dz-icon,
.dropzone.is-drag .dz-icon {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--surface);
}
.dz-preview {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.dropzone:has(.dz-preview:not([hidden])) {
  border-style: solid;
  border-color: var(--border);
}
.dropzone:has(.dz-preview:not([hidden])):hover {
  background: var(--surface);
  border-color: var(--border-strong);
}
.dz-img {
  position: relative;
  flex: 1;
  min-height: 260px;
  margin: var(--s-2) var(--s-2) 0;
  border-radius: var(--r-md);
  background-color: var(--checker-b);
  background-image: conic-gradient(var(--checker-a) 25%, transparent 0 50%, var(--checker-a) 0 75%, transparent 0);
  background-size: 20px 20px;
  overflow: hidden;
}
.dz-img img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.dz-meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-3);
}
.dz-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.dz-name {
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dz-dims {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dz-replace {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  height: var(--h-sm);
  padding: 0 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.dropzone:hover .dz-replace {
  background: var(--surface-2);
  color: var(--text);
}

.enhance-first {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px var(--s-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.enhance-first:hover {
  border-color: var(--border-strong);
}
.enhance-first.is-suggested {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.enhance-first input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.ef-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ef-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}
.ef-title .i {
  color: var(--accent);
}
.ef-sub {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.45;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.tpl {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "icon text radio"
    "icon attrs attrs";
  column-gap: 10px;
  align-items: start;
  padding: 10px var(--s-3) 10px 10px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.tpl:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}
.tpl[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}
.tpl-icon {
  grid-area: icon;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.tpl[aria-checked="true"] .tpl-icon {
  border-color: var(--accent-border);
  background: var(--surface);
  color: var(--accent);
}
.tpl-text {
  grid-area: text;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.tpl-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.35;
}
.tpl-tag {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tpl-attrs {
  grid-area: attrs;
  margin-top: var(--s-1);
  overflow: hidden;
  color: var(--faint);
  font-size: var(--fs-2xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tpl[aria-checked="true"] .tpl-attrs {
  color: var(--muted);
}
.tpl-radio {
  grid-area: radio;
  width: 14px;
  height: 14px;
  margin-top: 2px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
}
.tpl[aria-checked="true"] .tpl-radio {
  border: 4px solid var(--accent);
}
.tpl-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 5px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-2xs);
  font-weight: 500;
  line-height: 16px;
}

.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: var(--h-md);
  padding: 3px 6px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  cursor: text;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.tag-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}
.tags {
  display: contents;
}
.tag-input input {
  flex: 1;
  min-width: 140px;
  height: 24px;
  padding: 0 var(--s-1);
  border: 0;
  outline: none;
  background: transparent;
  font-size: var(--fs-md);
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 24px;
  padding: 0 2px 0 var(--s-2);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.tag-x {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tag-x:hover {
  background: var(--border-strong);
  color: var(--text);
}
.suggestions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.suggestions:empty {
  display: none;
}
.suggest-label {
  margin-right: 2px;
  color: var(--muted);
  font-size: var(--fs-xs);
}
.suggest {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 22px;
  padding: 0 var(--s-2) 0 6px;
  border-radius: 999px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-xs);
  cursor: pointer;
}
.suggest:hover {
  border-style: solid;
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.new-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  margin: auto calc(-1 * var(--s-5)) 0;
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.cta-hint {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.projects {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin-top: var(--s-4);
}
.projects-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
}
.projects-head h2 {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(208px, 1fr));
  gap: var(--s-3);
}
.projects-empty {
  padding: var(--s-8);
  border-radius: var(--r-lg);
  border: 1px dashed var(--border-strong);
  color: var(--muted);
  text-align: center;
}
.project-card {
  position: relative;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.project-card:hover,
.project-card:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.project-open {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.project-open:focus-visible {
  outline-offset: -2px;
  border-radius: var(--r-lg);
}
.project-thumb {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--faint);
  overflow: hidden;
}
.project-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s var(--ease);
}
.project-card:hover .project-thumb img {
  transform: scale(1.02);
}
.project-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px var(--s-3) var(--s-3);
  min-width: 0;
}
.project-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-badge {
  position: absolute;
  top: var(--s-2);
  left: var(--s-2);
  padding: 0 6px;
  border-radius: var(--r-sm);
  background: var(--mock);
  color: #ffffff;
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 18px;
}
.project-delete {
  position: absolute;
  top: var(--s-2);
  right: var(--s-2);
  width: 28px;
  height: 28px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity 0.12s;
}
.project-card:hover .project-delete,
.project-delete:focus-visible {
  opacity: 1;
}
.project-delete:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ── Workspace ─────────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--inspector-w);
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  background: var(--canvas);
}

/* Versions rail */
.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.rail-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  height: var(--panel-head-h);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.filmstrip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  min-height: 0;
  padding: var(--s-3) var(--s-2);
  overflow-y: auto;
  scrollbar-width: thin;
}
.thumb {
  position: relative;
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  gap: var(--s-1);
  width: 72px;
  padding: 3px 3px var(--s-1);
  border: 1px solid transparent;
  border-radius: var(--r-lg);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.thumb img {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  object-fit: cover;
}
.thumb > span:not(.thumb-edit):not(.thumb-side):not(.spinner) {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.2;
}
.thumb:hover {
  background: var(--surface-2);
  color: var(--text);
}
.thumb.active {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.thumb.active img {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.thumb.compare-left img {
  border-color: var(--text-2);
  box-shadow: 0 0 0 1px var(--text-2);
}
.thumb-edit {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--accent);
  color: var(--accent-ink);
}
.thumb-side {
  position: absolute;
  top: 6px;
  left: 6px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: var(--r-sm);
  background: var(--text);
  color: var(--surface);
  font-size: var(--fs-2xs);
  font-weight: 700;
}
.thumb.pending {
  justify-content: center;
  height: 88px;
  border: 1px dashed var(--border-strong);
  cursor: default;
}
.rail-hint {
  padding: var(--s-2) var(--s-1);
  color: var(--faint);
  font-size: var(--fs-2xs);
  line-height: 1.4;
  text-align: center;
}

/* Canvas: header, stage, dock */
.canvas {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  container: canvas / inline-size;
}
.canvas-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex: none;
  height: var(--panel-head-h);
  padding: 0 var(--s-2) 0 var(--s-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.result-info {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.ri-title {
  flex: none;
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.ri-meta {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-info > .menu-wrap {
  flex: none;
}
.ri-details-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  height: 24px;
  padding: 0 6px 0 var(--s-2);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.ri-details-btn:hover,
.ri-details-btn.is-open {
  border-color: var(--border-strong);
  color: var(--text);
}
.ri-details-btn .chev {
  color: var(--muted);
  transition: transform 0.15s;
}
.ri-details-btn.is-open .chev {
  transform: rotate(180deg);
}
.ri-details-btn.has-note {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}
.details-pop {
  width: min(380px, 80vw);
  max-height: min(60vh, 480px);
  overflow-y: auto;
}
.details-body {
  display: flex;
  flex-direction: column;
}
.details-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--s-3);
}
.details-block + .details-block {
  border-top: 1px solid var(--border);
}
.details-block h4 {
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.details-block p {
  font-size: var(--fs-sm);
}
.ri-changes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ri-chg {
  display: grid;
  grid-template-columns: minmax(0, 40%) minmax(0, 1fr);
  gap: var(--s-2);
  font-size: var(--fs-sm);
}
.ri-chg b {
  overflow: hidden;
  color: var(--muted);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ri-chg span {
  overflow-wrap: anywhere;
}
.ri-prompt {
  color: var(--text);
}
.ri-areas {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.ri-ref {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  object-fit: cover;
}
.ri-note {
  color: var(--warn);
  white-space: pre-line;
}

.canvas-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}
.result-actions {
  display: flex;
  align-items: center;
  gap: var(--s-1);
}
.result-actions:empty,
.result-actions:empty + .tool-sep {
  display: none;
}
.tool-sep {
  width: 1px;
  height: 20px;
  margin: 0 6px;
  background: var(--border);
}
.tool-sep:not(:has(~ :not([hidden]))) {
  display: none;
}
@container canvas (max-width: 520px) {
  .canvas-head {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--panel-head-h);
    padding-block: 6px;
    row-gap: var(--s-1);
  }
  .canvas-tools {
    margin-left: auto;
  }
}
@container canvas (max-width: 760px) {
  .collapsible > span {
    display: none;
  }
  .collapsible {
    width: var(--h-sm);
    padding: 0;
  }
  .ri-meta {
    display: none;
  }
}

.stage {
  position: relative;
  flex: 1;
  min-height: 280px;
  overflow: hidden;
  touch-action: pan-x pan-y; /* the page still scrolls, but pinching zooms the image (bindZoom in app.js) */
  background-color: var(--checker-b);
  background-image: conic-gradient(var(--checker-a) 25%, transparent 0 50%, var(--checker-a) 0 75%, transparent 0);
  background-size: 24px 24px;
}
.stage-img {
  position: absolute;
  top: var(--s-4);
  left: var(--s-4);
  width: calc(100% - 2 * var(--s-4));
  height: calc(100% - 2 * var(--s-4));
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  /* Zoom: set on .stage by the app (STAGE_PAD in app.js matches the inset). Dots and marked areas read the image's
     drawn rectangle, so they follow it. */
  transform: translate(var(--pan-x, 0px), var(--pan-y, 0px)) scale(var(--zoom, 1));
  transform-origin: center center;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.08));
}
.stage.is-zoomed {
  cursor: grab;
  touch-action: none;
}
.stage.is-panning {
  cursor: grabbing;
}
.stage.is-zoomed.is-marking {
  cursor: crosshair;
}

.stage-badge {
  position: absolute;
  top: var(--s-3);
  left: var(--s-3);
  padding: 2px var(--s-2);
  border-radius: var(--r-md);
  background: rgba(24, 24, 27, 0.72);
  color: #ffffff;
  font-size: var(--fs-xs);
  font-weight: 500;
  backdrop-filter: blur(6px);
  pointer-events: none;
}
.stage.is-marking .stage-badge {
  display: none;
}

.zoom-bar {
  position: absolute;
  right: var(--s-3);
  bottom: var(--s-3);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  cursor: default;
}
.zoom-btn,
.zoom-level {
  display: grid;
  place-items: center;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.zoom-btn {
  width: 26px;
}
.zoom-level {
  min-width: 46px;
  padding: 0 6px;
  font: 500 var(--fs-xs) / 1 var(--font);
  font-variant-numeric: tabular-nums;
}
.zoom-btn:hover:not(:disabled),
.zoom-level:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
.zoom-btn:disabled,
.zoom-level:disabled {
  color: var(--faint);
  cursor: default;
}

.compare {
  position: absolute;
  inset: 0;
  cursor: ew-resize;
  touch-action: none;
  --pos: 50%;
  --pos-n: 0.5;
}
.compare:focus-visible {
  outline-offset: -3px;
}
/* The right side is clipped by this wrapper, in stage coordinates, so zooming the image inside doesn't move the seam. */
.compare-top {
  position: absolute;
  top: var(--s-4);
  left: var(--s-4);
  width: calc(100% - 2 * var(--s-4));
  height: calc(100% - 2 * var(--s-4));
  clip-path: inset(0 0 0 var(--pos));
}
.compare-top .stage-img {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--s-4) + (100% - 2 * var(--s-4)) * var(--pos-n));
  width: 2px;
  margin-left: -1px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}
.compare-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #ffffff;
  color: #18181b;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
}
.compare-pickers {
  position: absolute;
  top: var(--s-3);
  left: var(--s-3);
  right: var(--s-3);
  display: flex;
  justify-content: space-between;
  gap: var(--s-2);
  pointer-events: none;
}
.compare-pick {
  position: relative;
  pointer-events: auto;
}
.compare-pick::after {
  content: "";
  position: absolute;
  right: 9px;
  top: 50%;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  color: var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.compare-pick select {
  appearance: none;
  height: 26px;
  padding: 0 24px 0 var(--s-2);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
}
.compare-pick.right select {
  color: var(--accent-text);
}

/* On-image editing: dots, whole-image chips and the field popover, all inside the stage. Dots use fixed colors
   because they sit on arbitrary images. */
.hotspots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hs-dot {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background: rgba(24, 24, 27, 0.8);
  color: #ffffff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  font: 600 var(--fs-2xs) / 1 var(--font);
  font-variant-numeric: tabular-nums;
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.12s;
}
.hs-dot:hover,
.hs-dot.is-hover,
.hs-dot:focus-visible {
  z-index: 3;
  transform: scale(1.15);
}
.hs-dot.is-changed {
  background: var(--accent);
}
.hs-dot.is-open {
  z-index: 4;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent), 0 1px 6px rgba(0, 0, 0, 0.35);
}
.hs-tip {
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  padding: 3px var(--s-2);
  border-radius: var(--r-md);
  background: rgba(24, 24, 27, 0.9);
  color: #ffffff;
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity 0.12s;
  pointer-events: none;
}
.hs-dot.tip-left .hs-tip {
  left: auto;
  right: calc(100% + 6px);
}
.hs-dot:hover .hs-tip,
.hs-dot.is-hover .hs-tip,
.hs-dot:focus-visible .hs-tip {
  opacity: 1;
}
.hs-dot.is-open .hs-tip {
  opacity: 0;
}
.hs-chips {
  position: absolute;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
}
.hs-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 var(--s-2);
  border-radius: 999px;
  border: 0;
  background: rgba(24, 24, 27, 0.8);
  color: #ffffff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
  font-size: var(--fs-xs);
  font-weight: 500;
  backdrop-filter: blur(6px);
  pointer-events: auto;
  cursor: pointer;
}
.hs-chip:hover,
.hs-chip.is-hover {
  background: rgba(24, 24, 27, 0.92);
}
.hs-chip.is-changed,
.hs-chip.is-open {
  background: var(--accent);
}
.hs-count {
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: var(--fs-2xs);
  line-height: 16px;
}
.hs-pop {
  position: absolute;
  z-index: 5;
  display: flex;
  flex-direction: column;
  width: min(340px, calc(100% - 16px));
  max-height: calc(100% - 16px);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: pop-in 0.12s var(--ease);
}
.hs-pop-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) 6px var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
}
.hs-pop-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-md);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hs-pop-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-height: 0;
  padding: var(--s-3);
  overflow-y: auto;
  container: attrs / inline-size;
}
.hs-badge {
  display: grid;
  flex: none;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  font-size: var(--fs-2xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hs-badge.area {
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.mount-empty {
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* Marked areas for the version prompt. Fixed colors apart from the accent: they sit on top of arbitrary images. */
.area-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.area-layer.is-marking {
  z-index: 3;
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}
.area-box {
  position: absolute;
  border: 2px solid var(--accent);
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), inset 0 0 0 1px rgba(255, 255, 255, 0.55);
  transition: background 0.12s;
}
.area-box.is-hover {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
}
.area-box.is-draft {
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.area-layer.is-marking .area-box:not(.is-draft) {
  cursor: move;
}
.area-tag {
  position: absolute;
  top: -2px;
  left: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 3px 0 5px 0;
  background: var(--accent);
  color: #ffffff;
  font: 600 var(--fs-2xs) / 18px var(--font);
  text-align: center;
  pointer-events: none;
}
.area-ref {
  position: absolute;
  left: var(--s-1);
  bottom: var(--s-1);
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  border: 2px solid #ffffff;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  object-fit: cover;
  pointer-events: none;
}
.area-x {
  position: absolute;
  top: -10px;
  right: -10px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #18181b;
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.area-x:hover {
  background: #dc2626;
}
.area-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 2px solid var(--accent);
  background: #ffffff;
  cursor: nwse-resize;
}

.mark-hint,
.overlay-notice {
  position: absolute;
  left: 50%;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 2 * var(--s-6));
  padding: var(--s-1) var(--s-1) var(--s-1) var(--s-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  font-size: var(--fs-sm);
  transform: translateX(-50%);
}
.mark-hint {
  top: var(--s-3);
}
.overlay-notice {
  bottom: var(--s-3);
}
.mark-hint > span,
.overlay-notice > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan {
  position: absolute;
  inset: 0;
  background: var(--scan-overlay);
  pointer-events: none;
}
.scan-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  overflow: hidden;
  background: var(--accent-soft);
}
.scan-bar::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 35%;
  background: var(--accent);
  animation: indeterminate 1.3s ease-in-out infinite;
}
@keyframes indeterminate {
  from {
    left: -35%;
  }
  to {
    left: 100%;
  }
}
.scan-label {
  position: absolute;
  left: 50%;
  bottom: var(--s-4);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  max-width: calc(100% - 2 * var(--s-4));
  padding: 6px var(--s-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  white-space: nowrap;
  transform: translateX(-50%);
}
.scan-label > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}
.rendering {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  padding: var(--s-5);
  background: var(--overlay);
  backdrop-filter: blur(4px);
  color: var(--text-2);
  font-size: var(--fs-md);
  font-weight: 500;
  text-align: center;
}

/* Dock: the composer for the next version */
.dock {
  position: relative;
  flex: none;
  padding: var(--s-3) var(--s-4) var(--s-4);
  border-top: 1px solid var(--border);
  background: var(--canvas);
}
.composer {
  display: flex;
  flex-direction: column;
  max-width: 880px;
  margin: 0 auto;
  border-radius: var(--r-xl);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus), var(--shadow-md);
}
.composer-input {
  display: block;
  width: 100%;
  min-height: 44px;
  max-height: 132px;
  padding: var(--s-3) var(--s-3) var(--s-1);
  border: 0;
  outline: none;
  background: transparent;
  font-size: var(--fs-md);
  line-height: 1.5;
  resize: none;
}
.composer-input::placeholder {
  color: var(--muted);
}
.composer-input:disabled {
  cursor: not-allowed;
}
.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: var(--s-1) var(--s-2) var(--s-2);
}
.composer-left,
.composer-right {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.composer-right {
  gap: 6px;
  margin-left: auto;
}
.select-model select {
  max-width: 220px;
}
.btn-gen {
  min-width: 132px;
}
@container canvas (max-width: 620px) {
  .btn-kbd,
  #markAreaBtn > span {
    display: none;
  }
  .btn-gen {
    min-width: 0;
  }
  .select-model select {
    max-width: 150px;
  }
}

.area-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--s-1) var(--s-3) 0;
}
.area-chips:empty {
  display: none;
}
.area-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 2px 0 3px;
  border-radius: var(--r-md);
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--fs-xs);
  font-weight: 500;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.area-chip.is-drop {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}
.area-chip-n {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #ffffff;
  font-size: var(--fs-2xs);
  font-weight: 600;
}
.area-chip-img {
  position: relative;
  display: inline-flex;
}
.area-chip-attach,
.area-chip-thumb {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--accent-text);
  cursor: pointer;
  overflow: hidden;
}
.area-chip-attach:hover {
  background: var(--surface);
}
.area-chip-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.area-chip-unattach {
  position: absolute;
  top: -5px;
  right: -5px;
  display: grid;
  place-items: center;
  width: 13px;
  height: 13px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  cursor: pointer;
}
.area-chip .tag-x {
  color: var(--accent-text);
}
.area-chip .tag-x:hover {
  background: var(--surface);
}

.changes-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--h-sm);
  padding: 0 10px 0 var(--s-1);
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.changes-chip .n {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.changes-chip.has {
  color: var(--accent-text);
}
.changes-chip.has .n {
  background: var(--accent);
  color: var(--accent-ink);
}
.changes-chip.has:hover,
.changes-chip[aria-expanded="true"] {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
.changes-chip:disabled {
  cursor: default;
}
.changes-pop {
  position: absolute;
  bottom: calc(100% - var(--s-2));
  left: 50%;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(460px, calc(100% - 2 * var(--s-4)));
  max-height: min(50vh, 420px);
  padding: var(--s-1);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  transform: translateX(-50%);
  animation: pop-in 0.12s var(--ease);
}
.chg {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px var(--s-2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.chg:hover,
.chg:focus-visible {
  background: var(--surface-2);
  outline: none;
}
.chg-path {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 500;
}
.chg-vals {
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}
.chg-vals s {
  color: var(--muted);
}
.chg-to {
  color: var(--accent-text);
  font-weight: 500;
}

/* ── Inspector ─────────────────────────────────────────── */
.inspector {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
.insp-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
  height: var(--panel-head-h);
  padding: 0 var(--s-2) 0 var(--s-4);
  border-bottom: 1px solid var(--border);
}
.insp-title {
  flex: 1;
  font-size: var(--fs-md);
  font-weight: 600;
}
.insp-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px var(--s-2);
  flex: none;
  padding: 6px var(--s-3) 6px 6px;
  border-bottom: 1px solid var(--border);
}
.insp-meta .select-wrap {
  flex: none;
}
.status-items {
  display: contents;
  color: var(--muted);
  font-size: var(--fs-xs);
}
.status-items > span:not(.status-carried) {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  white-space: nowrap;
}
.status-editing {
  color: var(--accent-text);
  font-weight: 500;
}
.status-lock {
  color: var(--text-2);
}
.status-lowres {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  height: 20px;
  padding: 0 6px;
  border: 1px solid var(--warn-border);
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
}
.status-lowres:hover:not(:disabled) {
  border-color: var(--warn);
}
.status-carried {
  flex-basis: 100%;
  margin: var(--s-1) 0 2px 6px;
  padding: 6px 10px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-xs);
  line-height: 1.45;
}

.insp-tools {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  flex: none;
  padding: 10px var(--s-3);
  border-bottom: 1px solid var(--border);
}
.tools-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.workspace[data-edit-view="image"] .tools-row {
  display: none;
}
.workspace[data-edit-view="image"] .insp-tools:has(.refine-field[hidden]) {
  display: none;
}
.refine-field {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--h-md);
  padding: 0 2px 0 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  animation: pop-in 0.12s var(--ease);
}
.refine-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}
.refine-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: var(--fs-md);
}
.refine-field input::placeholder {
  color: var(--muted);
}
.refine-field .btn {
  height: 26px;
}
.refine-field .link-btn {
  font-size: var(--fs-sm);
  padding: 0 var(--s-1);
}

.editor-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--s-8) var(--s-6);
  text-align: center;
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--s-2);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.editor-empty strong {
  font-size: var(--fs-md);
  font-weight: 600;
}
.editor-empty p {
  max-width: 36ch;
  color: var(--muted);
  font-size: var(--fs-sm);
}
.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-2);
  margin-top: var(--s-3);
}

.editor-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}
.editor {
  container: attrs / inline-size;
  padding-bottom: var(--s-8);
}
.editor.is-busy {
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.15s;
}

/* Sections: one per top-level attribute group. The header sticks while its fields scroll. */
.section + .section {
  border-top: 1px solid var(--border);
}
.section-top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--s-1);
  height: 36px;
  padding: 0 var(--s-2) 0 var(--s-1);
  background: var(--surface);
}
.section:not(.collapsed) > .section-top {
  box-shadow: 0 1px 0 var(--border);
}
.section-head {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: var(--h-sm);
  padding: 0 var(--s-2) 0 6px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.section-head:hover {
  background: var(--surface-2);
}
.section-head .chev {
  color: var(--muted);
  transition: transform 0.15s var(--ease);
}
.section.collapsed .chev {
  transform: rotate(-90deg);
}
.section-title {
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.section-head .mod {
  display: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.section.is-dirty > .section-top .mod {
  display: block;
}
.section.is-dirty > .section-top .section-title {
  color: var(--accent-text);
}
.section-head .count {
  margin-left: auto;
  color: var(--faint);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.section.collapsed .section-body {
  display: none;
}
.section-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px var(--s-3) var(--s-3) var(--s-4);
}
.section-compact .section-body {
  padding-top: var(--s-2);
}

/* Field rows: stacked in narrow containers (the on-image popover), label | value | actions when there is room. */
.field-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: none;
  opacity: 0;
  transition: opacity 0.12s;
}
.section-top:hover .section-actions,
.section-top:focus-within .section-actions,
.field:hover > .field-label .field-actions,
.field:focus-within > .field-label .field-actions,
.group-head:hover .field-actions,
.group-head:focus-within .field-actions,
.field-actions:focus-within {
  opacity: 1;
}
@media (hover: none) {
  .field-actions {
    opacity: 1;
  }
}

.field {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 3px 0;
  border-radius: var(--r-md);
}
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-height: var(--h-xs);
}
.field-label label {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 1.35;
}
.control {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}
.was {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.was:empty {
  display: none;
}

@container attrs (min-width: 340px) {
  .field {
    display: grid;
    grid-template-columns: var(--label-w) minmax(0, 1fr);
    column-gap: var(--s-2);
    row-gap: 2px;
    align-items: start;
  }
  .field-label {
    display: contents;
  }
  .field-label label {
    grid-column: 1;
    grid-row: 1;
    padding-top: 5px;
  }
  /* Actions float over the end of the label column, so the value column keeps its full width. */
  .field-label .field-actions {
    position: absolute;
    top: 4px;
    left: calc(var(--label-w) - 56px);
    padding-left: var(--s-2);
    background: linear-gradient(to right, transparent, var(--surface) var(--s-2));
  }
  .field > .control,
  .field > .list,
  .field > .add-btn,
  .field > .was {
    grid-column: 2;
  }
  .field > .add-btn {
    justify-self: start;
  }
}

/* Changed, new and flashed fields */
.field.is-changed::before,
.group.is-new::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 5px;
  bottom: 5px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.field.is-changed > .field-label label {
  color: var(--accent-text);
  font-weight: 500;
}
.flash {
  animation: flash 1s ease-out;
}
@keyframes flash {
  from {
    background: var(--accent-soft);
    box-shadow: 0 0 0 4px var(--accent-soft);
  }
  to {
    background: transparent;
    box-shadow: 0 0 0 4px transparent;
  }
}

.input {
  display: block;
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: var(--h-sm);
  margin: 0;
  padding: 4px var(--s-2);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: var(--field-bg);
  font-size: var(--fs-md);
  line-height: 1.45;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
textarea.input {
  overflow: hidden;
  resize: none;
}
.input:hover {
  background: var(--field-hover);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--focus);
}
.input.invalid {
  border-color: var(--danger);
}
.field.is-changed > .control > .input,
.field.is-changed .list-item > .input {
  background: var(--accent-soft);
}
.field.is-changed > .control > .input:focus,
.field.is-changed .list-item > .input:focus {
  background: var(--surface);
}
input[type="number"].input {
  max-width: 160px;
}

.switch {
  position: relative;
  flex: none;
  width: 32px;
  height: 18px;
  margin: 5px 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s var(--ease);
}
.switch[aria-checked="true"] {
  background: var(--accent);
}
.switch[aria-checked="true"]::after {
  transform: translateX(14px);
}

.swatches {
  display: flex;
  flex: none;
  gap: var(--s-1);
}
.swatch {
  position: relative;
  flex: none;
  width: var(--h-sm);
  height: var(--h-sm);
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--sw, transparent);
  box-shadow: inset 0 0 0 2px var(--surface);
  cursor: pointer;
  overflow: hidden;
}
.swatch:hover {
  border-color: var(--faint);
}
.swatch:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.swatch.empty {
  background: linear-gradient(135deg, transparent 46%, var(--border-strong) 46% 54%, transparent 54%), var(--surface-2);
}
.swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.list {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  min-width: 0;
}
.list-item {
  display: flex;
  align-items: flex-start;
  gap: var(--s-1);
}
.list-item > .mini-btn {
  margin-top: 3px;
  opacity: 0;
}
.list-item:hover > .mini-btn,
.list-item:focus-within > .mini-btn {
  opacity: 1;
}

.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  height: 24px;
  padding: 0 var(--s-2) 0 6px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
}
.add-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.add-attr {
  margin-top: 2px;
}
.add-attr-form {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) auto auto;
  gap: var(--s-1);
  align-items: center;
  padding: var(--s-1);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.add-attr-form .input {
  background: var(--surface);
  border-color: var(--border);
}
.add-attr-form .btn {
  height: var(--h-sm);
}

/* Nested groups and repeated items */
.group {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: var(--s-1) 0 2px;
}
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-height: 26px;
}
.group-title {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.group.is-dirty > .group-head .group-title {
  color: var(--accent-text);
}
.group-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: 3px;
  padding-left: var(--s-3);
  border-left: 1px solid var(--border);
}
.group.is-dirty > .group-body {
  border-left-color: var(--accent-border);
}
.obj-array {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.obj-array > .add-btn {
  margin-top: 2px;
}
.obj-array-head {
  margin-top: var(--s-2);
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Deleted attributes stay in place until restored */
.deleted-attr,
.deleted-section {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--h-sm);
  padding: 2px var(--s-2) 2px 0;
  border-radius: var(--r-md);
}
.deleted-section {
  margin: 0;
  padding: 6px var(--s-3) 6px var(--s-4);
  border-top: 1px solid var(--border);
}
.editor > .deleted-section:first-child {
  border-top: 0;
}
.deleted-text {
  display: flex;
  flex: 1;
  gap: var(--s-2);
  min-width: 0;
}
.deleted-label {
  flex: none;
  width: var(--label-w);
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-sm);
  text-decoration: line-through;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deleted-section .deleted-label {
  flex: 1;
  width: auto;
  font-weight: 600;
}
.deleted-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--faint);
  font-size: var(--fs-sm);
  text-decoration: line-through;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deleted-section .deleted-value {
  flex: none;
  text-decoration: none;
  font-size: var(--fs-xs);
}
.deleted-tag {
  order: 2;
  flex: none;
  padding: 0 6px;
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 18px;
}
.deleted-attr .link-btn,
.deleted-section .link-btn {
  order: 3;
  flex: none;
  font-size: var(--fs-xs);
}

/* Search */
mark.hit {
  border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: inherit;
}
.filter-hide {
  display: none !important;
}
.filter-empty {
  padding: var(--s-8) var(--s-4);
  color: var(--muted);
  text-align: center;
}
.editor.is-filtering .add-attr,
.editor.is-filtering .obj-array > .add-btn,
.editor.is-filtering .section-actions,
.editor.is-filtering .deleted-attr,
.editor.is-filtering .deleted-section {
  display: none;
}
.editor.is-filtering .section.collapsed .section-body {
  display: flex;
}
.editor.is-filtering .section.collapsed .chev {
  transform: none;
}
.editor.is-filtering .section-head {
  cursor: default;
}
.editor.is-filtering .section-head:hover {
  background: transparent;
}

/* Loading skeleton */
.skel {
  display: flex;
  flex-direction: column;
  padding: var(--s-3) var(--s-4) var(--s-4);
  border-bottom: 1px solid var(--border);
}
.skel-line {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.skel-title {
  width: 32%;
  height: 10px;
  margin: var(--s-1) 0 var(--s-3);
}
.skel-label {
  width: 24%;
  height: 8px;
  margin: 10px 0 6px;
}
.skel-input {
  height: var(--h-sm);
  border-radius: var(--r-md);
}
@container attrs (min-width: 340px) {
  .skel {
    display: grid;
    grid-template-columns: var(--label-w) minmax(0, 1fr);
    column-gap: var(--s-2);
    align-items: center;
  }
  .skel-title {
    grid-column: 1 / -1;
  }
  .skel-label {
    width: 60%;
    margin: 6px 0;
  }
  .skel-input {
    margin: 3px 0;
  }
}
@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* On-image legend */
.dot-panel {
  flex: 1;
  min-height: 0;
  padding: var(--s-1) var(--s-2) var(--s-4);
  overflow-y: auto;
}
.dp-intro {
  margin: var(--s-2) var(--s-2) var(--s-1);
  color: var(--muted);
  font-size: var(--fs-sm);
}
.dp-note {
  margin: var(--s-2) var(--s-1) var(--s-1);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-sm);
}
.dp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: var(--s-3) var(--s-2) var(--s-1);
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.dp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px var(--s-2);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.dp-item:hover,
.dp-item.is-hover {
  background: var(--surface-2);
}
.dp-item.is-open {
  background: var(--accent-soft);
}
.dp-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.dp-label {
  overflow: hidden;
  font-size: var(--fs-md);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dp-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dp-mod {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.dp-item.is-changed .dp-mod {
  background: var(--accent);
}
.dp-item.is-changed .hs-badge:not(.area),
.dp-item.is-open .hs-badge:not(.area) {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ── Dialogs ───────────────────────────────────────────── */
.dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  padding: 0;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
.dialog[open] {
  animation: dialog-in 0.16s var(--ease);
}
.dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}
@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.99);
  }
}
.dialog-wide {
  width: min(820px, calc(100vw - 32px));
}
.dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 50px);
  max-height: calc(100dvh - 50px);
}
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex: none;
  min-height: 52px;
  padding: 0 var(--s-2) 0 var(--s-5);
  border-bottom: 1px solid var(--border);
}
.dialog-head h3 {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.dialog-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-height: 0;
  padding: var(--s-5);
  overflow-y: auto;
}
.dialog-body-flush {
  padding: 0;
}
.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  flex: none;
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.form-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
}
.form-foot small {
  font-size: var(--fs-xs);
}

.tabs {
  display: flex;
  align-self: stretch;
  gap: var(--s-4);
}
.tab {
  position: relative;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  color: var(--text);
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.json-pre {
  min-height: 320px;
  max-height: 64vh;
  margin: 0;
  padding: var(--s-4) var(--s-5);
  overflow: auto;
  background: var(--surface-2);
  font: 12.5px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.json-pre:focus-visible {
  outline-offset: -2px;
}
.j-key {
  color: var(--j-key);
}
.j-str {
  color: var(--j-str);
}
.j-num {
  color: var(--j-num);
}
.j-bool,
.j-null {
  color: var(--j-bool);
}

.model-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.model-group-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.model-group-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.model-group-head h4 {
  font-size: var(--fs-md);
  font-weight: 600;
}
.model-group-head p {
  color: var(--muted);
  font-size: var(--fs-xs);
}
.model-options,
.dl-options {
  display: flex;
  flex-direction: column;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.dl-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px var(--s-3);
  background: var(--surface);
  cursor: pointer;
  transition: background 0.12s;
}
.dl-opt + .dl-opt {
  border-top: 1px solid var(--border);
}
.dl-opt:hover {
  background: var(--surface-2);
}
.dl-opt:has(input:checked) {
  background: var(--accent-soft);
}
.dl-opt.is-disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
.dl-opt input[type="radio"] {
  flex: none;
  width: 15px;
  height: 15px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  cursor: inherit;
}
.dl-opt-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.dl-opt-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}
.dl-opt-sub {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.45;
}
.dl-opt-dims {
  flex: none;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.model-id {
  font-family: var(--mono);
  font-size: var(--fs-sm);
}
.model-id.is-label {
  font-family: var(--font);
  font-size: var(--fs-md);
}
.model-default-tag {
  padding: 0 6px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--text-2);
  font-family: var(--font);
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 18px;
}
.model-custom-input {
  height: var(--h-sm);
  margin-top: 6px;
  font-family: var(--mono);
  font-size: var(--fs-sm);
}

.dl-info {
  color: var(--muted);
  font-size: var(--fs-sm);
}
.dl-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.dl-group legend {
  margin-bottom: var(--s-2);
  padding: 0;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.dl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.dl-label {
  font-size: var(--fs-sm);
  font-weight: 600;
}
.dl-status {
  margin-right: auto;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.enhance-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.enhance-img {
  width: 64px;
  height: 64px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  object-fit: cover;
}
.enhance-meta {
  display: flex;
  flex-direction: column;
}
.enhance-res {
  color: var(--muted);
  font-size: var(--fs-sm);
}
.enhance-res.is-low {
  color: var(--warn);
  font-weight: 500;
}

/* ── Toasts ────────────────────────────────────────────── */
.toasts {
  position: fixed;
  top: calc(var(--topbar-h) + var(--s-3));
  left: 50%;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  width: min(460px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
  padding: var(--s-2) 6px var(--s-2) var(--s-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  line-height: 1.45;
  pointer-events: auto;
  animation: toast-in 0.18s var(--ease);
}
.toast > .i {
  margin-top: 1px;
}
.toast > span {
  flex: 1;
  min-width: 0;
  padding-top: 1px;
  overflow-wrap: anywhere;
}
.toast-success > .i {
  color: var(--ok);
}
.toast-error {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}
.toast-error > .i {
  color: var(--danger);
}
.toast-info > .i {
  color: var(--accent);
}
/* In the workspace, toasts sit over the top of the stage, clear of the canvas header and the inspector. */
@media (min-width: 961px) {
  body[data-view="workspace"] .toasts {
    top: calc(var(--topbar-h) + var(--panel-head-h) + var(--s-3));
    left: calc(var(--rail-w) + (100vw - var(--rail-w) - var(--inspector-w)) / 2);
    width: min(460px, calc(100vw - var(--rail-w) - var(--inspector-w) - 32px));
  }
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* ── Appearance picker ─────────────────────────────────── */
.appearance-pop {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  width: 300px;
  padding: var(--s-3);
}
.ap-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.ap-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: var(--s-2);
  padding: 0;
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ap-value {
  color: var(--text-2);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.theme-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
.theme-opt {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 6px var(--s-2);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.theme-opt:hover {
  background: var(--surface-2);
}
.theme-opt:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}
.theme-opt:has(input:focus-visible),
.accent-opt:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.theme-opt input,
.accent-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.theme-name {
  font-size: var(--fs-xs);
  font-weight: 500;
}
/* Miniature of each theme: a page, a panel and an accent bar. Fixed colors, since they show other themes. */
.theme-preview {
  position: relative;
  width: 100%;
  height: 38px;
  border-radius: var(--r-md);
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: var(--pv-bg);
  overflow: hidden;
}
.theme-preview::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  right: 40%;
  bottom: 6px;
  border-radius: 3px;
  background: var(--pv-panel);
}
.theme-preview::after {
  content: "";
  position: absolute;
  right: 6px;
  top: 8px;
  width: 26%;
  height: 5px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 9px 0 var(--pv-line), 0 18px 0 var(--pv-line);
}
.theme-preview[data-preview="light"] {
  --pv-bg: #eeeef0;
  --pv-panel: #ffffff;
  --pv-line: #d4d4d8;
}
.theme-preview[data-preview="bright"] {
  --pv-bg: #ffffff;
  --pv-panel: #f3f5f8;
  --pv-line: #cdd3dc;
  box-shadow: inset 0 2px 0 var(--accent);
}
.theme-preview[data-preview="dark"] {
  --pv-bg: #0b0b0d;
  --pv-panel: #1d1d20;
  --pv-line: #37373d;
  border-color: rgba(255, 255, 255, 0.12);
}
.theme-preview[data-preview="system"] {
  --pv-bg: linear-gradient(90deg, #eeeef0 50%, #0b0b0d 50%);
  --pv-panel: linear-gradient(90deg, #ffffff 50%, #1d1d20 50%);
  --pv-line: #8b8b94;
}
.accent-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.accent-opt {
  position: relative;
  border-radius: 50%;
  cursor: pointer;
}
.accent-dot {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--swatch);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s var(--ease), box-shadow 0.12s;
}
.accent-dot .i {
  opacity: 0;
}
.accent-opt:hover .accent-dot {
  transform: scale(1.08);
}
.accent-opt:has(input:checked) .accent-dot {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--swatch);
}
.accent-opt:has(input:checked) .accent-dot .i {
  opacity: 1;
}

/* ── Color accents ─────────────────────────────────────── */
/* Each template has a hue (--tint), used for its icon on the home screen and its badge on project cards. */
[data-template="product"],
.tpl[data-id="product"] {
  --tint: var(--c-blue);
}
[data-template="portrait"],
.tpl[data-id="portrait"] {
  --tint: var(--c-rose);
}
[data-template="automotive"],
.tpl[data-id="automotive"] {
  --tint: var(--c-orange);
}
[data-template="interior"],
.tpl[data-id="interior"] {
  --tint: var(--c-teal);
}
[data-template="food"],
.tpl[data-id="food"] {
  --tint: var(--c-amber);
}
[data-template="document"],
.tpl[data-id="document"] {
  --tint: var(--c-violet);
}
.tpl[data-id="none"] {
  --tint: var(--c-slate);
}
.tpl .tpl-icon,
.tpl[aria-checked="true"] .tpl-icon {
  border-color: color-mix(in srgb, var(--tint, var(--c-slate)) 30%, var(--surface));
  background: color-mix(in srgb, var(--tint, var(--c-slate)) var(--tint-soft-mix), var(--surface));
  color: color-mix(in srgb, var(--tint, var(--c-slate)) var(--tint-text-mix), var(--text));
}
.project-tpl {
  position: absolute;
  left: var(--s-2);
  bottom: var(--s-2);
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--tint, var(--c-slate)) 88%, #000000);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* Editor sections cycle through the hues: a marker by the title and a matching guide line for nested groups. */
.editor > .section:nth-of-type(7n + 1) {
  --tint: var(--c-blue);
}
.editor > .section:nth-of-type(7n + 2) {
  --tint: var(--c-violet);
}
.editor > .section:nth-of-type(7n + 3) {
  --tint: var(--c-teal);
}
.editor > .section:nth-of-type(7n + 4) {
  --tint: var(--c-orange);
}
.editor > .section:nth-of-type(7n + 5) {
  --tint: var(--c-rose);
}
.editor > .section:nth-of-type(7n + 6) {
  --tint: var(--c-green);
}
.editor > .section:nth-of-type(7n + 7) {
  --tint: var(--c-amber);
}
.section-head .section-title::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: var(--s-2);
  border-radius: 2px;
  background: var(--tint, var(--c-slate));
  vertical-align: 1px;
}
.section .group-body {
  border-left-color: color-mix(in srgb, var(--tint, var(--c-slate)) 35%, var(--border));
}
.section .obj-array-head {
  color: color-mix(in srgb, var(--tint, var(--c-slate)) var(--tint-text-mix), var(--text));
}

/* Smaller touches */
.thumb > span:not(.thumb-edit):not(.thumb-side) .i {
  color: var(--c-amber);
}
.status-lock {
  display: inline-flex;
  padding: 0 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c-violet) var(--tint-soft-mix), var(--surface));
  color: color-mix(in srgb, var(--c-violet) var(--tint-text-mix), var(--text));
  line-height: 20px;
}
.dz-icon,
.empty-icon {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.model-group:nth-of-type(1) {
  --tint: var(--c-violet);
}
.model-group:nth-of-type(2) {
  --tint: var(--c-orange);
}
.model-group-icon {
  border-color: color-mix(in srgb, var(--tint, var(--c-slate)) 30%, var(--surface));
  background: color-mix(in srgb, var(--tint, var(--c-slate)) var(--tint-soft-mix), var(--surface));
  color: color-mix(in srgb, var(--tint, var(--c-slate)) var(--tint-text-mix), var(--text));
}
.ef-title .i {
  color: var(--c-amber);
}

/* ── Phone panel tabs ──────────────────────────────────── */
/* Only shown by the phone layout below; wider screens show the canvas and the inspector side by side. */
.pane-tabs {
  display: none;
  gap: var(--s-1);
  padding: var(--s-1) var(--s-2) calc(var(--s-1) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.pane-tab {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: var(--h-lg);
  padding: 0 var(--s-3);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.pane-tab:hover {
  color: var(--text);
}
.pane-tab[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.pane-badge {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1180px) {
  :root {
    --rail-w: 84px;
    --inspector-w: 360px;
  }
  .thumb {
    width: 64px;
  }
  .thumb img {
    width: 56px;
    height: 56px;
  }
}

/* Tablet: canvas and inspector stack; the versions rail becomes a strip above the canvas. */
@media (max-width: 960px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    height: auto;
  }
  .rail {
    flex-direction: row;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .rail-head {
    flex-direction: column;
    height: auto;
    padding: 0 var(--s-3);
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }
  .filmstrip {
    flex-direction: row;
    padding: var(--s-2);
    overflow-x: auto;
    overflow-y: hidden;
  }
  .rail-hint {
    align-self: center;
    white-space: nowrap;
  }
  .canvas {
    min-height: 0;
  }
  .stage {
    flex: none;
    height: 58vh;
  }
  .dock {
    position: sticky;
    bottom: 0;
    z-index: 15;
  }
  .inspector {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  .editor-scroll,
  .dot-panel {
    overflow: visible;
  }
  .section-top {
    top: var(--topbar-h);
  }
  .new-card {
    grid-template-columns: minmax(0, 1fr);
  }
  .new-media {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .dropzone {
    min-height: 260px;
  }
}

@media (max-width: 600px) {
  .home {
    padding: var(--s-5) var(--s-3) var(--s-10);
  }
  .template-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .new-options {
    padding: var(--s-4) var(--s-4) 0;
  }
  .new-foot {
    flex-direction: column-reverse;
    align-items: stretch;
    margin: auto calc(-1 * var(--s-4)) 0;
    padding: var(--s-3) var(--s-4);
  }
  .projects-head {
    flex-wrap: wrap;
  }
  .search-sm {
    width: 100%;
  }
  .crumb-name {
    width: 38vw;
  }
  .save-status span {
    display: none;
  }
  .canvas-head {
    padding-left: var(--s-3);
  }
  .stage {
    height: 48vh;
  }
  .dock {
    padding: var(--s-2);
  }
}

/* Short landscape screens (a phone on its side): the stacked layout gives the image the whole screen, and the composer
   follows it instead of covering it. */
@media (min-width: 721px) and (max-width: 960px) and (max-height: 560px) {
  .stage {
    height: calc(100dvh - var(--topbar-h) - var(--s-6));
    min-height: 220px;
  }
  .dock {
    position: relative;
  }
}

/* Phones: the workspace fills the screen, and the canvas and the attribute inspector take turns in it, switched by the
   tab bar at the bottom (data-pane on .workspace, set by setPane() in app.js). The dock shows in both: the whole
   composer with the image, only its Generate row with the attributes. */
@media (max-width: 720px) {
  .topbar {
    gap: var(--s-2);
    padding: 0 var(--s-1) 0 var(--s-2);
  }
  .topbar-left {
    flex: 1;
  }
  .topbar-right {
    gap: 0;
  }
  body[data-view="setup"] .topbar {
    padding-left: var(--s-3);
  }
  body[data-view="workspace"] .brand,
  .crumb-sep,
  .crumb-link > span {
    display: none;
  }
  .crumb {
    flex: 1;
  }
  .crumb-link {
    width: var(--h-md);
    height: var(--h-md);
    padding: 0;
  }
  .crumb-link .i {
    display: block;
  }
  .crumb-name {
    flex: 1;
    width: auto;
    padding: 0 6px;
  }
  body[data-view="workspace"] .pill-mock {
    width: 24px;
    padding: 0;
    justify-content: center;
  }
  body[data-view="workspace"] .pill-mock > span:last-child {
    display: none;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
  }
  body[data-view="workspace"] {
    overflow: hidden;
    overscroll-behavior: none;
  }
  .rail {
    grid-row: 1;
  }
  .canvas {
    grid-row: 2 / 4;
  }
  .inspector {
    display: none;
    grid-row: 1 / 3;
    border-top: 0;
  }
  .pane-tabs {
    display: flex;
    grid-row: 4;
  }
  .workspace[data-pane="attrs"] .rail,
  .workspace[data-pane="attrs"] .canvas-head,
  .workspace[data-pane="attrs"] .stage,
  .workspace[data-pane="attrs"] .composer-input,
  .workspace[data-pane="attrs"] .area-chips,
  .workspace[data-pane="attrs"] .composer-left {
    display: none;
  }
  .workspace[data-pane="attrs"] .canvas {
    grid-row: 3;
  }
  .workspace[data-pane="attrs"] .inspector {
    display: flex;
  }
  /* While typing, the keyboard needs the room: the tab bar goes, and with the attributes so does the Generate row. */
  .workspace:has(:is(textarea, input:not([type="checkbox"], [type="radio"], [type="color"], [type="file"])):focus) .pane-tabs,
  .workspace[data-pane="attrs"]:has(.inspector :is(textarea, input:not([type="checkbox"], [type="radio"], [type="color"])):focus) .canvas {
    display: none;
  }

  /* Versions: a compact strip */
  .rail-head {
    display: none;
  }
  .filmstrip {
    gap: var(--s-1);
    padding: 6px var(--s-2);
  }
  .thumb {
    width: 58px;
    padding: 2px 2px 3px;
    gap: 2px;
  }
  .thumb img {
    width: 50px;
    height: 50px;
  }
  .thumb.pending {
    height: 72px;
  }
  .rail-hint {
    padding-left: var(--s-2);
  }

  /* Canvas */
  .canvas-head {
    padding: 0 var(--s-1) 0 var(--s-3);
  }
  .stage {
    flex: 1;
    height: auto;
    min-height: 0;
    touch-action: none;
  }
  .stage-badge {
    top: var(--s-2);
    left: var(--s-2);
  }
  .zoom-bar {
    right: var(--s-2);
    bottom: var(--s-2);
  }
  .mark-hint,
  .overlay-notice {
    max-width: calc(100% - 2 * var(--s-2));
  }
  .dock {
    position: relative;
    padding: var(--s-2);
  }
  .composer {
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
  }
  .composer-input {
    max-height: 96px;
    padding: 10px var(--s-3) 2px;
  }
  .composer-row {
    padding: 2px var(--s-1) var(--s-1);
    row-gap: var(--s-1);
  }
  .workspace[data-pane="attrs"] .composer-row {
    padding: var(--s-1);
  }
  .changes-pop {
    width: calc(100% - 2 * var(--s-2));
  }
  /* The on-image field popover docks along the bottom of the stage instead of floating by its dot. */
  .hs-pop {
    left: var(--s-2) !important;
    right: var(--s-2);
    top: auto !important;
    bottom: var(--s-2);
    width: auto;
    max-height: min(60%, 420px);
  }
  .stage:has(.hs-pop) .zoom-bar {
    display: none;
  }

  /* Inspector: internal scrolling again (the tablet layout scrolls the page), and stacked fields */
  .insp-head {
    padding-left: var(--s-3);
  }
  .editor-scroll,
  .dot-panel {
    overflow-y: auto;
  }
  .section-top {
    top: 0;
  }
  .section-body {
    padding: var(--s-1) var(--s-3) var(--s-3);
  }
  .field {
    display: flex;
    align-items: stretch;
    gap: 3px;
    padding: var(--s-1) 0;
  }
  .field-label {
    display: flex;
  }
  .field-label label {
    padding-top: 0;
  }
  .field-label .field-actions {
    position: static;
    padding-left: 0;
    background: none;
  }
  .skel {
    display: flex;
  }
  .add-attr-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .add-attr-form .btn {
    width: 100%;
  }

  .toasts {
    top: calc(var(--topbar-h) + var(--s-2));
    width: calc(100vw - 2 * var(--s-3));
  }
}

/* Dialogs on phones open as sheets from the bottom edge. */
@media (max-width: 600px) {
  .dialog,
  .dialog-wide {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-bottom: 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  .dialog[open] {
    animation: sheet-in 0.2s var(--ease);
  }
  .dialog-inner {
    max-height: calc(92dvh - 1px); /* the sheet's top border */
  }
  .dialog-head {
    padding-left: var(--s-4);
  }
  .dialog-body {
    padding: var(--s-4);
  }
  .dialog-body-flush {
    padding: 0;
  }
  .dialog-foot {
    padding: var(--s-3) var(--s-4) calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
    border-radius: 0;
  }
  .json-pre {
    min-height: 40dvh;
    max-height: none;
    padding: var(--s-3) var(--s-4);
  }
  .dl-row {
    flex-wrap: wrap;
  }

  .home-head h1 {
    font-size: var(--fs-xl);
  }
  .dropzone {
    min-height: 200px;
  }
  .dz-img {
    min-height: 200px;
  }
  .tpl-attrs {
    display: none;
  }
  .project-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-2);
  }
  .project-text {
    padding: var(--s-2) 10px 10px;
  }
}
@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

/* Touch screens: controls grow to finger size, hover-only actions are always shown, and text fields use 16px text so
   the browser doesn't zoom the page when one is focused. */
@media (pointer: coarse) {
  :root {
    --h-xs: 28px;
    --h-sm: 36px;
    --h-md: 40px;
    --h-lg: 44px;
  }
  .seg-btn {
    height: 32px;
  }
  .zoom-btn,
  .zoom-level {
    height: 36px;
  }
  .zoom-btn {
    width: 36px;
  }
  .add-btn {
    height: 32px;
  }
  .ri-details-btn {
    height: 30px;
  }
  .refine-field .btn {
    height: 32px;
  }
  .compare-pick select {
    height: 34px;
    font-size: var(--fs-sm);
  }
  .suggest,
  .tag {
    height: 30px;
  }
  .tag-x {
    width: 24px;
    height: 24px;
  }
  .area-chip {
    height: 34px;
  }
  .area-chip-attach,
  .area-chip-thumb {
    width: 28px;
    height: 28px;
  }
  .area-chip-unattach {
    width: 18px;
    height: 18px;
  }
  .switch {
    width: 40px;
    height: 24px;
    margin: 6px 0;
  }
  .switch::after {
    width: 20px;
    height: 20px;
  }
  .switch[aria-checked="true"]::after {
    transform: translateX(16px);
  }
  .hs-dot {
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
  }
  .area-handle {
    right: -9px;
    bottom: -9px;
    width: 18px;
    height: 18px;
  }
  .area-x {
    top: -13px;
    right: -13px;
    width: 26px;
    height: 26px;
  }
  /* Invisible margins so small targets on the image are easy to hit */
  .hs-dot::before,
  .area-handle::before,
  .area-x::before {
    content: "";
    position: absolute;
    inset: -8px;
  }
  .search-kbd,
  .btn-kbd {
    display: none !important;
  }
  .list-item > .mini-btn,
  .project-delete {
    opacity: 1;
  }
  .menu-item {
    font-size: var(--fs-lg);
  }
  /* Larger action buttons need more of the label column they float over */
  @container attrs (min-width: 340px) {
    .field-label .field-actions {
      left: calc(var(--label-w) - 68px);
    }
  }
}
@media (pointer: coarse) and (max-width: 720px) {
  .input,
  .text-input,
  .composer-input,
  .search-field input,
  .refine-field input,
  .tag-input input,
  .crumb-name,
  .select-wrap select,
  .compare-pick select {
    font-size: 16px;
  }
}
