/* A Little Piece of Autumn: a Thanksgiving greeting that plays like a small film. One screen, no scrolling; the body's data-s says where the story stands:
   idle -> opening -> unfolding -> forest -> greeting -> message -> complete.
   Lettering from the font library: Imperial Script (the greeting), Forum (small capitals), Spectral (the message). Only transform and opacity are animated. */
:root {
  --gold: #C68A37; --copper: #A64F32; --ivory: #F7EEDC; --green: #354B38; --antique: #D7AD62; --champagne: #F6DFA9; --amber: #B96B32; --burgundy: #713E3D; --dark: #1D3026; --cream: #FFF9ED; --walnut: #513B2C; --sage: #879276;
  --gold-metallic: linear-gradient(125deg, #8B632D 0%, #C68A37 22%, #F6DFA9 42%, #D7AD62 57%, #A97631 78%, #F4D18B 100%);
  --script: 'Imperial Script', 'Snell Roundhand', cursive; --caps: 'Forum', Georgia, serif; --text: 'Spectral', Georgia, 'Times New Roman', serif;
  /* the envelope's width decides the envelope (3 by 2), the folded card inside it and how far the card rises */
  --ew: clamp(230px, min(78vw, 62svh), 520px); --eh: calc(var(--ew) * 2 / 3);
  --cw: calc(var(--ew) * .9); --ch: calc(var(--cw) * 340 / 540);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--dark); color: var(--cream); font-family: var(--text); font-size: 17px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--champagne); outline-offset: 4px; border-radius: 3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pic { display: block; } .pic svg { display: block; width: 100%; height: 100%; }
[hidden] { display: none !important; }

/* ---------- the wood ---------- */
#world { position: fixed; inset: 0; z-index: 0; overflow: hidden; }
#forest { position: absolute; inset: -3%; transition: transform 2.600s cubic-bezier(.3, 0, .2, 1); transform: scale(1); will-change: transform; }
/* seven flat pictures, one over the other. Each is drawn once; from then on only transform and opacity ever change, so nothing is repainted while the greeting plays. */
.fl { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; will-change: transform; -webkit-user-select: none; user-select: none; pointer-events: none; }
#world::after { content: ''; position: absolute; inset: 0; background: #0E1A13; opacity: .26; transition: opacity 2s ease; pointer-events: none; }
/* the layers drift apart with the pointer (--px, --py run from -1 to 1), the near ones furthest */
.fl-sky { transform: translate(calc(var(--px, 0) * -3px), calc(var(--py, 0) * -2px)); }
.fl-far { transform: translate(calc(var(--px, 0) * -7px), calc(var(--py, 0) * -4px)); }
.fl-ground { transform: translate(calc(var(--px, 0) * -11px), calc(var(--py, 0) * -5px)); }
.fl-near { transform: translate(calc(var(--px, 0) * -30px), calc(var(--py, 0) * -14px)); }
.fl-sky, .fl-far, .fl-ground, .fl-near { transition: transform .5s ease-out; }
/* the two halves of the middle wood lean a little in the breeze, out of step with each other; the light drifts across */
.fl-treesL { transform-origin: 20% 80%; animation: swayL 8s ease-in-out infinite alternate; }
.fl-treesR { transform-origin: 80% 80%; animation: swayR 10.500s ease-in-out -3s infinite alternate; }
@keyframes swayL { from { transform: rotate(-.5deg) translateX(-2px); } to { transform: rotate(.6deg) translateX(3px); } }
@keyframes swayR { from { transform: rotate(.5deg) translateX(2px); } to { transform: rotate(-.6deg) translateX(-3px); } }
.fl-beams { opacity: .55; animation: beams 11s ease-in-out infinite alternate; transition: opacity 2s ease; }
@keyframes beams { from { transform: translateX(-1.500%); } to { transform: translateX(2%); } }
/* once the card has opened the wood is the whole world: nearer, the light full, the veil lifted; it dims again behind the message */
body:is([data-s="forest"], [data-s="greeting"], [data-s="message"], [data-s="complete"]) #forest { transform: scale(1.08); }
body:is([data-s="forest"], [data-s="greeting"]) #world::after { opacity: 0; }
body:is([data-s="forest"], [data-s="greeting"], [data-s="message"], [data-s="complete"]) .fl-beams { opacity: .95; }
body:is([data-s="message"], [data-s="complete"]) #world::after { opacity: .36; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#fx-front { position: fixed; z-index: 4; }

/* ---------- the stage ---------- */
#stage { position: fixed; inset: 0; z-index: 2; display: grid; place-items: center; align-content: center; gap: clamp(14px, 3svh, 30px); padding: max(58px, env(safe-area-inset-top)) 16px max(26px, env(safe-area-inset-bottom)); text-align: center; pointer-events: none; }
#stage > * { grid-area: 1 / 1; pointer-events: auto; }
.hello, .cue { position: absolute; left: 0; right: 0; margin: 0; pointer-events: none; transition: opacity .6s ease; text-shadow: 0 2px 14px rgba(12, 22, 16, .8); }
.hello { top: calc(50% - var(--eh) / 2 - clamp(64px, 11svh, 104px)); font-family: var(--script); font-size: clamp(34px, 8vw, 58px); line-height: 1; color: var(--cream); }
.cue { top: calc(50% + var(--eh) / 2 + clamp(26px, 5svh, 46px)); font-family: var(--caps); letter-spacing: .3em; font-size: 14px; color: var(--champagne); animation: cue 2.6s ease-in-out infinite; }
@keyframes cue { 50% { opacity: .45; } }
body:not([data-s="idle"]) .hello, body:not([data-s="idle"]) .cue { opacity: 0; animation: none; }

/* ---------- the envelope. Layers inside .envwrap: glow 0, back 1, the card 2, the pocket 3, the flap 4 (1 once it is open), the button 6.
   The WHOLE wrap floats and comes forward: nothing moves the envelope's own frame while the card lies between its layers. ---------- */
.envwrap { position: relative; display: grid; place-items: center; isolation: isolate; width: var(--ew); height: var(--eh); transition: transform .8s cubic-bezier(.3, 0, .2, 1); will-change: transform; }
.envwrap > * { grid-area: 1 / 1; }
.envwrap.sealed { animation: float 6.5s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(-1.800%) rotate(-2.200deg); } 50% { transform: translateY(2.200%) rotate(1.600deg); } }
.envwrap.s-near { transform: translateY(8%) scale(1.07); }
.envwrap.s-rise { transform: translateY(20%) scale(1.07); }
.envframe { position: relative; width: var(--ew); height: var(--eh); }
.ev { position: absolute; display: block; }
.env-back { inset: 0; z-index: 1; border-radius: 1.400%; box-shadow: 0 calc(var(--ew) * .05) calc(var(--ew) * .1) rgba(8, 16, 11, .6), 0 calc(var(--ew) * .01) calc(var(--ew) * .02) rgba(8, 16, 11, .5); }
.env-front { inset: 0; z-index: 3; }
.env-flapbox { left: 0; top: 0; width: 100%; height: 64.500%; z-index: 4; perspective: 1500px; perspective-origin: 50% 0; }
.flap { position: absolute; inset: 0; transform-origin: 50% 0; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.45, .05, .3, 1); will-change: transform; }
.ff, .fb { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
/* the inside of the flap faces the back without being stood on its head, so the open flap points up from the fold */
.fb { transform: rotateX(180deg) scaleY(-1); }
.seal { position: absolute; left: 50%; top: 96.900%; width: 19%; aspect-ratio: 1; transform: translate(-50%, -50%) translateZ(1px); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
/* the seal's glow is a halo behind it that only fades in (it used to be a filter on the wax itself) */
.seal::before { content: ''; position: absolute; inset: -45%; border-radius: 50%; background: radial-gradient(circle, rgba(255, 244, 210, .95), rgba(246, 223, 169, .5) 40%, transparent 68%); opacity: 0; transition: opacity .3s ease; }
.seal svg { overflow: visible; }
.seal .cracks { opacity: 0; transition: opacity .15s ease; }
.seal .shard { transition: transform .6s cubic-bezier(.2, .7, .3, 1), opacity .6s ease; transform-box: fill-box; transform-origin: 50% 50%; }
.s-glow .seal::before { opacity: 1; }
.s-break .seal::before { opacity: 0; transition-duration: .6s; }
.s-crack .seal .cracks { opacity: 1; }
.s-break .seal .cracks { opacity: 0; }
.s-break .seal .s0 { transform: translate(-70%, -90%) rotate(-50deg); opacity: 0; } .s-break .seal .s1 { transform: translate(90%, -50%) rotate(60deg); opacity: 0; }
.s-break .seal .s2 { transform: translate(60%, 100%) rotate(-40deg); opacity: 0; } .s-break .seal .s3 { transform: translate(-90%, 70%) rotate(45deg); opacity: 0; } .s-break .seal .s4 { transform: scale(1.5); opacity: 0; }
.s-flap .flap { transform: rotateX(178deg); }
.s-back .env-flapbox { z-index: 1; }
.open { inset: -6%; z-index: 6; padding: 0; border: 0; background: none; border-radius: 8px; }
.envwrap:not(.sealed) .open { display: none; }
/* the warm light that escapes from inside, between the liner and the card */
.glowin { z-index: 1; width: 86%; height: 60%; align-self: start; border-radius: 50%; background: radial-gradient(ellipse at 50% 60%, rgba(255, 244, 210, .95), rgba(246, 223, 169, .5) 40%, transparent 70%); opacity: 0; transform: translateY(-10%) scale(.6); transition: opacity .8s ease, transform 1s ease; pointer-events: none; }
.s-back .glowin { opacity: 1; transform: translateY(-46%) scale(1.25); }
.s-open .glowin { opacity: 0; }

/* ---------- the card: folded inside the envelope, it rises from behind the pocket, comes free, and opens along its crease ---------- */
.fcard { position: relative; z-index: 2; width: var(--cw); height: var(--ch); perspective: 1600px; transition: transform .85s cubic-bezier(.3, 0, .2, 1), opacity 1.200s ease; will-change: transform, opacity; }
.envwrap.sealed .fcard { visibility: hidden; }
.fc-base, .fc-cover { position: absolute; inset: 0; border-radius: 5px; }
.fc-base { overflow: visible; }
.fc-base > .pic { position: absolute; inset: 0; }
.fc-cover { transform-origin: 50% 100%; transform-style: preserve-3d; transition: transform 1.100s cubic-bezier(.4, 0, .2, 1); will-change: transform; }
.fc-out, .fc-in { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.fc-in { transform: rotateX(180deg); }
.s-out .fcard { transform: translateY(calc(var(--eh) * -.78)); }
/* free of the envelope: the card is in front now, and only now may the envelope sink away */
.s-free .fcard { z-index: 7; transform: translateY(calc(var(--eh) * -.2 - var(--ch) * .5 * var(--grow, 1.25))) scale(var(--grow, 1.25)); }
.s-free .envframe, .s-free .glowin { animation: envgo .8s ease both; }
@keyframes envgo { to { opacity: 0; transform: translateY(46%) scale(.94); } }
.s-open .fc-cover { transform: rotateX(-180deg); }
/* the paper trees stand on the crease (the lower edge of the upper leaf) and rise one after another */
.trees { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; }
.pt { position: absolute; bottom: -1%; aspect-ratio: 100 / 160; transform-origin: 50% 100%; transform: scaleY(0) rotateX(60deg); opacity: 0; transition: transform .8s cubic-bezier(.2, 1.3, .4, 1), opacity .3s ease; }
.s-pop .pt { transform: none; opacity: 1; }
.fc-in .stream, .fc-in .glint { opacity: 0; transition: opacity 1.200s ease 1.200s; }
.s-pop .fc-in .stream { opacity: 1; } .s-pop .fc-in .glint { opacity: .8; animation: glint 2.600s ease-in-out infinite; }
@keyframes glint { 50% { opacity: .25; } }
/* the little world outgrows its card and becomes the wood all round */
.s-world .fcard { transform: translateY(calc(var(--eh) * -.2)) scale(calc(var(--grow, 1.25) * 3.4)); opacity: 0; transition: transform 2s cubic-bezier(.5, 0, .3, 1), opacity 1.300s ease .35s; }

/* ---------- Happy Thanksgiving ---------- */
#greet { z-index: 3; align-self: center; transition: transform 1.400s cubic-bezier(.3, 0, .2, 1); pointer-events: none; }
.forline { margin: 0 0 .2em; font-family: var(--caps); letter-spacing: .16em; font-size: clamp(13px, 3.200vw, 17px); color: var(--champagne); text-shadow: 0 2px 12px rgba(12, 22, 16, .9); opacity: 0; transition: opacity 1.200s ease .6s; text-wrap: balance; }
.forline:empty { display: none; }
#t-greet { margin: 0; padding: .12em .2em .2em; font-family: var(--script); font-weight: 400; font-size: clamp(54px, min(15vw, 15svh), 132px); line-height: 1.02; text-wrap: balance;
  background: var(--gold-metallic); background-size: 220% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 1px rgba(60, 36, 12, .8)); opacity: 0; transform: translateY(14px) scale(.94); transition: opacity 1.600s ease, transform 2s cubic-bezier(.2, .8, .3, 1); will-change: transform, opacity; }
/* a soft dark pool behind the lettering keeps it readable over the bright wood */
#greet::before { content: ''; position: absolute; left: 50%; top: 50%; width: min(96vw, 900px); height: 180%; transform: translate(-50%, -50%); background: radial-gradient(ellipse at center, rgba(12, 22, 16, .62), rgba(12, 22, 16, 0) 66%); opacity: 0; transition: opacity 1.600s ease; z-index: -1; pointer-events: none; }
#greet { position: relative; }
#greet.on::before { opacity: 1; }
#greet.on #t-greet { opacity: 1; transform: none; }
#greet.on .forline { opacity: 1; }
/* when the message opens the greeting moves up and makes room */
body:is([data-s="message"], [data-s="complete"]) #greet { align-self: start; transform: translateY(max(8px, 2svh)) scale(.62); transform-origin: 50% 0; }

/* ---------- the golden leaf ---------- */
.gleaf { z-index: 5; position: relative; width: clamp(120px, 34vw, 190px); aspect-ratio: 1; padding: 0; border: 0; background: none; align-self: end; margin-bottom: clamp(30px, 9svh, 110px); animation: gleaf 1.700s cubic-bezier(.2, .8, .3, 1) both, gbob 3.400s ease-in-out 1.700s infinite alternate; will-change: transform; }
.gleaf .pic { position: absolute; inset: 0; }
.gl-t { position: absolute; inset: 0; display: grid; place-items: center; padding-top: 6%; font-family: var(--script); font-size: clamp(28px, 8vw, 44px); color: #4A2E0E; text-shadow: 0 1px 0 rgba(255, 244, 210, .7); }
@keyframes gleaf { from { transform: translate(18vw, -34svh) scale(.18) rotate(-150deg); opacity: 0; } 30% { opacity: 1; } to { transform: none; opacity: 1; } }
@keyframes gbob { from { transform: translateY(0) rotate(-3deg); } to { transform: translateY(-10px) rotate(4deg); } }

/* ---------- the message: ivory stationery that unfolds from its top edge ---------- */
#msg { z-index: 6; align-self: center; width: min(92vw, 520px); margin-top: clamp(70px, 17svh, 150px); padding: clamp(18px, 4.500vw, 34px) clamp(18px, 5vw, 40px) clamp(16px, 4vw, 28px); background: linear-gradient(160deg, #FFF9ED, #F3E6CC); color: var(--walnut); border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(198, 138, 55, .7) inset, 0 0 0 7px #FBF3E0 inset, 0 0 0 8px rgba(215, 173, 98, .8) inset, 0 22px 50px rgba(8, 16, 11, .6); transform-origin: 50% 0; animation: unfold 1.300s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes unfold { from { transform: perspective(1200px) rotateX(-88deg); opacity: 0; } 35% { opacity: 1; } to { transform: perspective(1200px) rotateX(0); opacity: 1; } }
.m-top { width: 54px; height: 54px; margin: 0 auto 6px; }
.m-text { margin: 0; font-size: clamp(17px, 4.300vw, 21px); line-height: 1.55; text-wrap: pretty; overflow-wrap: anywhere; white-space: pre-line; }
.m-thanks { margin: .7em 0 0; font-family: var(--script); font-size: clamp(32px, 8.500vw, 46px); line-height: 1.1; color: #8B5A1E; }
.m-sign { margin: .5em 0 0; font-style: italic; font-size: clamp(16px, 4vw, 19px); }
#ctrl { z-index: 6; align-self: end; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: max(4px, 1svh); animation: fadeup .9s ease 1s both; }
@keyframes fadeup { from { opacity: 0; transform: translateY(10px); } }
.btn { min-height: 48px; padding: 8px 20px; border: 1px solid var(--antique); border-radius: 2px; background: var(--gold-metallic); color: #2E1D0A; font-family: var(--caps); letter-spacing: .1em; font-size: 15px; box-shadow: 0 6px 18px rgba(8, 16, 11, .5); }
.btn.ghost { background: rgba(17, 30, 22, .78); color: var(--cream); }
.fine { flex-basis: 100%; margin: 0; min-height: 1.3em; font-size: 14px; color: var(--champagne); text-shadow: 0 1px 8px rgba(12, 22, 16, .9); }
.linkish { position: fixed; z-index: 9030; left: 12px; top: 12px; min-height: 44px; padding: 0 14px; border: 1px solid rgba(246, 223, 169, .5); border-radius: 2px; background: rgba(17, 30, 22, .72); color: var(--champagne); font-family: var(--caps); letter-spacing: .1em; font-size: 14px; }

/* ---------- the leaves a guest can touch: each turns and shows one word; one of them is gold ---------- */
#words { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.wleaf { position: absolute; width: clamp(40px, 6.500vw, 62px); aspect-ratio: 1; padding: 0; border: 0; background: none; pointer-events: auto; animation: wdrift 9s ease-in-out infinite alternate; will-change: transform; }
.wleaf .pic { transition: transform .9s cubic-bezier(.3, 1.4, .5, 1); }
.wleaf b { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.6); padding: 3px 12px; border-radius: 99px; background: var(--cream); color: var(--walnut); font-family: var(--caps); font-weight: 400; letter-spacing: .08em; font-size: 15px; white-space: nowrap; opacity: 0; transition: opacity .4s ease, transform .5s ease; box-shadow: 0 4px 12px rgba(8, 16, 11, .5); }
.wleaf.on .pic { transform: rotate(200deg) scale(1.3); }
.wleaf.on b { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.wleaf.gold .pic { animation: shimmer 3.800s ease-in-out infinite; }
@keyframes shimmer { 50% { transform: scale(1.14) rotate(8deg); } }
@keyframes wdrift { from { transform: translate(0, 0) rotate(-12deg); } to { transform: translate(14px, 22px) rotate(16deg); } }
.extra { position: fixed; z-index: 7; left: 50%; bottom: clamp(90px, 16svh, 150px); transform: translateX(-50%); margin: 0; padding: 8px 18px; border-radius: 99px; background: rgba(255, 249, 237, .96); color: var(--walnut); font-family: var(--script); font-size: clamp(24px, 6vw, 32px); line-height: 1.1; white-space: nowrap; box-shadow: 0 8px 22px rgba(8, 16, 11, .55); animation: fadeup .6s ease both; }
/* while the message is open the touchable leaves step aside */
body:is([data-s="opening"], [data-s="unfolding"], [data-s="forest"]) #words, body:is([data-s="message"], [data-s="complete"]) #words { opacity: .0; pointer-events: none; visibility: hidden; }
#words { transition: opacity .8s ease; }

/* ---------- less motion: the wood is still, the story is told in a few plain steps ---------- */
body.rm .fl-treesL, body.rm .fl-treesR, body.rm .fl-beams, body.rm .envwrap.sealed, body.rm .cue, body.rm .wleaf, body.rm .gleaf, body.rm .wleaf.gold .pic, body.rm .s-pop .fc-in .glint { animation: none; }
body.rm #forest, body.rm .fl { transition: none; transform: none; }
body.rm #t-greet, body.rm .fcard, body.rm .fc-cover, body.rm .flap, body.rm .pt, body.rm .envwrap { transition-duration: .01s; }
body.rm #msg, body.rm #ctrl { animation: none; }
@media (max-height: 560px) and (orientation: landscape) { :root { --ew: clamp(200px, 50svh, 360px); } #msg { margin-top: 70px; width: min(92vw, 640px); } .m-top { display: none; } }
