@font-face {
  font-family: 'Innovator Grotesk';
  src: url('fonts/InnovatorGrotesk-Regular.otf') format('opentype');
  font-weight: 400;
}

@font-face {
  font-family: 'Innovator Grotesk';
  src: url('fonts/InnovatorGrotesk-Medium.otf') format('opentype');
  font-weight: 500;
}

@font-face {
  font-family: 'Innovator Grotesk';
  src: url('fonts/InnovatorGrotesk-Bold.otf') format('opentype');
  font-weight: 700;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #EDEDED;
  --surface: #F9F9F9;
  --bg-panel: #FFFFFF;
  --border: #dedede;
  --border-active: #969696;
  --text: #2B2B2B;
  --text-dim: #71717a;

  --slider-fill: var(--border);

  /* Accent = high-contrast "selected" / "active" foreground.
     On a light theme this is the dark colour; foreground text on accent
     is white. Used by primary buttons, active segmented buttons,
     checked toggles, and slider fills. */
  --accent: #2B2B2B;
  --accent-fg: #FFFFFF;
  --accent-hover: #444444;

  --ring: rgba(43, 43, 43, 0.15);
  --input-bg: #e3e3e3;
  --hover-bg: #ececec;
  --font: 'Innovator Grotesk', system-ui, sans-serif;
  --innovator: 'Innovator Grotesk', sans-serif;
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

/* ── Layout ───────────────────────────────────────────────── */
#app {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ── Canvas Viewport ──────────────────────────────────────── */
#canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  /* Reserve space on the right for the floating panel (320px panel
     + 24px gutter on each side + small buffer = 380px) so the canvas
     never extends underneath the GUI on wide aspect ratios. */
  padding-right: 380px;
}

#artboard {
  position: relative;
  /* width/height and --scale set dynamically by sketch.js */
  /* canvas is placed inside this wrapper */
  box-shadow: 0 0 0 1px var(--border);
  overflow: hidden;
  /* prevents canvas bleeding */
}

#p5-target canvas {
  display: block;
}

/* ── Overlays ─────────────────────────────────────────────── */
#overlays {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.overlay-layer {
  position: absolute;
}

/* Stacking order inside #overlays:
   slides (image) sit BEHIND the headline + fill-box and the footer. */
#overlay-image     { z-index: 1; }
#overlay-headline  { z-index: 2; }
#overlay-footer    { z-index: 3; }

/* Headline Overlay */
#overlay-headline {
  width: 100%;
  top: calc(206.36px * var(--scale));
  /* default; overridden by JS */
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding-left: 0;
  /* overridden by JS */
  padding-right: 0;
  pointer-events: auto;
}

.headline-text {
  font-family: var(--innovator);
  font-weight: 400;
  font-size: calc(120px * var(--scale));
  line-height: 1.1;
  letter-spacing: calc(-4.8px * var(--scale));
  color: #fff;
  /* overridden by JS */
  white-space: pre-wrap;
  transition: color 0.2s;
  cursor: text;
  outline: none;
}

.headline-text:focus {
  /* subtle hint while editing */
  box-shadow: inset 0 -2px 0 0 currentColor;
}

/* Highlighted words — colour set via inline style="color:..." */
.headline-hl {
  /* color is set inline by JS; no background, no padding */
}

/* Image Placeholder Overlay */
#overlay-image {
  left: 50%;
  transform: translateX(-50%);
  top: calc(559.2px * var(--scale));
  width: calc(1662.28px * var(--scale));
  height: calc(954.46px * var(--scale));
  background: #171717;
  border-radius: calc(12px * var(--scale));
  border: calc(20px * var(--scale)) solid #683a27;
  box-shadow:
    0 calc(8px * var(--scale)) calc(12px * var(--scale)) calc(6px * var(--scale)) rgba(0, 0, 0, 0.3),
    0 calc(4px * var(--scale)) calc(4px * var(--scale)) 0 rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transform-origin: top center;
  pointer-events: auto;
  cursor: pointer;
}

#image-placeholder-inner {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#uploaded-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

#placeholder-icon {
  width: calc(80px * var(--scale));
  height: calc(80px * var(--scale));
  color: rgba(255, 255, 255, 0.1);
}

/* Footer Overlay
   --footer-scale lets specific aspect ratios (e.g. 9:16) inflate the
   footer block while contents keep their relative positioning. */
#overlay-footer {
  width: 100%;
  height: calc(190px * var(--scale) * var(--footer-scale, 1));
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(100px);
  -webkit-backdrop-filter: blur(100px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding:
    calc(48.6px * var(--scale) * var(--footer-scale, 1)) calc(48.6px * var(--scale) * var(--footer-scale, 1)) calc(48.6px * var(--scale) * var(--footer-scale, 1)) calc(45px * var(--scale) * var(--footer-scale, 1));
  box-shadow:
    0 calc(8px * var(--scale)) calc(16.8px * var(--scale)) 0 rgba(0, 0, 0, 0.29),
    0 calc(7.2px * var(--scale)) calc(10.8px * var(--scale)) 0 rgba(0, 0, 0, 0.15),
    0 calc(3.6px * var(--scale)) calc(3.6px * var(--scale)) 0 rgba(0, 0, 0, 0.3),
    inset 0 calc(4px * var(--scale)) calc(4px * var(--scale)) 0 rgba(255, 255, 255, 0.1);
}

#footer-byline {
  font-family: var(--innovator);
  font-weight: 400;
  font-size: calc(54.517px * var(--scale) * var(--footer-text-scale, 1));
  color: #fff;
  /* overridden by JS applyTextAdaptation() */
  line-height: 1.1;
  letter-spacing: calc(-1.6355px * var(--scale) * var(--footer-text-scale, 1));
  white-space: nowrap;
  transition: color 0.2s;
}

#overlay-footer .pai-logo {
  height: calc(71.51px * var(--scale) * var(--footer-text-scale, 1));
}

.footer-logo-wrap {
  display: flex;
  align-items: center;
}

.pai-logo {
  height: calc(71.51px * var(--scale));
  width: auto;
  display: block;
  object-fit: contain;
  /* Keeps logo readable on any background */
  mix-blend-mode: normal;
}

/* ── Floating Panel ───────────────────────────────────────── */
#panel {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 320px;
  max-height: calc(100vh - 48px);
  background: var(--bg-panel);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 100;
  font-family: var(--font);
  box-shadow: 4px 0px 16px rgba(0, 0, 0, 0.1);
  user-select: none;
}

/* Canvas area should fill full width when panel floats above it */
#app {
  position: relative;
}

#panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: grab;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.02), transparent);
}

#panel-header:active {
  cursor: grabbing;
}

#panel-header::before {
  content: '';
  display: block;
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
}

#panel-header {
  position: relative;
  padding-top: 18px;
}

#panel-header h1 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

#panel-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
}

#panel-scroll::-webkit-scrollbar {
  width: 4px;
}

#panel-scroll::-webkit-scrollbar-track {
  background: transparent;
}

#panel-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── Sections ─────────────────────────────────────────────── */
.section {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.section:last-child {
  border-bottom: none;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section.collapsible .section-header {
  cursor: pointer;
  user-select: none;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.section-label.sub {
  margin-bottom: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.section-content {
  display: flex;
  flex-direction: column;
}

.section.collapsed .section-content {
  display: none;
}


/* ── Composition Cards ────────────────────────────────────── */
.comp-cards {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.comp-card {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-dim);
}

.comp-card:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

.comp-card.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--hover-bg);
}

.comp-card svg {
  width: 40px;
  height: 40px;
  fill: currentColor;
}

.comp-card span {
  font-size: 12px;
  font-weight: 500;
}

/* Image composition — preset picker */
.img-preset-picker {
  display: flex;
  gap: 8px;
  flex: 1;
}

.img-preset-btn {
  flex: 1;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: none;
  transition: border-color 0.15s;
  aspect-ratio: 16 / 9;
}

.img-preset-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.img-preset-btn:hover {
  border-color: var(--text-dim);
}

.img-preset-btn.active {
  border-color: var(--accent);
}

/* ── Grouping ─────────────────────────────────────────────── */
.ctrl-group {
  display: none;
}

.ctrl-group.active {
  display: block;
}

/* ── Controls ─────────────────────────────────────────────── */
.control-row {
  margin-bottom: 3px;
}

/* Action button used inside control rows (e.g. "New Seed") */
.ctrl-btn {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ctrl-btn:hover {
  background: var(--hover-bg);
  border-color: var(--text-dim);
}

.control-row label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.control-row .val {
  color: var(--text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ── Slider Row (DialKit full-row fill) ──────────────────── */
.slider-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 36px;
  background: var(--surface);
  border-radius: 6px;
  overflow: hidden;
  cursor: ew-resize;
  margin-bottom: 3px;
  background: #fff;
}

/* Fill bar — grows from left based on --fill custom property */
.slider-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: var(--fill, 0%);
  height: 100%;
  background: var(--slider-fill);
  border-radius: 6px 0 0 6px;
  pointer-events: none;
  transition: width 0.05s linear;
}

.slider-row .ctrl-label {
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  position: relative;
  z-index: 1;
  pointer-events: none;
  user-select: none;
}

.slider-row .val {
  font-size: 12px;
  color: var(--text-dim);
  position: relative;
  z-index: 1;
  pointer-events: none;
  user-select: none;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}

.slider-row input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: ew-resize;
  z-index: 2;
  margin: 0;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}

/* Fallback for any stray range inputs NOT inside .slider-row (e.g. stop sliders in modals) */
input[type="range"]:not(.slider-row input) {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  width: 100%;
}

/* Select & Number */
select,
input[type="number"],
.text-input {
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus,
input[type="number"]:focus,
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--ring);
}

/* Multi-line textarea variant */
.textarea-input {
  min-height: 70px;
  resize: vertical;
  line-height: 1.5;
}

/* Color Picker */
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
}

.color-label {
  margin-bottom: 0 !important;
}

input[type=color] {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
}

input[type=color]::-webkit-color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

/* Toggle */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--text-dim);
}

.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle.small-tog {
  width: 28px;
  height: 16px;
  margin: 0;
}

.toggle.small-tog .toggle-thumb {
  width: 12px;
  height: 12px;
}

.toggle.small-tog input:checked~.toggle-thumb {
  transform: translateX(12px);
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--border);
  transition: .2s;
  border-radius: 20px;
}

.toggle-thumb {
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text);
  transition: .2s;
  border-radius: 50%;
}

.toggle input:checked+.toggle-track {
  background-color: var(--accent);
}

.toggle input:checked+.toggle-track+.toggle-thumb {
  background-color: var(--accent-fg);
}

.toggle input:checked~.toggle-thumb {
  transform: translateX(16px);
}

/* ── Footer ───────────────────────────────────────────────── */
#panel-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  flex: 1;
}

.btn:hover {
  background: var(--hover-bg);
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.small {
  padding: 4px 8px;
  font-size: 12px;
  flex: none;
}

/* ── Segmented Control ────────────────────────────────────── */
.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  background: var(--input-bg);
}

/* Locked variant — controls forced into a single value by another
   constraint (e.g. palette mode is locked to "sync" when Fill Behind
   Text is off). Visually dimmed, all clicks ignored. */
.segmented.locked,
.toggle-row.locked {
  opacity: 0.45;
  pointer-events: none;
  cursor: not-allowed;
}

/* Per-button disabled state inside an otherwise interactive segmented.
   Used for the Bottom baseline option when Fill Behind Text is off. */
.segmented .seg-btn.disabled {
  opacity: 0.35;
  pointer-events: none;
  cursor: not-allowed;
}

.seg-btn {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 5px 0;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.seg-btn+.seg-btn {
  border-left: 1px solid var(--border);
}

.seg-btn:hover:not(.active) {
  color: var(--text);
  background: var(--hover-bg);
}

.seg-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.seg-btn svg {
  display: block;
  margin: 0 auto;
}

.seg-caption {
  display: block;
  font-size: 11px;
  margin-top: 4px;
  color: inherit;
}

.stroke-sw {
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 3px;
  vertical-align: middle;
}

.stroke-sw.marketing {
  background: #683a27;
}

.stroke-sw.frosty {
  background: linear-gradient(135deg, #dceaff, #a6d0ff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

.segmented.tall .seg-btn {
  padding: 10px 0;
}

/* Grid variant — buttons are independent tiles, useful for 5+ options */
.segmented.grid {
  display: grid;
  gap: 4px;
  background: transparent;
  border: none;
  overflow: visible;
}

.segmented.grid.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.segmented.grid.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.segmented.grid .seg-btn {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 2px;
  background: var(--input-bg);
}

.segmented.grid .seg-btn+.seg-btn {
  border-left: 1px solid var(--border);
}

.segmented.grid .seg-btn.active {
  border-color: var(--accent);
  background: var(--hover-bg);
  color: var(--text);
}

/* ── Palette Swatches ────────────────────────────────────── */
.palette-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.palette-sw {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.palette-sw:hover {
  border-color: var(--text-dim);
}

.palette-sw.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.palette-sw-fill {
  display: block;
  height: 18px;
  border-radius: 3px;
  /* Diagonal hatch pattern indicates "no palette" / custom slot. */
  background: repeating-linear-gradient(45deg, var(--input-bg) 0 4px, var(--surface) 4px 8px);
}

.palette-sw-label {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  font-weight: 500;
}

.palette-sw.active .palette-sw-label {
  color: var(--text);
}

/* ── Anchor Position Grid ────────────────────────────────── */
.anchor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 84px;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--input-bg);
}

.anchor-cell {
  position: relative;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s;
}

.anchor-cell::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 4px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}

.anchor-cell:hover {
  background: var(--hover-bg);
}

.anchor-cell:hover::before {
  background: var(--text);
}

.anchor-cell.active {
  background: var(--hover-bg);
}

.anchor-cell.active::before {
  background: var(--accent);
  transform: translate(-50%, -50%) scale(1.8);
  box-shadow: 0 0 0 2px var(--ring);
}

/* ── Curve Preview ────────────────────────────────────────── */
#curve-preview {
  width: 100%;
  height: 60px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 8px;
}

/* ── Gradient Bar (clean, click-to-recolor stops) ─────────── */
.grad-bar-outer {
  position: relative;
  width: 100%;
  margin: 0;
}

#grad-bar {
  display: block;
  width: 100%;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.grad-markers {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Stops sit INSIDE the bar — small clean dots, evenly aligned by % */
.grad-stop-dot {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
  border: 1.5px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  pointer-events: auto;
  z-index: 3;
  transition: transform 0.12s, box-shadow 0.12s;
}

.grad-stop-dot:hover {
  transform: translate(-50%, -50%) scale(1.2);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 0 3px rgba(255, 255, 255, 0.2);
}

/* Hidden colour input — click the dot to open native picker */
.grad-stop-color-hidden {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  border: none;
  background: transparent;
  padding: 0;
}

/* ── Gradient action buttons (Flip + Shuffle) ─────────────── */
.grad-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin: 0;
}

.grad-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.grad-action-btn:hover {
  background: var(--hover-bg);
  border-color: var(--text-dim);
}

.grad-action-btn.active {
  background: var(--hover-bg);
  border-color: var(--accent);
  color: var(--text);
}

/* Dark variant — used by Save Preset + Shuffle in the Asset Size section
   so they read as primary actions, matching the Export PNG button. */
.grad-action-btn.dark {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.grad-action-btn.dark:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.grad-action-btn svg {
  display: block;
  flex-shrink: 0;
}

/* ── Stop List ────────────────────────────────────────────── */
.grad-stops-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.stop-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.stop-color-input {
  flex-shrink: 0;
  margin: 0;
  width: 28px !important;
  height: 24px !important;
}

.stop-pos-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stop-pos-slider {
  flex: 1;
}

.stop-pos-val {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  min-width: 28px;
}

.stop-delete {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
}

.stop-delete:hover {
  background: rgba(239, 68, 68, 0.1);
}

.stop-delete:disabled {
  color: var(--border);
  cursor: not-allowed;
}

/* ── Palette mode locked / labelled stops ──────────────────── */
.stop-row.stop-locked {
  opacity: 0.42;
  pointer-events: none;
}

.stop-label {
  font-size: 9px;
  color: var(--text-dim);
  min-width: 62px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
}

.stop-lock-icon {
  color: var(--text-dim);
  display: flex;
  align-items: center;
  margin-left: 6px;
  flex-shrink: 0;
}

/* ── Text base control (Dark/Light + opacity) ──────────────── */
.text-base-ctrl {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Gradient Actions Row ─────────────────────────────────── */
.grad-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.subdivide-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.subdivide-input {
  width: 36px !important;
}

.subdivide-input:focus {
  border-color: var(--accent);
}

/* ── Background Preset Swatches ───────────────────────────── */
.bg-swatch-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.bg-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.bg-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--accent);
}

/* ── Background Gradient Preset Buttons ──────────────────── */
/* ── Presets ─────────────────────────────────────────────── */
.preset-save-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.preset-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 6px 5px 10px;
  transition: border-color 0.15s;
  box-shadow: 0 1px 0 1px rgba(0, 0, 0, 0);
}

.preset-chip:hover {
  background: var(--bg-panel);
  box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
}

.preset-name {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-del {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-family: inherit;
}

.preset-del:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.preset-empty {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 10px 0;
}

.bg-grad-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.bg-grad-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  min-width: 52px;
}

.bg-grad-btn:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

.bg-grad-btn.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--hover-bg);
}

.bg-grad-swatch {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 5px;
  flex-shrink: 0;
}

/* ── Image Thumb Pickers ─────────────────────────────────── */
.img-style-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.img-idx-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.img-thumb {
  aspect-ratio: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, transform 0.15s;
}

.img-thumb:hover {
  border-color: var(--text-dim);
}

.img-thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Multi Image Instance ─────────────────────────────────── */
.img-instance {
  flex-shrink: 0;
}

/* ── Shuffle button full width ────────────────────────────── */
#btn-shuffle-imgs {
  width: 100%;
  margin-top: 4px;
}

/* ── Color & Theme Section ───────────────────────────────── */
.color-theme-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* Left column: swatch grid */
.ct-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.ct-swatch-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s;
  flex-shrink: 0;
  outline: none;
}

.ct-swatch-btn:hover {
  transform: scale(1.15);
}

.ct-swatch-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* Right column: mode toggle */
.ct-mode-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.ct-mode-btn {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
  min-width: 54px;
  text-align: center;
}

.ct-mode-btn:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

.ct-mode-btn.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--hover-bg);
}

/* ── Image Preset Picker (Background Presets) ─────────────── */
.img-preset-picker {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.img-preset-btn {
  flex: 1;
  height: 52px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--input-bg);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s;
  padding: 0;
}

.img-preset-btn:hover {
  border-color: var(--text-dim);
}

.img-preset-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.img-preset-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* ── CT Palette Gradient Swatches (Color & Theme section) ─── */
.ct-palette-swatch {
  width: 100%;
  height: 40px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  background: transparent;
  padding: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
  display: block;
}

.ct-palette-swatch:hover {
  border-color: var(--text-dim);
}

.ct-palette-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ── BG Mode groups (solid / gradient visibility) ─────────── */
#bg-solid-group,
#bg-grad-group {
  display: flex;
  flex-direction: column;
}

/* ── Segmented grid (keep square corners in grid mode) ─────── */
.segmented.grid {
  border-radius: 6px;
}

.segmented.grid .seg-btn {
  border-radius: 6px;
}

/* ── Toggle-row label sizing (explicit) ────────────────────── */
.toggle-row label:first-child {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
  margin-bottom: 0;
}

/* ══════════════════════════════════════════════════════════════
   TWEAKPANE v3 — DialKit-style overrides
   (Tweakpane v3 uses tp-fld_* class names, not tp-fldv_*)
   ══════════════════════════════════════════════════════════════ */

/* Force Innovator Grotesk on every Tweakpane element + reset all width/indent */
.tp-dfwv,
.tp-cnt,
.tp-rotv,
.tp-rot,
.tp-fldv,
.tp-fld,
.tp-fldv_t,
.tp-fld_t,
.tp-fldv_c,
.tp-fld_c,
.tp-fldv_b,
.tp-fld_b,
.tp-fldv_m,
.tp-fld_m,
.tp-fldv_i,
.tp-fld_i,
.tp-brkv,
.tp-brk,
.tp-lblv,
.tp-lbl,
.tp-cntv,
.tp-cnt {
  font-family: var(--font) !important;
  font-feature-settings: normal !important;
}

/* Tweakpane indent — kill it (it eats ~16px on the left) */
.tp-fldv_i,
.tp-fld_i {
  display: none !important;
  width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
}

/* Force all Tweakpane content to span full width */
.tp-rotv,
.tp-rot,
.tp-fldv,
.tp-fld,
.tp-fldv_c,
.tp-fld_c {
  width: 100% !important;
  margin: 0 !important;
  --cnt-h-padding: 0 !important;
  --cnt-v-padding: 0 !important;
}

/* Pane outer container — transparent, no shadow/border */
.tp-dfwv,
.tp-cnt {
  width: 100% !important;
  position: static !important;
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
}

/* Root view — transparent */
.tp-rotv,
.tp-rot {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* Root title — hidden (we use our own panel-header) */
.tp-rotv_t,
.tp-rot_t {
  display: none !important;
}

/* Root content wrapper — no extra padding */
.tp-rotv_c,
.tp-rot_c {
  padding: 0 !important;
  background: transparent !important;
}

/* Folder view — module card */
.tp-fldv,
.tp-fld {
  background: var(--surface) !important;
  border-radius: 10px !important;
  margin-bottom: 10px !important;
  padding: 0 14px !important;
  overflow: hidden !important;
}

.tp-fldv:hover,
.tp-fld:hover {
  border-color: var(--border-active) !important;
}

/* First folder gets a slight top margin */
.tp-rotv>.tp-fldv:first-child,
.tp-rot>.tp-fld:first-child {
  margin-top: 10px !important;
}

/* ── Spacing system ─────────────────────────────────────────
   --space-1 = 4px   (hairline)
   --space-2 = 8px   (tight)
   --space-3 = 12px  (default element gap)
   --space-4 = 16px  (sub-section gap)
   --space-5 = 20px  (section padding)
   --space-6 = 24px  (between sections)
*/
:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
}

/* ── Folder header — CORRECT Tweakpane v3 structure ─────────
   <button class="tp-fld_b">              ← clickable button (the "header bar")
     <div class="tp-fld_t">Title Text</div>  ← title TEXT
   </button>
   <div class="tp-fld_m">▶</div>          ← chevron mark
*/

/* The button = the visible header bar, full width, generous height */
.tp-fldv_b,
.tp-fld_b {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  width: 100% !important;
  min-height: 52px !important;
  height: auto !important;
  padding: var(--space-4) 0 !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer !important;
  user-select: none !important;
  text-align: left !important;
  font-family: var(--font) !important;
  position: relative !important;
}

/* The TITLE TEXT — large, bold, pure white, unclipped */
.tp-fldv_t,
.tp-fld_t {
  display: block !important;
  flex: 1 1 auto !important;
  min-width: 0 !important;
  width: auto !important;
  height: auto !important;
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  border: none !important;
  font-family: var(--font) !important;
  font-size: 15px !important;
  letter-spacing: -0.01em !important;
  line-height: 1.2 !important;
  color: var(--text) !important;
  opacity: 1 !important;
  text-transform: none !important;
  text-align: left !important;
  white-space: nowrap !important;
  overflow: visible !important;
  text-overflow: clip !important;
}

/* The chevron MARK — fixed size on the right of the button */
.tp-fldv_m,
.tp-fld_m {
  position: absolute !important;
  right: 0 !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  width: 16px !important;
  height: 16px !important;
  flex-shrink: 0 !important;
  color: var(--text) !important;
  opacity: 0.6 !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: opacity 0.15s, transform 0.2s !important;
}

.tp-fld_b:hover~.tp-fld_m,
.tp-fld_b:hover .tp-fld_m,
.tp-fld:hover .tp-fld_m {
  opacity: 1 !important;
}

/* Folder content area — uses spacing system + subtle divider */
.tp-fldv_c,
.tp-fld_c {
  padding: var(--space-4) 0 var(--space-5) !important;
  background: transparent !important;
  border: none !important;
  border-top: 1px solid var(--border) !important;
}

/* Collapsed folder — fully removes content padding & divider */
.tp-fldv:not(.tp-fldv-expanded) .tp-fldv_c,
.tp-fld:not(.tp-fld-expanded) .tp-fld_c {
  padding: 0 !important;
  border-top: none !important;
}

/* Tweakpane inner blade containers — remove backgrounds */
.tp-brkv,
.tp-brk,
.tp-lblv,
.tp-lbl,
.tp-sldv,
.tp-sld,
.tp-chdv,
.tp-chd {
  background: transparent !important;
}

/* ── Custom content injected via into() ──────────────────────
   HIERARCHY:
   - Section title (folder header)  : 14px / 600 / #fff
   - Sub-section label (.sub)       : 11px / 600 / uppercase / dim
   - Control label                  : 12px / 500 / dim
   - Value text                     : 12px / 400 / text
   SPACING:
   - Element gap inside content     : var(--space-3) = 12px
   - Sub-section margin             : var(--space-4) = 16px
*/
.tp-custom {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: 0;
}

/* Default control row */
.tp-custom .control-row {
  margin-bottom: 0;
}

/* Slider row — uniform height */
.tp-custom .slider-row {
  margin-bottom: 0;
  height: 40px;
}

/* Sub-section label — TIER 2 hierarchy */
.tp-custom .section-label.sub {
  margin-top: var(--space-4);
  margin-bottom: var(--space-1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0.9;
  line-height: 1;
}

.tp-custom .section-label.sub:first-child {
  margin-top: 0;
}

/* Toggle rows — uniform height */
.tp-custom .toggle-row {
  margin-bottom: 0;
  min-height: 32px;
  padding: var(--space-1) 0;
  align-items: center;
}

/* Color rows — uniform height */
.tp-custom .color-row {
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: 8px;
}

/* Segmented controls — uniform height */
.tp-custom .segmented:not(.grid) {
  min-height: 34px;
  border-radius: 8px;
}

.tp-custom .segmented:not(.grid) .seg-btn {
  padding: var(--space-2) 0;
  font-size: 12px;
  font-weight: 500;
}

/* Control labels — TIER 3 hierarchy */
.tp-custom .control-row>label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: var(--space-2);
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.2;
}

/* Slider label & value — TIER 4 (in-control text) */
.tp-custom .slider-row .ctrl-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.tp-custom .slider-row .val {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}

/* ── Theme Circles ─────────────────────────────────────────── */
.theme-circle-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 0 4px;
}

.theme-circle-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--circle-color);
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  flex-shrink: 0;
  outline: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.theme-circle-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.theme-circle-btn.active {
  border-color: var(--text);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

/* ── Section heading row inside Color & Theme — Theme label ── */
.theme-section-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}

/* ══════════════════════════════════════════════════════════════
   GLOBAL HIERARCHY POLISH
   ══════════════════════════════════════════════════════════════ */

/* Panel header — keep clean & minimal */
#panel-header {
  padding: 16px 18px;
}

#panel-header h1 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
}

#panel-header h2 {
  display: none;
  /* redundant subtitle */
}

#panel-footer {
  padding: 14px 18px;
  gap: 10px;
}

#panel-footer .btn {
  height: 36px;
  font-size: 12px;
  font-weight: 500;
}

/* Comp cards — slightly more breathing room */
.tp-custom .comp-cards {
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 14px;
}

.tp-custom .comp-card {
  padding: 14px 6px;
  border-radius: 8px;
}

.tp-custom .comp-card svg {
  width: 32px;
  height: 32px;
}

.tp-custom .comp-card span {
  font-size: 11px;
}

/* Background swatches — even rounded squares */
.tp-custom .bg-swatch {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.tp-custom .bg-swatch-row {
  gap: 8px;
  margin-top: 8px;
}

/* BG gradient buttons — consistent sizing */
.tp-custom .bg-grad-btn {
  padding: 8px;
  border-radius: 8px;
}

/* Gradient bar — taller, more touchable */
.tp-custom #grad-bar {
  height: 32px;
  border-radius: 8px;
}

.tp-custom .grad-bar-outer {
  margin-top: 6px;
  margin-bottom: 4px;
}

/* Curve preview — consistent rounded */
.tp-custom #curve-preview {
  border-radius: 8px;
}

/* Anchor grid — slightly bigger hit area */
.tp-custom .anchor-grid {
  width: 96px;
  border-radius: 8px;
}

/* Action buttons inside controls — taller */
.tp-custom .ctrl-btn {
  height: 36px;
  border-radius: 8px;
}

.tp-custom .btn.small {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
}

/* Text inputs / textareas — taller, comfortable */
.tp-custom select,
.tp-custom input[type="number"],
.tp-custom .text-input {
  height: 36px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.tp-custom .textarea-input {
  height: auto;
  min-height: 80px;
  padding: 10px 12px;
}

/* File input — nicer presentation */
.tp-custom input[type="file"] {
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 0;
}

/* Image preset / thumb pickers — consistent radius */
.tp-custom .img-preset-btn,
.tp-custom .img-thumb {
  border-radius: 8px;
}

/* Presets section — sit comfortably above pane */
.section:first-child {
  padding-top: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.section:first-child .section-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}

.preset-save-row {
  gap: 8px;
}

.preset-save-row .text-input {
  height: 34px;
  font-size: 12px;
}

.preset-save-row .seg-btn {
  height: 34px;
  border-radius: 8px;
}

.preset-chip {
  padding: 7px 8px 7px 12px;
  border-radius: 8px;
}

/* ══════════════════════════════════════════════════════════════
   COLOR & THEME — scoped spacing
   Visual structure (top → bottom):
     [Theme label]                    ─ tier-3 label
     [Warm/Cool circles]              ─ swatch row
     ─────────  16px gap  ─────────
     [Mode segmented]                 ─ Light / Dark
     ─────────  20px gap  ─────────
     [SHAPE GRADIENT label]           ─ tier-2 sub-section
       Mode segmented (Normal/Sym/Sync)
       Flip Bar Gradient toggle
       Gradient bar (interactive)
       Hint line
       Shuffle button
     ─────────  20px gap  ─────────
     [BACKGROUND label]               ─ tier-2 sub-section
       BG Type (Solid/Gradient)
       Color picker / Gradient presets
       Swatches grid
   ══════════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════════════════════════
   ASSET SIZE — scoped spacing
   Order:
     [Aspect Ratio segmented]
     PRESETS sub-label
     [filtered preset list]
     [Save Preset] [Shuffle]
   ══════════════════════════════════════════════════════════════ */

.tp-custom.section-asset-size {
  gap: var(--space-3);
}

/* Aspect Ratio segmented — full-width tier-1 control */
.section-asset-size #ctrl-aspect {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
}

/* Sub-section label uses the same divider treatment as elsewhere */
.section-asset-size .section-label.sub {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1;
}

/* Inner wrapper holding the list + action row */
.section-asset-size .section-presets {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Preset list uses the GUI's spacing tokens & 8px radius for chips */
.section-asset-size .preset-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
}

.section-asset-size .preset-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-2) 0 var(--space-3);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.15s, background 0.15s;
}

.section-asset-size .preset-chip:hover {
  border-color: var(--text-dim);
  background: var(--hover-bg);
}

.section-asset-size .preset-name {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  padding: 0;
  height: 100%;
  letter-spacing: 0;
}

.section-asset-size .preset-del {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.section-asset-size .preset-del:hover {
  background: rgba(239,68,68,0.12);
  color: #ef4444;
}

.section-asset-size .preset-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: var(--space-3);
  text-align: center;
  background: var(--input-bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin: 0;
}

/* Action row: Save Preset + Shuffle, even 2-col split */
.section-asset-size .preset-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin: 0;
}

.tp-custom.section-color-theme {
  gap: var(--space-3);
}

/* "Theme" label above the circles */
.section-color-theme .theme-section-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin: 0 0 var(--space-2);
  letter-spacing: 0;
  line-height: 1;
}

/* Warm / Cool circles row */
.section-color-theme .theme-circle-row {
  display: flex;
  gap: var(--space-3);
  padding: 0;
  margin: 0 0 var(--space-3);
  align-items: center;
  min-height: 32px;
}

.section-color-theme .theme-circle-btn {
  width: 28px;
  height: 28px;
  margin: 0;
}

/* Light / Dark mode row — full width, no label, prominent (top hierarchy) */
.section-color-theme .mode-row-noLabel {
  margin: var(--space-1) 0 var(--space-2);
}

.section-color-theme #ct-mode-col {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
}

.section-color-theme #ct-mode-col .ct-mode-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 10px 0;
}

/* Sub-section labels (Shape Gradient / Background) — clear separators */
.section-color-theme .section-label.sub {
  margin-top: var(--space-5);
  margin-bottom: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1;
}

/* Inside Shape Gradient section: clean ordered stack */
.section-color-theme .control-row {
  margin: 0;
}

/* Stops Mode segmented (Normal | Symmetrical | Sync) — sits above bar */
.section-color-theme #ctrl-palette-mode {
  width: 100%;
  min-height: 34px;
  margin: 0 0 var(--space-3);
}

/* Gradient bar — full-width, clear gap to action row */
.section-color-theme .grad-bar-outer {
  margin: 0 0 var(--space-3);
}

/* Action row (Flip + Shuffle) — even split */
.section-color-theme .grad-action-row {
  margin: 0;
}

/* BG Type segmented (no label) — full width */
.section-color-theme #ctrl-bg-mode {
  margin-top: var(--space-1);
  width: 100%;
  min-height: 38px;
}

.section-color-theme .control-row.no-label {
  display: block;
}

/* ══════════════════════════════════════════════════════════════
   COMPOSITION — scoped spacing
   Visual structure (top → bottom):
     [Rectangle | Circular | Image]      ─ comp cards
     ─── group of type-specific controls
     [CURVE DISTRIBUTION]                ─ tier-2 sub-section
     [8-tile grid]
     [Flip Curve Shape] toggle
     [curve preview canvas]
     [Blur slider]
   ══════════════════════════════════════════════════════════════ */

.tp-custom.section-background {
  gap: var(--space-3);
}

/* Comp cards row — even 3-col grid, consistent height */
.section-background .comp-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
}

.section-background .comp-card {
  padding: var(--space-3) var(--space-1);
  border-radius: 8px;
  gap: var(--space-2);
}

.section-background .comp-card svg {
  width: 28px;
  height: 28px;
}

.section-background .comp-card span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
}

/* Type-group inner spacing */
.section-background .ctrl-group {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
}

.section-background .ctrl-group.active {
  display: flex;
}

/* Anchor grid centered */
.section-background .anchor-grid {
  width: 96px;
  border-radius: 8px;
}

/* Sub-section labels (Text-Aware Positioning, Fine Tune, Curve Distribution) */
.section-background .section-label.sub {
  margin-top: var(--space-4);
  margin-bottom: var(--space-1);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1;
}

/* First sub-label of a group has no top divider */
.section-background .ctrl-group .section-label.sub:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

/* Curve grid (4-col tile picker) — clean even cells */
.section-background #ctrl-curve.segmented.grid {
  gap: var(--space-1);
}

.section-background #ctrl-curve .seg-btn {
  aspect-ratio: 1;
  padding: 0;
  border-radius: 8px;
}

.section-background #ctrl-curve .seg-btn svg {
  width: 70%;
  height: 70%;
}

/* Curve controls wrap — same flex/gap rhythm as type-groups */
.section-background #curve-controls-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
}

.section-background #curve-controls-wrap[style*="display: none"] {
  display: none !important;
}

/* Curve preview canvas — clean, full-width, no label */
.section-background .curve-preview-wrap {
  margin: 0;
}

.section-background #curve-preview {
  width: 100%;
  height: 56px;
  border-radius: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  display: block;
}

/* New Seed button — same height as other action buttons */
.section-background #noise-reseed-row .ctrl-btn {
  height: 36px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
}

/* Image preset picker row — label + picker side by side */
.section-background .img-preset-picker {
  margin: 0;
}

/* Hidden conditional rows — collapse fully (no parent flex gap) */
.section-background .ctrl-group [style*="display: none"],
.section-background #curve-controls-wrap [style*="display: none"] {
  margin: 0 !important;
}

/* ── Translate section ───────────────────────────────────── */
.section-translate {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.section-translate .tp-custom-select.translate-preview-sel {
  width: 100%;
  height: 32px;
  padding: 0 var(--space-2);
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
}

.section-translate .translate-targets {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-2);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.section-translate .translate-target-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}

.section-translate .translate-target-row input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.section-translate .translate-btn {
  height: 36px;
  width: 100%;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  margin-top: var(--space-1);
}

.section-translate .translate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.section-translate .translate-status {
  font-size: 11px;
  color: var(--text-dim);
  min-height: 14px;
  line-height: 1.3;
}

.section-translate .translate-status.error {
  color: #ff8080;
}

/* Image group preset picker — clean spacing */
.section-background #group-img-comp .img-preset-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.section-background #group-img-comp .img-preset-btn {
  aspect-ratio: 16 / 9;
  border-radius: 8px;
}

/* ══════════════════════════════════════════════════════════════
   HEADLINE — scoped spacing
   Sub-sections (top → bottom):
     TEXT       : textarea + highlight words input
     COLOUR     : text base toggle + opacity, highlight colour
     FILL       : fill toggle, fill colour
     TYPOGRAPHY : alignment, font weight, font size, line height
     POSITION   : y position, L/R padding
   ══════════════════════════════════════════════════════════════ */

.tp-custom.section-text-content {
  gap: var(--space-3);
}

/* Sub-section labels with consistent dividers */
.section-text-content .section-label.sub {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1;
}

/* First sub-label of the section: no top divider */
.section-text-content .section-label.sub:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

/* Textarea — comfortable height */
.section-text-content #ctrl-hl-text {
  min-height: 84px;
  padding: var(--space-3);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

/* Highlight Words input */
.section-text-content #ctrl-hl-words {
  height: 36px;
  border-radius: 8px;
}

/* Text Base control (Dark/Light + opacity) inside Colour group */
.section-text-content .text-base-ctrl {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.section-text-content .text-base-ctrl .control-row {
  margin-bottom: 0;
}

.section-text-content .text-base-ctrl>.control-row:first-child {
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: center;
  gap: var(--space-3);
}

.section-text-content .text-base-ctrl>.control-row:first-child>label {
  margin-bottom: 0;
}

.section-text-content .text-base-ctrl #ctrl-hl-text-base {
  width: 100%;
  min-height: 32px;
  border-radius: 8px;
}

/* Colour rows in Headline */
.section-text-content .color-row {
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: 8px;
}

.section-text-content .color-row>label {
  margin-bottom: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

/* Toggle row (Fill Behind Text) — uniform height with neighbors */
.section-text-content .toggle-row {
  margin: 0;
  min-height: 36px;
  padding: var(--space-1) 0;
  align-items: center;
}

.section-text-content .toggle-row label:first-child {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

/* Typography segmented (alignment, font weight) — full width, no label */
.section-text-content #ctrl-hl-align,
.section-text-content #ctrl-hl-font {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
}

.section-text-content .control-row.no-label {
  display: block;
}

.section-text-content .control-row.no-label>label {
  display: none;
}

/* Sliders — uniform 40px height with consistent rhythm */
.section-text-content .slider-row {
  height: 40px;
  margin: 0;
}

/* ══════════════════════════════════════════════════════════════
   IMAGE PLACEHOLDER — scoped spacing
   Sub-sections (top → bottom):
     UPLOAD       : choose-image button
     PRESETS      : style picker, image grid, shuffle
     POSITION     : scale, y offset
     STROKE       : preset segmented, weight, opacity, corner radius
     DISTRIBUTION : multi toggle + (count, mode, spacing)
   ══════════════════════════════════════════════════════════════ */

.tp-custom.section-image {
  gap: var(--space-3);
}

/* Sub-section labels with dividers */
.section-image .section-label.sub {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1;
}

.section-image .section-label.sub:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

/* Custom upload button (replaces ugly default file input) */
.section-image .img-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px dashed var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.section-image .img-upload-btn:hover {
  background: var(--hover-bg);
  border-color: var(--text-dim);
  border-style: solid;
}

/* ── Image presets — overhauled ────────────────────────────
   Layout: compact style tabs (1-5) → larger image gallery (2-col) → shuffle */

/* Style tabs row — compact numbered chips */
.section-image .img-style-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-1);
  margin: var(--space-1) 0 0;
  padding: 4px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.section-image .img-style-tab {
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.section-image .img-style-tab:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.section-image .img-style-tab.active {
  background: var(--accent);
  color: var(--accent-fg);
}

/* Image gallery — large 2-col cards */
.section-image .img-gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin: 0;
}

.section-image .img-gallery-card {
  position: relative;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--input-bg);
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.section-image .img-gallery-card:hover {
  border-color: var(--text-dim);
  transform: translateY(-1px);
}

.section-image .img-gallery-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.section-image .img-gallery-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.section-image .img-gallery-empty {
  grid-column: 1 / -1;
  padding: var(--space-4);
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--input-bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.section-image .control-row>label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: var(--space-2);
}

/* Shuffle button uses .grad-action-btn — no extra rules needed */

/* Sliders — uniform height */
.section-image .slider-row {
  height: 40px;
  margin: 0;
}

/* Stroke preset segmented — full width, taller for swatches */
.section-image #ctrl-img-stroke {
  width: 100%;
  min-height: 48px;
  border-radius: 8px;
}

.section-image #ctrl-img-stroke .seg-btn {
  padding: var(--space-2) 0;
}

/* Multi toggle row */
.section-image .toggle-row {
  margin: 0;
  min-height: 36px;
  padding: var(--space-1) 0;
  align-items: center;
}

/* Multi-image group inner gap */
.section-image #img-multi-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

/* Distribution mode segmented */
.section-image #ctrl-img-dist-mode {
  width: 100%;
  min-height: 38px;
  border-radius: 8px;
}

.section-image .control-row.no-label {
  display: block;
}

/* ══════════════════════════════════════════════════════════════
   FOOTER — controls live inline inside the Text Content (.section-
   headline) folder. Only two ID-scoped rules remain; layout is
   inherited from the .section-text-content .text-base-ctrl rules above.
   ══════════════════════════════════════════════════════════════ */

#ctrl-ft-byline {
  height: 36px;
  border-radius: 8px;
}

.section-text-content #ctrl-ft-text-base {
  width: 100%;
  min-height: 32px;
  border-radius: 8px;
}

.section-color-theme #bg-solid-group,
.section-color-theme #bg-grad-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

/* Background colour picker */
.section-color-theme #bg-solid-group .color-row {
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: 8px;
}

/* BG swatch grid — even cells, fixed columns */
.section-color-theme #bg-swatch-container {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-2);
  margin: 0;
}

.section-color-theme .bg-swatch {
  width: 100%;
  height: 32px;
  border-radius: 8px;
  margin: 0;
}

/* BG gradient presets — even grid */
.section-color-theme #bg-grad-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin: 0;
}

.section-color-theme .bg-grad-btn {
  padding: var(--space-2);
  border-radius: 8px;
  min-width: 0;
}

.section-color-theme .bg-grad-swatch {
  width: 100%;
  aspect-ratio: 1;
  height: auto;
}

/* Flip BG gradient toggle — sits under the gradient grid */
.section-color-theme #bg-grad-flip-row {
  margin-top: var(--space-2);
}

/* ── Highlight selection popup ──────────────────────────────
   Floats above any text selection inside the live headline. */
.highlight-popup {
  position: absolute;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--text);              /* high-contrast on dark canvas bg */
  color: var(--accent-fg);
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4),
              0 2px 6px rgba(0,0,0,0.3);
  user-select: none;
  white-space: nowrap;
  transition: transform 0.1s;
}
.highlight-popup:hover {
  transform: translateY(-1px);
}
.highlight-popup:active {
  transform: translateY(0);
}
.highlight-popup svg {
  display: block;
}

/* When every word in the selection is already highlighted, the popup
   becomes a Cancel control — same shape, contrasting colour. */
.highlight-popup.is-cancel {
  background: #ef4444;     /* red */
  color: #ffffff;
  border-color: rgba(0,0,0,0.25);
}