/* Builder page. Tokens, buttons, nav and the copy swap come from styles.css. */

.builder {
  width: min(var(--max), calc(100% - 2 * var(--gutter)));
  margin: 0 auto;
  padding: clamp(32px, 5vw, 64px) 0 0;
}
.builder-head { display: grid; gap: 12px; margin-bottom: clamp(24px, 3vw, 36px); }
.builder-head h1 { font-size: clamp(42px, 6vw, 76px); font-weight: 700; letter-spacing: -0.02em; }

.builder-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 36px);
  align-items: start;
}

/* ---------- Stage ---------- */

.stage { position: sticky; top: 92px; display: grid; gap: 14px; scroll-margin-top: 92px; }
.stage-card {
  --pad: 14px;
  padding: var(--pad);
  border: var(--stroke) solid var(--ink);
  border-radius: 32px;
  background: var(--card);
  box-shadow: 0 6px 0 var(--ink);
}
/* The art's own corners follow the card's, inset by its padding. */
.stage-art { overflow: hidden; aspect-ratio: 1; border: 2px solid var(--ink); border-radius: calc(32px - var(--pad)); background: var(--paper-2); }
.stage-art svg { width: 100%; height: 100%; display: block; }

.stage-name {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 18px;
  border: var(--stroke) solid var(--ink);
  border-radius: 999px;
  background: var(--card);
}
.stage-name label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.stage-name input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  outline: none;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--sun);
  cursor: pointer;
  transition-property: scale, rotate;
  transition-duration: 160ms;
  transition-timing-function: var(--ease-out);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { scale: 0.96; }
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { rotate: 12deg; } }

.stage-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.stage-actions .btn { flex: 1 1 auto; }
.btn[data-copied] { background: var(--green-tint); }

/* ---------- Controls ---------- */

.controls {
  display: grid;
  gap: 4px;
  padding: 8px 20px;
  border: var(--stroke) solid var(--ink);
  border-radius: 28px;
  background: var(--card);
}
.group { display: grid; gap: 12px; margin: 0; padding: 16px 0; border: 0; border-bottom: 2px dashed rgb(22 22 22 / 0.18); min-width: 0; }
.group:last-child { border-bottom: 0; }
.group legend { float: left; width: 100%; margin-bottom: 12px; font-family: var(--font-display); font-weight: 600; font-size: 17px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; clear: both; }
.chip-opt {
  min-height: 38px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition-property: scale, background-color, color;
  transition-duration: 150ms;
  transition-timing-function: var(--ease-out);
}
.chip-opt:active { scale: 0.96; }
.chip-opt[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
@media (hover: hover) and (pointer: fine) { .chip-opt[aria-pressed="false"]:hover { background: var(--sun-tint); } }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; clear: both; }
.swatch {
  width: 34px;
  height: 34px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--swatch);
  cursor: pointer;
  transition-property: scale, box-shadow;
  transition-duration: 150ms;
  transition-timing-function: var(--ease-out);
}
.swatch:active { scale: 0.96; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--ink); }

.custom-color { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.custom-color input { width: 34px; height: 34px; padding: 0; border: 2px solid var(--ink); border-radius: 50%; background: none; cursor: pointer; }
.custom-color input::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.custom-color input::-moz-color-swatch { border: 0; border-radius: 50%; }

.slider { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 12px; clear: both; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.slider input { width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer; appearance: none; -webkit-appearance: none; }
.slider input::-webkit-slider-runnable-track { height: 10px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper-2); }
.slider input::-moz-range-track { height: 6px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper-2); }
.slider input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -9px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--sun);
}
.slider input::-moz-range-thumb { width: 20px; height: 20px; border: 2px solid var(--ink); border-radius: 50%; background: var(--sun); }

/* ---------- Herd ---------- */

.herd { padding: clamp(56px, 8vw, 96px) 0 0; }
.herd-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.herd-head h2 { font-size: clamp(32px, 4vw, 48px); font-weight: 700; }
.herd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.herd-card {
  --pad: 8px;
  display: grid;
  gap: 8px;
  width: 100%;
  padding: var(--pad) var(--pad) 12px;
  border: var(--stroke) solid var(--ink);
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition-property: translate, box-shadow, scale;
  transition-duration: 160ms;
  transition-timing-function: var(--ease-out);
}
.herd-card:active { scale: 0.96; }
@media (hover: hover) and (pointer: fine) { .herd-card:hover { translate: 0 -3px; box-shadow: 0 7px 0 var(--ink); } }
.herd-art { display: block; overflow: hidden; aspect-ratio: 1; border-radius: calc(22px - var(--pad)); }
.herd-art svg { width: 100%; height: 100%; display: block; }
.herd-name { font-family: var(--font-display); font-weight: 600; font-size: 16px; }

.footer--compact { margin-top: clamp(56px, 8vw, 96px); }

@media (max-width: 860px) {
  .builder-grid { grid-template-columns: 1fr; }
  .stage { position: static; }
}

/* ---------- Reshape handles ---------- */

.stage-frame { position: relative; }
.handles { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; touch-action: none; }
.handle { cursor: grab; outline: none; }
.handle[data-handle="side"] { cursor: ew-resize; }
.handle[data-handle="belly"] { cursor: ns-resize; }
.handle[data-active] { cursor: grabbing; }
.handle-hit { fill: transparent; }
.handle-dot {
  fill: var(--sun);
  stroke: var(--ink);
  stroke-width: 4;
  transition: r 150ms var(--ease-out), fill 150ms ease;
}
.handle-glyph { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.handle[data-active] .handle-dot, .handle:focus-visible .handle-dot { r: 17; fill: #fff; }
.handle:focus-visible .handle-dot { stroke: var(--blue); stroke-width: 6; }
@media (hover: hover) and (pointer: fine) { .handle:hover .handle-dot { r: 16; } }
.stage-hint { margin-top: -4px; font-size: 13px; color: var(--ink-3); text-align: center; }

/* ---------- Tabs ---------- */

.controls { gap: 0; padding: 14px 16px 18px; }
/* Tabs wrap rather than scroll sideways: a hidden horizontal scroll strands tabs for mouse users. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 12px;
  border-bottom: 2px dashed rgb(22 22 22 / 0.18);
}
.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition-property: background-color, color, scale;
  transition-duration: 150ms;
  transition-timing-function: var(--ease-out);
}
.tab:active { scale: 0.96; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); }
@media (hover: hover) and (pointer: fine) { .tab[aria-selected="false"]:hover { background: var(--sun-tint); } }
.tab-count { padding: 0 6px; border-radius: 999px; background: var(--paper-2); color: var(--ink-2); font-size: 11px; line-height: 18px; font-variant-numeric: tabular-nums; }
.tab[aria-selected="true"] .tab-count { background: rgb(255 255 255 / 0.18); color: var(--paper); }

.panel { display: grid; gap: 4px; padding-top: 8px; }
.panel .group { display: grid; gap: 12px; padding: 12px 0; border-bottom: 2px dashed rgb(22 22 22 / 0.18); }
.panel .group:last-child { border-bottom: 0; }
.panel h3 { font-family: var(--font-display); font-weight: 600; font-size: 17px; }

/* ---------- Picture grid ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  max-height: min(620px, 70vh);
  overflow-y: auto;
  padding: 4px 4px 8px;
  margin: 0 -4px;
  overscroll-behavior: contain;
}
.tile {
  --pad: 5px;
  display: grid;
  gap: 4px;
  padding: var(--pad) var(--pad) 7px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--card);
  cursor: pointer;
  text-align: center;
  transition-property: scale, background-color, box-shadow, translate;
  transition-duration: 150ms;
  transition-timing-function: var(--ease-out);
}
.tile:active { scale: 0.96; }
.tile[aria-pressed="true"] { background: var(--sun); box-shadow: 0 3px 0 var(--ink); translate: 0 -2px; }
@media (hover: hover) and (pointer: fine) { .tile[aria-pressed="false"]:hover { background: var(--sun-tint); } }
.tile-art { display: grid; place-items: center; overflow: hidden; aspect-ratio: 1; border-radius: calc(18px - var(--pad)); background: var(--paper); }
.tile-art svg { width: 100%; height: 100%; display: block; }
.tile-none { font-family: var(--font-display); font-weight: 600; font-size: 14px; color: var(--ink-3); }
.tile-label { font-size: 12px; font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.accent-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 4px 0 10px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.swatches--small .swatch { width: 28px; height: 28px; }
.custom-color input { width: 34px; height: 34px; }
