/* ═══════════════════════════════════════════════════════════
   opening.css — Envelope Scene · Folds · Seal · Cover Text
   ═══════════════════════════════════════════════════════════ */

/* ── Opening Overlay ──────────────────────────────────────── */
.opening {
  position: fixed;
  inset: 0;
  z-index: 30;
  width: min(100%, var(--max-width));
  height: 100svh;
  height: 100dvh;
  margin: auto;
  background: var(--burgundy);
  overflow: clip;
  isolation: isolate;
  opacity: 1;
  visibility: visible;
  transition: opacity 1s ease, visibility 1s;
  box-shadow: 0 0 80px #2c081a40;
}
.opening.finished {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── Stage ────────────────────────────────────────────────── */
.opening-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  container-type: inline-size;
  perspective: 1600px;
}

/* ── Destination (hero revealed behind opening envelope) ──── */
.opening-destination {
  position: absolute;
  inset: 0;
  background: url('../assets/images/palace-hero.webp') center / cover;
  transform: scale(1.055);
}

/* ── Envelope Scene ───────────────────────────────────────── */
.envelope-scene {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100cqw, 56.25svh);
  height: max(100svh, 177.778cqw);
  width: max(100cqw, 56.25dvh);
  height: max(100dvh, 177.778cqw);
  transform: translate(-50%, -50%);
  perspective: 1800px;
  isolation: isolate;
}

/* ── Envelope Folds — Photograph divided along real creases ─ */
.envelope-fold {
  position: absolute;
  inset: 0;
  background: url('../assets/stationery/embossed-envelope.webp') center / 100% 100% no-repeat;
  backface-visibility: hidden;
  will-change: transform;
}

/* ── Fold Clip-paths (matching reference geometry exactly) ── */
.envelope-left   { clip-path: polygon(0 10.8%, 50.3% 49.4%, 0 84.5%);         transform-origin: 0 50%;    z-index: 2; }
.envelope-right  { clip-path: polygon(100% 10.8%, 49.7% 49.4%, 100% 84.5%);  transform-origin: 100% 50%; z-index: 2; }
.envelope-bottom { clip-path: polygon(0 84%, 50% 49.1%, 100% 84%, 100% 100%, 0 100%); transform-origin: 50% 100%; z-index: 3; }

/* ── Upper Flap Assembly ──────────────────────────────────── */
.envelope-upper {
  position: absolute;
  inset: 0;
  transform-origin: 50% 0;
  z-index: 4;
  transform-style: preserve-3d;
  will-change: transform;
}
.envelope-top {
  clip-path: polygon(0 0, 100% 0, 100% 11.5%, 50% 49.5%, 0 11.5%);
}

/* ── Wax Seal Button ──────────────────────────────────────── */
.seal-button {
  position: absolute;
  left: 50%;
  top: 49.3%;
  width: 32%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  background: transparent;
  filter: drop-shadow(0 9px 7px #25071170);
  border-radius: 50%;
  backface-visibility: hidden;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}
.seal-face {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}
.seal-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: filter 0.3s;
}
.seal-button:hover img,
.seal-button:focus-visible img {
  filter: brightness(1.15) drop-shadow(0 0 8px #e3c18b80);
}
.seal-button:disabled { pointer-events: none; }
.seal-button:focus,
.seal-button:focus-visible { outline: none; box-shadow: none; }

/* ── Seal Monogram ────────────────────────────────────────── */
.seal-monogram {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.1em;
  padding-top: 0.04em;
  font-family: var(--names);
  font-weight: 400;
  font-style: normal;
  font-size: clamp(32px, 9cqw, 58px);
  line-height: 1;
  color: #e6c17c;
  text-shadow: 0 1px 1px #4e181a, 0 -1px 0 #fff0c7;
  pointer-events: none;
}
.seal-monogram i { font-size: 0.6em; font-style: italic; }

/* ── Cover Lettering ──────────────────────────────────────── */
.cover-lettering {
  position: absolute;
  top: 70%;
  left: 12%;
  width: 76%;
  z-index: 5;
  text-align: center;
  color: #f8e3be;
  pointer-events: none;
  text-shadow: 0 2px 10px #320b1b;
  transition: opacity 0.4s;
}
.cover-lettering p {
  font: 400 clamp(35px, 8.5cqw, 55px) / 1.25 var(--script);
}
.cover-lettering svg {
  display: block;
  width: 38%;
  max-width: 150px;
  margin: 9px auto 0;
  fill: none;
  stroke: #e0bc7d;
  stroke-width: 0.9;
  stroke-linecap: round;
}

/* ── Cover Hint ───────────────────────────────────────────── */
.cover-hint {
  position: absolute;
  width: 100%;
  bottom: max(45px, calc(38px + env(safe-area-inset-bottom, 0px)));
  z-index: 5;
  text-align: center;
  color: #ffe8bf;
  pointer-events: none;
  text-shadow: 0 1px 8px #320b1b;
  transition: opacity 0.35s;
}
.cover-hint p  { font: 9px / 1.8 var(--serif); letter-spacing: 3px; }
.cover-hint span {
  display: block;
  width: 1px;
  height: 25px;
  margin: 15px auto 0;
  background: linear-gradient(#e3c18b, transparent);
}

/* ── Playing State — hide lettering during animation ─────── */
.opening.playing .cover-lettering,
.opening.playing .cover-hint { opacity: 0; }

/* ── Screen-reader status ─────────────────────────────────── */
.opening-status {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* Focus handling on the opening overlay */
.opening:focus,
.opening:focus-visible { outline: none; box-shadow: none; }
.opening:has(.seal-button:focus-visible) .cover-hint p {
  text-decoration: underline;
  text-underline-offset: 5px;
}
