/* Shared — palette, paper texture, wax seal, envelope primitives. */
:root{
  --red:#a31621; --red-deep:#7e1420; --gold:#d4af37; --gold-light:#f3cf5a;
  --cream:#f7efdd; --paper:#fdf8ee; --ink:#3d2c1e; --mint:#9fd3b8;
  --shadow:0 18px 45px rgba(59,32,8,.28);
  /* Motion language — every transition on the site uses these, never raw ease/linear.
   * Only transform and opacity are animated, so nothing drops frames. */
  --dur-1:160ms; --dur-2:240ms; --dur-3:400ms; --dur-4:700ms;
  --ease-out:cubic-bezier(.22,1,.36,1);
  --ease-spring:cubic-bezier(.34,1.45,.64,1);
  --ease-flap:cubic-bezier(.65,.02,.23,1);   /* paper lag: slow, then swings, then settles */
  --ease-page:cubic-bezier(.45,.02,.2,1);    /* book leaf: creep, sweep, land soft */
  /* reusable paper-grain tile (same recipe as .paper-grain, for layering into backgrounds) */
  --noise:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='table' tableValues='0 0.09'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}
*{box-sizing:border-box; -webkit-tap-highlight-color:transparent}
html,body{margin:0;padding:0}
body{
  font-family:"PingFang SC","Microsoft YaHei","Noto Sans SC",system-ui,sans-serif;
  color:var(--ink); background:#e9dfc9;
  background-image:radial-gradient(ellipse at 50% 30%,#f4ecd9 0%,#e7dbc0 55%,#d9c9a6 100%);
  min-height:100dvh;
}
/* Cream paper grain: SVG turbulence noise tiled as an overlay */
.paper-grain{position:relative}
.paper-grain::before{
  content:""; position:absolute; inset:0; pointer-events:none; opacity:.5; mix-blend-mode:multiply;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='table' tableValues='0 0.06'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}
.handwriting{font-family:"Ma Shan Zheng","Caveat","Segoe Script",cursive}
.btn{
  display:inline-block; border:none; cursor:pointer; border-radius:999px;
  padding:12px 26px; font-size:16px; letter-spacing:.06em;
  background:linear-gradient(160deg,var(--red) 0%,var(--red-deep) 100%);
  color:#fdf3da; box-shadow:0 8px 22px rgba(126,20,32,.35), inset 0 1px 0 rgba(255,255,255,.35), inset 0 -2px 5px rgba(0,0,0,.18);
  transition:transform var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
}
.btn:hover{transform:translateY(-1px); box-shadow:0 12px 26px rgba(126,20,32,.4), inset 0 1px 0 rgba(255,255,255,.35)}
.btn:active{transform:translateY(1px) scale(.97); box-shadow:0 4px 12px rgba(126,20,32,.3), inset 0 1px 0 rgba(255,255,255,.25)}
.btn.gold{background:linear-gradient(160deg,#e3bc4f,#b8912c); color:#3d2c1e; box-shadow:0 8px 22px rgba(150,116,32,.35)}
.btn.ghost{background:transparent; color:var(--red-deep); border:1.5px solid var(--red); box-shadow:none}

/* ---- Wax seal (artwork is the CardSeal SVG; this is just the stage) ---- */
.wax-seal{
  position:relative; width:104px; height:104px; user-select:none; touch-action:none;
  /* shadow follows the irregular blob alpha, so it sits on the paper like real wax */
  filter:drop-shadow(0 10px 13px rgba(60,5,12,.45)) drop-shadow(0 2px 3px rgba(60,5,12,.3));
}
.wax-seal>svg{width:100%; height:100%; display:block; overflow:visible}
/* crack pieces: full-seal copies clipped to jagged sectors */
.wax-seal .piece{
  position:absolute; inset:0; display:block; pointer-events:none;
  filter:drop-shadow(0 4px 6px rgba(60,5,12,.35));
  transition:transform .85s cubic-bezier(.3,.6,.4,1), opacity .5s var(--ease-out) .22s;
}
/* staggered, gravity-biased falls — pieces separate, drop, spin, then fade */
.wax-seal .piece.p2{transition-delay:.045s,.265s}
.wax-seal .piece.p3{transition-delay:.075s,.295s}
.wax-seal.cracked{filter:none}
.wax-seal.cracked .piece.p1{transform:translate(-31px,27px) rotate(-17deg); opacity:0}
.wax-seal.cracked .piece.p2{transform:translate(25px,9px) rotate(13deg); opacity:0}
.wax-seal.cracked .piece.p3{transform:translate(15px,40px) rotate(22deg); opacity:0}

/* ---- Envelope ---- */
.envelope{position:relative; width:min(340px,86vw); aspect-ratio:34/24; margin:0 auto; perspective:900px}
.env-back{
  position:absolute; inset:0; border-radius:8px; box-shadow:var(--shadow);
  /* interior shading + paper grain under the card */
  background:
    var(--noise),
    radial-gradient(ellipse 90% 70% at 50% 30%, rgba(120,90,40,.16), rgba(120,90,40,0) 70%),
    linear-gradient(165deg,#f1e5c9,#e2d0ab);
}
.env-card{
  position:absolute; left:5%; top:3%; width:90%; height:92%; border-radius:6px; overflow:hidden;
  transition:transform 1.1s var(--ease-out), opacity var(--dur-3) var(--ease-out); z-index:2;
  box-shadow:0 6px 18px rgba(59,32,8,.25); background:var(--paper);
}
.env-card svg{width:100%; height:100%; display:block}
/* Pocket: three fold panels (left / right / bottom) meeting at the centre,
 * drawn as an SVG so each fold gets its own light and a visible seam */
.env-pocket{
  position:absolute; inset:0; z-index:3; border-radius:8px; pointer-events:none;
  clip-path:polygon(0 32%,50% 66%,100% 32%,100% 100%,0 100%);
  filter:drop-shadow(0 -3px 5px rgba(90,60,20,.20));
  background-image:
    var(--noise),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 340 240' preserveAspectRatio='none'%3E%3Cg stroke='rgba(120,90,40,0.4)' stroke-width='1.2'%3E%3Cpolygon points='0,77 170,158 0,240' fill='%23f2e4c6'/%3E%3Cpolygon points='340,77 170,158 340,240' fill='%23e9d7b4'/%3E%3Cpolygon points='0,240 170,158 340,240' fill='%23efe0c0'/%3E%3C/g%3E%3C/svg%3E");
  background-size:100% 100%, 100% 100%;
}
/* Flap: a 3D wrapper with two faces — cream front, polka-dot lining back */
.env-flap{
  position:absolute; left:0; top:0; width:100%; height:52%; z-index:4;
  transform-origin:top center; transition:transform .95s var(--ease-flap);
  transform-style:preserve-3d;
}
.flap-face{
  position:absolute; inset:0; clip-path:polygon(0 0,100% 0,50% 100%);
  backface-visibility:hidden; -webkit-backface-visibility:hidden; border-radius:8px 8px 0 0;
}
.flap-face.front{
  background:var(--noise), linear-gradient(168deg,#fdf6e3 0%,#f4e7c8 55%,#ecd9b4 100%);
  filter:drop-shadow(0 7px 9px rgba(90,60,20,.28));
}
/* thin gold edge line following the flap tip */
.flap-face.front::after{
  content:""; position:absolute; left:50%; bottom:13%; width:64px; height:3px; border-radius:2px;
  transform:translateX(-50%);
  background:linear-gradient(90deg, rgba(212,175,55,0), #d4af37 22%, #f3cf5a 50%, #d4af37 78%, rgba(212,175,55,0));
  box-shadow:0 1px 2px rgba(120,90,20,.35);
}
.flap-face.back{
  transform:rotateX(180deg);
  /* red polka-dot lining, revealed when the flap opens */
  background:
    radial-gradient(circle at 11px 11px, rgba(255,240,220,.9) 2.4px, transparent 3.1px) 0 0/24px 24px,
    radial-gradient(circle at 23px 23px, rgba(255,240,220,.55) 1.8px, transparent 2.4px) 0 0/24px 24px,
    linear-gradient(200deg,#b3242e,#8e1620);
}
.envelope.open .env-flap{transform:rotateX(178deg); z-index:1}
/* the card waits a beat inside the opened envelope, then slides out */
.envelope.open .env-card{transform:translateY(-58%) scale(.97); transition-delay:.1s,0s}
/* envelope dips and settles the moment the flap releases */
.envelope.open{animation:envSink var(--dur-4) var(--ease-spring)}
@keyframes envSink{0%{transform:translateY(0)} 35%{transform:translateY(5px)} 100%{transform:translateY(0)}}
.envelope .seal-pos{position:absolute; left:50%; top:47%; transform:translate(-50%,-50%); z-index:5; transition:opacity var(--dur-3) var(--ease-out)}
.envelope.open .seal-pos{opacity:0; pointer-events:none}

@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{animation-duration:.01ms !important; transition-duration:.01ms !important}
}
