/* Isolated 5-stage preview — easy to remove. Does not change homepage layout. */

.eg-preview-page {
  min-height: 100vh;
  background: var(--cream);
  padding: 5.5rem 1.5rem 4rem;
}

.eg-preview-note {
  max-width: 560px;
  margin: 0 auto 2.5rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

.eg-explainer {
  text-align: center;
}

.eg-titles {
  position: relative;
  height: 1.7em;
  margin: 0 auto 1.15rem;
  max-width: 560px;
}

.eg-stage-title {
  position: absolute;
  inset: 0;
  margin: 0;
  font-family: 'Alegreya', serif;
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1.35;
  color: var(--green-dark);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.eg-explainer[data-stage="1"] [data-title="1"],
.eg-explainer[data-stage="2"] [data-title="2"],
.eg-explainer[data-stage="3"] [data-title="3"],
.eg-explainer[data-stage="4"] [data-title="4"],
.eg-explainer[data-stage="5"] [data-title="5"] {
  opacity: 1;
  transform: none;
}

.eg-frame {
  position: relative;
  width: min(560px, 100%);
  margin: 0 auto;
  aspect-ratio: 16 / 12.15;

  /* Shared geometry. The stage 3–5 canvas is the laptop screen footprint, so
     every later object inherits the position stage 2 ended with. */
  --screen-left: 1.8%;
  --screen-top: 6.4%;
  --screen-width: 96.4%;
  --screen-height: 82.5%;

  /* Canvas is 540 x 351 at any frame width, so a square of width W% needs
     height W% * this factor. */
  --canvas-aspect: 1.53846;

  /* The closed album footprint is the single source of truth. Stage 3's final
     six-photo block and Stage 4's closed book both resolve to these values, so
     the handoff cannot drift. */
  --closed-x: 26%;
  --closed-y: 22%;
  --closed-w: 48%;
  --closed-h: 55%;

  /* The book container is always the OPEN footprint. Closed is its right half,
     brought to centre by --shift; width itself never animates. */
  --book-left: calc(var(--closed-x) - var(--closed-w) / 2);
  --book-top: var(--closed-y);
  --book-width: calc(2 * var(--closed-w));
  --book-height: var(--closed-h);

  /* Stage 3's six selected photos tile the closed footprint exactly:
     3 cells + 2 gaps across, 2 cells + 1 gap down. */
  --pick-gap: 8px;
  --pick-w: calc((var(--closed-w) - 2 * var(--pick-gap)) / 3);
  --pick-h: calc((var(--closed-h) - var(--pick-gap)) / 2);
  --pick-step-x: calc(var(--pick-w) + var(--pick-gap));
  --pick-step-y: calc(var(--pick-h) + var(--pick-gap));

  --pick-start-w: 17.4%;
  --pick-start-h: calc(var(--pick-start-w) * var(--canvas-aspect));

  --handoff: 0.45s;
  --flip: 0.9s;
  --flip-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

.eg-laptop {
  position: absolute;
  left: 0;
  right: 0;
  top: 4%;
  width: 100%;
  opacity: 0;
  z-index: 1;
  transition: opacity var(--handoff) ease;
}

.eg-laptop-lid {
  background: var(--green-dark);
  border-radius: 14px 14px 8px 8px;
  padding: 10px 10px 8px;
  box-shadow: var(--shadow);
}

.eg-screen {
  position: relative;
  background: #f7f3ec;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16 / 10.4;
}

.eg-laptop-base {
  width: 108%;
  margin: -2px 0 0 -4%;
  height: 14px;
  background: #163628;
  border-radius: 0 0 10px 10px;
  box-shadow: var(--shadow);
}

.eg-laptop-indent {
  width: 18%;
  height: 4px;
  margin: 3px auto 0;
  background: rgba(249, 246, 241, 0.16);
  border-radius: 0 0 4px 4px;
}

.eg-library {
  display: flex;
  height: 100%;
}

.eg-sidebar {
  width: 22%;
  min-width: 86px;
  padding: 0.85rem 0.7rem;
  background: #efe9df;
  border-right: 1px solid rgba(27, 67, 50, 0.08);
  text-align: left;
}

.eg-sidebar-brand {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 0.85rem;
}

.eg-nav-item {
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--text-light);
  padding: 0.32rem 0.4rem;
  border-radius: 4px;
  margin-bottom: 0.15rem;
}

.eg-nav-item.is-active {
  background: rgba(45, 106, 79, 0.1);
  color: var(--green-dark);
  font-weight: 500;
}

.eg-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.eg-toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem 0.45rem;
}

.eg-toolbar-title {
  font-family: 'Alegreya', serif;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--green-dark);
}

.eg-toolbar-count {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.eg-photo-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  margin: 0 0.7rem 0.65rem 0.55rem;
  mask-image: linear-gradient(to bottom, transparent, #000 10%, #000 90%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 10%, #000 90%, transparent);
}

.eg-photo-track {
  display: flex;
  flex-direction: column;
  animation: eg-photo-scroll 16s linear infinite;
  will-change: transform;
}

/* Stage 1 internal motion waits for its ENTER transition to finish. */
.eg-photo-track,
.eg-scrollbar-thumb {
  animation-play-state: paused;
}

.eg-explainer.eg-s1-run[data-stage="1"] .eg-photo-track,
.eg-explainer.eg-s1-run[data-stage="1"] .eg-scrollbar-thumb {
  animation-play-state: running;
}

.eg-photo-set {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  padding-bottom: 5px;
}

.eg-scrollbar {
  position: absolute;
  top: 6px;
  right: 3px;
  bottom: 6px;
  width: 3px;
  border-radius: 99px;
  background: rgba(27, 67, 50, 0.08);
}

.eg-scrollbar-thumb {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 18%;
  border-radius: 99px;
  background: rgba(27, 67, 50, 0.28);
  animation: eg-scroll-thumb 16s linear infinite;
}

.eg-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 3px;
  overflow: hidden;
}

.eg-thumb.bg-sand { background: #e7dfd2; }
.eg-thumb.bg-cream { background: #f3eee4; }
.eg-thumb.bg-sage { background: #dce8dc; }
.eg-thumb.bg-mist { background: #e4ebe3; }
.eg-thumb.bg-leaf { background: #d5e3d4; }

.eg-scene {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(27, 67, 50, 0.08) 26%, transparent 26%);
}

.eg-scene::before,
.eg-scene::after {
  content: '';
  position: absolute;
  background: var(--green-mid);
}

.scene-couple::before,
.scene-parent::before,
.scene-portrait::before,
.scene-kids::before,
.scene-walk::before,
.scene-three::before,
.scene-bench::before {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  top: 22%;
  left: 22%;
  background: #2d6a4f;
}

.scene-couple::after,
.scene-parent::after,
.scene-kids::after,
.scene-walk::after,
.scene-three::after,
.scene-bench::after {
  width: 22%;
  height: 22%;
  border-radius: 50%;
  top: 28%;
  left: 52%;
  background: #1b4332;
}

.scene-couple::before { left: 20%; top: 24%; }
.scene-couple::after { left: 50%; top: 27%; width: 24%; height: 24%; }
.scene-parent::before { width: 30%; height: 30%; left: 18%; top: 20%; }
.scene-parent::after { width: 18%; height: 18%; left: 54%; top: 38%; background: #4aba61; }
.scene-portrait::before { left: 36%; top: 18%; width: 28%; height: 28%; }
.scene-portrait::after {
  left: 28%;
  top: 48%;
  width: 44%;
  height: 42%;
  border-radius: 42% 42% 8% 8%;
  background: #1b4332;
}
.scene-kids::before { width: 20%; height: 20%; left: 22%; top: 30%; background: #2d6a4f; }
.scene-kids::after { width: 20%; height: 20%; left: 52%; top: 32%; background: #4aba61; }
.scene-group::before {
  width: 20%;
  height: 20%;
  border-radius: 50%;
  top: 24%;
  left: 16%;
  box-shadow: 22px 4px 0 #1b4332, 42px -2px 0 #2d6a4f;
}
.scene-group::after {
  left: 18%;
  top: 50%;
  width: 64%;
  height: 38%;
  border-radius: 40% 40% 10% 10%;
  background: #2d6a4f;
}
.scene-three::before {
  width: 18%;
  height: 18%;
  left: 18%;
  top: 22%;
  box-shadow: 20px 6px 0 #1b4332, 40px 2px 0 #5a7a62;
}
.scene-three::after {
  left: 16%;
  top: 48%;
  width: 68%;
  height: 40%;
  border-radius: 36% 36% 8% 8%;
  background: #1b4332;
}
.scene-outdoor::before {
  width: 18%;
  height: 42%;
  left: 22%;
  top: 38%;
  border-radius: 40% 40% 8% 8%;
  background: #2d6a4f;
}
.scene-outdoor::after {
  width: 28%;
  height: 28%;
  left: 48%;
  top: 18%;
  border-radius: 50% 50% 46% 50%;
  background: #1b4332;
}
.scene-walk::before { left: 28%; top: 20%; width: 22%; height: 22%; }
.scene-walk::after {
  left: 24%;
  top: 46%;
  width: 28%;
  height: 40%;
  border-radius: 40% 40% 8% 8%;
}
.scene-picnic::before {
  width: 70%;
  height: 18%;
  left: 15%;
  top: 62%;
  border-radius: 4px;
  background: #2d6a4f;
}
.scene-picnic::after {
  width: 20%;
  height: 20%;
  border-radius: 50%;
  left: 28%;
  top: 28%;
  box-shadow: 22px 6px 0 #1b4332;
  background: #4aba61;
}
.scene-window::before {
  inset: 16% 18% 28% 18%;
  width: auto;
  height: auto;
  border-radius: 3px;
  background: #dce8dc;
  box-shadow: inset 0 0 0 2px #2d6a4f;
}
.scene-window::after {
  width: 16%;
  height: 16%;
  border-radius: 50%;
  left: 42%;
  top: 32%;
  background: #1b4332;
}
.scene-garden::before {
  width: 36%;
  height: 36%;
  border-radius: 50%;
  left: 32%;
  top: 14%;
  background: #2d6a4f;
}
.scene-garden::after {
  width: 18%;
  height: 34%;
  left: 41%;
  top: 48%;
  border-radius: 8px 8px 3px 3px;
  background: #1b4332;
}
.scene-bench::before { left: 18%; top: 22%; width: 22%; height: 22%; }
.scene-bench::after {
  left: 14%;
  top: 68%;
  width: 72%;
  height: 10%;
  border-radius: 2px;
  background: #5a7a62;
}

.eg-upload {
  position: relative;
  height: 100%;
  background: #f7f3ec;
}

.eg-drop {
  position: absolute;
  left: 50%;
  top: 54%;
  width: 58%;
  transform: translate(-50%, -50%);
  border: 1.5px dashed rgba(45, 106, 79, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  padding: 1.05rem 1rem 0.95rem;
  z-index: 2;
}

.eg-drop-title {
  font-family: 'Alegreya', serif;
  font-size: 0.98rem;
  font-weight: 400;
  color: var(--green-dark);
  margin-bottom: 0.2rem;
}

.eg-drop-label {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.eg-progress {
  height: 5px;
  border-radius: 99px;
  background: rgba(27, 67, 50, 0.08);
  overflow: hidden;
}

.eg-progress-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: var(--green-mid);
  transform: scaleX(0);
  transform-origin: left center;
}

.eg-check {
  width: 18px;
  height: 18px;
  margin: 0.7rem auto 0;
  border-radius: 50%;
  background: var(--green-mid);
  opacity: 0;
  transform: scale(0.7);
}

.eg-check::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 4px;
  width: 5px;
  height: 8px;
  border: solid #fff;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

.eg-check {
  position: relative;
}

.eg-fly {
  position: absolute;
  width: 13%;
  opacity: 0;
  z-index: 1;
}

.eg-fly .eg-thumb {
  box-shadow: 0 3px 10px rgba(27, 67, 50, 0.1);
}

.eg-fly-1 { left: 6%; top: 6%; z-index: 0; }
.eg-fly-2 { left: 22%; top: 2%; }
.eg-fly-3 { left: 58%; top: 5%; }
.eg-fly-4 { left: 78%; top: 8%; }
.eg-fly-5 { left: 4%; top: 28%; z-index: 0; }
.eg-fly-6 { left: 82%; top: 26%; }
.eg-fly-7 { left: 10%; top: 48%; }
.eg-fly-8 { left: 76%; top: 50%; }
.eg-fly-9 { left: 18%; top: 68%; }
.eg-fly-10 { left: 62%; top: 70%; }
.eg-fly-11 { left: 38%; top: 4%; z-index: 0; }
.eg-fly-12 { left: 48%; top: 74%; z-index: 0; }

/* Stage 2 keeps its approved choreography, gated on the RUN phase. */
.eg-s2-run .eg-fly-1 { animation: eg-converge 1.05s ease 0.04s forwards; }
.eg-s2-run .eg-fly-2 { animation: eg-converge 1.05s ease 0.10s forwards; }
.eg-s2-run .eg-fly-3 { animation: eg-converge 1.05s ease 0.16s forwards; }
.eg-s2-run .eg-fly-4 { animation: eg-converge 1.05s ease 0.22s forwards; }
.eg-s2-run .eg-fly-5 { animation: eg-converge 1.05s ease 0.28s forwards; }
.eg-s2-run .eg-fly-6 { animation: eg-converge 1.05s ease 0.34s forwards; }
.eg-s2-run .eg-fly-7 { animation: eg-converge 1.05s ease 0.40s forwards; }
.eg-s2-run .eg-fly-8 { animation: eg-converge 1.05s ease 0.46s forwards; }
.eg-s2-run .eg-fly-9 { animation: eg-converge 1.05s ease 0.52s forwards; }
.eg-s2-run .eg-fly-10 { animation: eg-converge 1.05s ease 0.58s forwards; }
.eg-s2-run .eg-fly-11 { animation: eg-converge 1.05s ease 0.64s forwards; }
.eg-s2-run .eg-fly-12 { animation: eg-converge 1.05s ease 0.70s forwards; }
.eg-s2-run .eg-progress-fill { animation: eg-fill 1.1s ease 0.9s forwards; }
.eg-s2-run .eg-check { animation: eg-check-in 0.35s ease 1.85s forwards; }
.eg-s2-run .eg-fly { animation-fill-mode: forwards; }

/* ==================================================================
   STAGE 3–5 ARCHITECTURE
   Shared geometry: the canvas is the laptop screen footprint, the closed book
   is the right half of the open book, and the stage 3 selected rectangle is
   the closed book footprint. Internal motion is driven by monotonic marker
   classes set by the controller, never by long transition-delay chains.
   ================================================================== */

.eg-explainer[data-stage="1"] .eg-laptop,
.eg-explainer[data-stage="2"] .eg-laptop {
  opacity: 1;
}

.eg-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--handoff) ease;
}

.eg-explainer[data-stage="1"] .eg-layer-library,
.eg-explainer[data-stage="2"] .eg-layer-upload {
  opacity: 1;
}

/* ---------- shared canvas ---------- */

.eg-stage-canvas {
  position: absolute;
  left: var(--screen-left);
  top: var(--screen-top);
  width: var(--screen-width);
  height: var(--screen-height);
  z-index: 3;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--handoff) ease;
}

.eg-explainer[data-stage="3"] .eg-stage-canvas,
.eg-explainer[data-stage="4"] .eg-stage-canvas,
.eg-explainer[data-stage="5"] .eg-stage-canvas,
.eg-explainer[data-stage="final"] .eg-stage-canvas {
  opacity: 1;
  visibility: visible;
}

/* Loop reset: kill every in-flight transition inside the canvas so no
   interpolated stage 3–5 value can survive into the next loop. */
.eg-explainer[data-stage="reset"] .eg-stage-canvas,
.eg-explainer[data-stage="reset"] .eg-stage-canvas *,
.eg-explainer[data-stage="1"] .eg-stage-canvas,
.eg-explainer[data-stage="1"] .eg-stage-canvas *,
.eg-explainer[data-stage="2"] .eg-stage-canvas,
.eg-explainer[data-stage="2"] .eg-stage-canvas * {
  transition: none !important;
  animation: none !important;
}

/* Scroll playback never loops, so there is nothing to protect against: let the
   canvas fade out normally when the visitor scrubs backwards from stage 3 into
   stage 2. Its children stay frozen, so they hold their last pose while it goes. */
.eg-explainer.is-scrub[data-stage="1"] .eg-stage-canvas,
.eg-explainer.is-scrub[data-stage="2"] .eg-stage-canvas {
  transition: opacity var(--handoff) ease !important;
}

/* ---------- stage 3: photo selection ---------- */

.eg-pick {
  position: absolute;
  inset: 0;
}

.eg-pick-tile {
  position: absolute;
  width: var(--pick-start-w);
  height: var(--pick-start-h);
  opacity: 1;
  transition:
    left 0.62s ease,
    top 0.62s ease,
    width 0.62s ease,
    height 0.62s ease,
    opacity 0.4s ease;
}

.eg-pick-tile .eg-thumb {
  width: 100%;
  height: 100%;
  box-shadow: 0 3px 10px rgba(27, 67, 50, 0.08);
  outline: 2px solid transparent;
  outline-offset: 0;
  transition: outline-color 0.3s ease, box-shadow 0.3s ease;
}

.eg-pick-mark {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--green-mid);
  opacity: 0;
  transform: scale(0.7);
  z-index: 2;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.eg-pick-mark::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 3px;
  width: 4px;
  height: 7px;
  border: solid #fff;
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(45deg);
}

/* Opening grid: 12 tiles, 4 x 3, no overlap, spanning ~76% of the canvas. */
.eg-pick-tile:nth-child(1)  { left: 11.9%; top: 7%; }
.eg-pick-tile:nth-child(2)  { left: 31.5%; top: 7%; }
.eg-pick-tile:nth-child(3)  { left: 51.1%; top: 7%; }
.eg-pick-tile:nth-child(4)  { left: 70.7%; top: 7%; }
.eg-pick-tile:nth-child(5)  { left: 11.9%; top: 36.6%; }
.eg-pick-tile:nth-child(6)  { left: 31.5%; top: 36.6%; }
.eg-pick-tile:nth-child(7)  { left: 51.1%; top: 36.6%; }
.eg-pick-tile:nth-child(8)  { left: 70.7%; top: 36.6%; }
.eg-pick-tile:nth-child(9)  { left: 11.9%; top: 66.2%; }
.eg-pick-tile:nth-child(10) { left: 31.5%; top: 66.2%; }
.eg-pick-tile:nth-child(11) { left: 51.1%; top: 66.2%; }
.eg-pick-tile:nth-child(12) { left: 70.7%; top: 66.2%; }

.eg-s3-select .eg-pick-tile.is-kept .eg-thumb {
  outline-color: var(--green-mid);
  box-shadow: 0 4px 14px rgba(27, 67, 50, 0.14);
}

.eg-s3-select .eg-pick-tile.is-kept .eg-pick-mark {
  opacity: 1;
  transform: scale(1);
}

/* Sequential pick, bounded inside the s3-select step (1.1s of 1.3s). */
.eg-s3-select .eg-pick-tile:nth-child(2) .eg-thumb,
.eg-s3-select .eg-pick-tile:nth-child(2) .eg-pick-mark { transition-delay: 0s; }
.eg-s3-select .eg-pick-tile:nth-child(5) .eg-thumb,
.eg-s3-select .eg-pick-tile:nth-child(5) .eg-pick-mark { transition-delay: 0.16s; }
.eg-s3-select .eg-pick-tile:nth-child(7) .eg-thumb,
.eg-s3-select .eg-pick-tile:nth-child(7) .eg-pick-mark { transition-delay: 0.32s; }
.eg-s3-select .eg-pick-tile:nth-child(10) .eg-thumb,
.eg-s3-select .eg-pick-tile:nth-child(10) .eg-pick-mark { transition-delay: 0.48s; }
.eg-s3-select .eg-pick-tile:nth-child(11) .eg-thumb,
.eg-s3-select .eg-pick-tile:nth-child(11) .eg-pick-mark { transition-delay: 0.64s; }
.eg-s3-select .eg-pick-tile:nth-child(12) .eg-thumb,
.eg-s3-select .eg-pick-tile:nth-child(12) .eg-pick-mark { transition-delay: 0.8s; }

.eg-s3-dim .eg-pick-tile:not(.is-kept) {
  opacity: 0.2;
}

/* Selected six regroup into the closed-book footprint: x 26–74%, y 22–77%. */
.eg-s3-group .eg-pick-tile:not(.is-kept) {
  opacity: 0;
}

.eg-s3-group .eg-pick-tile.is-kept {
  width: var(--pick-w);
  height: var(--pick-h);
}

.eg-s3-group .eg-pick-tile:nth-child(2) {
  left: var(--closed-x);
  top: var(--closed-y);
}

.eg-s3-group .eg-pick-tile:nth-child(5) {
  left: calc(var(--closed-x) + var(--pick-step-x));
  top: var(--closed-y);
}

.eg-s3-group .eg-pick-tile:nth-child(7) {
  left: calc(var(--closed-x) + 2 * var(--pick-step-x));
  top: var(--closed-y);
}

.eg-s3-group .eg-pick-tile:nth-child(10) {
  left: var(--closed-x);
  top: calc(var(--closed-y) + var(--pick-step-y));
}

.eg-s3-group .eg-pick-tile:nth-child(11) {
  left: calc(var(--closed-x) + var(--pick-step-x));
  top: calc(var(--closed-y) + var(--pick-step-y));
}

.eg-s3-group .eg-pick-tile:nth-child(12) {
  left: calc(var(--closed-x) + 2 * var(--pick-step-x));
  top: calc(var(--closed-y) + var(--pick-step-y));
}

/* Stage 4 ENTER: the cover forms over the rectangle the tiles just made. */
.eg-explainer[data-stage="4"] .eg-pick-tile,
.eg-explainer[data-stage="5"] .eg-pick-tile,
.eg-explainer[data-stage="final"] .eg-pick-tile {
  opacity: 0;
  transition-duration: 0.32s;
}

/* ---------- stage 4–5: one physical book ---------- */

.eg-book {
  position: absolute;
  left: var(--book-left);
  top: var(--book-top);
  width: var(--book-width);
  height: var(--book-height);
  --shift: -25%;
  --lift: 0px;
  --scale: 1;
  transform: translate(var(--shift), var(--lift)) scale(var(--scale));
  perspective: 1600px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 2;
  transition:
    opacity 0.42s ease,
    transform var(--flip) var(--flip-ease);
}

.eg-explainer[data-stage="4"] .eg-book,
.eg-explainer[data-stage="5"] .eg-book {
  opacity: 1;
  visibility: visible;
}

.eg-book-stage {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

/* Both halves are exactly half the container, so closed width is half of open
   width by construction — no width or scale animation is involved. */
.eg-page-static,
.eg-leaf {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 50%;
}

.eg-page-static {
  background: #fff;
  border-radius: 0 5px 5px 0;
  box-shadow: 0 8px 22px rgba(27, 67, 50, 0.1);
}

.eg-spine {
  position: absolute;
  left: 50%;
  top: 4%;
  bottom: 4%;
  width: 5px;
  margin-left: -2.5px;
  background: linear-gradient(90deg, rgba(27, 67, 50, 0.1), rgba(27, 67, 50, 0.03), rgba(27, 67, 50, 0.1));
  opacity: 0;
  transform: translateZ(0.2px);
  transition: opacity 0.4s ease;
}

.eg-leaf {
  transform-style: preserve-3d;
  transform: translateZ(0.6px) rotateY(0deg);
  transform-origin: left center;
  transition: transform var(--flip) var(--flip-ease);
}

.eg-leaf-front,
.eg-leaf-back {
  position: absolute;
  inset: 0;
  background: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 0 5px 5px 0;
  box-shadow: 0 8px 22px rgba(27, 67, 50, 0.12);
  transition: box-shadow 0.5s ease;
}

.eg-leaf-back {
  transform: rotateY(180deg);
  border-radius: 5px 0 0 5px;
}

/* Opening and closing are the same rotation in opposite directions. The
   container shift keeps the visible book centred as the leaf swings. */
.eg-s4-open .eg-leaf { transform: translateZ(0.6px) rotateY(-180deg); }
.eg-s4-open .eg-book { --shift: 0%; }
.eg-s4-open .eg-spine { opacity: 1; }

.eg-s4-close .eg-leaf { transform: translateZ(0.6px) rotateY(0deg); }
.eg-s4-close .eg-book { --shift: -25%; }
.eg-s4-close .eg-spine { opacity: 0; }

.eg-cover-face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12% 16%;
  box-sizing: border-box;
  border-radius: inherit;
  box-shadow: inset 0.3em 0 0 #f4efe6;
}

.eg-cover-title {
  font-family: 'Alegreya', serif;
  font-size: clamp(0.6rem, 1.65vw, 0.84rem);
  font-weight: 400;
  line-height: 1.35;
  color: var(--green-dark);
  text-align: center;
  max-width: 11ch;
}

.eg-page {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 7px;
  padding: 11px;
  box-sizing: border-box;
}

.eg-page-left {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.eg-page-right {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1.25fr 1fr;
}

.eg-slot {
  min-width: 0;
  min-height: 0;
  background: #f4efe6;
  border-radius: 2px;
  overflow: hidden;
}

.eg-slot-wide {
  grid-column: 1 / -1;
}

.eg-slot .eg-thumb {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  opacity: 0;
  transform: translateY(9px) scale(0.94);
  transition: opacity 0.34s ease, transform 0.34s ease;
}

.eg-s4-fill .eg-slot .eg-thumb {
  opacity: 1;
  transform: none;
}

/* Approved placement stagger, bounded inside the s4-fill step (1.12s of 1.4s). */
.eg-s4-fill .eg-page-left .eg-slot:nth-child(1) .eg-thumb { transition-delay: 0s; }
.eg-s4-fill .eg-page-left .eg-slot:nth-child(2) .eg-thumb { transition-delay: 0.13s; }
.eg-s4-fill .eg-page-left .eg-slot:nth-child(3) .eg-thumb { transition-delay: 0.26s; }
.eg-s4-fill .eg-page-left .eg-slot:nth-child(4) .eg-thumb { transition-delay: 0.39s; }
.eg-s4-fill .eg-page-right .eg-slot:nth-child(1) .eg-thumb { transition-delay: 0.52s; }
.eg-s4-fill .eg-page-right .eg-slot:nth-child(2) .eg-thumb { transition-delay: 0.65s; }
.eg-s4-fill .eg-page-right .eg-slot:nth-child(3) .eg-thumb { transition-delay: 0.78s; }

/* ---------- stage 5: finished product ---------- */

.eg-s5-settle .eg-book {
  --lift: -5px;
  transition: opacity 0.42s ease, transform 0.5s ease;
}

.eg-s5-settle .eg-leaf-front {
  box-shadow: 0 15px 32px rgba(27, 67, 50, 0.18);
}

/* The delivery scene sits in the band below the album so the book stays the
   hero. Everything shares one baseline at 94.6% of the canvas. */
.eg-complete-cue {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

/* --- dotted route: a wide, shallow dome drawn with one dashed top border --- */
.eg-route {
  position: absolute;
  left: 41.6%;
  top: 90.3%;
  width: 10.8%;
  height: 4.25%;
  border-top: 1.6px dashed rgba(45, 106, 79, 0.38);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  opacity: 0;
  transform: scaleX(0.5);
  transform-origin: left center;
  transition: opacity 0.4s ease, transform 0.42s ease;
}

/* --- delivery vehicle: cream cargo box, green cab, two dark wheels --- */
.eg-truck {
  position: absolute;
  left: 31.6%;
  top: 85.5%;
  width: 10%;
  height: 9.1%;
  opacity: 0;
  transform: translateX(-80%);
  transition: opacity 0.34s ease, transform 0.68s cubic-bezier(0.32, 0, 0.24, 1);
}

.eg-truck-cargo {
  position: absolute;
  left: 0;
  top: 4%;
  width: 58%;
  height: 66%;
  border-radius: 2px;
  background: #e7dfd2;
  box-shadow: inset 0 -1px 0 rgba(27, 67, 50, 0.07);
}

.eg-truck-cab {
  position: absolute;
  left: 58%;
  top: 26%;
  width: 30%;
  height: 44%;
  border-radius: 1px 5px 2px 2px;
  background: var(--green-mid);
}

.eg-truck-window {
  position: absolute;
  left: 62%;
  top: 31%;
  width: 14%;
  height: 15%;
  border-radius: 1px;
  background: #dce8dc;
}

.eg-truck-wheel {
  position: absolute;
  bottom: 0;
  width: 15%;
  height: 25.3%;
  border-radius: 50%;
  background: var(--green-dark);
}

.eg-wheel-rear  { left: 13%; }
.eg-wheel-front { left: 63%; }

/* --- home: green gable roof over a cream body, with a small shrub --- */
.eg-house {
  position: absolute;
  left: 52.4%;
  top: 82%;
  width: 8.5%;
  height: 12.5%;
  opacity: 0;
  transform: translateY(7px) scale(0.9);
  transform-origin: 50% 100%;
  transition: opacity 0.36s ease, transform 0.36s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.eg-house-roof {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 44%;
  background: var(--green-dark);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.eg-house-body {
  position: absolute;
  left: 11%;
  right: 11%;
  top: 40%;
  bottom: 0;
  border-radius: 1px 1px 2px 2px;
  background: #e7dfd2;
  box-shadow: inset 0 -1px 0 rgba(27, 67, 50, 0.07);
}

.eg-house-door {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 21%;
  height: 33%;
  margin-left: -10.5%;
  border-radius: 2px 2px 0 0;
  background: var(--green-mid);
}

.eg-house-shrub {
  position: absolute;
  left: 89%;
  bottom: 0;
  width: 15%;
  height: 20%;
  border-radius: 50% 50% 26% 26%;
  background: rgba(45, 106, 79, 0.4);
}

/* --- completion badge --- */
/* Sized from the canvas so it scales with everything else, and anchored to the
   house's centre line (82% + 12.5% / 2) so the two stay aligned at any width. */
.eg-complete-check {
  position: absolute;
  left: 63.4%;
  top: 88.25%;
  width: 5%;
  height: calc(5% * var(--canvas-aspect));
  border-radius: 50%;
  background: var(--green-mid);
  box-shadow: 0 5px 16px rgba(27, 67, 50, 0.2);
  opacity: 0;
  transform: translateY(-50%) scale(0.7);
  transition: opacity 0.38s ease, transform 0.38s cubic-bezier(0.34, 1.4, 0.64, 1);
}

/* The tick is clipped out of the full circle box, so its bounding box is
   centred by construction rather than by nudged offsets. */
.eg-complete-check::after {
  content: '';
  position: absolute;
  inset: 0;
  background: #fff;
  clip-path: polygon(
    29.7% 44.8%,
    42.8% 57.9%,
    70.1% 27.1%,
    77.9% 34%,
    43.2% 73.1%,
    22.3% 52.2%
  );
}

.eg-s5-settle .eg-house {
  opacity: 1;
  transform: none;
}

.eg-s5-settle .eg-route {
  opacity: 1;
  transform: scaleX(1);
  transition-delay: 0.16s;
}

.eg-s5-truck .eg-truck {
  opacity: 1;
  transform: translateX(0);
}

.eg-s5-check .eg-complete-check {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* ---------- final statement ---------- */

.eg-finale {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 1.25rem;
  font-family: 'Alegreya', serif;
  font-size: clamp(1.4rem, 4.4vw, 1.8rem);
  font-weight: 400;
  line-height: 1.3;
  color: var(--green-dark);
  opacity: 0;
  transform: translateY(6px) scale(0.985);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.eg-explainer[data-stage="final"] .eg-finale {
  opacity: 1;
  transform: none;
}

/* Book and delivery scene dissolve as the statement arrives — same central
   area, no blank frame, no second copy of the book. */
.eg-explainer[data-stage="final"] .eg-book {
  opacity: 0;
  visibility: visible;
  --scale: 0.98;
  transition: opacity 0.55s ease, transform 0.55s ease;
}

/* Fading the wrapper takes house, route, truck and check out as one piece. */
.eg-explainer[data-stage="final"] .eg-complete-cue {
  opacity: 0;
  transform: scale(0.985);
  transform-origin: 50% 88%;
  transition: opacity 0.45s ease, transform 0.55s ease;
}

@keyframes eg-photo-scroll {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, -50%, 0); }
}

@keyframes eg-scroll-thumb {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, 430%, 0); }
}

@keyframes eg-converge {
  0% { opacity: 0; transform: scale(0.94); }
  18% { opacity: 1; }
  62% { opacity: 1; left: 43.5%; top: 47%; transform: scale(0.52); }
  100% { opacity: 0; left: 43.5%; top: 47%; transform: scale(0.15); visibility: hidden; }
}

@keyframes eg-fill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes eg-check-in {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 640px) {
  .eg-preview-page {
    padding: 4.5rem 1rem 3rem;
  }

  .eg-sidebar {
    display: none;
  }

  .eg-toolbar {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .eg-drop {
    width: 70%;
  }

  .eg-drop-title {
    font-size: 0.9rem;
  }

  .eg-laptop-lid {
    padding: 8px 8px 6px;
  }

  .eg-pick-mark {
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
  }

  .eg-pick-mark::after {
    left: 4px;
    top: 2px;
    width: 3px;
    height: 6px;
  }

  .eg-page {
    gap: 5px;
    padding: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .eg-photo-track,
  .eg-scrollbar-thumb,
  .eg-fly,
  .eg-progress-fill,
  .eg-check,
  .eg-pick-tile,
  .eg-slot .eg-thumb,
  .eg-leaf,
  .eg-book,
  .eg-complete-cue,
  .eg-complete-check,
  .eg-house,
  .eg-truck,
  .eg-route {
    animation: none !important;
    transition: none !important;
  }

  .eg-explainer.is-static .eg-layer,
  .eg-explainer.is-static .eg-stage-canvas,
  .eg-explainer.is-static .eg-book,
  .eg-explainer.is-static .eg-complete-cue {
    opacity: 0;
    visibility: hidden;
    transition: none;
  }

  .eg-explainer.is-static .eg-laptop,
  .eg-explainer.is-static .eg-layer-library {
    opacity: 1;
    visibility: visible;
    transform: none;
  }

  .eg-explainer.is-static .eg-finale {
    position: static;
    opacity: 1;
    transform: none;
    padding: 1.4rem 0 0;
  }

  .eg-explainer.is-static .eg-frame {
    aspect-ratio: auto;
    min-height: 0;
  }

  .eg-explainer.is-static .eg-laptop {
    position: relative;
    top: 0;
  }

  .eg-explainer.is-static .eg-titles,
  .eg-explainer.is-static [data-title="1"] {
    opacity: 1;
    transform: none;
  }
}
