#envelope {
  --join-x: 50%;
  --join-y: 48.5%;
  --upper: 0%;
  --lower: 94%;
  --paper: #eedfce;
  --plate: url("assets/embossed-stationery.webp");
  overflow: hidden;
  isolation: isolate;
  background: var(--paper) var(--plate) center / 100% 100% no-repeat;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#envelope.unfolding {background:transparent}
.paper-stage,.paper-fold,.paper-face,.envelope-lining,.seam-light,.seam-reflection {
  position:absolute; inset:0; pointer-events:none;
}
.paper-stage {isolation:isolate}
.envelope-lining {
  background:radial-gradient(ellipse 82% 67% at 50% 50%,#e4c6a4 18%,#ca9f76 70%,#a97d58);
}
.seam-light {
  background:
    radial-gradient(ellipse 11% 7% at 50% 48.5%, #fffcef 4%, #ffe7a9aa 42%, transparent),
    radial-gradient(ellipse 75% 58% at 50% 49%, #ffecba, #f1bf71 28%, #d49c5d 62%, #ba875c 100%);
  opacity:0;
}
.paper-face {
  background:var(--paper) var(--plate) center / 100% 100% no-repeat;
  clip-path:var(--leaf);
}
.petal {
  position:absolute; opacity:0; pointer-events:none;
  background-image:url('assets/pearl-relief.webp'); background-repeat:no-repeat;
}
.unfolding .petal {animation:var(--pulse,petal-bloom) var(--life,.9s) var(--start) both}
@keyframes petal-bloom {0%,100% {opacity:0} 40% {opacity:1}}
@keyframes ray-bloom {
  0% {opacity:0;transform:scale(.38)}
  40% {opacity:1;transform:scale(.92)}
  54% {opacity:.98;transform:scale(1)}
  100% {opacity:0;transform:scale(1)}
}
.paper-face::after {content:''; position:absolute; inset:0; opacity:0}
.paper-face::after {
  background:linear-gradient(171deg,transparent 8%,#fff8eb25 24%,#fff8e50f 37%,#78512d42 55%);
}
.fold-top {
  --leaf:polygon(0 0,100% 0,100% var(--upper),50% var(--join-y),0 var(--upper));
  z-index:4; transform-origin:50% 0;
}
.fold-left {
  --leaf:polygon(0 var(--upper),50% var(--join-y),0 var(--lower));
  z-index:2;
}
.fold-right {
  --leaf:polygon(100% var(--upper),100% var(--lower),50% var(--join-y));
  z-index:2;
}
.fold-bottom {
  --leaf:polygon(0 100%,0 var(--lower),50% var(--join-y),100% var(--lower),100% 100%);
  z-index:1;
}
.wax-seal {
  position:absolute; top:var(--join-y); left:var(--join-x);
  width:clamp(70px,24%,112px); aspect-ratio:1;
  padding:0; border:0; border-radius:50%; background:transparent;
  transform:translate(-50%,-50%); cursor:pointer; pointer-events:auto;
  touch-action:manipulation;
}
.wax-seal img {
  display:block; width:100%; height:100%; object-fit:contain;
  filter:drop-shadow(0 2px 1.4px #53381c53);
}
.wax-seal:focus-visible {outline:2px solid #86623a;outline-offset:6px}
.wax-seal:active img {scale:.98}
.seal-hint {
  position:absolute; top:calc(var(--join-y) + clamp(44px,15vw,67px));
  left:5%; right:5%; z-index:6; pointer-events:none; text-align:center;
  color:#705840; text-shadow:0 1px 5px #fff8e9;
  font:1rem/1.6 var(--arabic); animation:hint-in 1s .45s both;
}
@keyframes hint-in {from {opacity:0;translate:0 3px} to {opacity:1;translate:0 0}}
.seam-reflection {
  z-index:3; opacity:0;
  background:
    radial-gradient(ellipse 5% 2.2% at 50% 48.5%,#fff6dcd9,transparent),
    radial-gradient(ellipse 35% 17% at 50% 48.5%,#ffe5a976 1%,#ffcf7b29 36%,transparent 83%);
  mix-blend-mode:screen;
}
.unfolding .wax-seal {pointer-events:none}
.unfolding .seal-hint {animation:hide-hint .18s both}
@keyframes hide-hint {to {opacity:0}}
/* One acceleration curve for the entire lift. The shadow is pre-rasterized. */
.fold-top::before {
  content:'';position:absolute;inset:0;opacity:0;
  background:url('assets/fold-shadow.webp') center / 100% 100% no-repeat;
}
.unfolding .fold-top {animation:lift-tip 2.85s .84s cubic-bezier(.45,0,.34,1) both}
.unfolding .fold-top::before {animation:fold-shadow 1.7s .84s ease-out both}
.unfolding .wax-seal img {animation:tilt-wax 2.85s .84s cubic-bezier(.45,0,.34,1) both}
@keyframes lift-tip {from{transform:scaleY(1)} to{transform:scaleY(.615)}}
@keyframes tilt-wax {from{transform:scaleY(1)} to{transform:scaleY(1.48)}}
@keyframes fold-shadow {from{opacity:0} to{opacity:1}}
.unfolding .fold-top .paper-face::after {animation:edge-turn 2.5s 1.1s ease both}
@keyframes edge-turn {from {opacity:0} to {opacity:.52}}
.unfolding .seam-light {animation:light-from-fold 2.16s 1.55s ease-in-out both}
@keyframes light-from-fold {0% {opacity:0} 42% {opacity:.68} 75%,100% {opacity:1}}
.unfolding .seam-reflection {animation:reflected-light 1.85s 1.85s ease-in-out both}
@keyframes reflected-light {0% {opacity:0} 64% {opacity:1} 100% {opacity:.5}}
.unfolding .paper-stage {transition:opacity 1.45s cubic-bezier(.4,0,.25,1)}
.exposing .paper-stage {opacity:0}
@media(prefers-reduced-motion:reduce){.seal-hint{animation:none}}
