/* The screen is the envelope: four paper flaps meet under a gold wax seal. A tap breaks the seal and the flaps fold away past the edges of the screen, opening onto the garden. */
:root { --tip: 48%; --seal: clamp(84px, min(26.5vw, 14.4svh), 128px); --fold: cubic-bezier(.6, .02, .3, 1); }
.cover-active { overflow: hidden; }
.invitation-cover { position: fixed; inset: 0; z-index: 80; overflow: hidden; color: var(--ink); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.envelope { position: absolute; inset: 0; perspective: calc(max(100vw, 100vh) * 1.25); perspective-origin: 50% 46%; }

.flap { position: absolute; }
.flap-paper, .flap-shade, .flap-foil { position: absolute; inset: 0; }
.flap-paper { background: var(--crease), var(--light), url('assets/paper-grain.png') 0 0 / 96px, var(--paper-tone); }
/* One soft window light from the top left falls across every flap (each gradient is centred on the same point of the screen, in that flap's own box), and each flap bends down into a crease where it folds over the screen edge. */
.flap { --glow: radial-gradient(circle 125vmax at var(--lx) var(--ly), #fffdf75c, #fffdf700 42%, #3b2a1200 58%, #3b2a121c); --light: var(--glow); }
.flap-top { --lx: 22%; --ly: 12.5%; --crease: linear-gradient(#3b2a1230, #3b2a1200 3px, #fffaf075 5px, #fffaf000 18px); }
.flap-left { --lx: 42.3%; --ly: 6%; --crease: linear-gradient(90deg, #3b2a1230, #3b2a1200 3px, #fffaf060 5px, #fffaf000 18px); }
.flap-right { --lx: -50%; --ly: 6%; --crease: linear-gradient(270deg, #3b2a1238, #3b2a1200 3px, #fffaf038 5px, #fffaf000 16px); }
.flap-bottom { --lx: 22%; --ly: -67.9%; --crease: linear-gradient(0deg, #3b2a1234, #3b2a1200 3px, #fffaf040 5px, #fffaf000 16px); }
/* The cut edges of the two top flaps catch the light: a hairline of paper thickness, brightest on the side facing the window. */
.flap-top::after, .flap-bottom::after { content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.flap-top::after { background: linear-gradient(90deg, #fffefa, #fffcf4d9 48%, #f7efdf99 52%, #efe4cf80); clip-path: polygon(0 -3px, 50% calc(100% - 3px), 100% -3px, 100% 0, 50% 100%, 0 0); }
.flap-bottom::after { background: linear-gradient(90deg, #fffefa, #fffcf4cc 48%, #fbf6ebb3 52%, #f5ecdc8c); clip-path: polygon(0 100%, 50% 0, 100% 100%, 100% calc(100% + 3px), 50% 3px, 0 calc(100% + 3px)); }
.flap-shade { background: #3b2c15; opacity: 0; }
.flap-left { inset: 0 auto 0 0; width: 52%; transform-origin: 0 50%; --paper-tone: linear-gradient(100deg, #f2eadb, #e9dfca); --shade: .3; }
.flap-right { inset: 0 0 0 auto; width: 52%; transform-origin: 100% 50%; --paper-tone: linear-gradient(260deg, #ede4d1, #e6dbc5); --shade: .34; }
.flap-left > i { clip-path: polygon(0 0, 100% 47%, 0 100%); }
.flap-right > i { clip-path: polygon(100% 0, 0 47%, 100% 100%); }
.flap-bottom { inset: 44% 0 0; transform-origin: 50% 100%; filter: drop-shadow(0 0 1px #3b2a1229) drop-shadow(0 1px 3px #3b2a121a); --paper-tone: linear-gradient(0deg, #efe7d6, #f6efe2 85%); --shade: .14; }
.flap-bottom > i { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.flap-top { inset: 0 0 auto; height: var(--tip); transform-origin: 50% 0; filter: drop-shadow(0 1px 1px #3b2a1240) drop-shadow(1px 5px 8px #3b2a1224); --paper-tone: linear-gradient(#fdf9f0, #f5eddf); --shade: .42; }
.flap-top > i { clip-path: polygon(0 0, 100% 0, 50% 100%); }
.flap-top > .flap-foil { background: linear-gradient(90deg, #9c7b40, #d9bd80 16%, #f4e4b5 27%, #b8975a 44%, #ead3a0 60%, #a8874b 78%, #d8bd82 92%, #a88a50); clip-path: polygon(0 -26px, 50% calc(100% - 26px), 100% -26px, 100% -24px, 50% calc(100% - 24px), 0 -24px); opacity: .9; }
.lift-shadow { position: absolute; inset: 0; background: linear-gradient(#2e210c4d, transparent 58%); opacity: 0; pointer-events: none; }

.envelope-crest { position: absolute; left: 12%; right: 12%; top: 8%; text-align: center; }
.cover-calligraphy { display: block; width: min(32vw, 18svh, 180px); aspect-ratio: 3; margin: 0 auto min(1.5svh, 12px); background: linear-gradient(100deg, #9b7a41, #dcc185 45%, #a8864b 70%, #c9a866); -webkit-mask: url('assets/bismillah-gold-web.png') center / contain no-repeat; mask: url('assets/bismillah-gold-web.png') center / contain no-repeat; }
.cover-couples { display: grid; gap: min(1svh, 8px); }
.cover-couple { font: 400 min(5.7vw, 3.4svh, 36px)/1.1 var(--serif); letter-spacing: -.2px; color: var(--ink); white-space: nowrap; text-shadow: 0 1px 0 #fffdf7b3; }
.cover-couple em { color: var(--gold); padding: 0 .16em; }
.cover-date { margin-top: min(1.4svh, 12px); font: 500 clamp(10px, min(2.7vw, 1.4svh), 11px)/1 var(--sans); letter-spacing: .32em; color: #7d6a40; text-shadow: 0 1px 0 #fffdf7a6; }
.envelope-address { position: absolute; left: 17%; right: 17%; top: 52%; text-align: center; color: var(--ink); }
.envelope-address > p:first-child { font: 500 clamp(9.5px, min(2.3vw, 1.2svh), 10.5px)/1.5 var(--sans); letter-spacing: .26em; text-transform: uppercase; color: #7d6a40; margin-bottom: min(.8svh, 6px); }
.cover-guest { font: italic 400 min(7vw, 3.4svh, 36px)/1.15 var(--serif); overflow-wrap: anywhere; text-shadow: 0 1px 0 #fffdf7b3; }
.long-guest .cover-guest { font-size: min(5.6vw, 2.8svh, 30px); }

/* The seal is one image of real-looking gold wax (rendered from docs/wax-seal.svg), pressed with the sprig from the printed card. When it cracks, two shards of the same image replace it, split along the tip of the top flap: one rides away on the top flap, the other on the bottom flap, and a few crumbs fall. */
.wax-seal, .seal-shard, .seal-crumbs { position: absolute; left: 50%; width: var(--seal); height: var(--seal); translate: -50% -50%; }
.wax-seal, .seal-crumbs { top: calc(var(--tip) - var(--seal) * .22); }
.wax-seal { filter: drop-shadow(0 1px 1px #4a32148c) drop-shadow(0 4px 5px #4a321447); transition: scale .18s ease; }
.seal-face, .seal-shard > i { position: absolute; inset: 0; background: url('assets/wax-seal.webp') center / contain no-repeat; }
.wax-seal::after { content: ''; position: absolute; inset: -10px; border: 1px solid #ad8f56; border-radius: 50%; opacity: 0; animation: seal-ring 2.8s ease-out 1.6s infinite; }
.pressing .wax-seal { scale: .96; }
.seal-shard { visibility: hidden; z-index: 2; transform-origin: 49% 65%; filter: drop-shadow(0 1px 1px #4a32148c) drop-shadow(0 3px 4px #4a321440); }
.seal-shard-top { top: calc(100% - var(--seal) * .22); }
.seal-shard-bottom { top: calc((var(--tip) - 44%) / .56 - var(--seal) * .22); }
.seal-shard-top > i { clip-path: polygon(-5% -5%, 105% -5%, 105% 41%, 93% 44%, 86% 47%, 79% 47%, 72% 52%, 66% 54%, 60% 59%, 55% 60%, 49% 65%, 45% 59%, 40% 58%, 34% 53%, 28% 51%, 21% 47%, 14% 46%, 7% 42%, -5% 40%); }
.seal-shard-bottom > i { clip-path: polygon(-5% 40%, 7% 42%, 14% 46%, 21% 47%, 28% 51%, 34% 53%, 40% 58%, 45% 59%, 49% 65%, 55% 60%, 60% 59%, 66% 54%, 72% 52%, 79% 47%, 86% 47%, 93% 44%, 105% 41%, 105% 105%, -5% 105%); }
.seal-crumbs { pointer-events: none; }
.seal-crumbs i { position: absolute; left: var(--x); top: var(--y); width: var(--s); height: var(--s); opacity: 0; background: linear-gradient(135deg, #f1d9a0, #b88b45 55%, #6f4c1d); clip-path: polygon(12% 30%, 62% 0, 100% 48%, 72% 100%, 18% 84%); }
.seal-crumbs i:nth-child(1) { --x: 21%; --y: 47%; --s: 6px; --dx: -30px; --up: 16px; --fall: 62px; --r: -200deg; --d: 0ms; }
.seal-crumbs i:nth-child(2) { --x: 34%; --y: 53%; --s: 4px; --dx: -14px; --up: 22px; --fall: 84px; --r: 140deg; --d: 12ms; }
.seal-crumbs i:nth-child(3) { --x: 46%; --y: 60%; --s: 5px; --dx: -5px; --up: 10px; --fall: 70px; --r: -110deg; --d: 4ms; }
.seal-crumbs i:nth-child(4) { --x: 57%; --y: 59%; --s: 4px; --dx: 9px; --up: 18px; --fall: 92px; --r: 180deg; --d: 20ms; }
.seal-crumbs i:nth-child(5) { --x: 70%; --y: 52%; --s: 7px; --dx: 24px; --up: 12px; --fall: 58px; --r: 230deg; --d: 2ms; }
.seal-crumbs i:nth-child(6) { --x: 85%; --y: 46%; --s: 4px; --dx: 34px; --up: 20px; --fall: 76px; --r: -150deg; --d: 30ms; }

.envelope-trigger { position: absolute; inset: 0; z-index: 5; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: pointer; touch-action: manipulation; }
.envelope-trigger:focus-visible { outline: 2px solid var(--gold); outline-offset: -12px; }
@supports selector(:has(*)) {
  .envelope-trigger:focus-visible { outline: none; }
  .invitation-cover:has(.envelope-trigger:focus-visible) .wax-seal { outline: 2px solid var(--gold); outline-offset: 12px; border-radius: 50%; }
}
.cover-hint { position: absolute; left: 8%; right: 8%; bottom: calc(max(24px, 4svh) + env(safe-area-inset-bottom)); z-index: 6; text-align: center; font: italic 400 min(5.2vw, 2.7svh, 23px)/1.3 var(--serif); color: #3f5452; pointer-events: none; }

/* Arrival: the names settle onto the paper and the seal is pressed on. */
.envelope-crest, .envelope-address { animation: cover-arrive 1.1s var(--ease) .15s backwards; }
.envelope-address { animation-delay: .3s; }
.wax-seal { animation: seal-stamp .75s cubic-bezier(.3, 1.45, .5, 1) .5s backwards; }
.cover-hint { animation: cover-fade .8s ease 1.1s backwards; }

/* Opening: the seal cracks, then the top, bottom and side flaps fold out towards you in turn. */
.opening .cover-hint { opacity: 0; transition: opacity .2s; pointer-events: none; }
.opening .wax-seal { scale: .96; animation: seal-hide 0s 70ms forwards; }
.opening .wax-seal::after { display: none; }
.opening .seal-shard-top { animation: shard-top .5s cubic-bezier(.2, .8, .3, 1) 70ms forwards; }
.opening .seal-shard-bottom { animation: shard-bottom .5s cubic-bezier(.2, .8, .3, 1) 70ms forwards; }
.opening .seal-crumbs i { animation: crumb .7s calc(70ms + var(--d)) forwards; }
.opening .flap-top { animation: fold-top .78s var(--fold) .24s forwards; }
.opening .lift-shadow { animation: lift-shadow .78s ease .24s forwards; }
.opening .flap-bottom { animation: fold-bottom .8s var(--fold) .56s forwards; }
.opening .flap-left { animation: fold-left .9s var(--fold) .72s forwards; }
.opening .flap-right { animation: fold-right .9s var(--fold) .72s forwards; }
.opening .flap-top .flap-shade { animation: flap-shade .78s var(--fold) .24s forwards; }
.opening .flap-bottom .flap-shade { animation: flap-shade .8s var(--fold) .56s forwards; }
.opening .flap-left .flap-shade, .opening .flap-right .flap-shade { animation: flap-shade .9s var(--fold) .72s forwards; }

@keyframes cover-arrive { from { opacity: 0; transform: translateY(14px); } }
@keyframes cover-fade { from { opacity: 0; } }
@keyframes seal-stamp { from { opacity: 0; scale: 1.45; } }
@keyframes seal-ring { 0% { opacity: 0; transform: scale(.9); } 25% { opacity: .75; } 100% { opacity: 0; transform: scale(1.4); } }
@keyframes seal-hide { to { visibility: hidden; } }
@keyframes shard-top { from { visibility: visible; scale: .96; } 35% { scale: 1; transform: translate(-.4px, -1.6px) rotate(-1.6deg); } to { visibility: visible; transform: translate(0, -1px) rotate(-1deg); } }
@keyframes shard-bottom { from { visibility: visible; scale: .96; } 35% { scale: 1; transform: translate(.4px, 1.2px) rotate(1deg); } to { visibility: visible; transform: translate(0, .8px) rotate(.6deg); } }
@keyframes crumb { from { opacity: 1; animation-timing-function: cubic-bezier(.2, .6, .4, 1); } 28% { transform: translate(calc(var(--dx) * .4), calc(var(--up) * -1)) rotate(calc(var(--r) * .3)); animation-timing-function: cubic-bezier(.5, 0, .9, .5); } 80% { opacity: 1; } to { opacity: 0; transform: translate(var(--dx), var(--fall)) rotate(var(--r)); } }
@keyframes fold-top { 82% { opacity: 1; } to { transform: rotateX(96deg); opacity: 0; } }
@keyframes fold-bottom { 82% { opacity: 1; } to { transform: rotateX(-96deg); opacity: 0; } }
@keyframes fold-left { 82% { opacity: 1; } to { transform: rotateY(-96deg); opacity: 0; } }
@keyframes fold-right { 82% { opacity: 1; } to { transform: rotateY(96deg); opacity: 0; } }
@keyframes flap-shade { to { opacity: var(--shade); } }
@keyframes lift-shadow { 40% { opacity: 1; } to { opacity: 0; } }

@media (orientation: landscape) and (max-height: 520px) {
  .envelope-crest { top: 8%; }
  .cover-calligraphy { width: 76px; margin-bottom: 4px; }
  .cover-couple { font-size: min(4.4svh, 22px); }
  .cover-couples { gap: 4px; }
  .cover-date { font-size: 9px; margin-top: 6px; }
  .envelope-address { top: 44%; }
  .envelope-address > p:first-child { font-size: 8px; margin-bottom: 2px; }
  .cover-guest, .long-guest .cover-guest { font-size: 21px; }
  .cover-hint { bottom: calc(18px + env(safe-area-inset-bottom)); font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .invitation-cover *, .invitation-cover *::after { animation: none !important; transition: none !important; }
}
