/* Opening: envelope with a wax seal. Theme hooks: --op-bg --env --env-2 --env-edge --env-ink --seal --seal-hi --seal-lo --seal-ink */
.op-envelope {
  /* private aliases: theme values (set on <html>) win, otherwise these defaults */
  --_env: var(--env, color-mix(in srgb, var(--paper) 90%, var(--accent)));
  --_env-2: var(--env-2, color-mix(in srgb, var(--paper) 78%, var(--accent)));
  --_env-edge: var(--env-edge, color-mix(in srgb, var(--_env-2) 85%, black));
  --_seal: var(--seal, #8E2B2B); --_seal-hi: var(--seal-hi, #C9574B); --_seal-lo: var(--seal-lo, #561312); --_seal-ink: var(--seal-ink, #F1D7A1);
  overflow-y: auto; padding: 24px 16px;
}
.op-envelope .op-inner { display: flex; flex-direction: column; align-items: center; gap: 22px; width: min(420px, 100%); margin: auto; transition: opacity .6s ease, transform .9s ease; }
.op-envelope .op-head { display: flex; flex-direction: column; align-items: center; gap: 2px; transition: opacity .5s ease; }
.env { position: relative; width: min(330px, 86vw); aspect-ratio: 330 / 224; margin-top: 26px; perspective: 1100px; }
.env-back { position: absolute; inset: 0; border-radius: 6px; background: var(--_env-2); box-shadow: 0 34px 50px -26px rgba(0, 0, 0, .55), 0 2px 4px rgba(0, 0, 0, .12); }
.env-card {
  position: absolute; inset: 5% 6% auto; height: 90%; z-index: 2; border-radius: 4px; padding: 16px 12px; overflow: hidden;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 -6px 18px -10px rgba(0, 0, 0, .3);
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  transition: transform 1.1s cubic-bezier(.2, .8, .2, 1) .75s;
}
.env-card .op-title { font-size: 12px; }
.env-card .op-names { font-size: clamp(18px, 5.4vw, 24px); line-height: 1.45; }
.env-card .op-date { font-size: 13px; }
.env-card-orn { width: 90px; height: 16px; flex: none; background: var(--accent); -webkit-mask: var(--orn-div) center / contain no-repeat; mask: var(--orn-div) center / contain no-repeat; }
.env-front {
  position: absolute; inset: 0; z-index: 3; border-radius: 0 0 6px 6px;
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  background:
    linear-gradient(to top, rgba(0, 0, 0, .06), transparent 40%),
    conic-gradient(from 0deg at 50% 54%, transparent 0 53.7deg, var(--_env-2) 53.7deg 122deg, var(--_env) 122deg 238deg, var(--_env-2) 238deg 306.3deg, transparent 306.3deg);
}
.env-flap {
  position: absolute; inset: 0 0 auto; height: 60%; z-index: 4; transform-origin: 50% 0;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .16)) drop-shadow(0 6px 10px rgba(0, 0, 0, .08)); /* on the unclipped wrapper so the shadow survives */
  transition: transform .85s cubic-bezier(.55, 0, .3, 1) .2s, z-index 0s .62s;
}
.env-flap::before {
  content: ""; position: absolute; inset: 0; clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(180deg, color-mix(in srgb, var(--_env) 92%, white), var(--_env) 55%, var(--_env-edge));
}
.env-seal {
  position: absolute; left: 50%; top: 60%; z-index: 5; width: 82px; height: 82px; padding: 0; border: 0; background: none; cursor: pointer;
  transform: translate(-50%, -50%); -webkit-tap-highlight-color: transparent; border-radius: 50%;
}
.env-seal::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--_seal-hi); opacity: 0;
  animation: sealPulse 2.4s ease-out infinite;
}
.seal-p {
  position: absolute; inset: 0; display: grid; place-items: center;
  border-radius: 47% 53% 49% 51% / 52% 46% 54% 48%;
  background: radial-gradient(circle at 34% 28%, var(--_seal-hi), var(--_seal) 46%, var(--_seal-lo) 100%);
  box-shadow: 0 5px 12px rgba(0, 0, 0, .38), inset 0 -3px 6px rgba(0, 0, 0, .25), inset 0 2px 3px rgba(255, 255, 255, .22);
  transition: transform .8s cubic-bezier(.3, .6, .4, 1), opacity .8s ease;
}
.seal-p::before { content: ""; position: absolute; inset: 11px; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, .22); box-shadow: inset 0 2px 3px rgba(0, 0, 0, .35), 0 1px 0 rgba(255, 255, 255, .14); }
.seal-p.a { clip-path: polygon(0 0, 52% 0, 46% 22%, 57% 40%, 44% 58%, 55% 77%, 47% 100%, 0 100%); }
.seal-p.b { clip-path: polygon(52% 0, 100% 0, 100% 100%, 47% 100%, 55% 77%, 44% 58%, 57% 40%, 46% 22%); }
.seal-m { position: relative; display: flex; align-items: center; gap: 3px; font-family: var(--display); font-size: 25px; line-height: 1; color: var(--_seal-ink); text-shadow: 0 -1px 0 rgba(0, 0, 0, .4), 0 1px 0 rgba(255, 255, 255, .25); }
.seal-m i { font-style: normal; font-size: .55em; opacity: .85; }
.env-seal:hover .seal-p { transform: scale(1.05); }
.env-seal:focus-visible { outline-offset: 8px; }
@keyframes sealPulse { 0% { transform: scale(.9); opacity: .7; } 80%, 100% { transform: scale(1.35); opacity: 0; } }

/* opening sequence */
.op-envelope.is-opening .env-seal { pointer-events: none; outline: none; }
.op-envelope.is-opening .env-seal::after { display: none; }
.op-envelope.is-opening .seal-p.a { transform: translate(-26px, 46px) rotate(-34deg); opacity: 0; }
.op-envelope.is-opening .seal-p.b { transform: translate(24px, 52px) rotate(28deg); opacity: 0; }
.op-envelope.is-opening .env-flap { transform: rotateX(180deg); z-index: 1; }
.op-envelope.is-opening .env-card { transform: translateY(-56%); }
.op-envelope.is-opening .op-hint, .op-envelope.is-opening .op-head { opacity: 0; }
.op-envelope.is-gone { transform: translateY(-14%); }
.op-envelope.is-gone .op-inner { transform: scale(1.08); }

@media (max-height: 600px) { .env { margin-top: 10px; width: min(280px, 80vw); } .op-envelope .op-inner { gap: 12px; } }
@media (prefers-reduced-motion: reduce) {
  .env-card, .env-flap, .seal-p, .op-envelope .op-inner { transition: none; }
  .op-envelope.is-gone { transform: none; }
}
