/* ==========================================================================
   Generator / "Build your bottle"
   Desktop: preview left, questions right (both fill the viewport).
   Mobile: preview sticks to the top, questions scroll under it,
           actions sit in a bottom bar.
   ========================================================================== */

.page-builder { overflow-x: hidden; }

.builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 460px);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    'stage panel'
    'stage actions';
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  padding-right: calc(var(--edge) - var(--gutter)); /* on very wide screens the panel stops where the menu stops */
}

/* ---------- Stage ---------- */
.builder-stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  background:
    radial-gradient(60% 55% at 50% 45%, rgba(77, 162, 255, .12), transparent 70%),
    var(--bg);
  overflow: hidden;
}
.bottle-canvas {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
  outline: none;
}
.bottle-canvas:active { cursor: grabbing; }
.bottle-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.bottle-canvas canvas { width: 100% !important; height: 100% !important; }

.stage-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  transition: opacity .4s;
}
.stage-loading.is-done { opacity: 0; }
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.drag-hint {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 12px;
  border-radius: var(--pill);
  background: rgba(10, 18, 28, .7);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 13px;
  color: var(--text-2);
  pointer-events: none;
  transition: opacity .5s var(--ease), transform .5s var(--ease);
}
.drag-hint .icon { animation: nudge 2.4s var(--ease) infinite; }
.drag-hint.is-hidden { opacity: 0; transform: translate(-50%, 8px); }
@keyframes nudge { 0%, 100% { transform: translateX(-3px); } 50% { transform: translateX(4px); } }

.stage-tools { position: absolute; top: 16px; right: 16px; display: flex; gap: 8px; }
.icon-btn--glass {
  background: rgba(10, 18, 28, .6);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.stage-swatches {
  position: absolute;
  top: 18px;
  left: var(--edge); /* in line with the menu and page content */
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--pill);
  background: rgba(10, 18, 28, .6);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.stage-swatches .swatch { width: 14px; height: 14px; border-radius: 50%; transition: background-color .3s; }

.swatch {
  flex: none;
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}

/* ---------- Panel ---------- */
.builder-panel {
  grid-area: panel;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid var(--line);
  padding: 32px var(--gutter) 24px 32px; /* right edge in line with the menu */
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.panel-head { margin-bottom: 28px; }
.panel-head .h2 { margin-bottom: 10px; }
.panel-head .muted { font-size: 1rem; }

.builder-form { display: flex; flex-direction: column; gap: 12px; }

.q {
  margin: 0;
  padding: 18px 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 0;
  transition: border-color .25s;
}
.q:focus-within { border-color: var(--line-strong); }
.q legend {
  float: left; /* lets legend sit inside the fieldset padding */
  width: 100%;
  padding: 0;
  margin-bottom: 4px;
  display: flex;
  gap: 10px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
}
.q legend + * { clear: both; }
.q-num { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.q-part {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 14px 28px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .02em;
}
.q-part svg { flex: none; }

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-body {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  white-space: nowrap; /* keep labels like "Public transport" on one line */
  color: var(--text-2);
  transition: border-color .2s, background-color .2s, color .2s;
}
.choice:hover .choice-body { border-color: rgba(255, 255, 255, .4); color: #fff; }
.choice input:checked + .choice-body {
  border-color: #fff;
  background: rgba(255, 255, 255, .07);
  color: #fff;
  box-shadow: inset 0 0 0 1px #fff;
}
.choice input:focus-visible + .choice-body { outline: 2px solid var(--accent); outline-offset: 2px; }

/* range */
.range-wrap { display: grid; gap: 10px; padding-left: 0; }
.range-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.range-value {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-2);
}
.range-value strong { font-size: 1.6rem; font-weight: 400; color: #fff; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; min-width: 2ch; }
.range-bin { font-size: 12px; color: var(--muted); }

.range-stepper { display: flex; gap: 6px; }
.range-stepper button {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: transparent;
  font-size: 18px;
  line-height: 1;
  transition: background-color .2s, color .2s;
}
.range-stepper button:hover { background: #fff; color: var(--bg); }

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
  --pct: 10%;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--thumb, #fff) var(--pct), rgba(255, 255, 255, .14) var(--pct));
}
input[type='range']::-moz-range-track { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .14); }
input[type='range']::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--thumb, #fff); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--thumb, #fff);
  border: 3px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}
input[type='range']::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--thumb, #fff);
  border: 3px solid #fff;
}
input[type='range']:focus-visible { outline: none; }
input[type='range']:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.range-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.panel-foot { display: flex; justify-content: flex-start; margin-top: 20px; }

/* ---------- Actions ---------- */
.builder-actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  padding: 16px var(--gutter) 20px 32px;
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.builder-actions .btn { width: 100%; }

/* ---------- Tablet / mobile ---------- */
@media (max-width: 959px) {
  .builder {
    display: block;
    height: auto;
    padding-right: 0;
  }
  .builder-stage {
    position: sticky;
    top: var(--header-h);
    z-index: 2;
    height: 46vh;
    height: 46svh;
    min-height: 280px;
    border-bottom: 1px solid var(--line);
  }
  .builder-panel {
    border-left: 0;
    overflow: visible;
    padding: 24px var(--gutter) calc(120px + env(safe-area-inset-bottom));
  }
  .builder-actions {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    border-left: 0;
    padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
    background: rgba(10, 18, 28, .92);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  .drag-hint { bottom: 16px; }
  .stage-swatches { top: 12px; left: var(--gutter); }
  .stage-tools { top: 10px; right: var(--gutter); }
}

@media (max-width: 420px) {
  .builder-actions { grid-template-columns: 1fr 1.3fr; }
  .builder-actions .btn { padding-inline: 12px; font-size: 15px; }
  .q { padding: 16px 14px 18px; }
  .q-part { margin-left: 0; }
  .choices { grid-template-columns: 1fr 1fr; }
}

/* very short landscape phones: don't let the sticky preview eat the screen */
@media (max-width: 959px) and (max-height: 520px) {
  .builder-stage { position: relative; top: 0; height: 70vh; }
}

@media (max-width: 959px) {
  .page-builder .cookie-banner { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .page-builder .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
}

/* keep focused/scrolled-to questions clear of the sticky preview + bottom bar */
@media (max-width: 959px) {
  .q, .q * { scroll-margin-top: calc(var(--header-h) + 46svh + 16px); scroll-margin-bottom: 100px; }
}

#save-design.is-saved { color: #ff6b8a; }
#save-design.is-saved svg path { fill: currentColor; }
