/* =====================================================================
   CHERUB WAITLIST · ENVELOPE INTRO
   A cobalt envelope, embossed like the closing invitation card, sits on a
   paper screen while the page loads; its wax seal fills from the bottom.
   Then the envelope (style 'plane') or the invitation inside it (style
   'letter') folds into a paper plane that flies onto the page and lands
   on the Join the waitlist button's icon. The page doesn't move: the
   paper screen fades away behind the plane.
   js/intro.js runs it. Timing and the style are `intro` in js/config.js.
   ===================================================================== */

.intro { display: none; }
html.has-intro .intro { display: block; position: fixed; inset: 0; z-index: 1000; pointer-events: auto; }
html.is-sealed { overflow: hidden; }
.intro.is-flying { pointer-events: none; }

/* The paper screen over the page. It fades away as the plane takes off. */
.intro__screen { position: absolute; inset: 0; background-color: var(--intro-screen); transition: opacity 0.8s ease; }
.intro__screen::before { content: ""; position: absolute; inset: 0; background-image: var(--grain-image); background-size: var(--grain-size); opacity: var(--grain-opacity); }
.intro.is-flying .intro__screen { opacity: 0; }
:root { --intro-screen: var(--color-paper); }

.intro__stage { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 22px; }

/* ---------- Envelope -------------------------------------------------- */
/* 30% of the screen's width, never smaller than 280px */
.intro__envelope {
  --env-w: clamp(280px, 30vw, 620px);
  --tip: 52%;   /* how far down the flap's point reaches. If you change it, change 52 in the two paths in index.html and TIP in js/intro.js */
  --seal: clamp(64px, calc(var(--env-w) * 0.25), 150px);  /* wax seal size */
  position: relative; width: var(--env-w); aspect-ratio: 1.45; perspective: 1600px; perspective-origin: 50% 0;
}
.intro__envelope::before {
  content: ""; position: absolute; inset: 0; border-radius: 2px; pointer-events: none;
  box-shadow: 0 2px 4px rgba(10, 18, 60, calc(0.16 * var(--shadow-strength))), 0 30px 60px -24px rgba(10, 18, 60, calc(0.5 * var(--shadow-strength)));
}

/* Envelope paper: cobalt stock with the blind emboss and grain */
.intro-paper { position: absolute; inset: 0; isolation: isolate; background-color: var(--color-cobalt); }
.intro-paper::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image: var(--emboss-image); background-size: auto 115%; background-position: center; background-repeat: repeat-x;
  opacity: var(--emboss-opacity);
  -webkit-mask-image: radial-gradient(ellipse 40% 36% at 50% 56%, rgba(0, 0, 0, var(--emboss-centre)) 0%, #000 100%);
  mask-image: radial-gradient(ellipse 40% 36% at 50% 56%, rgba(0, 0, 0, var(--emboss-centre)) 0%, #000 100%);
}
.intro-paper::after { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; background-image: var(--grain-image); background-size: var(--grain-size); opacity: var(--grain-opacity-band); }

/* Layers, back to front: inside (1), open flap (0, above the envelope's top edge), the
   invitation (2), the front pocket and its details (3), the closed flap and seal (4) */
.intro__inside { position: absolute; inset: 0; z-index: 1; border-radius: 2px; background: linear-gradient(to bottom, #aab2e6, var(--color-cobalt-soft) 55%, #dfe3ff); }
.intro__flap-open { position: absolute; inset: 0; z-index: 0; transform-origin: 50% 0; transform: rotateX(90deg); }
.intro__liner { position: absolute; inset: 0; clip-path: polygon(0 0, 100% 0, 50% var(--tip)); background: linear-gradient(to bottom, #c9cffa, var(--color-cobalt-mist)); }
.intro__pocket, .intro__seams, .intro__flap-shadow, .intro__name { z-index: 3; }
.intro__pocket { clip-path: polygon(0 0, 50% var(--tip), 100% 0, 100% 100%, 0 100%); }
.intro__seams { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.16)); }
.intro__seams path { fill: none; stroke: rgba(0, 6, 70, 0.3); stroke-width: 1.25; vector-effect: non-scaling-stroke; }
.intro__flap-shadow { position: absolute; inset: 0; filter: blur(6px); opacity: calc(0.9 * var(--shadow-strength)); }
.intro__flap-shadow i { position: absolute; inset: 0; background: rgba(0, 4, 60, 0.55); clip-path: polygon(0 0, 100% 0, 50% calc(var(--tip) + 6px)); }
.intro__name {
  position: absolute; left: 0; right: 0; top: calc(var(--tip) + var(--seal) / 2 + var(--env-w) * 0.03); margin: 0; padding-left: 0.22em;
  text-align: center; font: 900 clamp(13px, calc(var(--env-w) * 0.05), 28px) / 1 var(--font-display); letter-spacing: 0.22em; color: #fff;
  text-shadow: 0 1px 0 rgba(0, 6, 80, 0.4);
}

/* Closed flap, hinged at the top edge. In the letter version js/intro.js lifts it to upright,
   where it is edge-on, and the open flap behind the letter folds the rest of the way back. */
.intro__flap { position: absolute; inset: 0; z-index: 4; transform-origin: 50% 0; transform-style: preserve-3d; }
.intro__flap-paper { clip-path: polygon(0 0, 100% 0, 50% var(--tip)); background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.05), rgba(0, 0, 50, 0.1)); }
.intro__flap-edge { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro__flap-edge path { fill: none; stroke: rgba(255, 255, 255, 0.3); stroke-width: 2; vector-effect: non-scaling-stroke; }

/* Wax seal on the flap's point. The bright copy shows from the bottom up as --fill grows. */
.intro__seal {
  --fill: 0;   /* set by js/intro.js, 0 to 1 */
  position: absolute; left: 50%; top: var(--tip); width: var(--seal); aspect-ratio: 1; translate: -50% -50%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  filter: drop-shadow(0 6px 9px rgba(0, 6, 60, calc(0.5 * var(--shadow-strength)))) drop-shadow(0 1px 2px rgba(0, 6, 60, calc(0.55 * var(--shadow-strength))));
}
.intro__seal img { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro__seal-dim { filter: brightness(0.5); }
.intro__seal-fill {
  -webkit-mask-image: linear-gradient(to top, #000 calc(var(--fill) * 108% - 8%), transparent calc(var(--fill) * 108%));
  mask-image: linear-gradient(to top, #000 calc(var(--fill) * 108% - 8%), transparent calc(var(--fill) * 108%));
}
.intro.is-full .intro__seal { animation: seal-pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes seal-pop { 40% { scale: 1.06; } }

/* ---------- The invitation (letter version) --------------------------- */
.intro__letter {
  position: absolute; z-index: 2; left: 6%; right: 6%; top: 5%; height: 88%; padding: 6%; isolation: isolate;
  background: var(--color-surface);
  box-shadow: 0 0 0 1px rgba(10, 18, 60, 0.06), 0 8px 18px -10px rgba(10, 18, 60, calc(0.35 * var(--shadow-strength)));
}
.intro--plane .intro__letter, .intro--plane .intro__inside, .intro--plane .intro__flap-open { display: none; }
/* A faint paper grain, and a thin cobalt frame like a printed invitation */
.intro__letter::after { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; background-image: var(--grain-image); background-size: var(--grain-size); opacity: 0.1; }

.intro__letter::before { content: ""; position: absolute; inset: 4.5%; border: 1px solid rgba(36, 56, 255, 0.3); pointer-events: none; }
.intro__letter-body { display: grid; justify-items: center; gap: calc(var(--env-w) * 0.012); text-align: center; transition: opacity 0.2s ease; }
.intro__letter-body img { width: 24%; height: auto; margin-bottom: calc(var(--env-w) * 0.01); }
.intro__letter-title { margin: 0; font: 900 clamp(15px, calc(var(--env-w) * 0.058), 32px) / 1.05 var(--font-display); letter-spacing: -0.02em; color: var(--color-ink); }
.intro__letter-text { margin: 0; font-size: clamp(11px, calc(var(--env-w) * 0.032), 16px); line-height: 1.3; color: var(--color-ink-muted); }
.intro.is-ready .intro__letter { cursor: pointer; transition: translate 0.3s var(--ease-out); }
.intro.is-ready .intro__letter:hover { translate: 0 -6px; }
.intro.is-folding .intro__letter-body { opacity: 0; }

/* "tap the letter to RSVP", shown once the invitation is out */
.intro__hint { margin: 0; font-size: clamp(1.4rem, 1.1rem + 0.8vw, 1.9rem); opacity: 0; translate: 0 6px; transition: opacity 0.4s ease, translate 0.4s var(--ease-out); pointer-events: none; }
.intro.is-ready .intro__hint { opacity: 1; translate: 0 0; }
.intro--plane .intro__hint { display: none; }

/* ---------- Paper plane and its flight path --------------------------- */
.intro__sky { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.intro__plane { opacity: 0; filter: drop-shadow(0 10px 10px rgba(10, 18, 60, calc(0.3 * var(--shadow-strength)))); }
.intro__plane.is-on { opacity: 1; }
.intro__facet { stroke-width: 1; stroke-linejoin: round; transition: fill 0.35s ease, stroke 0.35s ease; }
/* Folded from the cobalt envelope */
.intro--plane .intro__facet { stroke: rgba(255, 255, 255, 0.28); }
.intro--plane .intro__facet--top { fill: #4a5bff; }
.intro--plane .intro__facet--low { fill: var(--color-cobalt); }
.intro--plane .intro__facet--keel { fill: var(--color-cobalt-deep); }
.intro--plane .intro__facet--sliver { fill: var(--color-cobalt); }
/* Folded from the white invitation */
.intro--letter .intro__facet { stroke: rgba(36, 56, 255, 0.22); }
.intro--letter .intro__facet--top { fill: #ffffff; }
.intro--letter .intro__facet--low { fill: #eef0f7; }
.intro--letter .intro__facet--keel { fill: #d5daea; }
.intro--letter .intro__facet--sliver { fill: #f6f7fb; }
/* Turning white as it settles onto the white icon of the cobalt button */
.intro__plane.is-arriving .intro__facet--top, .intro__plane.is-arriving .intro__facet--sliver { fill: #ffffff; }
.intro__plane.is-arriving .intro__facet--low { fill: #e9ecff; }
.intro__plane.is-arriving .intro__facet--keel { fill: #c9d0ff; }
.intro__plane.is-arriving .intro__facet { stroke: rgba(36, 56, 255, 0.25); }
/* The dashed flight path, drawn behind the plane and faded once it lands */
/* The dashed trail. js/intro.js draws it on this canvas in this colour; each dash fades
   over `trailFade` ms (js/config.js) once the plane has passed it. */
.intro__trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; color: var(--color-cobalt); }

/* ---------- Preview switch (js/intro-switch.js) ---------------------- */
.intro-switch {
  position: fixed; left: 16px; bottom: 16px; z-index: 1100; display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.92); box-shadow: inset 0 0 0 1px var(--color-line), 0 8px 20px -10px rgba(10, 18, 60, calc(0.4 * var(--shadow-strength)));
  font: 500 12px/1 var(--font-ui); color: var(--color-ink-muted);
}
.intro-switch span { margin-right: 4px; }
.intro-switch button { height: 28px; padding: 0 12px; border: 0; border-radius: 999px; background: transparent; font: inherit; color: var(--color-ink); cursor: pointer; }
.intro-switch button:hover { background: var(--color-line-soft); }
.intro-switch button[aria-pressed="true"] { background: var(--color-cobalt); color: #fff; }
@media (max-width: 700px) { .intro-switch { bottom: 84px; } } /* above the bottom dock */
