/* ==========================================================================
   Envelope (v3) - full-bleed burgundy envelope with gold border and elephant
   seal.  Tall screens use the 9:16 mobile image, wide screens the 16:9
   desktop image; each covers the whole screen.  Shapes, seal position and
   image URLs come from envelope-shapes.css (generated by
   scripts/envelope_v3.py), which must load BEFORE this file.
   RULE: no CSS `transform` on .env-part, .env-flap, .card, .seal-hit,
   .tap-hint, .scroll-hint (GSAP animates them); only .flap-back has a base
   rotateX(180deg).  .env-box has NO z-index / transform / opacity so its
   children share the .stage stacking context with .card.
   Stack: shadow 0 < inside 1 < card 2 < body 3 < flap 4 (1 once open) < seal-hit 5 < tap-hint, scroll-hint 6.
   Load AFTER style.css.
   ========================================================================== */

/* Layout per screen shape.  Font sizes are fractions of the rendered
   envelope width (--bw). */
:root {
  /* wide screens: desktop image (16:9) */
  --env-py: 0.6;
  --ink-left: 22%;
  --ink-w: 56%;
  --dear-top: 20%;
  --dear-k: 0.028;
  --to-top: 26.5%;
  --to-k: 0.047;
  --hint-gap: 1%;
}

@media (max-aspect-ratio: 1/1) {
  :root {
    /* tall screens: mobile image (9:16) */
    --env-py: 0.45;
    --ink-left: 12%;
    --ink-w: 76%;
    --dear-top: 20%;
    --dear-k: 0.075;
    --to-top: 25.5%;
    --to-k: 0.105;
    --hint-gap: 2.6%;
  }
}

/* ---------- Locked scroll ---------- */
html.is-locked,
html.is-locked body {
  overflow: hidden;
  height: 100%;
  overscroll-behavior: none;
}

/* ---------- Stage ---------- */
.stage {
  position: relative;
  height: 100svh;
  overflow: hidden;
  background: var(--page-grain) 0 0 / 220px 220px, var(--page-bg);
}

/* Camera-zoom wrapper: no z-index / CSS transform (GSAP scales it). */
.zoom {
  position: absolute;
  inset: 0;
  transform-origin: 50% 32%;
}

/* ---------- Envelope box = the image, covering the whole screen ---------- */
.env-box {
  --bw: max(100vw, calc(100svh * var(--iw-ih)));
  --bh: calc(var(--bw) / var(--iw-ih));
  position: absolute;
  width: var(--bw);
  height: var(--bh);
  left: calc((100vw - var(--bw)) / 2);
  top: calc((100svh - var(--bh)) * var(--env-py));
}

.env-part {
  position: absolute;
  inset: 0;
}

/* ---------- Soft shadow under the envelope (slides away with it) ---------- */
.env-shadow {
  z-index: 0;
  border-radius: 3px;
  background: #3a0d16;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.55), 0 10px 22px rgba(0, 0, 0, 0.35);
}

/* ---------- Inside of the envelope (seen through the opening) ---------- */
.env-inside {
  z-index: 1;
  background: linear-gradient(180deg, #2c0910 0%, #3d0e17 45%, #4a121c 100%);
  box-shadow: inset 0 40px 70px rgba(0, 0, 0, 0.45);
  clip-path: var(--clip-inside-v);
}

/* ---------- Body: everything outside the V triangle, seal-less photo ---------- */
.env-body {
  z-index: 3;
  background: var(--env-body-img) no-repeat 0 0 / 100% 100%;
  clip-path: var(--clip-body-v);
}

/* ---------- Flap (flips up around its top edge) ---------- */
.env-flap {
  z-index: 4;
  transform-origin: 50% 0%;
  transform-style: preserve-3d;
}

.flap-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flap-front {
  background: var(--env-img) no-repeat 0 0 / 100% 100%;
  clip-path: var(--clip-flap);
}

.flap-back {
  transform: rotateX(180deg);
  clip-path: var(--clip-flap-back);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.05'/%3E%3C/svg%3E") 0 0 / 220px 220px,
    linear-gradient(0deg, #4f1a24, #63232e);
}

/* ---------- Ink printed on the flap ---------- */
.env__dear,
.env__to {
  position: absolute;
  left: var(--ink-left);
  width: var(--ink-w);
  margin: 0;
  /* room for script descenders and swashes: background-clip:text only paints inside the box (Safari clips the "y" otherwise) */
  padding: 0.05em 0.2em 0.35em;
  box-sizing: border-box;
  text-align: center;
  color: #e8cd8c;
  background: linear-gradient(180deg, #f6e3a6 0%, #d9b45f 55%, #b8862f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.35));
  font-family: var(--f-script);
  pointer-events: none;
}

.env__dear {
  top: var(--dear-top);
  font-size: calc(var(--bw) * var(--dear-k));
}

.env__to {
  top: var(--to-top);
  font-size: calc(var(--bw) * var(--to-k));
  line-height: 1.15;
}

/* ---------- Seal hit area ---------- */
.env-box .seal-hit {
  inset: auto;
  z-index: 5;
  width: var(--seal-w);
  aspect-ratio: 1;
  left: calc(var(--seal-x) - var(--seal-w) / 2);
  top: calc(var(--seal-y) - var(--seal-h) / 2);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.seal-hit:focus {
  outline: none;
}

.seal-hit:focus-visible {
  outline: 3px solid rgba(184, 134, 47, 0.8);
  outline-offset: 6px;
}

.seal-hit::after {
  content: "";
  position: absolute;
  inset: -6%;
  border-radius: 50%;
  border: 2px solid rgba(246, 227, 166, 0.85);
  box-shadow: 0 0 18px rgba(246, 227, 166, 0.45);
  pointer-events: none;
  animation: seal-ring 2.4s ease-out infinite;
}

.seal-hit.is-opened::after {
  animation: none;
  opacity: 0;
}

@keyframes seal-ring {
  0%   { transform: scale(0.92); opacity: 0.9; }
  100% { transform: scale(1.12); opacity: 0; }
}

/* ---------- Hints ---------- */
.tap-hint,
.scroll-hint,
.next-hint {
  position: absolute;
  margin: 0;
  text-align: center;
  pointer-events: none;
}

.tap-hint {
  left: 10%;
  width: 80%;
  top: calc(var(--seal-y) + var(--seal-h) / 2 + var(--hint-gap));
  z-index: 6;
  font-family: var(--f-body);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: #e3c98f;
  animation: tap-hint-pulse 2s ease-in-out infinite;
}

@keyframes tap-hint-pulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

.scroll-hint,
.next-hint {
  left: 0;
  right: 0;
  bottom: calc(max(4svh, env(safe-area-inset-bottom)) + 8px);
  z-index: 6;
  color: #e3c98f;
  opacity: 0;
  visibility: hidden;
}

.scroll-hint span,
.next-hint span {
  display: block;
}

/* Shown once the card has turned: the same hint, as a button that scrolls on to the
   next section.  The padding enlarges the tap area, so bottom drops by the same 10px. */
.next-hint {
  bottom: calc(max(4svh, env(safe-area-inset-bottom)) - 2px);
  width: max-content;
  margin: 0 auto;
  padding: 10px 18px;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
}

.scroll-hint__chevron {
  display: block;
  width: 14px;
  height: 14px;
  margin: 6px auto 0;
  border-right: 2px solid #d4a64a;
  border-bottom: 2px solid #d4a64a;
  transform: rotate(45deg);
  animation: chevron-bounce 1.6s ease-in-out infinite;
}

@keyframes chevron-bounce {
  0%, 100% { transform: rotate(45deg) translate(0, 0); opacity: 0.6; }
  50%      { transform: rotate(45deg) translate(4px, 4px); opacity: 1; }
}

/* ---------- Reduced motion ---------- */
/* Both card faces are stacked here, so the stage grows to fit them. */
html.reduced-motion .stage {
  height: auto;
  overflow: visible;
  padding: max(24px, env(safe-area-inset-top)) 0 24px;
}
html.reduced-motion .zoom {
  position: static;
}
html.reduced-motion .env-box,
html.reduced-motion .scroll-hint,
html.reduced-motion .next-hint {
  display: none;
}
