body { background: var(--red); }
/* The wash cools ivory-paper.jpg to the white of Fay's reference card, about rgb(245, 243, 233). */
.invitation { background: linear-gradient(#f5fafc9e, #f5fafc9e), url('illustrations/ivory-paper.jpg') center / 540px; }
.portrait-window { box-shadow: inset 0 0 20px #6d40282a; }
.portrait-ornament { opacity: 1; }
.button { box-shadow: none; }
.countdown-section { background: var(--red); border: 0; padding: 34px 18px 36px; margin-bottom: clamp(106px, 30vw, 180px); }
.countdown-section::after { content: ''; position: absolute; inset: calc(100% - 1px) 0 auto; aspect-ratio: 2172 / 557; background: var(--red); mask: url('./floral-lace.webp') center 61.7% / 100% auto no-repeat; pointer-events: none; }
.countdown-section h2 { max-width: 100%; margin: 0 auto 12px; font: 500 clamp(22px, 5.6vw, 28px)/1.35 var(--narrow); }
.countdown { max-width: 560px; padding: 0 0 4px; }
.countdown>div+div { border: 0; }
.countdown span { font-size: clamp(46px, 12.5vw, 64px); line-height: 1.05; }
.countdown small { font-size: var(--fs-fine); letter-spacing: .06em; text-transform: uppercase; margin-top: 6px; }
.countdown-date { margin-top: 12px; font-size: var(--fs-body); font-style: italic; }
.lettered-title { font-size: clamp(20px, 5.2vw, 28px); letter-spacing: .13em; line-height: 1.45; margin-bottom: 26px; }
.lettered-title span { font-size: clamp(68px, 17vw, 88px); line-height: 1.12; }
.details-section { --faint: #f8f3e94d; margin: calc(var(--gap-section) * .6) -40px 0; padding: 28px 40px 30px; color: var(--paper); background: var(--red); }
.details-panel { padding: 2px 22px 8px; margin-bottom: 0; }
.details-section a:focus-visible, .details-section summary:focus-visible { outline-color: var(--paper); }
.details-section .travel-card svg { stroke: currentColor; fill: #cd929440; }
.save-date { border-color: var(--red); }
@media (max-width: 600px) {
  .details-section { margin-inline: -24px; padding-inline: 16px; }
  .details-panel { padding-inline: 16px; }
}

.curl { width: 100%; height: 38px; margin: 12px auto 4px; }
.reply-section { margin: calc(var(--gap-section) * .6) -40px 0; padding: 40px 28px; background: var(--red); }
.reply-card { border: solid transparent; border-width: 54px 40px; border-image: url('./ivory-lace-frame.webp') 15.3% / 1 / 0 round; padding: 16px 12px 24px; background: linear-gradient(#f5fafc9e, #f5fafc9e), url('illustrations/ivory-paper.jpg') center / 540px; background-clip: padding-box; }
.swan-ornament { display: block; width: 170px; max-width: 85%; height: auto; margin: 0 auto 10px; }
.reply-card .rsvp-section { padding-top: 0; }
.reply-card .crossword-section { padding-top: 10px; }
.reply-card .button { max-width: 100%; padding-inline: 18px; }
.reply-card .rsvp-deadline { line-height: 1.65; }
@media (max-width: 600px) {
  .curl { height: 31px; }
  .reply-section { margin-inline: -24px; padding: 32px 16px; }
  .reply-card { border-width: 40px 30px; padding-inline: 8px; }
  .reply-card h2 { font-size: clamp(32px, 9vw, 36px); }
}
/* On the smallest phones a slimmer lace frame gives the RSVP text 240px, not 196px. */
@media (max-width: 375px) {
  .reply-section { padding-inline: 12px; }
  .reply-card { border-width: 34px 24px; padding-inline: 4px; }
}

/* Above phone width the paper fills the screen: the content keeps a centred column and the
   burgundy bands run edge to edge, rather than a paper strip on a burgundy page. The lace
   repeats at a fixed height, because scaled to a wide band it would be ~280px tall. */
@media (min-width: 601px) {
  .invitation { --column: 520px; max-width: none; padding-inline: 0; box-shadow: none; }
  .invitation > :not(.countdown-section, .details-section, .reply-section) { width: min(var(--column), 100% - 80px); margin-inline: auto; }
  .countdown-section, .details-section, .reply-section { margin-inline: 0; }
  .details-section { padding-inline: max(40px, (100% - var(--column)) / 2); }
  .reply-card { max-width: 600px; margin-inline: auto; }
  .countdown-section { margin-bottom: 168px; }
  .countdown-section::after { aspect-ratio: auto; height: 150px; mask-size: auto 195px; mask-repeat: repeat-x; }
}

/* Wide screens: a wider column, the hero and Save the Date / Location side by side,
   and long reads keep a text measure. */
@media (min-width: 900px) {
  .invitation { --column: 952px; }
  /* Save the Date and Location side by side, their headings on one line. */
  .date-and-place { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 56px; align-items: baseline; }
  .date-and-place .save-date { margin: 0; }
  .date-and-place .location { padding-top: 0; }
  .date-and-place .location .curl { display: none; }
  .details-panel { max-width: 760px; margin-inline: auto; }
  .heart-row { --row: min(520px, 100%); }
  .reply-card { max-width: 660px; }
  .timeline-wrap { max-width: 760px; margin-inline: auto; }
  .timeline { --gutter: 96px; --icon: 136px; }
}

/* The hero in two columns: on wide screens, and on a phone held sideways, where stacked it ran to
   three screens. The portrait follows the screen's height so the names and RSVP stay beside it. */
@media (min-width: 900px), (min-width: 560px) and (max-height: 520px) and (orientation: landscape) {
  .cover { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: 'frame title' 'frame names' 'frame date' 'frame rsvp'; grid-template-rows: 1fr auto auto 1fr; column-gap: 56px; padding: clamp(16px, 6vh, 56px) 0 clamp(16px, 5.5vh, 52px); }
  .lettered-title { grid-area: title; align-self: end; margin-bottom: 4px; }
  .portrait-frame { grid-area: frame; align-self: center; width: min(425px, 100%, 55svh); margin: 0 auto; }
  .cover .names { grid-area: names; margin: 4px 0; }
  .cover-date { grid-area: date; margin: 8px 0 22px; }
  .cover .button { grid-area: rsvp; justify-self: center; align-self: start; }
}
@media (min-width: 560px) and (max-height: 520px) and (orientation: landscape) {
  .cover { column-gap: 32px; }
  .portrait-frame { width: min(425px, 100%, 55svh); }
  .lettered-title { font-size: 18px; letter-spacing: .1em; }
  .lettered-title span { font-size: min(88px, 16svh); }
  .cover .names { font-size: min(58px, 12svh); }
  .cover-date { margin: 4px 0 12px; }
}

/* The envelope (28 Nov, Fay: the lace piece in her screenshot). The head script seals the page; a tap
   breaks the seal and swings the flap open, then the letter comes all the way out (Amos, 28 Nov) as the
   envelope drops, and comes to the middle of the screen, where it opens. "invited" and the names wait for it.
   The letter is folded twice into the middle (Amos, 30 Nov: "Imagine a piece of paper, folded twice into the
   center. Then you unfold it ... without the weird flash transition"), across the screen's long side: top and
   bottom on a portrait screen, left and right (.fold-x) on a wide one. The card is its middle panel and a leaf
   folds over it from each side; open, the three cover the screen. Printed inside is the page itself, as it
   stands behind the envelope (the script copies the screen into each panel), so once the letter lies open
   the envelope is taken away and the same picture is the page, with nothing to fade.
   Everything is measured on the tap (--fold-w/h/a, --place, --rise, --to, --sink): the card is laid out at
   its size on the screen and scaled into the envelope.
   Smooth on phones (Amos, 29 Nov: "not smooth. There is a flicker"): every move is a transition to the
   is-open state, each moving part has its own layer from the start (will-change), and only transforms and
   opacity change while it runs. */
.envelope { display: none; }
.sealed { overflow: hidden; }
.sealed .envelope, .envelope.is-open { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; overflow: hidden; background: radial-gradient(circle at 50% 45%, #7a1530, var(--red) 55%, #4d0818); }
.envelope.is-open { pointer-events: none; }
.sealed .lettered-title span, .sealed .cover .names span { animation-play-state: paused; }
/* The whole screen is the button, so a tap anywhere opens it. */
.envelope-open { width: 100%; height: 100%; display: grid; align-content: center; justify-items: center; gap: 22px; padding: 16px; border: 0; background: none; color: var(--paper); cursor: pointer; }
.envelope-open:focus-visible { outline-color: var(--paper); outline-offset: -12px; }
.is-open .envelope-open { outline: none; }
/* At most half the screen's height, so the flap and card have room above it as it opens. */
.envelope-art { position: relative; width: min(84vw, 420px, 50svh); aspect-ratio: 440 / 316; container-type: inline-size; will-change: transform; transition: transform .75s .7s ease-in-out; }
.envelope-art > *, .envelope-art::before { position: absolute; }
.envelope-art::before { content: ''; inset: 0 1% 1.5%; box-shadow: 0 14px 22px #0000005c; }
.envelope-art > img { inset: 0; width: 100%; height: 100%; }
/* Once the letter is out and in front, the envelope fades behind it. */
.envelope-inside, .envelope-pocket, .envelope-art::before { transition: opacity .4s 1.8s; }
.envelope-inside { left: 3.5%; right: 3.5%; top: 0; height: 60%; background: #e4d6b9; }
.envelope-flap { z-index: 4; transform-origin: 50% 0; transform: perspective(900px) rotateX(0deg); filter: drop-shadow(0 2px 1.5px #5a3a1e33); will-change: transform; transition: transform .7s .15s ease-in-out, z-index 0s .5s, opacity .4s 1.8s; }
.envelope-pocket { z-index: 3; }
.envelope-seal { z-index: 5; transform-origin: 50% 61.4%; animation: seal-breathe 2.4s ease-in-out infinite; will-change: transform; transition: scale .35s ease-in, opacity .35s ease-in; }
.envelope-hint { font: italic 400 var(--fs-lead)/1.2 var(--body); letter-spacing: .03em; transition: opacity .3s, visibility 0s .3s; }
.is-open .envelope-seal { scale: 1.3; opacity: 0; }
.is-open .envelope-flap { transform: perspective(900px) rotateX(180deg); z-index: 1; }
.is-open .envelope-inside, .is-open .envelope-pocket, .is-open .envelope-flap, .is-open .envelope-art::before, .is-open .envelope-hint { opacity: 0; }
.is-open .envelope-hint { visibility: hidden; }
/* The folded letter: its middle panel, with a leaf folded over each half. */
.envelope-card { z-index: 2; left: 0; top: 0; width: var(--fold-w); height: var(--fold-h); transform-origin: 0 0; transform: var(--place, scale(0)); perspective: calc(4 * var(--fold-a)); will-change: transform; }
.letter-page, .leaf-page, .leaf-back { position: absolute; inset: 0; overflow: hidden; }
.leaf { position: absolute; left: 0; width: 100%; height: var(--fold-a); will-change: transform; }
/* A leaf is one flat sheet: the page printed on it, and over that its outside, drawn flipped so it reads
   the right way up while the leaf lies folded over. The outside goes the moment the leaf is edge-on to the
   eye, timed below (backface-visibility was ignored by the test WebKit, which showed it mirrored open). */
.leaf-back { transform: scaleY(-1); will-change: opacity; }
.leaf-start { bottom: 100%; transform-origin: 50% 100%; transform: rotateX(-180deg); }
.leaf-end { top: 100%; transform-origin: 50% 0; transform: rotateX(180deg); }
.fold-x .leaf { top: 0; width: var(--fold-a); height: 100%; }
.fold-x .leaf-start { left: auto; right: 100%; bottom: auto; transform-origin: 100% 50%; transform: rotateY(180deg); }
.fold-x .leaf-end { left: 100%; transform-origin: 0 50%; transform: rotateY(-180deg); }
.fold-x .leaf-back { transform: scaleX(-1); }
/* Outside, the letter as it was: "Amos & Fay" inside a border, the fold down its middle. */
.letter-cover { position: absolute; left: 0; top: 0; width: var(--fold-w); height: var(--fold-h); container-type: size; background: #fcf9f1; color: var(--red); }
.leaf-end .letter-cover { left: auto; top: auto; right: 0; bottom: 0; }
.letter-cover > span { position: absolute; inset: 4cqmin; display: grid; justify-items: center; padding-top: 9cqmin; border: .5cqmin solid #650c2066; font: 400 17cqmin/1.2 var(--script); }
.leaf-start .leaf-back::after { content: ''; position: absolute; inset: auto 0 0; height: 2px; background: #650c201f; }
.fold-x .leaf-start .leaf-back::after { inset: 0 0 0 auto; width: 2px; height: auto; }
/* The page, copied in by the script where it falls on each panel, set as the body is (the envelope would
   hand it its own paper-coloured text). */
.letter-site { position: absolute; font: var(--fs-body)/1.7 var(--body); color: var(--red); background: var(--red); }
/* Out: the letter rises past the pocket's top corners while the envelope drops (translate), comes to the
   front and to the middle of the screen at full size (transform), then opens: each leaf turns over on its
   fold, the first a moment before the second, printed side up. */
.is-open .envelope-art { transform: translateY(var(--sink)); }
.is-open .envelope-card { translate: 0 calc(-1 * var(--rise)); transform: var(--to); z-index: 6; transition: translate .75s .7s ease-in-out, transform .7s 1.45s ease-in-out, z-index 0s 1.45s; }
/* Edge-on: the eye is 4 leaves (the perspective) in front of the middle, a leaf's fold 1 leaf from it, so a
   leaf is edge-on once it has turned atan(4) of its 180 degrees, 42.2%, which this easing reaches 321.5ms in. */
.is-open .leaf { transform: none; transition: transform .9s 2.1s cubic-bezier(.45, 0, .25, 1); }
.is-open .leaf-end { transition-delay: 2.25s; }
.is-open .leaf-back { opacity: 0; transition: opacity 0s 2.4215s; }
.is-open .leaf-end .leaf-back { transition-delay: 2.5715s; }
@keyframes seal-breathe { 50% { transform: scale(1.06); } }
