/* hereby — invitation motion layer, shared by every template.
   1. Ribbon envelope: tap, the ribbon unties, the flap lifts, the envelope slides away and the cover arrives.
   2. Cover entrance and swipe up to enter.
   3. Scroll reveals: each block rises into view in a short stagger; the countdown counts up, then ticks.
   4. Floating music button (only when config.js names a track).
   Uses the individual translate / scale properties so template transforms (tilted cards etc.) are untouched. */

.inv .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- 1. Envelope ---------- */
.inv { --env-paper: url("env-paper.webp"); --env-liner: url("env-liner.webp"); --rib-filter: none; --env-ink: var(--chocolate); --env-stage: #5E4E41; }
.inv-env { position: absolute; inset: 0; z-index: 6; display: none; overflow: hidden; container-type: size; perspective: 1600px; background: var(--env-stage); color: var(--env-ink); -webkit-tap-highlight-color: transparent; }
.inv.env-shut .inv-env { display: block; }
.inv.env-shut .inv-music { display: none; }
.env-wrap { position: absolute; inset: 0; transform-style: preserve-3d; box-shadow: 0 24px 60px rgba(20, 14, 10, 0.4); }
.env-back { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(74, 58, 45, 0.3), rgba(74, 58, 45, 0) 50%), var(--env-liner) center top / cover no-repeat, #E9DCCB; }

/* pocket: everything below the V, with a soft shadow along its top edges */
.env-body { position: absolute; inset: 0; filter: drop-shadow(0 -3px 5px rgba(60, 44, 32, 0.22)); }
.env-pf { position: absolute; inset: 0; background: var(--env-paper) center / cover no-repeat, #F6EEE2; clip-path: polygon(0 0, 50% 47%, 100% 0, 100% 100%, 0 100%); }
.env-pf svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.env-pf path { fill: none; stroke: rgba(74, 58, 45, 0.16); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.env-note { position: absolute; left: 10%; right: 10%; bottom: 13%; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.env-to { font-style: italic; font-size: clamp(16px, 5cqw, 24px); }
.inv[lang="zh-Hant"] .env-to { font-style: normal; letter-spacing: 0.1em; }
.env-names { font-family: var(--hand); font-size: clamp(28px, 10cqw, 52px); line-height: 1.1; }
.env-names em { font-style: normal; font-size: 0.6em; color: var(--rose-deep); padding: 0 0.12em; }
.inv[lang="zh-Hant"] .env-names { font-family: var(--serif); font-size: clamp(22px, 7cqw, 36px); letter-spacing: 0.16em; }
.inv[lang="zh-Hant"] .env-names em { font-family: var(--serif); }

/* flap: the top triangle, hinged at the top edge. Paper outside, the painted liner inside. */
.env-flap { position: absolute; inset: 0 0 auto 0; height: 100%; transform-origin: 50% 0; filter: drop-shadow(0 4px 6px rgba(60, 44, 32, 0.28)); z-index: 2; }
.env-face, .env-liner { position: absolute; inset: 0; clip-path: polygon(0 0, 100% 0, 50% 57%); }
.env-face { background: var(--env-paper) center / cover no-repeat, #F6EEE2; }
.env-liner { background: var(--env-liner) center bottom / cover no-repeat, #E9DCCB; clip-path: polygon(0 57%, 100% 57%, 50% 0); transform: scaleY(-1); transform-origin: 50% 28.5%; opacity: 0; }

/* ribbon: a band across the flap's tip in two halves, tied with a painted bow */
.env-rib { position: absolute; z-index: 3; overflow: hidden; filter: var(--rib-filter) drop-shadow(0 2px 2px rgba(60, 44, 32, 0.25)); }
.env-rib b { position: absolute; background: url("env-ribbon.webp") 0 50% / auto 100% repeat-x; }
.env-rib.h { top: calc(57% - 5cqw); height: 10cqw; width: 50%; }
.env-rib.h.a { left: 0; } .env-rib.h.b { right: 0; }
.env-rib.h b { inset: 0; }
.env-rib.h.b b { background-position: 100% 50%; }
.env-bow { position: absolute; z-index: 4; left: 50%; top: 57%; width: 54cqw; aspect-ratio: 700 / 520; translate: -50% -38%; background: url("floral-bow.webp") center / contain no-repeat; filter: var(--rib-filter) drop-shadow(0 4px 5px rgba(60, 44, 32, 0.3)); animation: env-breathe 2.8s ease-in-out infinite; }
@keyframes env-breathe { 0%, 100% { scale: 1; } 50% { scale: 1.04; } }

.env-tap { position: absolute; inset: 0; z-index: 7; border: none; background: transparent; cursor: pointer; }
.env-tap:focus-visible { outline: 2px solid var(--rose-deep); outline-offset: -6px; }
.env-hint { position: absolute; z-index: 7; left: 0; right: 0; bottom: max(4%, 18px); text-align: center; pointer-events: none; font-size: 13px; font-weight: 600; letter-spacing: 0.24em; text-transform: uppercase; color: var(--env-ink); animation: env-hint 2.4s ease-in-out infinite; }
.inv[lang="zh-Hant"] .env-hint { font-size: 15px; font-weight: 400; letter-spacing: 0.4em; }
@keyframes env-hint { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
.env-skip { z-index: 8; color: var(--env-ink); }

/* the opening, about 3 s */
.inv.env-opening .env-tap, .inv.env-opening .env-skip { pointer-events: none; }
.inv.env-opening .env-hint, .inv.env-opening .env-skip { opacity: 0; transition: opacity 0.3s ease; }
.inv.env-opening .env-wrap { animation: env-step-back 3s cubic-bezier(0.45, 0, 0.2, 1) forwards; }
.inv.env-opening .env-bow { animation: env-untie 0.8s cubic-bezier(0.5, 0, 0.75, 0) forwards; }
.inv.env-opening .env-rib.h.a b { animation: env-slide-l 0.95s cubic-bezier(0.55, 0, 0.7, 0.2) 0.2s forwards; }
.inv.env-opening .env-rib.h.b b { animation: env-slide-r 0.95s cubic-bezier(0.55, 0, 0.7, 0.2) 0.2s forwards; }
.inv.env-opening .env-flap { animation: env-flap 1.1s cubic-bezier(0.4, 0, 0.2, 1) 0.85s forwards; }
.inv.env-opening .env-face { animation: env-face 1.1s linear 0.85s forwards; }
.inv.env-opening .env-liner { animation: env-liner 1.1s linear 0.85s forwards; }
.inv.env-opening .inv-env { animation: env-stage 3s ease forwards; }
@keyframes env-untie { 0% { scale: 1; rotate: 0deg; opacity: 1; } 30% { scale: 1.12; rotate: -4deg; opacity: 1; } 100% { scale: 0.5; rotate: 14deg; opacity: 0; translate: -50% -10%; } }
@keyframes env-slide-l { to { translate: -105% 0; opacity: 0.2; } }
@keyframes env-slide-r { to { translate: 105% 0; opacity: 0.2; } }
/* the step back happens first so the lifting flap stays in view */
@keyframes env-step-back { 0% { scale: 1; translate: 0 0; } 25% { scale: 0.8; translate: 0 6%; } 62% { scale: 0.8; translate: 0 6%; opacity: 1; } 100% { scale: 0.86; translate: 0 92%; opacity: 0; } }
@keyframes env-flap { 0% { transform: rotateX(0deg); } 100% { transform: rotateX(-178deg); } }
@keyframes env-face { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes env-liner { 0%, 49% { opacity: 0; } 50%, 100% { opacity: 1; } }
@keyframes env-stage { 0%, 55% { background-color: var(--env-stage); } 100% { background-color: transparent; } }

/* ---------- 2. Cover entrance ---------- */
.inv.cover-in:not(.open) .inv-cover { animation: inv-cover-in 1.3s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.inv.cover-in:not(.open) .inv-cover > * { animation: inv-rise 1s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(2) { animation-delay: 0.08s; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(3) { animation-delay: 0.16s; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(4) { animation-delay: 0.24s; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(5) { animation-delay: 0.32s; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(6) { animation-delay: 0.4s; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(7) { animation-delay: 0.5s; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(8) { animation-delay: 0.6s; }
.inv.cover-in:not(.open) .inv-cover > :nth-child(n+9) { animation-delay: 0.7s; }
@keyframes inv-cover-in { from { scale: 1.05; } }
@keyframes inv-rise { from { opacity: 0; translate: 0 22px; } }

/* ---------- 3. Scroll reveals ---------- */
.inv.rv-on .inv-body [data-rv]:not(.in) { opacity: 0; }
.inv.rv-on .inv-body [data-rv].in { animation: inv-rv 0.95s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; animation-delay: calc(var(--rv-i, 0) * 110ms); }
@keyframes inv-rv { from { opacity: 0; translate: 0 30px; } }
/* a ticking countdown digit drops in */
.inv-count b.flip { animation: inv-flip 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes inv-flip { from { translate: 0 -35%; opacity: 0; } }

/* ---------- 4. Music ---------- */
.inv-music { position: absolute; z-index: 5; left: max(14px, env(safe-area-inset-left, 0px)); bottom: max(14px, env(safe-area-inset-bottom, 0px)); width: 46px; height: 46px; padding: 0; display: flex; align-items: center; justify-content: center; border: 1px solid rgba(74, 58, 45, 0.25); border-radius: 50%; background: rgba(248, 243, 233, 0.82); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); color: var(--chocolate); box-shadow: 0 4px 14px rgba(60, 44, 32, 0.18); }
.inv-music[hidden] { display: none; }
.inv-music svg { width: 22px; height: 22px; }
.inv-music[aria-pressed="true"] svg { animation: inv-spin 6s linear infinite; }
.inv-music[aria-pressed="false"]::after { content: ""; position: absolute; width: 26px; height: 1.4px; background: currentColor; rotate: -45deg; }
@keyframes inv-spin { to { rotate: 360deg; } }

/* ---------- Per-template envelope: liner painting, ribbon colour, stage tint ---------- */
.inv[data-layout="rococo"] { --env-liner: url("ro-cover.jpg"); --env-stage: #1E2619; --rib-filter: hue-rotate(115deg) saturate(0.55) brightness(0.62); }
.inv[data-layout="lace"] { --env-liner: url("lace-satin.jpg"); --env-stage: #6B4A50; }
.inv[data-layout="floral"] { --env-liner: url("floral-scatter.jpg"); --env-stage: #8C7466; }
.inv[data-layout="collage"] { --env-liner: url("collage-scene.jpg"); --env-stage: #6F7863; --rib-filter: hue-rotate(75deg) saturate(0.45) brightness(0.85); }
.inv[data-layout="azure"] { --env-liner: url("azure-villa.jpg"); --env-stage: #1F3557; --rib-filter: hue-rotate(232deg) saturate(1.2) brightness(0.55); }
.inv[data-layout="ink"] { --env-stage: #2A2622; --rib-filter: grayscale(1) brightness(0.42) contrast(1.25); }

@media (prefers-reduced-motion: reduce) {
  .env-bow, .env-hint, .inv-music[aria-pressed="true"] svg { animation: none; }
  .inv.env-opening .env-wrap, .inv.env-opening .env-bow, .inv.env-opening .env-rib b, .inv.env-opening .env-flap, .inv.env-opening .env-face, .inv.env-opening .env-liner, .inv.env-opening .inv-env { animation: none; }
  .inv.env-opening .inv-env { opacity: 0; transition: opacity 0.45s ease; }
}

/* ---------- 5. Painted scene bands between sections (two per template, demo-style) ---------- */
.inv { --scene-a: url("sc-floral-a.webp"); --scene-b: url("sc-floral-b.webp"); }
.inv-scene { position: relative; align-self: stretch; margin: -12px calc(50% - min(50cqw, 330px)); aspect-ratio: 3 / 2; overflow: hidden; pointer-events: none;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 22%, #000 78%, transparent 100%); mask-image: linear-gradient(180deg, transparent 0%, #000 22%, #000 78%, transparent 100%); }
.inv-scene i { position: absolute; inset: -9% 0; background: var(--scene-a) center / cover no-repeat; translate: 0 calc(var(--sp, 0) * -7%); will-change: translate; }
.inv-scene[data-scene="b"] i { background-image: var(--scene-b); }
.inv[data-layout="rococo"] { --scene-a: url("sc-rococo-a.webp"); --scene-b: url("sc-rococo-b.webp"); }
.inv[data-layout="lace"] { --scene-a: url("sc-lace-a.webp"); --scene-b: url("sc-lace-b.webp"); }
.inv[data-layout="collage"] { --scene-a: url("sc-collage-a.webp"); --scene-b: url("sc-collage-b.webp"); }
.inv[data-layout="azure"] { --scene-a: url("sc-azure-a.webp"); --scene-b: url("sc-azure-b.webp"); }
.inv[data-layout="ink"] { --scene-a: url("sc-ink-a.webp"); --scene-b: url("sc-ink-b.webp"); }
@media (prefers-reduced-motion: reduce) { .inv-scene i { translate: none; } }
