/* Outfit builder, list first: pick one item per slot and the collage composes itself.
   "Juster bildet" switches the preview into the free canvas. Canvas styles also serve onboarding. */

.builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 34vw, 460px);
  gap: clamp(var(--space-5), 3vw, var(--space-9));
  align-items: start;
}

.builder-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: clamp(var(--space-5), 2.4vw, var(--space-7));
}
.builder-bar h1 { font-size: var(--text-3xl); letter-spacing: var(--tracking-display-serif); line-height: 1.08; }
.builder-bar p { margin-top: var(--space-2); color: var(--color-ink-2); }
.builder-bar .row { --row-gap: var(--space-2); }

/* ------------------------------------------------------------------ slots */
.slots { display: grid; gap: var(--space-3); }

.slot {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4) clamp(var(--space-4), 1.6vw, var(--space-5)) var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  box-shadow: 0 0 0 1px rgb(10 25 11 / .05), var(--shadow-sm);
}
.slot-head { display: flex; align-items: center; gap: var(--space-3); min-height: 36px; }
.slot-head .icon-box {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-green-tint);
  color: var(--color-green-ink);
}
.slot-head h2 { font-size: var(--text-md); line-height: 1.2; }
.slot-choice { display: block; font-size: var(--text-sm); font-weight: var(--weight-regular); color: var(--color-ink-3); }
.slot-head .push { margin-left: auto; display: flex; gap: var(--space-1); }

/* One row per slot that scrolls sideways: the radio options, then «Legg til plagg» outside the group. */
.slot-track {
  --pick-w: clamp(76px, 4.5rem + 2.2vw, 112px);
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  padding: 4px 2px 8px;
  margin: -4px -2px 0;
  scrollbar-width: thin;
}
.slot-options { display: flex; gap: var(--space-2); }

.pick {
  position: relative;
  flex: 0 0 var(--pick-w);
  display: grid;
  gap: 6px;
  align-content: start;
  text-align: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.25;
  color: var(--color-ink-2);
  text-decoration: none;
  scroll-snap-align: start;
  cursor: pointer;
}
.pick .garment-tile { border-radius: var(--radius-md); transition: box-shadow var(--dur-base) var(--ease-out), background-color var(--dur-base) var(--ease-out); }
.pick .garment-tile img { width: 86%; height: 86%; }
.pick:hover .garment-tile { background: var(--color-tile-2); }
.pick:has(> input:focus-visible) .garment-tile { outline: 2px solid var(--color-green-ink); outline-offset: 2px; }
.pick:has(> input:checked) { color: var(--color-ink); font-weight: var(--weight-semibold); }
.pick:has(> input:checked) .garment-tile { box-shadow: var(--shadow-selected); background: var(--color-green-tint); }
.pick:has(> input:checked)::after {
  content: "";
  position: absolute;
  right: 6px;
  top: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-green-bright) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230A190B' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.pick-ghost .garment-tile {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--color-line-control);
  color: var(--color-ink-3);
}
.pick-ghost .garment-tile .icon { width: 26px; height: 26px; }
.pick-ghost:hover .garment-tile { background: var(--color-tile-2); color: var(--color-ink); }
.pick-ghost:has(> input:checked) .garment-tile { box-shadow: inset 0 0 0 2px var(--color-green-ink); background: var(--color-green-tint); color: var(--color-ink); }
.pick-ghost:has(> input:checked)::after { display: none; }

.slot-empty {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
  color: var(--color-ink-2);
}

.add-slots {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-1);
}
.add-slots strong { margin-right: var(--space-2); font-size: var(--text-sm); }

/* ------------------------------------------------------------------ preview */
.preview {
  position: sticky;
  top: calc(var(--header-height) + var(--space-7));
  display: grid;
  gap: var(--space-4);
  padding: clamp(var(--space-4), 1.6vw, var(--space-5));
  border-radius: 28px;
  background: var(--color-surface);
  box-shadow: 0 0 0 1px rgb(10 25 11 / .05), var(--shadow-md);
}
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.preview-head h2 { font-size: var(--text-lg); }
.preview .canvas-paper { width: 100%; box-shadow: none; background: var(--color-tile); }
.preview .canvas-paper.is-adjusting { background: var(--color-surface); box-shadow: inset 0 0 0 2px var(--color-green), var(--shadow-sm); }
.preview .canvas-paper:not(.is-adjusting) .collage-piece { cursor: default; pointer-events: none; }
.preview .piece-toolbar,
.preview > .btn { justify-self: center; }

/* ------------------------------------------------------------------ save dialog */
.save-summary {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: var(--space-4);
  align-items: center;
}
.save-summary .collage { border-radius: var(--radius-md); box-shadow: none; }
.save-summary h2 { font-size: var(--text-xl); }
.save-summary p { margin-top: var(--space-1); font-size: var(--text-sm); }

/* ------------------------------------------------------------------ canvas (adjust mode, onboarding) */
.canvas-area {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  padding: clamp(var(--space-4), 2.5vw, var(--space-7)) var(--space-5);
  border-radius: var(--radius-xl);
  background-color: var(--color-tile);
  background-image: radial-gradient(rgb(10 25 11 / .14) 1px, transparent 1.4px);
  background-size: 20px 20px;
}
.canvas-paper {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  box-shadow: 0 0 0 1px rgb(10 25 11 / .05), var(--shadow-lg);
  touch-action: none;
  user-select: none;
  overflow: hidden;
}
.canvas-paper .collage-piece { cursor: grab; }
.canvas-paper .collage-piece:focus-visible { outline: none; }
.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-6);
  text-align: center;
  color: var(--color-ink-3);
  pointer-events: none;
}
.canvas-empty .icon { width: 40px; height: 40px; stroke-width: 1.5; }

.piece-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--color-ink);
  color: var(--color-paper);
  box-shadow: var(--shadow-md);
}
.piece-toolbar button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: inherit;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.piece-toolbar button:hover { background: rgb(255 255 255 / .14); }
.piece-toolbar button[disabled] { opacity: .35; cursor: not-allowed; }
.piece-toolbar .sep { width: 1px; height: 22px; margin: 0 4px; background: rgb(255 255 255 / .2); }
.piece-toolbar .is-danger { color: #ffb4a8; }
.canvas-hint { font-size: var(--text-sm); color: var(--color-ink-2); text-align: center; }

.avatar-render {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--color-tile-2), var(--color-tile));
  overflow: hidden;
  color: var(--color-ink-3);
  text-align: center;
}
.avatar-render svg.figure { width: 56%; color: #c7d6ca; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 900px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder-bar .row { display: none; }
  .preview { position: static; order: -1; }
  .preview .canvas-paper { width: min(100%, 280px); justify-self: center; }
  .save-bar {
    position: sticky;
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + var(--space-3));
    z-index: 5;
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3);
    border-radius: var(--radius-pill);
    background: rgb(255 255 255 / .94);
    box-shadow: 0 0 0 1px rgb(10 25 11 / .06), var(--shadow-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .save-bar .btn-primary { flex: 1; }
  .save-thumb { width: 40px; flex: none; align-self: center; border-radius: 10px; box-shadow: none; }
  .piece-toolbar button { width: 44px; height: 44px; }
}

@media (min-width: 901px) {
  .save-bar { display: none; }
}

.builder-notice { margin-bottom: var(--space-5); }
