/* Design: the wallet taken apart (section #design, driven by explode.js).

   Two layouts share the same markup:
   - "still" (the default: no script, no WebGL, model failed, or reduced motion):
     one calm screen with the picture beside the five notes;
   - "scroll" (data-mode="scroll", set by explode.js): a tall track with a
     sticky full-screen stage. Scrolling through the track takes the wallet
     apart; the notes fade in and out beside it.
   .explode-frame boxes are invisible: they mark where the wallet may sit, and
   explode.js fits the camera to them ("start" = assembled, "end" = apart). */

.explode {
  --explode-rail: 132px;         /* length of the progress line */
  position: relative;
  background: var(--bg);
}
.explode-track { position: relative; }
/* Nothing here moves by CSS transition except the canvas fading in: the layout must
   change at once (base.css gives every element a 0.01ms transition under reduced
   motion, which would apply it a frame late), because explode.js measures the new
   layout in the same instant to keep the page from slipping under the reader. */
.explode :not(.explode-canvas) { transition-property: none; }

/* ---------- Still layout ---------- */
.explode-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  align-items: center;
  gap: clamp(24px, 5vw, 88px);
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(96px, 16vh, 168px) var(--gutter);
}
.explode-copy { grid-area: 1 / 1; }
.explode-visual { grid-area: 1 / 2; position: relative; aspect-ratio: 1 / 1; min-width: 0; }
.explode-canvas, .explode-still { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; }
.explode-canvas { display: none; opacity: 0; transition: opacity 1.4s var(--ease-in-out); pointer-events: none; }
.explode-still { object-fit: contain; }
.explode[data-gl] .explode-canvas { display: block; }
.explode[data-gl] .explode-still { display: none; }
.explode[data-state="ready"] .explode-canvas { opacity: 1; }
.explode-frame { position: absolute; inset: 3%; visibility: hidden; pointer-events: none; }

.explode-intro .eyebrow { margin: 0 0 20px; }
.explode-title {
  margin: 0;
  font-size: clamp(44px, 6vw, 92px);
  font-weight: 300;
  line-height: 0.98;
  letter-spacing: -0.015em;
}
.explode-title strong { display: block; font-weight: 600; }

.explode-captions { list-style: none; margin: clamp(36px, 6vh, 64px) 0 0; padding: 0; display: grid; gap: 22px; }
.explode-caption .eyebrow { margin: 0 0 4px; }
/* The number is followed by a real space (so it is read as "01 Charging"); the margin makes up the rest of the gap. */
.explode-num { color: var(--gold); margin-right: 6.5px; }
.explode-line { margin: 0; font-size: clamp(19px, 1.6vw, 22px); font-weight: 300; line-height: 1.3; color: var(--text); text-wrap: balance; }
.explode-progress { display: none; }

/* Quiet loading state: a word and a hairline where the wallet will appear. */
.explode-loading {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  margin: 0; padding-bottom: 14px; color: var(--text-muted);
}
.explode-loading::after {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 56px; height: 1px; margin-left: -28px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  background-size: 200% 100%;
  animation: explode-wait 2.8s var(--ease-in-out) infinite;
}
.explode-loading[hidden] { display: none; }
@keyframes explode-wait { from { background-position: 100% 0; } to { background-position: -100% 0; } }
/* Reduced motion: the hairline stands still, whole, instead of sweeping. */
@media (prefers-reduced-motion: reduce) {
  .explode-loading::after { animation: none; background-size: 100% 100%; }
}

@media (max-width: 820px), (max-aspect-ratio: 4/5) {
  .explode-stage { grid-template-columns: minmax(0, 1fr); padding: 96px var(--gutter) 88px; gap: 28px; }
  .explode-copy { display: contents; }
  .explode-intro { grid-area: 1 / 1; }
  .explode-visual { grid-area: 2 / 1; aspect-ratio: 4 / 5; }
  .explode[data-state="failed"] .explode-visual, .explode:not([data-gl]) .explode-visual { aspect-ratio: 4 / 3; }
  .explode-captions { grid-area: 3 / 1; margin: 0; }
  .explode-title { font-size: clamp(44px, 13vw, 64px); }
}

/* ---------- Scroll layout ---------- */
/* How much scrolling the animation takes: about 2500 px on every screen (so it
   feels the same on a tall window as on a short one), and never more than 2.8
   screens of it. */
.explode[data-mode="scroll"] .explode-track { height: min(380vh, calc(100vh + 2500px)); }
.explode[data-mode="scroll"] .explode-stage {
  position: sticky; top: 0;
  display: block; max-width: none; margin: 0; padding: 0;
  height: 100vh; height: 100svh;
  overflow: hidden; overflow: clip;
}
.explode[data-mode="scroll"] .explode-visual { position: absolute; inset: 0; aspect-ratio: auto; }
.explode[data-mode="scroll"] .explode-frame[data-frame="start"] { inset: 20% 9% 16% 43%; }
.explode[data-mode="scroll"] .explode-frame[data-frame="end"] { inset: max(88px, 10vh) 8% max(40px, 5vh) 42%; }
.explode[data-mode="scroll"] .explode-loading { left: 67%; }
/* A phone held sideways: the screen is short and the taken-apart wallet is tall,
   so its area takes every pixel of height the nav leaves. */
@media (max-height: 520px) {
  .explode[data-mode="scroll"] .explode-frame[data-frame="start"] { inset: 84px 9% 24px 43%; }
  .explode[data-mode="scroll"] .explode-frame[data-frame="end"] { inset: 80px 6% 14px 42%; }
}

.explode[data-mode="scroll"] .explode-copy { display: block; position: absolute; inset: 0; pointer-events: none; }
.explode[data-mode="scroll"] .explode-intro,
.explode[data-mode="scroll"] .explode-captions {
  position: absolute; left: var(--gutter); top: 50%; translate: 0 -50%;
  width: min(34vw, 460px); margin: 0; padding-left: 34px;
}
/* The notes share one place; each starts level with the top of the progress line. */
.explode[data-mode="scroll"] .explode-captions { display: grid; gap: 0; top: calc(50% - var(--explode-rail) / 2); translate: none; }
.explode[data-mode="scroll"] .explode-caption { grid-area: 1 / 1; align-self: start; opacity: 0; }
.explode[data-mode="scroll"] .explode-caption .eyebrow { margin: 0 0 14px; }
.explode[data-mode="scroll"] .explode-line { font-size: clamp(28px, 2.9vw, 44px); line-height: 1.12; letter-spacing: -0.01em; }

/* Progress: a hairline that fills with gold as the wallet opens. */
.explode[data-mode="scroll"] .explode-progress {
  display: block; position: absolute; left: var(--gutter); top: 50%; translate: 0 -50%;
  width: 1px; height: var(--explode-rail); background: var(--line-strong);
}
.explode-progress span {
  position: absolute; inset: 0; background: var(--gold);
  transform-origin: 50% 0; transform: scaleY(var(--explode-p, 0));
}
/* Its tip, in the accent colour: where one is. A plain dot, with no glow round
   it: this colour is bright enough to be seen without one. It is there only
   while the wallet is on its way apart (it comes over the first fiftieth of the
   way and goes over the last). At either end nothing is under way, and the
   part of the page before or after, then partly in view, has an accent of its
   own: with the count on the cart that made three on a phone. */
.explode-progress::after {
  content: ""; position: absolute; left: -2px; top: -2.5px; width: 5px; height: 5px; border-radius: 50%;
  background: var(--pop);
  opacity: clamp(0, min(var(--explode-p, 0), 1 - var(--explode-p, 0)) * 50, 1);
  transform: translateY(calc(var(--explode-p, 0) * var(--explode-rail)));
}

@media (max-width: 820px), (max-aspect-ratio: 4/5) {
  /* Phones: the stack is tall, so it takes the middle of the screen; the
     opening line sits above it and the notes below. */
  .explode[data-mode="scroll"] .explode-frame[data-frame="start"] { inset: 236px 18px 150px 18px; }
  .explode[data-mode="scroll"] .explode-frame[data-frame="end"] { inset: 84px 22px calc(172px + env(safe-area-inset-bottom, 0px)) 22px; }
  .explode[data-mode="scroll"] .explode-loading { left: 50%; top: 46%; }
  .explode[data-mode="scroll"] .explode-intro,
  .explode[data-mode="scroll"] .explode-captions {
    left: var(--gutter); right: var(--gutter); width: auto; translate: none; padding-left: 0;
  }
  .explode[data-mode="scroll"] .explode-intro { top: 92px; }
  .explode[data-mode="scroll"] .explode-captions { top: auto; bottom: calc(44px + env(safe-area-inset-bottom, 0px)); }
  .explode[data-mode="scroll"] .explode-caption { align-self: end; }
  .explode[data-mode="scroll"] .explode-caption .eyebrow { margin: 0 0 8px; }
  .explode[data-mode="scroll"] .explode-line { font-size: clamp(24px, 6.6vw, 30px); }
  .explode[data-mode="scroll"] .explode-progress {
    left: var(--gutter); right: var(--gutter); top: auto; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); translate: none;
    width: auto; height: 1px;
  }
  .explode-progress span { transform-origin: 0 50%; transform: scaleX(var(--explode-p, 0)); }
  .explode-progress::after { left: calc(var(--explode-p, 0) * 100% - 2.5px); top: -2px; transform: none; }
}


/* ---------- Film version (?film=1, see explode.js) ----------
   The wallet's place is fixed inside each film frame, so the page fits round the
   picture: explode.js measures it and sets --film-top (the picture starts lower
   on a short screen, clear of the nav) and --film-copy-max (the notes stay
   narrower than the gap to the left of the wallet). */
.explode-film { top: var(--film-top, 0px); height: calc(100% - var(--film-top, 0px)); }
.explode[data-film="landscape"][data-mode="scroll"] .explode-intro,
.explode[data-film="landscape"][data-mode="scroll"] .explode-captions { width: min(34vw, 460px, var(--film-copy-max, 460px)); }
