/* Aly & Mimi — the arrival: envelope, wax seal, opening.
   Owned by the envelope agent. Colours and type come from tokens.css.
   Every moving part animates transform/opacity only; the paper, linen and
   wax are pre-rendered images so the runtime is just composited layers.
   (No @import of tokens.css: the page links it first; importing it again
   loaded the fonts twice in WebKit and added a serial request.)
   Timing: nothing here is timed; every duration and delay of the play lives
   in intro.js and runs through ms() from js/tempo.js (TEMPO 1.3, ?tempo=1 =
   the old speed). Any transition added here must be written
   calc(<base>ms * var(--tempo)). */

#intro {
  position: fixed;
  inset: 0;
  z-index: 95;               /* above everything the page draws (owner round 3: no grain over content): the scene carries its own laid paper and linen, nothing dirties it */
  overflow: hidden;
  background: var(--linen);
  color: var(--sage);
  font-family: var(--font-text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  /* envelope box, set from JS (px) */
  --ew: 273px;
  --eh: 349px;
  --elift: -4vh;
}
.intro-scene:focus-visible { outline: none; }
.intro-scene:focus-visible::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed var(--sage);
  border-radius: 6px;
  opacity: .55;
  pointer-events: none;
}

.intro-scene {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
/* the linen table: the scene's own, and the same on the empty #intro while
   the page's modules load (the stand-in below), so the hand-over is seamless */
.intro-scene,
html.intro-pending #intro:empty,
#intro.is-landed::before {
  background:
    radial-gradient(130% 95% at 16% 6%, rgba(255, 250, 246, .62), rgba(255, 250, 246, 0) 58%),
    linear-gradient(158deg, rgba(0, 0, 0, 0) 42%, rgba(96, 72, 62, .12) 100%),
    url("../assets/envelope/linen.webp") 0 0 / 160px 160px repeat,
    var(--linen);
}
/* the card at rest: the linen moves to a layer with a hole exactly where the
   card lies (--hole, set by intro.js), so whatever the page does with the
   landed card during its fade (the blank card is pixel-identical to the
   hero's paper, so it may simply go), the hero shows through in its place
   and never the linen behind it. Only the linen around the card fades. */
#intro.is-landed,
#intro.is-landed .intro-scene { background: transparent; }
#intro.is-landed::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: var(--hole, none);
  pointer-events: none;
}

/* ---- first paint: the closed envelope, drawn by CSS alone on the empty
   #intro (html.intro-pending, before any script has run), so a guest on a
   slow line sees the envelope with the page's first paint instead of a blank
   blush screen. Colour and shadow paint at once; the linen, laid-paper and
   front textures fill in as they arrive (this rule is also what requests them,
   long before the module graph has loaded). Same box as .env-wrap below: the
   formula mirrors size() in intro.js, so intro.js takes over in place. */
html.intro-pending #intro:empty::before {
  content: "";
  --pw: min(70vw, 36vh, 320px);
  --pvh: 1vh;
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--pw);
  height: calc(var(--pw) * 1.28);
  margin-left: calc(var(--pw) / -2);
  margin-top: calc(var(--pw) * -.64 + max(var(--pvh) * -4, var(--pw) * 1.28 * 1.1484 + 8px - var(--pvh) * 50));
  border-radius: 1.5px;
  background:
    url("../assets/envelope/laid.webp") 0 0 / 160px 160px repeat,
    url("../assets/envelope/env-front.webp") center / 100% 100% no-repeat,
    #e8cbc1;
  box-shadow:
    inset 0 0 0 1px rgba(255, 248, 242, .35),
    inset 0 -1px 0 rgba(96, 62, 52, .10),
    0 1px 2px rgba(96, 62, 52, .16),
    0 10px 22px rgba(96, 62, 52, .20),
    0 26px 48px rgba(96, 62, 52, .18);
  pointer-events: none;
}
@supports (height: 1dvh) {
  /* #intro is position:fixed, inset 0: its height is the dynamic viewport */
  html.intro-pending #intro:empty::before { --pw: min(70vw, 36dvh, 320px); --pvh: 1dvh; }
}

/* the envelope's box: perspective for the turn lives here */
.env-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--ew);
  height: var(--eh);
  margin-left: calc(var(--ew) / -2);
  margin-top: calc(var(--eh) / -2 + var(--elift));
  perspective: 1400px;
  perspective-origin: 50% 50%;
}

/* floats/breathes and later drops; carries the shadow with it */
.env-float {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.env-shadow {
  position: absolute;
  inset: 0;
  border-radius: 2px;
  box-shadow:
    0 1px 2px rgba(96, 62, 52, .16),
    0 10px 22px rgba(96, 62, 52, .20),
    0 26px 48px rgba(96, 62, 52, .18);
  transform-origin: 50% 100%;
}

.env-stage {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
}

/* no overflow clip on the faces: the opened flap lies above the envelope's
   top edge and must stay visible. The faces are swapped at the 90° point of
   the turn by stepped opacity keyframes that run on the compositor together
   with the rotation (Chrome does not cull a face with composited children,
   and a JS swap on a timer is late whenever the main thread is busy). */
.env-face {
  position: absolute;
  inset: 0;
  border-radius: 1.5px;
}

.env-front {
  background:
    url("../assets/envelope/laid.webp") 0 0 / 160px 160px repeat,
    url("../assets/envelope/env-front.webp") center / 100% 100% no-repeat,
    #e8cbc1;
  box-shadow: inset 0 0 0 1px rgba(255, 248, 242, .35), inset 0 -1px 0 rgba(96, 62, 52, .10);
}

.env-name {
  position: absolute;
  left: 7%;
  right: 7%;
  top: 50%;
  transform: translateY(-52%);
  text-align: center;
  text-wrap: balance;
  /* the script the names are written in on the card (owner, 2026-10-06) */
  font-family: var(--font-script);
  font-size: calc(var(--ew) * .128);
  line-height: 1.12;
  letter-spacing: 0;
  color: var(--sage);
  text-shadow: 0 .5px 0 rgba(255, 248, 242, .35);
  /* generous vertical and side margins so the script's swashes are never cut */
  clip-path: inset(-40% 100% -40% -10%);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.env-name small {
  display: block;
  font-size: .74em;
  letter-spacing: 0;
  opacity: .85;
  margin-bottom: .04em;
}

/* the back: pocket, flap, seal. The face itself is a plain painted sheet
   (opacity 0 until the turn passes 90°, never culled: Chromium drops the
   background of a backface-hidden face that also carries a perspective).
   The flap's 3D context lives on the inner wrapper below. */
.env-back {
  transform: rotateY(180deg);
  opacity: 0;
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
  background:
    url("../assets/envelope/laid.webp") 0 0 / 160px 160px repeat,
    url("../assets/envelope/env-back.webp") center / 100% 100% no-repeat,
    #e8cbc1;
  box-shadow: inset 0 0 0 1px rgba(255, 248, 242, .30);
}
.env-front {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
/* flat 3D context with its own perspective so the flap's hinge reads right
   and z-order stays a plain stacking order */
.env-back-3d {
  position: absolute;
  inset: 0;
  perspective: 1100px;
  perspective-origin: 50% 18%;
}

/* the flap's cast shadow on the pocket: a tight rim just outside the arch,
   offset down-right (light from top-left), pre-rendered from the flap's own
   silhouette so the flap reads as a sheet lying on the paper. 720x640 px ==
   1000x889 envelope units. */
.flap-shadow {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 69.44%;
  background: url("../assets/envelope/flap-cast.webp") 0 0 / 100% 100% no-repeat;
  pointer-events: none;
}

.env-flap {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 64.84%;            /* 830 of 1280 envelope units */
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transform: rotateX(0deg);
}
/* no backface culling here: the faces are swapped at 90° by stepped opacity
   keyframes on the compositor, and Chrome drops the inner face under the
   animated turn when culling is on */
.flap-face {
  position: absolute;
  inset: 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.flap-outer { background-image: url("../assets/envelope/flap-outer.webp"); }
.flap-inner {
  background-image: url("../assets/envelope/flap-inner.webp");
  transform: rotateX(180deg);
  opacity: 0;                 /* the liner: shown once the flap passes 90° */
}

/* a thin dried sprig tucked under the wax (pre-rendered engraving, sprig.webp
   from design/envelope/make-sprig.mjs). It rides with the flap until the
   seal lets go of it, then it drops. */
.env-sprig {
  position: absolute;
  left: 23%;
  top: 71%;
  width: 54%;
  aspect-ratio: 300 / 120;
  background: url("../assets/envelope/sprig.webp") center / 100% 100% no-repeat;
  transform: rotate(-33deg);
  transform-origin: 50% 50%;
  pointer-events: none;
}

.env-seal {
  position: absolute;
  left: 35.5%;
  top: 49.6%;               /* centre at (500, 780) units */
  width: 29%;
  aspect-ratio: 1 / 1;
  /* a hair toward the viewer: the wax sits ON the flap. Once the flap is a
     composited 3D layer Chrome depth-sorts a coplanar sibling behind it
     (z-index has no say), and the seal would vanish during the play. */
  transform: translateZ(1px);
  pointer-events: none;
}
/* the wax's cast shadow: tight under the blob, thrown down-right */
.seal-shadow {
  position: absolute;
  inset: 2% -6% -12% 4%;
  border-radius: 50%;
  background: radial-gradient(50% 50% at 50% 50%, rgba(56, 40, 32, .50), rgba(56, 40, 32, .22) 42%, rgba(56, 40, 32, 0) 68%);
  opacity: 1;
}
/* the two halves of the wax, cut along the crack in the images themselves */
.seal-half {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  transform-origin: 50% 50%;
}
.seal-half.is-left  { background-image: url("../assets/envelope/seal-l.webp"); }
.seal-half.is-right { background-image: url("../assets/envelope/seal-r.webp"); }
.seal-flake {
  position: absolute;
  width: 4%;
  height: 3%;
  border-radius: 1px;
  background: var(--sage-deep);
  opacity: 0;
}

/* the card lives outside the 3D stage, in a holder that tracks the envelope.
   The pocket's front (flaps opaque, mouth transparent) is drawn OVER the
   card, so the card is hidden exactly where paper covers it and nowhere
   else — with no clip-path on a moving layer. */
.env-card-holder {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;                 /* shown once the flap passes 90° */
}
.env-pocket {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: url("../assets/envelope/pocket.webp") center / 100% 100% no-repeat;
  pointer-events: none;
}
.env-card {
  position: absolute;
  left: 5%;
  top: 3.5%;
  width: 90%;
  aspect-ratio: 3 / 4;
  transform-origin: 0 0;
  border-radius: 1px;
  background: var(--paper);
  box-shadow:
    0 1px 2px rgba(70, 42, 34, .14),
    0 6px 14px rgba(70, 42, 34, .16),
    0 18px 36px rgba(70, 42, 34, .12);
}
.env-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.intro-prompt {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(50% + var(--eh) / 2 + var(--elift) + 26px);
  text-align: center;
  font-family: var(--font-text);
  font-size: 17px;
  letter-spacing: .04em;
  color: var(--sage);
  opacity: .78;
  pointer-events: none;
}

.intro-skip {
  position: absolute;
  top: max(14px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  min-width: 44px;
  min-height: 44px;
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-family: var(--font-text);
  font-size: 15px;
  letter-spacing: .05em;
  color: var(--sage);
  padding: 10px 12px;
  cursor: pointer;
  opacity: .72;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: rgba(117, 125, 94, .5);
}
.intro-skip:focus-visible { outline: 1px dashed var(--sage); outline-offset: 2px; opacity: 1; }
.intro-skip[hidden] { display: none; }

/* layers are promoted once the scene has faded in (is-armed), not at the
   tap, so promotion and first raster are not paid inside the turn; the
   faces and the card holder sit at opacity 0 (not visibility hidden) so their
   pixels exist before they are needed. Released when the card rests. */
/* the preserve-3d containers promote transform only: will-change: opacity is a
   grouping property and would flatten them (no real perspective in the turn) */
#intro.is-armed .env-float,
#intro.is-armed .env-stage,
#intro.is-armed .env-flap { will-change: transform; }
#intro.is-armed .env-face,
#intro.is-armed .flap-face,
#intro.is-armed .seal-half,
#intro.is-armed .env-sprig,
#intro.is-armed .env-card-holder,
#intro.is-armed .env-pocket,
#intro.is-armed .env-card,
#intro.is-armed .intro-prompt,
#intro.is-armed .intro-skip { will-change: transform, opacity; }

@media (prefers-reduced-motion: reduce) {
  .env-shadow { box-shadow: 0 6px 18px rgba(96, 62, 52, .22); }
}
