/* The opening experience: envelope → card slides out → card opens to the note (videos start playing). */
body.opening { min-height: 100svh; background: radial-gradient(130% 80% at 50% 0%, var(--tint-2), var(--tint) 50%, var(--cream)); overflow-x: hidden; }
.o-logo { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: var(--ink); font: var(--display-weight) 19px/1 var(--display); font-variation-settings: var(--display-vary); z-index: 5; }
.o-logo .wm { font-size: 22px; }
.stage { position: relative; min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 64px 16px 40px; perspective: 1600px; }
.stage.waiting { text-align: center; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
.o-head { text-align: center; max-width: 560px; margin-bottom: 26px; transition: opacity .5s ease, transform .5s ease; }
.o-head h1 { font-size: clamp(28px, 7vw, 44px); margin-bottom: 6px; }
.o-head p { color: var(--ink-soft); font-size: 17px; margin: 0; }
[data-state="opening"] .o-head { opacity: 0; transform: translateY(-14px); }
[data-state="out"] .o-head, [data-state="card"] .o-head, [data-state="open"] .o-head { opacity: 0; transform: translateY(-14px); pointer-events: none; height: 0; margin: 0; overflow: hidden; }

/* ---------- envelope ---------- */
.env { --w: min(86vw, 430px); --env: #F9DCCB; --env-dark: #EFC6AF; --env-light: #FDEBE0; --seal: #D9606E;
  position: relative; display: block; width: var(--w); aspect-ratio: 7 / 5; border: 0; padding: 0; background: none; cursor: pointer;
  animation: envIn .9s cubic-bezier(.2,.9,.25,1.25) both; transform-style: preserve-3d; -webkit-tap-highlight-color: transparent; }
[data-palette="cornflower"] .env { --env: #DCE5F7; --env-dark: #C5D3EF; --env-light: #EAF0FB; }
@keyframes envIn { from { opacity: 0; transform: translateY(-40px) rotate(-6deg) scale(.9); } }
.env:not(.opening):hover { transform: rotate(-1.5deg) translateY(-3px); transition: transform .25s ease; }
.env > span { position: absolute; display: block; }
.env-back { inset: 0; border-radius: 12px; background: var(--env-dark); box-shadow: 0 22px 50px rgba(59,42,36,.22), 0 4px 10px rgba(59,42,36,.1); }
.env-card { left: 7%; right: 7%; top: 6%; height: 125%; border-radius: 6px; overflow: hidden; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); transition: transform .8s cubic-bezier(.3,.7,.2,1); z-index: 1; }
.env-card img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0%; }
.env-pocket { inset: 0; z-index: 2; border-radius: 12px; overflow: hidden;
  background: linear-gradient(160deg, var(--env-light), var(--env) 60%);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%); }
.env-pocket::before { content: ""; position: absolute; inset: 0; background:
  linear-gradient(to top right, transparent 49.6%, rgba(59,42,36,.07) 50%, transparent 50.6%) left bottom / 50.5% 100% no-repeat,
  linear-gradient(to top left, transparent 49.6%, rgba(59,42,36,.07) 50%, transparent 50.6%) right bottom / 50.5% 100% no-repeat; }
.env-to { position: absolute; left: 0; right: 0; bottom: 9%; text-align: center; font: 500 clamp(26px, 7.4vw, 38px)/1.05 var(--hand); letter-spacing: -.02em; color: var(--ink); }
.env-to small { display: block; font: 600 12px/1.6 var(--body); letter-spacing: .02em; color: var(--ink-soft); font-style: normal; }
.env-stamp { position: absolute; right: 6%; bottom: 10%; width: 15%; aspect-ratio: 4 / 5; background: #fff; padding: 4px; border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,.15), inset 0 0 0 2px #fff, inset 0 0 0 3px rgba(226,59,78,.35); transform: rotate(6deg); }
.env-stamp svg { width: 100%; height: 100%; }
.env-flap { left: 0; right: 0; top: 0; height: 60%; z-index: 3; transform-origin: 50% 0; transition: transform .7s cubic-bezier(.5,0,.3,1), z-index 0s .35s;
  background: linear-gradient(180deg, var(--env-light), var(--env));
  clip-path: polygon(0 0, 100% 0, 52% 96%, 50% 100%, 48% 96%); filter: drop-shadow(0 2px 2px rgba(0,0,0,.08)); border-radius: 12px 12px 0 0; }
.env-seal { left: 50%; top: 60%; width: 17%; aspect-ratio: 1; transform: translate(-50%, -62%); z-index: 4; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--seal) 70%, #fff), var(--seal) 60%, color-mix(in srgb, var(--seal) 70%, #000));
  box-shadow: 0 3px 6px rgba(0,0,0,.25), inset 0 -2px 4px rgba(0,0,0,.2); color: rgba(255,255,255,.85); display: grid; place-items: center;
  transition: transform .35s cubic-bezier(.5,-0.4,.6,1.4), opacity .3s ease; }
.env-seal svg { width: 52%; height: 52%; }
.env-seal::after { content: ""; position: absolute; inset: -5%; border-radius: 50%; border: 3px dashed color-mix(in srgb, var(--seal) 75%, #000); opacity: .35; }
.o-tap { margin: 22px 0 0; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; transition: opacity .3s ease; }
.o-tap::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--primary-dark); animation: ping 1.4s ease-out infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary-dark) 45%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
.env.wiggle { animation: wiggle 2.6s ease-in-out infinite; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 84% { transform: rotate(-2.5deg); } 88% { transform: rotate(2.5deg); } 92% { transform: rotate(-1.5deg); } 96% { transform: rotate(1deg); } }

/* opening */
.env.opening { cursor: default; animation: none; }
.env.opening .env-seal { transform: translate(-50%, -62%) scale(1.25); opacity: 0; }
.env.opening .env-flap { transform: rotateX(180deg); z-index: 0; }
.env.opening ~ .o-tap { opacity: 0; }
.env.pulled .env-card { transform: translateY(-62%); }
.env.leaving { transition: transform .8s cubic-bezier(.6,0,.4,1), opacity .6s ease .2s; transform: translateY(70vh) rotate(8deg); opacity: 0; }

/* ---------- the card ---------- */
.gift { position: relative; display: flex; flex-direction: column; align-items: center; }
.book { --cw: min(76vw, 360px); position: relative; width: var(--cw); aspect-ratio: 5 / 7; transform-style: preserve-3d; cursor: pointer;
  transition: transform 1s cubic-bezier(.45,.05,.25,1); transform-origin: 0 50%; }
.book .page-in, .book .cover, .book .face { position: absolute; inset: 0; border-radius: 6px 12px 12px 6px; }
.page-in { background: #FFFDF9; box-shadow: 0 20px 50px rgba(59,42,36,.2); overflow: hidden; }
.page-in .paper { position: absolute; inset: 0; padding: 14% 12%; display: flex; flex-direction: column; justify-content: center; gap: 12px;
  background: linear-gradient(90deg, rgba(59,42,36,.07), transparent 9%), none; }
.page-in .hand { margin: 0; color: var(--ink); font-family: var(--hand); font-weight: 300; font-size: clamp(19px, 4.9vw, 24px); line-height: 1.35; }
.page-in .to { font-weight: 500; }
.page-in .note { white-space: pre-wrap; word-break: break-word; }
.page-in .sig { text-align: right; margin-top: 6px; }
.page-in .made { position: absolute; left: 0; right: 0; bottom: 5%; display: flex; gap: 6px; align-items: center; justify-content: center; font-size: 11px; color: var(--ink-soft); letter-spacing: .04em; }
.page-in .made .wm { font-size: 12px; letter-spacing: -.02em; }
.cover { transform-origin: 0 50%; transform-style: preserve-3d; transition: transform 1.15s cubic-bezier(.45,.05,.25,1); }
.face { backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.face.front { background: #fff; box-shadow: 0 20px 50px rgba(59,42,36,.25), 0 2px 6px rgba(59,42,36,.12); }
.face.front img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0%; }
.face.back { transform: rotateY(180deg); background: #FFFDF9; box-shadow: 0 20px 50px rgba(59,42,36,.18); }
.face.back .pattern { position: absolute; inset: 0; opacity: .5; background:
  radial-gradient(circle at 20% 30%, var(--primary) 0 3px, transparent 3.5px) 0 0 / 38px 38px,
  radial-gradient(circle at 70% 70%, var(--tint-2) 0 4px, transparent 4.5px) 0 0 / 38px 38px; }
.shine { position: absolute; inset: 0; background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,.55) 45%, transparent 60%); transform: translateX(-120%); pointer-events: none; }
.book.shimmer .shine { animation: shine 1.4s ease .2s; }
@keyframes shine { to { transform: translateX(120%); } }
.book.open { cursor: default; transform: translateX(50%) scale(var(--s, 1)); }
.book.open.inside-only { transform: none; }
.book.open .cover { transform: rotateY(-178deg); }
.book.nudge .cover { animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 0%, 70%, 100% { transform: rotateY(0); } 80% { transform: rotateY(-14deg); } 90% { transform: rotateY(-4deg); } }
.o-hint { margin: 18px 0 0; font-weight: 700; color: var(--ink); }

/* video card */
.vcard { position: relative; width: min(74vw, 340px); aspect-ratio: 9 / 16; border-radius: 22px; overflow: hidden; background: #111; box-shadow: 0 24px 60px rgba(59,42,36,.3); }
.vcard video { width: 100%; height: 100%; object-fit: cover; }
.vplay { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 74px; height: 74px; border-radius: 50%; border: 0; background: rgba(255,255,255,.92); display: grid; place-items: center; color: var(--ink); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.vplay svg { width: 30px; height: 30px; margin-left: 4px; }
.vnote { width: min(80vw, 360px); margin-top: -18px; position: relative; z-index: 2; background: #FFFDF9; border-radius: 10px; padding: 18px 20px; box-shadow: 0 12px 30px rgba(59,42,36,.18); transform: rotate(-1.5deg); opacity: 0; translate: 0 20px; transition: opacity .6s ease .6s, translate .6s ease .6s; }
.gift.shown .vnote { opacity: 1; translate: 0 0; }
.vnote .hand { margin: 0; font-family: var(--hand); font-weight: 300; font-size: 20px; line-height: 1.3; white-space: pre-wrap; }
.vnote .sig { text-align: right; }

/* after */
.o-actions { margin-top: 30px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; animation: fade .5s ease; width: 100%; max-width: 560px; }
.sendon { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 20px; text-align: center; width: 100%; }
.sendon h2 { font-size: 24px; margin-bottom: 4px; }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.share-row .btn { min-height: 46px; padding: 0 20px; }
@media (min-width: 900px) { .book { --cw: min(32vw, 380px); } }
@media (prefers-reduced-motion: reduce) { .env, .book, .cover { transition: none !important; animation: none !important; } }
