:root {
  color-scheme: dark;
  --ivory: #eee4d2;
  --burgundy: #8b485c;
  --ink: #332e2a;
  --serif: "Cormorant Garamond","Noto Serif Display",Georgia,serif;
  --mono: "IBM Plex Mono","Liberation Mono",monospace;
}
*, *::before, *::after { box-sizing:border-box; }
[hidden] { display:none !important; }
body {
  margin:0; min-height:100svh; display:flex; flex-direction:column;
  background:#101313; color:var(--ivory); font-family:var(--serif);
}
body::before { content:""; position:fixed; inset:0; pointer-events:none; opacity:.055; background:url(grain.svg); }
button { cursor:pointer; font:inherit; color:inherit; }
button:focus-visible, [tabindex="-1"]:focus-visible { outline:2px solid #c69eae; outline-offset:5px; }
.mast,.folio { width:min(90%,1400px); margin-inline:auto; display:flex; align-items:center; position:relative; }
.mast { padding:24px 0 18px; justify-content:space-between; border-bottom:1px solid #82827640; }
.brand { display:flex; align-items:center; gap:9px; font-size:1.3rem; letter-spacing:-.055em; }
.brand svg { height:27px; width:27px; stroke:#c4b594; stroke-width:1.3; fill:none; }
.mast i { font-size:1rem; color:#c8c0af; }
.folio { padding:18px 0 22px; gap:16px; color:#bcb6a8; font: .75rem var(--mono); }
.rule { height:1px; background:#82827640; flex:1; }
main { position:relative; isolation:isolate; flex:1; display:grid; place-items:center; padding:28px 20px; }
#arrival { width:min(100%,560px); text-align:center; }
h1,h2,p { margin:0; }
h1 { margin-bottom:clamp(34px,6vh,66px); font-size:clamp(2.2rem,4.3vw,4.1rem); font-weight:400; letter-spacing:-.055em; line-height:1.13; text-wrap:balance; }
.parcel { position:relative; width:min(100%,485px); display:inline-grid; justify-items:center; gap:clamp(32px,6vh,60px); }
.envelope { display:block; width:94%; aspect-ratio:1.63; transform:rotate(-5deg); position:relative;  }
.env-back,.pocket,.flap,.folds,.flap svg { position:absolute; inset:0; width:100%; height:100%; }
.env-back { border-radius:3px; background:#ccbea2; box-shadow:1px 2px 1px #615443, 3px 5px 0 -2px #b7a78c, 0 22px 27px #0009, 0 40px 65px #0007; }
.pocket { z-index:3; overflow:hidden; border-radius:3px; clip-path:polygon(0 0,50% 46%,100% 0,100% 100%,0 100%); }
.pocket::after,.flap::after,#letter::before { content:""; position:absolute; inset:0; background:url(grain.svg); opacity:.24; mix-blend-mode:multiply; pointer-events:none; }
.flap { z-index:4; transform-origin:50% 0; filter:drop-shadow(0 2px 1.5px #6c503c66); }
.flap::after { clip-path:polygon(0 0,100% 0,53% 55%,50% 56.5%,46% 55%); }
.engraving { position:absolute; width:39%; bottom:-9%; left:0%; transform:rotate(-18deg); mix-blend-mode:multiply; opacity:.86; }
.postmark { position:absolute; right:6%; bottom:10%; border:3px double #a09778; padding:4px 10px; border-radius:50%; font-style:italic; font-size:.83rem; color:#817355; transform:rotate(-9deg); }
.seal {
  position:absolute; width:15.6%; aspect-ratio:1; z-index:5; left:42.2%; top:42%; display:grid; place-items:center;
  border-radius:48% 51% 44% 52% / 50% 44% 53% 46%;
  background:radial-gradient(ellipse at 35% 24%,#a15969 0%,#884657 42%,#783d50 65%,#a76374 79%,#613040 92%);
  border:2px solid #9e586a; box-shadow:inset 2px 2px 2px #e19da366,inset -3px -3px 3px #48203199,1px 4px 4px #35201e77;
}
.seal::before { content:""; position:absolute; inset:11%; border-radius:48%; box-shadow:inset 1px 2px 2px #50232eaa,0 1px 1px #d49398; }
.seal svg { width:77%; fill:none; stroke:#e4acaa; stroke-width:1.4; filter:drop-shadow(1px 1px 0 #4b2531); }
.action,#reveal,#retry,#replay { display:inline-grid; place-items:center; min-height:46px; padding:9px 24px; border:1px solid #857864; border-radius:2px; background:none; font:italic 1.08rem var(--serif); }
.parcel:has(#open:hover) .seal { filter:brightness(1.08); }
#open:hover .action,#replay:hover,#retry:hover { background:#eee4d212; }
[data-scene="opening"] .seal { animation:unseal .58s ease-in forwards; }
[data-scene="opening"] .action { opacity:0; }
@keyframes unseal { to { transform:translate(25%,-55%) rotate(22deg) scale(.94); opacity:0; } }
@keyframes unfold { 0% { transform:perspective(1300px) rotateX(0); } 49% {z-index:4;} 50%,100% {z-index:1;} 100% {transform:perspective(1300px) rotateX(168deg);} }
@keyframes fadeout { to { opacity:0; } }
@keyframes settle { from { opacity:0; transform:translateY(14px); } to {opacity:1;transform:none;} }
#letter { position:relative; width:min(100%,540px); background:#eee4d2; color:var(--ink); padding:clamp(34px,6vw,64px); box-shadow:0 18px 54px #0008; border:1px solid #c6baa6; overflow:hidden; }
#letter::after { content:""; position:absolute; inset:10px; border:1px solid #aa9a802e; pointer-events:none; }
.letter-sprig { width:85px; height:90px; object-fit:contain; margin:0 0 12px -8px; mix-blend-mode:multiply; }
#letter h2,#ending h2 { font-size:clamp(2.1rem,5vw,3.7rem); line-height:1.05; font-weight:400; letter-spacing:-.055em; }
#prose { position:relative; margin:24px 0; font:1.085rem/1.65 Georgia,serif; }
#prose p+p { margin-top:1.05em; }
#prose p:last-child { font-style:italic; }
#signature,#recipient { font-style:italic; margin-bottom:16px; }
#reveal { color:#70384a; border-color:#a4837a; padding:9px 18px; position:relative; }
#reveal:hover { background:#8b485c0c; }
#type-dust { position:fixed; inset:0; overflow:hidden; pointer-events:none; z-index:7; }
#type-dust span { position:absolute; font:15px/1 var(--mono); color:#eee4d2; }
body[data-scene="bloom"],body[data-scene="final"] { background:#000; }
:is([data-scene="bloom"],[data-scene="final"]) :is(.mast,.folio), :is([data-scene="bloom"],[data-scene="final"])::before { display:none; }
:is([data-scene="bloom"],[data-scene="final"]) main { padding:0; }
#bloom { position:relative; overflow:clip; width:100%; height:100svh; display:grid; grid-template-columns:minmax(0,1fr); grid-template-rows:minmax(0,1fr) auto; justify-items:center; background:black; color:var(--ivory); }
#bouquet { display:block; width:100%; height:100%; min-height:0; object-fit:contain; }
#ending { text-align:center; width:min(100%,660px); padding:4px 20px max(10px,env(safe-area-inset-bottom)); visibility:hidden; }
#ending h2 { font-style:italic; font-size:clamp(1.9rem,4.6vw,3.25rem); }
#ending p { margin:7px 0 0; font-size:1.04rem; line-height:1.5; }
.media-message { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); text-align:center; width:min(90%,420px); }
.media-message:has(#status:not(:empty)) { background:#08090cee; padding:16px; }
#retry { margin-top:14px; }
@media(max-width:520px) {
  .mast { padding:18px 0 14px; } .folio { padding:12px 0 15px; }
  main { padding:22px 18px; } .parcel { width:93%; gap:38px; } .envelope {width:100%;}
  #letter { padding:30px 25px; } .letter-sprig {height:74px;} h1 {margin-bottom:48px;}
}
@media(prefers-reduced-motion:reduce) {
  *,*::before,*::after { animation-duration:.001ms !important; animation-delay:0s !important; }
}
#skip { min-height:44px; padding:8px 16px; background:#111; border:1px solid #756b5e; }
#bouquet:focus { outline:none; }

/* Leave room for the turning flap and rising sheet. */
[data-scene="opening"] h1 { animation:fadeout .24s ease-in forwards; }
body[data-scene="dissolve"] { background:#000; transition:background-color 1.3s ease-in; }
[data-scene="dissolve"] :is(.mast,.folio) { animation:fadeout 1.1s ease-in both; }
h2[tabindex="-1"]:focus { outline:none; }
@media(prefers-reduced-motion:reduce) {
  body[data-scene="dissolve"] { transition:none; }
}
.mast { color:#b3ac9d; border-color:#82827622; }
.mast i { margin-left:auto; font-size:.88rem; }
.brand { font-size:.95rem; letter-spacing:0; }
.brand svg { width:20px; height:20px; }
.folio { font:italic .88rem var(--serif); color:#a49d91; }
#open { border:0; padding:0; background:none; }
#open::before { content:""; position:absolute; inset:0; }
#open:focus-visible { outline-offset:4px; }
[data-scene="opening"] #arrival { position:fixed; z-index:2; }
[data-scene="opening"] .envelope { animation:straighten 1.9s ease-in-out forwards; }
@keyframes straighten { 32% { transform:rotate(-5deg); } to { transform:rotate(0); } }
[data-scene="opening"] :is(.pocket,.env-back,.flap) { animation:lower-pocket .84s 1.05s ease-in both; }
[data-scene="opening"] .flap { animation:unfold 1.05s .2s ease-in-out forwards, lower-pocket .84s 1.05s ease-in both; }
@keyframes lower-pocket { 56% { opacity:1; } to { translate:0 min(54svh,440px); opacity:0; } }
.envelope #letter { position:absolute; top:0; left:0; z-index:2; text-align:left; transform-origin:0 0; }
[data-scene="dissolve"] #bloom { position:fixed; inset:0; z-index:-1; animation:ink-to-bloom 1.96s linear both; }
@keyframes ink-to-bloom { 0% { opacity:0; } 62% { opacity:.78; } to { opacity:1; } }
[data-scene="final"] #ending { visibility:visible; animation:settle .75s ease-out both; }
#replay { min-height:44px; color:#c0b5a4; font-size:.91rem; border:0; text-decoration:underline; text-underline-offset:4px; text-decoration-color:#827468; }
#skip { position:absolute; bottom:12px; z-index:1; }
[data-scene="dissolve"] #letter { mask-size:100% 300%; mask-repeat:no-repeat; }
@media(max-height:500px) {
  #ending { padding:0 12px 2px; }
  #ending h2 { font-size:1.45rem; }
  #ending p { margin:3px 0 0; font-size:.9rem; }
}

#arrival,#letter,#ending,#gift-error { min-width:0; overflow-wrap:anywhere; }
main { grid-template-columns:minmax(0,1fr); }
#prose p,#dedication { white-space:pre-line; }
#sender { font-style:italic; margin-bottom:16px; }
#ending { max-height:55svh; overflow:auto; }
#preview-bar { display:flex; justify-content:space-between; align-items:center; padding:0 5%; height:44px; flex:none; background:#31262b; font: .88rem var(--mono); }
#preview-bar a,#gift-error a { color:var(--ivory); text-underline-offset:3px; }
body:has(#preview-bar:not([hidden])) #bloom { height:calc(100svh - 44px); }
body:has(#preview-bar:not([hidden]))[data-scene="dissolve"] #bloom { top:44px; }
#gift-error { max-width:480px; text-align:center; }
#gift-error a { display:inline-block; margin-top:1.5rem; }
