/* ==========================================================================
   Book builder page. Builds on site.css and pages.css.
   ========================================================================== */

.pp { background: var(--tint-blue); overflow-x: clip; }
.pp-noscript { font-weight: 700; padding-top: var(--space-3); }

.pp-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
  padding-top: var(--space-4);
  padding-bottom: var(--space-6);
}

/* ---------- The preview ---------- */
.stage { position: sticky; top: 104px; min-width: 0; }

.stage-bar { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.stage-progress { flex: 1; min-width: 0; }
.stage-track {
  display: block;
  height: 14px;
  background: #fff;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}
.stage-fill { display: block; width: 0; height: 100%; background: var(--rainbow); background-size: 400px 100%; transition: width 0.3s ease; }
.stage-count { display: block; font-size: 0.95rem; font-weight: 700; margin-top: 0.25rem; }
.stage-close {
  display: none;
  flex: none;
  width: 48px;
  height: 48px;
  border: var(--line) solid var(--ink);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font: 800 1.6rem/1 var(--display);
  cursor: pointer;
}

.stage-page {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: var(--space-1);
}
.stage-sheet {
  /* Sized by screen height too, so the crayons stay in view on a laptop */
  width: 100%;
  max-width: max(260px, calc((100vh - 520px) * 0.833));
  margin: 0 auto;
  min-width: 0;
  filter: drop-shadow(6px 7px 0 var(--ink));
}
#page-view .rg { cursor: pointer; }
#page-view .is-coloured .rg { cursor: default; }
.stage-confetti {
  position: absolute;
  inset: -40px;
  width: calc(100% + 80px);
  height: calc(100% + 80px);
  pointer-events: none;
}
.stage-nav {
  width: 48px;
  height: 48px;
  border: var(--line) solid var(--ink);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font: 800 1.8rem/1 var(--display);
  cursor: pointer;
  padding: 0 0 4px;
}
.stage-nav:hover:not(:disabled) { background: var(--c2); }
.stage-nav:disabled { opacity: 0.35; cursor: default; }

.stage-label { text-align: center; font-weight: 700; margin: var(--space-2) auto var(--space-1); }

.stage-crayons { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.key-crayon {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  border: var(--line) solid var(--ink);
  border-radius: 12px 12px 8px 8px;
  font: 800 1.1rem/1 var(--display);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.key-crayon:hover { transform: translateY(2px); }
.key-crayon[aria-pressed="true"] { transform: translateY(-7px) rotate(-6deg); box-shadow: 3px 3px 0 var(--ink); }
.key-crayon.is-done .key-num { visibility: hidden; }
.key-crayon.is-done::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; }

.stage-hint { text-align: center; margin: var(--space-1) auto; font-size: 1rem; min-height: 1.6em; }
.stage-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem var(--space-3);
  margin-top: var(--space-1);
}
.stage-note { text-align: center; font-size: 0.95rem; color: var(--ink-soft); margin: var(--space-2) auto 0; }

.stage-thumbs {
  list-style: none;
  padding: 0.35rem 0.35rem 0.75rem;
  margin: var(--space-2) 0 0;
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  scrollbar-width: thin;
}
.stage-thumbs li { flex: 0 0 66px; }
.thumb {
  display: block;
  width: 100%;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.85;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.thumb:hover { transform: translateY(2px); opacity: 1; }
.thumb[aria-current="true"] { opacity: 1; outline: 3px solid var(--ink); outline-offset: 2px; }

/* Nothing to colour on the cover */
.on-cover .stage-bar, .on-cover .stage-crayons, .on-cover .stage-hint, .on-cover #page-colour, .on-cover #page-restart { display: none; }

/* Page turns and redraws */
.turn-next svg { animation: turn-next 0.28s ease; }
.turn-prev svg { animation: turn-prev 0.28s ease; }
.pop svg { animation: page-pop 0.3s ease; }
.rg.just-filled { animation: shape-pop 0.35s ease; }
.rg.is-wrong { animation: shape-wobble 0.35s ease; }
@keyframes turn-next { from { transform: translateX(24px) rotate(1.5deg); opacity: 0; } }
@keyframes turn-prev { from { transform: translateX(-24px) rotate(-1.5deg); opacity: 0; } }
@keyframes page-pop { 40% { transform: scale(1.018); } }
@keyframes shape-pop { 40% { transform: scale(1.07); } }
@keyframes shape-wobble { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

/* ---------- Full-screen colouring ---------- */
.is-colouring { overflow: hidden; }
.is-colouring .stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: var(--space-3);
  overflow-x: hidden;
  overflow-y: auto;
  justify-content: safe center;
  border: 0;
  background: var(--sun);
}
.is-colouring .stage-close { display: block; }
.is-colouring .stage-thumbs, .is-colouring .stage-note, .is-colouring #colour-open { display: none; }
.is-colouring .stage-sheet { max-width: max(280px, calc((100dvh - 330px) * 0.833)); }
.is-colouring .page { touch-action: none; }
.is-colouring .stage-page { flex: none; width: 100%; max-width: 900px; margin: 0 auto; }
.is-colouring .stage-bar, .is-colouring .stage-crayons, .is-colouring .stage-hint { width: 100%; max-width: 900px; margin-left: auto; margin-right: auto; }

@media (min-width: 961px) and (max-height: 820px) {
  .stage { top: 96px; }
  .stage-thumbs, .stage-note { display: none; }
}

/* ---------- Options ---------- */
.builder { min-width: 0; }
.builder h1 { font-size: clamp(2rem, 4vw, 2.9rem); margin-bottom: var(--space-1); }
.pp-back { display: inline-block; font-weight: 700; margin-bottom: var(--space-2); text-underline-offset: 4px; }
.pp-meta { font-weight: 700; margin-bottom: 0.25rem; }
.pp-blurb { color: var(--ink-soft); margin-bottom: var(--space-3); }

.group {
  position: relative;
  min-width: 0;
  margin: 0 0 var(--space-3);
  padding: var(--space-3);
  background: #fff;
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
}
.group legend {
  float: left;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0;
  margin-bottom: var(--space-3);
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.4rem;
  line-height: 1.15;
}
.group legend + * { clear: both; }
.group-num {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--c2);
  border: var(--line) solid var(--ink);
  border-radius: 46% 54% 50% 50% / 55% 45% 55% 45%;
  font-size: 1.15rem;
}
.group:nth-of-type(2) .group-num { background: var(--c1); }
.group:nth-of-type(3) .group-num { background: var(--c4); }
.group:nth-of-type(4) .group-num { background: var(--c3); }
.group:nth-of-type(5) .group-num { background: var(--c5); }
.optional { font-family: var(--body); font-weight: 400; font-size: 1rem; color: var(--ink-soft); }

.book-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.book-tab {
  padding: 0.7rem 0.75rem;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  line-height: 1.2;
}
.book-tab:hover { background: var(--tint-yellow); }
.book-tab[aria-current="true"] { box-shadow: var(--sticker); }
.book-tab[aria-current="true"][data-colour="purple"] { background: var(--c5); }
.book-tab[aria-current="true"][data-colour="blue"] { background: var(--c4); }
.book-tab[aria-current="true"][data-colour="green"] { background: var(--c3); }
.book-tab[aria-current="true"][data-colour="red"] { background: var(--c1); }

.field-label { display: block; font-weight: 700; margin-bottom: 0.5rem; }
.field {
  display: block;
  width: 100%;
  font: inherit;
  color: var(--ink);
  padding: 0.7em 0.9em;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  background: #fff;
  resize: vertical;
}
.field::placeholder { color: #6E789F; }
.field-help { font-size: 0.95rem; color: var(--ink-soft); margin: 0.5rem 0 0; }

.surprise {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  background: var(--tint-yellow);
  color: var(--ink);
}

.option-set { margin-bottom: var(--space-3); }
.option-set:last-child { margin-bottom: 0; }
.option-label { font-weight: 700; margin: 0 0 0.6rem; }
.option { position: relative; cursor: pointer; min-width: 0; }
.option input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }

.option-row { display: grid; gap: 0.75rem; }
.is-swatches { grid-template-columns: repeat(var(--count), minmax(0, 46px)); gap: 0.65rem; }
.swatch-dot {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: var(--line) solid var(--ink);
  border-radius: 50%;
  transition: transform 0.12s ease;
}
.swatch:hover .swatch-dot { transform: scale(0.92); }
.swatch input:checked + .swatch-dot { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ink); }
.swatch input:focus-visible + .swatch-dot { outline: 3px solid var(--c4); outline-offset: 7px; }

.is-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.is-tiles[data-group="pet"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.is-tiles[data-group="glasses"] { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 75%; }
.tile { display: block; }
.tile-art {
  display: block;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  background: var(--tint-yellow);
  overflow: hidden;
  transition: transform 0.12s ease;
}
.tile-art svg { display: block; width: 100%; height: 76px; }
.tile:hover .tile-art { transform: translate(1px, 2px); }
.tile input:checked ~ .tile-art { background: var(--c2); box-shadow: 3px 3px 0 var(--ink); }
.tile input:focus-visible ~ .tile-art { outline: 3px solid var(--c4); outline-offset: 2px; }
.tile-name { display: block; text-align: center; font-size: 0.95rem; font-weight: 700; margin-top: 0.35rem; line-height: 1.2; }

.level-options { display: grid; gap: 0.75rem; }
.level-option { position: relative; display: block; cursor: pointer; }
.level-option input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.level-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: var(--space-2);
  align-items: center;
  padding: 0.75rem var(--space-2);
  border: var(--line) solid var(--ink);
  border-radius: 14px;
  transition: transform 0.12s ease;
}
.level-mini { display: block; width: 76px; }
.level-text { display: grid; gap: 0.1rem; font-size: 1rem; line-height: 1.35; }
.level-text strong { font-family: var(--display); font-size: 1.2rem; }
.level-years-sm { font-weight: 700; }
.level-option:hover .level-card { background: var(--tint-yellow); transform: translate(1px, 2px); }
.level-option input:checked + .level-card { background: var(--tint-green); box-shadow: var(--sticker); }
.level-option input:focus-visible + .level-card { outline: 3px solid var(--c4); outline-offset: 2px; }

/* ---------- Signup ---------- */
.buy {
  padding: var(--space-4) var(--space-3);
  background: #FFE27A;
  border: var(--line) solid var(--ink);
  border-radius: 24px;
  box-shadow: 8px 8px 0 var(--ink);
}
.buy h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: 0.6rem; }
.buy-eyebrow { font-family: var(--display); font-weight: 800; margin-bottom: 0.35rem; }
.buy-note { font-size: 0.95rem; margin: var(--space-1) 0 0; }

/* ---------- Below the builder ---------- */
.pp-faq { background: var(--tint-peach); padding: var(--space-6) 0; border-top: var(--line) solid var(--ink); }
.pp-faq .faqs { margin-top: var(--space-3); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .is-product .site-header { position: static; }
  .pp-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); padding-top: 0; padding-bottom: var(--space-5); }

  /* Keep the page in view while choosing options */
  .stage {
    top: 0;
    z-index: 20;
    margin: 0 calc(-1 * var(--space-3));
    padding: 0.75rem var(--space-3);
    background: var(--tint-blue);
    border-bottom: var(--line) solid var(--ink);
  }
  .stage-page { grid-template-columns: 44px minmax(0, 200px) 44px; justify-content: center; }
  .stage-sheet { max-width: none; }
  .stage-nav, .stage-close { width: 44px; height: 44px; }
  .stage-label { margin: 0.5rem auto 0.4rem; font-size: 0.95rem; }
  .stage-bar, .stage-crayons, .stage-hint, .stage-thumbs, .stage-note { display: none; }
  .stage-actions { margin-top: 0; gap: 0.5rem var(--space-2); }
  .stage-actions .btn { font-size: 0.95rem; padding: 0.45em 0.9em; }
  .stage-actions .link-btn { font-size: 0.95rem; }

  .is-colouring .stage { padding: var(--space-2); }
  .is-colouring .stage-bar { display: flex; }
  .is-colouring .stage-crayons { display: flex; }
  .is-colouring .stage-hint { display: block; }
  .is-colouring .stage-page { grid-template-columns: 1fr 1fr; justify-content: stretch; row-gap: var(--space-1); }
  .is-colouring .stage-sheet { grid-column: 1 / -1; grid-row: 1; max-width: min(100%, calc((100dvh - 340px) * 0.833)); }
  .is-colouring .stage-prev { grid-row: 2; justify-self: end; }
  .is-colouring .stage-next { grid-row: 2; justify-self: start; }
  .is-colouring .stage-label { order: -1; display: none; }

  .builder h1 { margin-top: 0; }
  .surprise { position: static; margin-bottom: var(--space-3); }
  .is-tiles[data-group="glasses"] { max-width: none; }
}

@media (max-width: 480px) {
  .group { padding: var(--space-2); }
  .buy { padding: var(--space-3) var(--space-2); }
  .is-tiles { gap: 0.6rem; }
  .is-tiles[data-group="pet"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tile-art svg { height: 64px; }
  .tile-name { font-size: 0.82rem; }
}
