/* Opening animations for shared cards (card.html and the editor preview). The scene box is where the card ends up. */
.op { position: relative; width: 100%; }
.op-scene { position: relative; width: 100%; aspect-ratio: 3 / 2; perspective: 1600px; }

/* the card */
.op-card {
  position: absolute; inset: 0; z-index: 2; padding: 0; border: 0; background: none; cursor: default;
  perspective: 2200px; transition: transform .75s cubic-bezier(.3, .1, .2, 1.1), opacity .5s;
}
.op.is-open .op-card { cursor: pointer; }
.op-flipper { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .9s cubic-bezier(.3, .1, .2, 1.15); }
.op.is-flipped .op-flipper { transform: rotateY(180deg); }
.op-face {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 6px;
  box-shadow: var(--shadow); backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--paper);
}
.op-back { transform: rotateY(180deg); }

/* gate: the "Open it" prompt shown before the animation */
.op-gate {
  position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center; padding: 16px; transition: opacity .3s;
}
.op-gate-title { margin: 0; font: 700 clamp(22px, 4.5vw, 34px)/1.15 var(--display); letter-spacing: -.01em; }
.op-gate-from { margin: 0 0 10px; font: 600 clamp(20px, 3.6vw, 28px)/1.2 var(--hand); color: var(--muted); }
.op.is-opening .op-gate { opacity: 0; pointer-events: none; }
.op:not(.op-envelope):not(.op-waxseal):not(.op-scratch):not(.is-opening) .op-card { opacity: 0; transform: scale(.85); }
/* envelope, wax seal and scratch keep the card in view, so their button sits under the scene */
.op-envelope .op-gate, .op-waxseal .op-gate, .op-scratch .op-gate { inset: auto 0 -64px; padding: 0; }

/* ---------- envelope ----------
   Layers, back to front: envelope back (1), card (2), pocket (3), flap (4), seal (5).
   Every layer fills the scene so their translate percentages line up. */
.op-envelope { padding: 24% 0 12%; }  /* room for the open flap above and the envelope below */
.op-env {
  position: absolute; inset: 0; --drop: 16%; transform: translateY(var(--drop));
  transition: transform .55s cubic-bezier(.5, 0, .75, 0), opacity .5s;
  cursor: pointer;
}
.op-env-back { z-index: 1; border-radius: 8px; background: #e2d6bb; box-shadow: var(--shadow); }
.op-env-pocket {
  z-index: 3; border-radius: 8px;
  background:
    linear-gradient(#fbf6ea, #f3ead6) padding-box,
    repeating-linear-gradient(135deg, #c8312f 0 18px, #fbf6ea 18px 26px, #1f4fa0 26px 44px, #fbf6ea 44px 52px) border-box;
  border: 10px solid transparent;
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8%;
}
.op-env-to { font: 600 clamp(22px, 5vw, 40px)/1 var(--hand); color: #23365f; }
.op-env-flap {
  z-index: 4; transform-origin: top;
  background: linear-gradient(#f1e8d3, #ddd0b2);
  clip-path: polygon(0 0, 100% 0, 50% 58%);
  transition: transform .6s cubic-bezier(.4, 0, .2, 1), opacity .5s;
}
.op-env-seal { z-index: 5; pointer-events: none; transition: transform .55s cubic-bezier(.5, 0, .75, 0), opacity .2s; }
.op-env-seal i {
  position: absolute; left: 50%; top: 58%; width: 12%; aspect-ratio: 1; transform: translate(-50%, -66%);
  display: grid; place-items: center; border-radius: 50%; font-style: normal;
  background: radial-gradient(circle at 35% 35%, #d9473f, #9e2320); color: #fbe3d8;
  font-size: clamp(14px, 3vw, 26px); box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
}
.op-envelope:not(.is-opening) .op-env { animation: op-wiggle 3.4s ease-in-out 1.2s infinite; }
@keyframes op-wiggle {
  0%, 84%, 100% { transform: translateY(var(--drop)) rotate(0); }
  88% { transform: translateY(var(--drop)) rotate(-1.4deg); }
  92% { transform: translateY(var(--drop)) rotate(1.2deg); }
  96% { transform: translateY(var(--drop)) rotate(-.5deg); }
}
.op-envelope .op-card { transform: translateY(19%) scale(.9); }
.op-envelope.s-flap .op-env-seal { opacity: 0; }
.op-envelope.s-flap .op-env-flap { transform: translateY(var(--drop)) rotateX(180deg); }
.op-envelope.s-out .op-env-flap { z-index: 0; }
.op-envelope.s-out .op-card { transform: translateY(-36%) scale(.9); transition-duration: .9s; }
.op-envelope.s-drop .op-env { --drop: 95%; opacity: 0; }
.op-envelope.s-drop .op-env-flap { transform: translateY(var(--drop)) rotateX(180deg); }
.op-envelope.s-done .op-card { z-index: 6; transform: none; }
.op-envelope.s-done .op-env { visibility: hidden; }
.op-envelope.s-done { padding: 0; transition: padding .75s cubic-bezier(.3, .1, .2, 1.1); }

/* ---------- air mail swoop ---------- */
.op-airmail.s-go .op-card { animation: op-swoop 1.4s cubic-bezier(.2, .7, .25, 1) both; }
@keyframes op-swoop {
  0% { opacity: 0; transform: translate(70%, -60%) rotate(28deg) scale(.35); }
  15% { opacity: 1; }
  60% { transform: translate(-4%, 6%) rotate(-7deg) scale(1.02); }
  80% { transform: translate(1.5%, -1%) rotate(2deg) scale(1); }
  100% { opacity: 1; transform: none; }
}

/* ---------- confetti ---------- */
.op-confetti.s-go .op-card { animation: op-pop .8s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes op-pop { 0% { opacity: 0; transform: scale(.5) rotate(-6deg); } 100% { opacity: 1; transform: none; } }
.op-fx { position: absolute; inset: 0; pointer-events: none; z-index: 7; overflow: visible; }
.op-bit {
  position: absolute; left: 50%; top: 45%; width: 10px; height: 5px; background: var(--c); border-radius: 1px; opacity: 0;
  animation: op-bit var(--d) cubic-bezier(.15, .7, .4, 1) var(--delay) forwards;
}
.op-bit.round { width: 8px; height: 8px; border-radius: 50%; }
@keyframes op-bit {
  0% { opacity: 1; transform: translate(-50%, -50%) rotate(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y) + 18vmin)) rotate(var(--r)); }
}

/* ---------- floating hearts ---------- */
.op-hearts.s-go .op-card { animation: op-rise 1.1s cubic-bezier(.2, .8, .3, 1) both; }
@keyframes op-rise { 0% { opacity: 0; transform: translateY(8%) scale(.96); } 100% { opacity: 1; transform: none; } }
.op-heart {
  position: absolute; bottom: -10%; left: var(--left); font-size: var(--s); line-height: 1; color: var(--c); opacity: 0; font-style: normal;
  animation: op-heart var(--d) ease-out var(--delay) forwards;
}
@keyframes op-heart {
  0% { opacity: 0; transform: translate(0, 0) scale(.6); }
  15% { opacity: .95; }
  100% { opacity: 0; transform: translate(var(--sway), -70vh) scale(1.1); }
}

/* ---------- wax seal (shared by the wax seal opening and the sealed countdown) ----------
   The seal is SVG (see sealSVG in opening.js), drawn as a top and a bottom half split along one crack.
   Breaking it: a quick press, the crack line runs across, then the halves part. */
.op, .sl {
  --ws-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .12 0 0 0 .1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.wx { position: relative; display: block; width: 100%; aspect-ratio: 1; }
/* app.css outlines every svg for its icons; the seal draws its own strokes */
.wx-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; stroke: none; stroke-width: 0; }
.wx-crack { stroke-dasharray: 100; stroke-dashoffset: 100; opacity: 0; }
.wx-broken .wx-crack, .op-waxseal.s-crack .wx-crack { opacity: 1; stroke-dashoffset: 0; transition: stroke-dashoffset .34s cubic-bezier(.3, 0, .2, 1) .1s, opacity .08s .1s; }
.wx-broken { animation: wx-press .44s ease-in-out; }
.op-waxseal.s-crack .wx-svg { animation: wx-press .44s ease-in-out; }
@keyframes wx-press {
  0% { transform: none; }
  40% { transform: scale(.97); }
  72% { transform: scale(1.006) rotate(-.4deg); }
  100% { transform: none; }
}
/* the sealed countdown: the halves part and fade with the envelope */
.wx-broken .wx-svg { transition: transform .9s cubic-bezier(.3, .1, .3, 1) .42s, opacity .5s ease-in .75s; }
.wx-broken .wx-top { transform: translate(-1%, -12%) rotate(-6deg); opacity: 0; }
.wx-broken .wx-bottom { transform: translate(1%, 5%) rotate(3deg); }
/* chips of wax flaking off along the crack */
.op-chip {
  position: absolute; left: calc(50% + var(--sx)); top: 50%; z-index: 2; width: var(--s); height: var(--s); pointer-events: none;
  background: linear-gradient(135deg, #c2342b, #6a0d0b); opacity: 0;
  animation: op-chip var(--d) cubic-bezier(.4, 0, .9, .6) var(--delay) forwards;
}
@keyframes op-chip {
  0% { opacity: 1; transform: translate(-50%, -50%) rotate(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)); }
}

/* ---------- wax seal opening: an ivory envelope with a navy liner, held shut by the seal ----------
   Layers, back to front: liner (1), card (2), pocket (3), flap shadow (3), flap (4), bottom half of the seal (5).
   The top half of the seal sits on the flap, so it lifts away with it. */
.op-waxseal { padding: 26% 0 12%; }
.op-waxseal .op-card { transform: translateY(19%) scale(.9); }
.ws {
  position: absolute; inset: 0; --drop: 16%; transform: translateY(var(--drop));
  transition: transform .55s cubic-bezier(.5, 0, .75, 0), opacity .5s; cursor: pointer;
}
.ws-back {
  z-index: 1; border-radius: 6px; box-shadow: var(--shadow);
  background: radial-gradient(rgba(214, 178, 104, .5) .8px, transparent 1.4px) 0 0 / 12px 12px, linear-gradient(#22325a, #172441);
  border: 5px solid #efe6d5;
}
.ws-pocket {
  z-index: 3; border-radius: 6px;
  background: var(--ws-grain), linear-gradient(168deg, #f7f1e6, #e9ddc6);
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
}
.ws-pocket::before, .ws-pocket::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.ws-pocket::before { /* the bottom fold, a shade darker */
  background: var(--ws-grain), linear-gradient(#efe5d1, #e2d4b8);
  clip-path: polygon(0 100%, 50% 47%, 100% 100%);
}
.ws-pocket::after { /* a soft line where the fold overlaps the sides */
  background: linear-gradient(rgba(80, 50, 15, .22), rgba(80, 50, 15, .08));
  clip-path: polygon(0 100%, 50% 47%, 100% 100%, 100% 98.6%, 50% 45.4%, 0 98.6%);
}
.ws-to {
  position: absolute; left: 0; right: 0; bottom: 11%; z-index: 1; text-align: center;
  font: italic 600 clamp(22px, 4.6vw, 38px)/1 "Cormorant Garamond", Georgia, serif; color: #3b2b1c; letter-spacing: .01em;
}
.ws-shade { z-index: 3; pointer-events: none; filter: blur(5px); opacity: .5; }
.ws-shade i { position: absolute; inset: 0; background: rgba(60, 35, 10, .6); clip-path: polygon(0 0, 100% 0, 50% 59%); transform: translateY(1.2%); }
.ws-flap { z-index: 4; transform-style: preserve-3d; transform-origin: top; transition: transform .95s cubic-bezier(.45, .05, .25, 1); }
.ws-face {
  position: absolute; inset: 0; border-radius: 6px 6px 0 0; clip-path: polygon(0 0, 100% 0, 50% 56%);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.ws-flap-out { background: var(--ws-grain), linear-gradient(180deg, #faf5ec 0%, #ede2cd 100%); }
.ws-flap-in {
  transform: rotateY(180deg);
  background: radial-gradient(rgba(214, 178, 104, .5) .8px, transparent 1.4px) 0 0 / 12px 12px, linear-gradient(#26375f, #1a2846);
}
.ws-seal { position: absolute; left: 50%; top: 56%; width: 23%; aspect-ratio: 1; transform: translate(-50%, -50%); }
.ws-seal-top { transform: translate(-50%, -50%) translateZ(1px); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.ws-sealbox { z-index: 5; }
/* While it waits, the whole envelope floats gently. Opening freezes the float where it is rather
   than snapping back, so the first movement starts from rest. */
.op-waxseal .op-scene { animation: ws-float 4.4s ease-in-out .8s infinite; }
.op-waxseal.is-opening .op-scene { animation-play-state: paused; }
@keyframes ws-float { 0%, 100% { transform: none; } 50% { transform: translateY(-1.2%); } }
.op-waxseal .op-card { transition: transform 1.05s cubic-bezier(.33, 0, .15, 1), opacity .5s; }
.op-waxseal.s-crack .ws-shade { opacity: 0; transition: opacity .45s ease-out; }
.op-waxseal.s-flap .ws-seal-bot .wx-svg { transform: translateY(2.5%) rotate(1.5deg); transition: transform .8s cubic-bezier(.3, 0, .2, 1); }
.op-waxseal.s-flap .ws-flap { transform: translateY(var(--drop)) rotateX(180deg); }
.op-waxseal.s-out .ws-flap { z-index: 0; }
.op-waxseal.s-out .op-card { transform: translateY(-36%) scale(.9); }
/* The envelope, open flap included, leaves as one layer (see opening.js). Fading the flap on its own
   would flatten its 3D turn and flip its back, with the seal's top half, into view. */
.ws-drop { position: absolute; inset: 0; z-index: 1; pointer-events: none; transition: transform .8s cubic-bezier(.45, 0, .7, .4), opacity .5s ease-in .25s; }
.op-waxseal.s-drop .ws-drop { transform: translateY(55%); opacity: 0; }
.op-waxseal.s-done .op-card { z-index: 6; transform: none; transition-duration: .9s; transition-timing-function: cubic-bezier(.25, .1, .25, 1); }
.op-waxseal.s-done { padding: 0; transition: padding .9s cubic-bezier(.25, .1, .25, 1); }
.op-waxseal.is-open .ws-drop { visibility: hidden; }

/* ---------- scratch to reveal: a silver foil canvas over the card ---------- */
.op-foil {
  position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; border-radius: 6px;
  touch-action: none; cursor: crosshair; transition: opacity .6s;
}
.op-sheen { position: absolute; inset: 0; z-index: 5; border-radius: 6px; overflow: hidden; pointer-events: none; }
.op-sheen::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -50%; width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .6), transparent);
  animation: op-sheen 3.8s ease-in-out 1s infinite;
}
@keyframes op-sheen { 0% { left: -50%; } 45%, 100% { left: 120%; } }
.op-scratch.is-scratching .op-sheen, .op-scratch.is-opening .op-sheen { display: none; }
.op-scratch.s-go .op-foil { opacity: 0; pointer-events: none; }

/* ---------- sealed until a date: closed envelope + countdown ---------- */
.sl { display: flex; flex-direction: column; align-items: center; gap: 22px; width: 100%; }
.sl-scene { position: relative; width: 88%; aspect-ratio: 3 / 2; }
.sl-env {
  position: absolute; inset: 0; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow);
  background:
    var(--ws-grain) padding-box, linear-gradient(#fbf6ea, #f1e7d1) padding-box,
    repeating-linear-gradient(135deg, #c8312f 0 18px, #fbf6ea 18px 26px, #1f4fa0 26px 44px, #fbf6ea 44px 52px) border-box;
  border: 10px solid transparent;
  transition: transform .75s cubic-bezier(.45, 0, .7, .4), opacity .5s ease-in .2s;
}
.sl-scene { animation: sl-float 4.5s ease-in-out infinite; }
.sl.is-cracking .sl-scene { animation-play-state: paused; }
.sl-env::before { /* the bottom fold */
  content: ""; position: absolute; inset: 0; background: linear-gradient(#f3ead6, #e9dcc0);
  clip-path: polygon(0 100%, 50% 46%, 100% 100%);
}
.sl-flap {
  position: absolute; inset: 0; z-index: 1; transform-origin: top;
  background: linear-gradient(#efe4cc, #dccdab); clip-path: polygon(0 0, 100% 0, 50% 60%);
  transition: transform .85s cubic-bezier(.45, .05, .25, 1);
}
.sl-to { position: absolute; left: 0; right: 0; bottom: 9%; z-index: 1; text-align: center; font: 600 clamp(22px, 5vw, 40px)/1 var(--hand); color: #23365f; }
.sl-wx { position: absolute; left: 50%; top: 60%; width: 22%; z-index: 2; transform: translate(-50%, -62%); }
.sl.is-due .sl-wx { animation: sl-pulse .9s ease-in-out infinite; }
@keyframes sl-pulse { 50% { transform: translate(-50%, -62%) scale(1.08); } }
@keyframes sl-float { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-2%) rotate(-.4deg); } }
.sl.is-cracking .sl-flap { transform: rotateX(180deg); transition-delay: .4s; }
.sl.is-gone .sl-env { transform: translateY(26%) scale(.94); opacity: 0; }
.sl-info { transition: opacity .5s ease-in-out .45s; }
.sl.is-cracking .sl-info { opacity: 0; }

/* every scene eases in rather than popping in, including the opening that follows the countdown */
.op, .sl { animation: op-in .5s ease-out; }
@keyframes op-in { from { opacity: 0; } }
.sl .op-fx { z-index: 3; }

.sl-info { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; max-width: 560px; }
.sl-info p { margin: 0; }
.sl-title { font: 700 clamp(22px, 4.2vw, 30px)/1.15 var(--display); letter-spacing: -.01em; }
.sl-title span { display: block; margin-top: 4px; font: 600 clamp(20px, 3.4vw, 26px)/1.2 var(--hand); color: var(--muted); }
.sl-count { display: flex; gap: 8px; justify-content: center; margin: 4px 0; }
.sl-count span {
  display: flex; flex-direction: column; align-items: center; min-width: 66px; padding: 10px 6px 8px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
}
.sl-count b { font: 700 30px/1 var(--display); font-variant-numeric: tabular-nums; }
.sl-count i { font-style: normal; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 5px; }
.sl-when { font-size: 15.5px; }
.sl-local, .sl-hint { color: var(--muted); font-size: 13.5px; }
@media (max-width: 420px) { .sl-count span { min-width: 58px; } .sl-count b { font-size: 24px; } }

/* reduced motion: a quick fade, no particles */
.op.is-reduced .op-card { animation: none !important; transition: opacity .3s; transform: none !important; opacity: 1 !important; z-index: 5; }
.op.is-reduced .op-env, .op.is-reduced .ws,
.op.is-reduced .op-foil, .op.is-reduced .op-sheen { display: none; }
.op.is-reduced { padding: 0; }
@media (prefers-reduced-motion: reduce) {
  .op-flipper { transition: none; }
  .op-env, .op-env-top, .ws, .op-scene, .op, .sl, .sl-scene, .op-sheen::after, .sl-env, .sl-wx { animation: none !important; }
}
