/* ============================================================
   Design tokens
   ============================================================ */
:root {
  color-scheme: dark;

  --bg: #1b1a18;
  --surface-1: #232220;
  --surface-2: #2a2825;
  --surface-3: #34322e;
  --surface-4: #403d38;
  --surface-sunken: #191816;

  --line: #35332f;
  --line-soft: #2c2a27;
  --line-strong: #48443e;

  --text: #f4f2ee;
  --text-2: #b0aaa0;
  --text-3: #857f76;

  --accent: #8579d8;
  --accent-soft: rgba(133, 121, 216, .15);
  --accent-line: rgba(133, 121, 216, .42);
  --accent-text: #b3a9ec;
  --accent-contrast: #ffffff;

  /* Warm accent for the main action: same colour family as the background,
     so it reads as important without fighting it. */
  --cta: #c2683f;
  --cta-hover: #d0774d;
  --cta-text: #ffffff;

  --ok: #5fd398;
  --warn: #ffc36b;
  --danger: #ff8a9b;
  --danger-soft: rgba(255, 90, 115, .13);
  --danger-line: rgba(255, 120, 140, .26);

  --checker-a: #201f1d;
  --checker-b: #232220;
  --scrim: rgba(12, 11, 10, .74);
  --overlay: rgba(10, 9, 8, .82);
  --bar: rgba(35, 34, 32, .93);

  --shadow-card: 0 18px 50px rgba(0, 0, 0, .3);
  --shadow-pop: 0 30px 90px rgba(0, 0, 0, .55);
  --ring: 0 0 0 3px rgba(133, 121, 216, .34);

  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;

  --h-sm: 34px;
  --h-md: 40px;
  --h-lg: 48px;

  --ease: 140ms cubic-bezier(.2, .7, .3, 1);

  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
}

/* Light palette: applied explicitly, or by system preference in auto mode. */
:root[data-theme="light"],
:root[data-theme="auto"].is-light {
  color-scheme: light;

  --bg: #faf9f7;
  --surface-1: #ffffff;
  --surface-2: #f5f3ef;
  --surface-3: #edeae4;
  --surface-4: #e0dcd4;
  --surface-sunken: #f6f4f1;

  --line: #e3dfd8;
  --line-soft: #ece9e3;
  --line-strong: #cfcac1;

  --text: #201f1d;
  --text-2: #57534c;
  --text-3: #857f76;

  --accent: #5f51c4;
  --accent-soft: rgba(95, 81, 196, .09);
  --accent-line: rgba(95, 81, 196, .34);
  --accent-text: #4b3fa6;
  --accent-contrast: #ffffff;

  --cta: #b45c30;
  --cta-hover: #c26a3c;
  --cta-text: #ffffff;

  --ok: #1f8f5f;
  --warn: #a2660b;
  --danger: #c2344c;
  --danger-soft: rgba(194, 52, 76, .08);
  --danger-line: rgba(194, 52, 76, .22);

  --checker-a: #eeebe5;
  --checker-b: #f6f4f1;
  --scrim: rgba(250, 249, 247, .74);
  --overlay: rgba(238, 235, 230, .88);
  --bar: rgba(255, 255, 255, .94);

  --shadow-card: 0 10px 30px rgba(60, 50, 35, .07);
  --shadow-pop: 0 24px 70px rgba(60, 50, 35, .22);
  --ring: 0 0 0 3px rgba(95, 81, 196, .24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body.auth-pending > main,
body.auth-locked > main,
body.auth-pending > dialog,
body.auth-locked > dialog {
  visibility: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 15% 18%, rgba(194, 104, 63, .2), transparent 34%),
    radial-gradient(circle at 88% 82%, rgba(133, 121, 216, .14), transparent 31%),
    var(--bg);
}

.auth-card {
  width: min(100%, 470px);
  padding: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 26px;
  background: color-mix(in srgb, var(--surface-1) 94%, transparent);
  box-shadow: var(--shadow-pop);
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 34px;
}

.auth-brand span {
  color: var(--cta-hover);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: .16em;
}

.auth-brand i {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--cta);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--cta) 14%, transparent);
}

.auth-copy h1 {
  margin-top: 7px;
  font-size: clamp(31px, 8vw, 44px);
}

.auth-kicker {
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

#authIntro {
  max-width: 390px;
  margin: 13px 0 25px;
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.55;
}

.auth-field {
  display: grid;
  gap: 8px;
}

.auth-field span {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 650;
}

.auth-field input {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: var(--surface-sunken);
  color: var(--text);
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}

.auth-field input:focus {
  border-color: var(--cta);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cta) 24%, transparent);
}

.auth-field input::placeholder { color: var(--text-3); }

.auth-code {
  font-size: 27px !important;
  font-weight: 760;
  letter-spacing: .22em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.auth-submit {
  width: 100%;
  min-height: 52px;
  margin-top: 12px;
  border: 0;
  border-radius: 13px;
  background: var(--cta);
  color: var(--cta-text);
  font-size: 14px;
  font-weight: 700;
}

.auth-submit:hover:not(:disabled) { background: var(--cta-hover); }

.auth-sent {
  margin: 0 0 18px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.45;
}

.auth-sent strong {
  color: var(--text);
  font-weight: 650;
  overflow-wrap: anywhere;
}

.auth-secondary-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.auth-secondary-actions button {
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
}

.auth-secondary-actions button:hover:not(:disabled) { color: var(--text); }
.auth-secondary-actions button:disabled { color: var(--text-3); }

.auth-status {
  min-height: 21px;
  margin: 17px 0 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.45;
}

.auth-status.error { color: var(--danger); }

.auth-security {
  margin: 12px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.5;
}

.auth-userbar {
  display: inline-flex;
  align-items: center;
  max-width: 310px;
  min-height: 38px;
  padding: 3px 4px 3px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.auth-userbar span {
  min-width: 0;
  overflow: hidden;
  color: var(--text-2);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-userbar button {
  min-height: 30px;
  margin-left: 8px;
  padding-inline: 9px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 11px;
}

@media (max-width: 540px) {
  .auth-gate { padding: 12px; }
  .auth-card { padding: 24px 20px; border-radius: 21px; }
  .auth-secondary-actions { align-items: flex-start; flex-direction: column; gap: 2px; }
  .auth-userbar { max-width: 100%; }
}

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

::selection { background: var(--accent-soft); }

/* ============================================================
   Typography
   ============================================================ */
h1 {
  margin: 0;
  font-size: clamp(26px, 3.4vw, 44px);
  font-weight: 700;
  line-height: 1.04;
  letter-spacing: -.035em;
}

h2 { font-weight: 650; letter-spacing: -.01em; }
h3 { font-weight: 650; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.subtitle {
  max-width: 720px;
  margin: 12px 0 0;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.55;
}

.ui-muted { color: var(--text-3); font-size: 12px; }

.helper {
  display: block;
  margin-top: 8px;
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.45;
}

/* ============================================================
   Shell & header
   ============================================================ */
.shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 40px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

/* compact title once the editor is open — the canvas needs the room */
.single-shell.editor-mode .header h1,
.pdf-shell.editor-mode .pdf-header h1 {
  font-size: 21px;
  letter-spacing: -.02em;
}

.workflow-switch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.workflow-switch-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 13px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: color var(--ease), background var(--ease);
}

a.workflow-switch-item:hover { color: var(--text); background: var(--surface-3); }

.workflow-switch-item.active {
  color: var(--text);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

.page-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; white-space: nowrap; }

/* ============================================================
   Surfaces
   ============================================================ */
.panel,
.canvas-card,
.result-card,
.single-upload-card {
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface-1);
  box-shadow: var(--shadow-card);
}

.canvas-card, .result-card { overflow: hidden; }

.canvas-header {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, .015);
}

.canvas-header strong { font-size: 14px; font-weight: 650; }

.canvas-header span {
  max-width: 420px;
  color: var(--text-3);
  font-size: 12px;
  text-align: right;
}

/* ============================================================
   Buttons
   ============================================================ */
button, .download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--h-md);
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  transition: background var(--ease), border-color var(--ease), color var(--ease), box-shadow var(--ease), opacity var(--ease);
}

button:disabled, .download:disabled {
  opacity: .42;
  cursor: not-allowed;
  box-shadow: none;
}

button:focus-visible,
.download:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.primary {
  width: 100%;
  margin-top: 12px;
  min-height: var(--h-lg);
  background: var(--cta);
  border-color: transparent;
  color: var(--cta-text);
  font-weight: 650;
}

.primary:hover:not(:disabled) { background: var(--cta-hover); }
.primary:active:not(:disabled) { background: var(--cta); filter: brightness(.94); }

.secondary {
  border-color: var(--line-strong);
  background: var(--surface-3);
  color: var(--text);
}

.secondary:hover:not(:disabled) { background: var(--surface-4); border-color: var(--line-strong); }

.secondary.active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--text);
}

.danger, .danger-subtle {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.danger:hover:not(:disabled), .danger-subtle:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft);
  filter: brightness(1.03);
}

.download {
  min-height: var(--h-sm);
  padding: 0 13px;
  border-color: rgba(95, 211, 152, .3);
  background: rgba(95, 211, 152, .14);
  color: var(--ok);
  font-size: 12px;
}

.download:hover { background: rgba(95, 211, 152, .22); }

.icon-button, .preview-dialog-close {
  width: 38px;
  min-height: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  font-size: 21px;
  font-weight: 400;
}

.icon-button:hover, .preview-dialog-close:hover { background: var(--surface-4); }

.full-button { width: 100%; }

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--h-md);
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-3);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}

.file-button:hover { background: var(--surface-4); }
.file-button input { display: none; }

.compact-primary { margin-top: 0; min-height: var(--h-md); padding-inline: 10px; }

/* Button rows */
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.button-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.button-row button { min-width: 0; padding-inline: 8px; }

.toolbar-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 0;
}

.simple-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.toolbar-row button { min-height: var(--h-sm); padding-inline: 6px; font-size: 12px; }

.area-actions { margin-top: 10px; }
.template-io { margin-top: 8px; }

/* ============================================================
   Segmented controls (mode / surface / presets / auto-manual)
   ============================================================ */
.mode-buttons,
.surface-quick,
.cylinder-preset-row,
.print-profile-quick,
.pdf-placement-choice {
  display: grid;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.mode-buttons,
.surface-quick,
.cylinder-preset-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.print-profile-quick,
.pdf-placement-choice { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.surface-quick, .cylinder-preset-row, .print-profile-quick { margin-bottom: 12px; }

.mode-button,
.surface-button,
.cylinder-preset,
.pdf-placement-choice button {
  min-width: 0;
  min-height: 38px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}

.mode-button:hover,
.surface-button:hover,
.cylinder-preset:hover,
.pdf-placement-choice button:hover { background: var(--surface-3); color: var(--text); }

.mode-button.active,
.surface-button.active,
.cylinder-preset.active,
.pdf-placement-choice button.active,
.pdf-placement-choice .secondary.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

.mode-button strong { display: block; }
.mode-button strong { font-size: 13px; font-weight: 650; }

.mode-button span { display: none; }

.mode-hint {
  min-height: 34px;
  margin: 9px 2px 0;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.45;
}

/* ============================================================
   Form controls
   ============================================================ */
.upload, .select-field, .text-field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.upload small { color: var(--text-3); font-weight: 500; line-height: 1.35; }
.optional { margin-top: 2px; }
.compact-field { margin-bottom: 9px; }
.compact-upload { margin-bottom: 0; }

select,
.text-field input,
.text-field textarea {
  width: 100%;
  min-height: var(--h-md);
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  outline: none;
  background: var(--surface-sunken);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: border-color var(--ease), box-shadow var(--ease);
}

select {
  appearance: none;
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) calc(50% + 1px), calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

select:hover, .text-field input:hover { border-color: var(--line-strong); }

select:focus,
.text-field input:focus,
.text-field textarea:focus,
.upload input:focus {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.upload input {
  width: 100%;
  padding: 10px 11px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}

.upload input:hover { border-color: var(--accent-line); background: var(--accent-soft); }

.upload input::file-selector-button {
  margin-right: 10px;
  padding: 7px 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.upload input:hover::file-selector-button { background: var(--surface-4); }

/* Sliders */
.field { margin: 14px 0; }
.compact-slider { margin: 11px 0; }

.field-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.compact-slider .field-title { font-size: 12px; }

output { color: var(--accent-text); font-variant-numeric: tabular-nums; font-weight: 650; }

input[type="range"] {
  width: 100%;
  height: 18px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-4);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  transition: box-shadow var(--ease);
}

input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 0 5px var(--accent-soft); }

input[type="range"]::-moz-range-track { height: 4px; border-radius: 999px; background: var(--surface-4); }
input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; border: 0; border-radius: 50%; background: var(--accent); }

/* Toggles */
.toggle-list { display: grid; gap: 8px; margin: 14px 0; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 32px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
}

.toggle-row:hover { color: var(--text); }
.toggle-row input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.compact-toggle { margin: 8px 0 10px; }

/* Color picker */
.single-color-field, .pdf-color-field {
  display: grid;
  gap: 7px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.single-color-field input, .pdf-color-field input {
  width: 100%;
  height: var(--h-md);
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  cursor: pointer;
}

/* ============================================================
   Status
   ============================================================ */
.status {
  min-height: 20px;
  margin: 10px 2px 0;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.status.error { color: var(--danger); }
.status.success { color: var(--ok); }

/* ============================================================
   Single-product layout
   ============================================================ */
.grid {
  display: grid;
  grid-template-columns: 344px minmax(0, 1fr);
  gap: 18px;
}

.controls {
  padding: 0;
  align-self: start;
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.simple-controls { padding: 0; }

/* the scrolling part of the sidebar */
.simple-section,
.advanced-group { flex: 0 0 auto; }

.controls > .simple-section {
  padding: 16px 16px 16px;
  margin: 0;
  border-bottom: 1px solid var(--line-soft);
}

.controls > .advanced-group {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-4) transparent;
}

.controls > .advanced-group::-webkit-scrollbar { width: 8px; }
.controls > .advanced-group::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 999px; }

.simple-section h2, .advanced-block h3 {
  margin: 0 0 11px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.control-group { border: 0; padding: 0; margin: 0; }
.control-group summary { margin: 0 0 12px; color: var(--text); font-size: 13px; font-weight: 650; cursor: pointer; user-select: none; }
.control-group:not([open]) summary { margin-bottom: 0; }

.advanced-group > summary {
  position: relative;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 40px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  list-style: none;
}

.advanced-group > summary:hover { background: var(--surface-3); }
.advanced-group > summary::-webkit-details-marker { display: none; }

.advanced-group > summary::after {
  content: "+";
  position: absolute;
  right: 15px;
  color: var(--accent-text);
  font-size: 17px;
}

.advanced-group[open] > summary { margin-bottom: 13px; }
.advanced-group[open] > summary::after { content: "−"; }

.advanced-block {
  margin: 0 0 14px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line-soft);
}

.advanced-block:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }

.advanced-block:first-of-type {
  padding: 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}

.single-layer-assets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

.single-layer-assets button {
  min-height: 42px;
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.single-layer-assets button:hover { background: var(--accent-soft); color: var(--text); filter: brightness(1.05); }

/* sticky CTA — always reachable, never buried under the settings scroll */
.main-generate {
  flex: 0 0 auto;
  width: auto;
  min-height: 60px;
  margin: 0;
  padding: 0 16px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--cta);
  color: var(--cta-text);
  font-size: 14px;
  box-shadow: none;
}

.main-generate:hover:not(:disabled) { background: var(--cta-hover); }

.cylinder-quick {
  margin: -2px 0 12px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.cylinder-tune summary { cursor: pointer; color: var(--accent-text); font-size: 12px; font-weight: 600; }

.editor-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.editor-zoom > span { color: var(--text-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.editor-zoom button { min-height: 32px; padding-inline: 10px; font-size: 12px; }
.editor-zoom input[type="range"] { flex: 1 1 120px; min-width: 100px; }
.editor-zoom output { min-width: 48px; text-align: right; font-size: 12px; }

/* ============================================================
   Workspace / canvas
   ============================================================ */
.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  min-width: 0;
}

.canvas-wrap, .result-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 600px;
  padding: 16px;
  overflow: auto;
  background-color: var(--checker-b);
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  scrollbar-width: thin;
}

.canvas-wrap::-webkit-scrollbar, .result-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.canvas-wrap::-webkit-scrollbar-thumb, .result-wrap::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 999px; }

canvas { display: block; max-width: 100%; max-height: 76vh; touch-action: none; }
#editorCanvas { display: block; max-width: none; max-height: none; cursor: crosshair; }

.result-wrap img { display: none; width: 100%; height: auto; max-height: 76vh; object-fit: contain; }
.result-wrap img.visible { display: block; cursor: zoom-in; }

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

.result-head-actions { display: flex; align-items: center; gap: 8px; }
.result-head-actions button, .result-head-actions .download { min-height: 34px; padding: 0 12px; font-size: 12px; }

/* Loader */
.preview-loader {
  position: absolute;
  right: 14px;
  bottom: 14px;
  padding: 8px 12px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--bar);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(8px);
}

.result-wrap .preview-loader {
  inset: 0;
  right: 0;
  bottom: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 11px;
  border: 0;
  border-radius: 0;
  background: var(--scrim);
  color: var(--text);
  font-size: 13px;
}

.result-wrap .preview-loader::before {
  content: "";
  width: 32px;
  height: 32px;
  border: 3px solid var(--surface-4);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: preview-spin .8s linear infinite;
}

@keyframes preview-spin { to { transform: rotate(360deg); } }

/* ============================================================
   Start screen
   ============================================================ */
.single-shell.start-mode { width: min(880px, calc(100% - 32px)); }

.single-shell.start-mode .header {
  align-items: center;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.single-shell.start-mode .header h1 { max-width: 700px; font-size: clamp(30px, 4.4vw, 46px); line-height: 1.04; }
.single-shell.start-mode .header-actions { justify-content: center; }
.single-shell.start-mode .workflow-switch { display: none; }

.single-start-subtitle {
  max-width: 560px;
  margin: 12px auto 0;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.55;
}

.single-shell.editor-mode .single-start-subtitle { display: none; }

.single-upload-card { padding: 26px; border-radius: var(--r-xl); }

.start-workflow-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  max-width: 400px;
  margin: 0 auto 22px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.start-workflow-switch a, .start-workflow-switch span {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: color var(--ease), background var(--ease);
}

.start-workflow-switch a:hover { color: var(--text); background: var(--surface-3); }

.start-workflow-switch .active {
  color: var(--text);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

.start-card-head { margin-bottom: 20px; text-align: center; }
.start-card-head h2 { margin: 7px 0 0; font-size: 21px; }

.start-kicker {
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.start-upload {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  transition: border-color var(--ease), background var(--ease);
}

.start-upload:hover { border-color: var(--line-strong); }
.start-upload > span { display: flex; align-items: center; gap: 9px; color: var(--text); font-size: 13px; }

.start-upload > span b {
  display: inline-grid;
  place-items: center;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 700;
}

.single-upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.single-start-button { grid-column: 1 / -1; min-height: 54px; margin-top: 2px; }

.single-global-status { max-width: 880px; margin: 10px auto 14px; text-align: center; }
.single-shell.editor-mode .single-global-status { max-width: none; margin: 10px 2px 14px; text-align: left; }

/* ============================================================
   Dialogs
   ============================================================ */
.single-dialog, .single-preview-dialog {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

.single-dialog::backdrop, .single-preview-dialog::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(10px);
}

.single-dialog { width: min(560px, calc(100vw - 28px)); }

.single-dialog-card {
  padding: 22px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: var(--surface-1);
  box-shadow: var(--shadow-pop);
}

.single-dialog-head, .single-dialog-actions, .single-text-options { display: flex; align-items: center; gap: 10px; }
.single-dialog-head { justify-content: space-between; margin-bottom: 16px; }
.single-dialog-head h2 { margin: 0; font-size: 19px; }
.single-dialog-actions { justify-content: flex-end; margin-top: 18px; }
.single-dialog-actions .primary { width: auto; margin: 0; min-height: var(--h-md); }

.single-dialog-card textarea {
  min-height: 100px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

.single-text-options { align-items: flex-end; }
.single-text-options > * { flex: 1; margin-bottom: 0; }

.single-preview-dialog { width: min(96vw, 1800px); height: min(94vh, 1200px); overflow: visible; }
.single-preview-dialog[open] { display: grid; place-items: center; }

.single-preview-dialog img {
  display: block;
  max-width: 100%;
  max-height: 94vh;
  object-fit: contain;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
}

.preview-dialog-close { position: fixed; z-index: 2; top: 20px; right: 20px; width: 44px; height: 44px; min-height: 44px; font-size: 26px; }

/* ============================================================
   Utilities
   ============================================================ */
.vibe-hidden { display: none !important; }
.empty-state.hidden, .hidden { display: none; }
.preview-loader.hidden, .result-wrap .preview-loader.hidden { display: none; }

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

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1180px) {
  .grid { grid-template-columns: 316px minmax(0, 1fr); }
}

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .canvas-wrap, .result-wrap { min-height: 460px; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 1500px); padding-top: 18px; }
  .header { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .grid { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; overflow: visible; }
  .controls > .advanced-group { overflow: visible; max-height: none; }
  .main-generate { position: sticky; bottom: 0; z-index: 5; }
  .canvas-wrap, .result-wrap { min-height: 340px; padding: 8px; }
  .canvas-header { align-items: flex-start; flex-direction: column; }
  .canvas-header span { text-align: left; }
}

@media (max-width: 680px) {
  .single-upload-grid { grid-template-columns: 1fr; }
  .workflow-switch { width: 100%; }
  .workflow-switch-item { flex: 1; padding-inline: 8px; }
}

@media (max-width: 600px) {
  .single-text-options { align-items: stretch; flex-direction: column; }
  .single-text-options > * { width: 100%; }
  .single-layer-assets { grid-template-columns: 1fr; }
}

/* ============================================================
   Icons
   ============================================================ */
.ico {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.ico-lg { width: 17px; height: 17px; }
.icon-only { padding-inline: 0; }

/* ============================================================
   Theme switch
   ============================================================ */
.theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
}

.theme-switch button {
  width: 34px;
  min-height: 30px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-3);
}

.theme-switch button:hover { background: var(--surface-3); color: var(--text); }

.theme-switch button.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

/* ============================================================
   Bend controls
   ============================================================ */
.bend-block { display: grid; gap: 10px; }

.bend-actions {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.bend-actions button { min-height: 34px; padding-inline: 12px; font-size: 12px; }

.expert-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
}

.expert-toggle input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.expert-toggle:hover { color: var(--text-2); }
