/* Native Zero-Iframe WebGL2 Paper-Unfolding Chapters
 * Three seamless scroll-driven paper engineering models on bare #F1ECE0 cream:
 *   1. #unfold-spiral  — Samarra Spiral Minaret (hands off seamlessly to #404D4D slate!)
 *   2. #unfold-earth   — Earth's Four Layers (360-deg carousel globe + orbital plan)
 *   3. #unfold-popup   — Mesopotamia Pop-Up Book World (owner's closing artwork)
 *
 * Crisp high-contrast editorial typography beside each stage, interactive beat scrub pills,
 * exact pixel-snapped still-to-WebGL zero-seam handoff, and 3-still fallback under reduced motion. */

.unfold-chapter {
  position: relative;
  background: var(--ground);
  color: var(--ink);
}

.unfold-stage {
  display: none;
}

.unfold-stills {
  padding: clamp(44px, 6vw, 84px) var(--gutter);
  width: min(100%, var(--wrap));
  margin-inline: auto;
}

.unfold-stills-grid {
  margin-top: 28px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(20px, 3vw, 40px);
  align-items: end;
}

.unfold-stills-grid figure {
  display: grid;
  gap: 12px;
}

.unfold-stills-grid img {
  width: 100%;
  height: auto;
  border-radius: var(--r-md);
}

.unfold-stills-grid h3 {
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
}

.unfold-stills-grid p {
  font-size: 15px;
  color: var(--soft);
}

/* =========================================================================
   LIVE WEBGL2 MODE (sticky viewport below fixed bar)
   ========================================================================= */
html[data-unfold-mode="live"] .unfold-chapter {
  height: 280vh;
  height: 280svh;
}

html[data-unfold-mode="live"] #unfold-earth,
html[data-unfold-mode="live"] #unfold-popup {
  height: 300vh;
  height: 300svh;
}

html[data-unfold-mode="live"] .unfold-stills {
  display: none;
}

html[data-unfold-mode="live"] .unfold-stage {
  display: block;
  position: sticky;
  top: var(--bar-h);
  height: calc(100vh - var(--bar-h));
  height: calc(100svh - var(--bar-h));
  overflow: hidden;
  background: var(--ground);
  contain: layout paint;
}

.unfold-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* Quiet editorial top-corner skip pill & bottom beat scrubber */
.unfold-skip {
  position: absolute;
  z-index: 6;
  top: 16px;
  inset-inline-start: var(--gutter);
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: rgba(241, 236, 224, 0.9);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.18s, background-color 0.18s;
}

.unfold-skip:hover {
  border-color: var(--slate);
  background: var(--sheet);
}

.unfold-skip svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Shared editorial caption block */
.uf-copy-rail {
  position: absolute;
  z-index: 4;
  inset-inline-start: var(--gutter);
  top: 50%;
  transform: translateY(-50%);
  width: min(31vw, 25rem);
  pointer-events: auto;
}

.uf-kicker {
  font-size: 13px;
  font-weight: 500;
  color: var(--soft);
  margin-bottom: 8px;
}

.uf-chapter-heading {
  font-size: clamp(22px, 2.4vw, 34px);
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink);
  text-wrap: balance;
}

html[lang="en"] .uf-chapter-heading {
  line-height: 1.16;
}

.uf-beats-stack {
  display: grid;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  min-height: 132px;
}

.uf-beat-item {
  grid-area: 1 / 1;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s var(--ease-out), transform 0.28s var(--ease-out);
  transform: translateY(8px);
}

.uf-beat-item.is-active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.uf-beat-item h3 {
  font-size: clamp(19px, 1.8vw, 24px);
  font-weight: 500;
  line-height: 1.38;
  color: var(--ink);
}

.uf-beat-item p {
  margin-top: 8px;
  font-size: clamp(15px, 1.15vw, 17px);
  color: var(--soft);
  line-height: 1.68;
  max-width: 34ch;
}

/* Interactive beat progress & jump controls */
.uf-progress-bar {
  margin-top: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.uf-counter {
  font-size: 13px;
  font-weight: 500;
  color: var(--soft);
  min-width: 4.5em;
  font-variant-numeric: tabular-nums;
}

.uf-pills {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.uf-pill {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
}

.uf-pill span {
  display: block;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  transition: background-color 0.2s var(--ease-std), transform 0.2s var(--ease-out);
}

.uf-pill:hover span {
  background: var(--soft);
}

.uf-pill.is-done span,
.uf-pill[aria-current="step"] span {
  background: var(--slate);
}

.uf-pill[aria-current="step"] span {
  height: 4px;
  background: var(--oxblood);
}

/* =========================================================================
   1. SAMARRA SPIRAL MINARET (#unfold-spiral) — exact framing grid
   ========================================================================= */
html[data-unfold-mode="live"] #unfold-spiral .unfold-stage {
  display: grid;
  grid-template-columns: minmax(300px, 36%) minmax(0, 1fr);
}

#unfold-spiral .unfold-canvas {
  visibility: hidden;
}

#unfold-spiral .unfold-canvas.is-on {
  visibility: visible;
}

#unfold-spiral .uf-copy-rail {
  position: relative;
  inset: auto;
  top: auto;
  transform: none;
  width: auto;
  grid-column: 1;
  align-self: center;
  padding-inline-start: var(--gutter);
  padding-inline-end: 12px;
}

#unfold-spiral .spiral-figure {
  grid-column: 2;
  min-width: 0;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  pointer-events: none;
}

#unfold-spiral .spiral-still {
  display: block;
  width: min(74vh, 86%, 760px);
  height: auto;
  aspect-ratio: 1;
}

#unfold-spiral .spiral-still.is-off {
  visibility: hidden;
}

/* =========================================================================
   2. EARTH FOUR LAYERS (#unfold-earth) — pixel-snapped still for 0px seam
   ========================================================================= */
#unfold-earth .earth-canvas {
  opacity: 0;
}

#unfold-earth .earth-sheet {
  position: absolute;
  --ph: min(76vh, 54vw);
  height: var(--ph);
  width: calc(var(--ph) * 0.8);
  top: calc(50% - var(--ph) / 2 + 4px);
  inset-inline-end: calc(31% - var(--ph) * 0.4);
  pointer-events: none;
  z-index: 1;
}

#unfold-earth .earth-page {
  display: block;
  width: 100%;
  height: 100%;
}

@supports (width: round(down, 1px, 1px)) and (height: 1svh) {
  #unfold-earth .earth-sheet {
    --ph: round(down, min(74svh, 54vw), 10px);
    top: round(down, calc(50% - var(--ph) / 2 + 4px), 1px);
    inset-inline-end: round(down, calc(31vw - var(--ph) * 0.4), 1px);
  }
}

/* =========================================================================
   3. MESOPOTAMIA POP-UP WORLD (#unfold-popup)
   ========================================================================= */
#unfold-popup .popup-canvas {
  visibility: hidden;
}

#unfold-popup .popup-model {
  position: absolute;
  inset-block: 5% 5%;
  inset-inline: 34.5% 2%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
}

#unfold-popup .popup-still {
  display: block;
  height: 90%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 152 / 244;
  object-fit: contain;
}

/* =========================================================================
   RESPONSIVE STAGE LAYOUTS (Tablets, Portrait & Mobile 390x844)
   ========================================================================= */
@media (max-width: 899px), (max-aspect-ratio: 1 / 1) {
  .unfold-stills-grid {
    grid-template-columns: minmax(0, 1fr);
    max-width: 30rem;
  }

  .uf-copy-rail {
    inset-inline: var(--gutter);
    width: auto;
    top: 56px;
    transform: none;
  }

  .uf-kicker {
    display: none;
  }

  .uf-chapter-heading {
    font-size: 16px;
    color: var(--soft);
    font-weight: 400;
  }

  .uf-beats-stack {
    margin-top: 8px;
    padding-top: 10px;
    min-height: 96px;
  }

  .uf-beat-item h3 {
    font-size: 19px;
  }

  .uf-beat-item p {
    font-size: 14px;
    margin-top: 4px;
    line-height: 1.55;
  }

  .uf-progress-bar {
    margin-top: 10px;
  }

  .unfold-skip {
    top: 10px;
    min-height: 36px;
    padding: 0 12px;
  }

  /* Spiral on mobile */
  html[data-unfold-mode="live"] #unfold-spiral .unfold-stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  #unfold-spiral .uf-copy-rail {
    grid-column: 1;
    grid-row: 1;
    padding: 54px var(--gutter) 0;
    align-self: start;
  }

  #unfold-spiral .spiral-figure {
    grid-column: 1;
    grid-row: 2;
  }

  #unfold-spiral .spiral-still {
    width: min(86vw, 48vh);
  }

  /* Earth on mobile: sheet upper half, words bottom */
  #unfold-earth .earth-sheet {
    --ph: min(48vh, 102vw);
    top: 9%;
    inset-inline-end: calc(50% - var(--ph) * 0.4);
  }

  @supports (width: round(down, 1px, 1px)) and (height: 1svh) {
    #unfold-earth .earth-sheet {
      --ph: round(down, min(46svh, 100vw), 10px);
      top: round(down, 9%, 1px);
      inset-inline-end: round(down, calc(50vw - var(--ph) * 0.4), 1px);
    }
  }

  #unfold-earth .uf-copy-rail {
    top: auto;
    bottom: 16px;
  }

  #unfold-earth .unfold-skip {
    top: auto;
    bottom: 14px;
    inset-inline-start: auto;
    inset-inline-end: var(--gutter);
  }

  /* Popup on mobile */
  #unfold-popup .popup-model {
    inset-block: 30% 2%;
    inset-inline: 2%;
  }

  #unfold-popup .popup-still {
    height: 94%;
  }
}
