/* Palette taken from the couple's engagement shoot: ivory piña cloth and champagne embroidery,
   on a warm linen ground. */
:root {
  --paper: #f6f0e6;
  --linen: #b9ad9d;
  --gold: #b08a52;
  --ink: #3b2e25;
  --ink-soft: #6f5c4b;

  /* Classic serif for the spaced capitals and body; a high-contrast italic for names and headings */
  --serif: "Cormorant Garamond", Garamond, Georgia, serif;
  --display: "Playfair Display", Didot, Georgia, serif;

  --vh: 100vh;
  --col: min(100vw, 480px);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
}

@supports (height: 100svh) {
  :root { --vh: 100svh; }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--linen);
}

html.is-locked,
html.is-locked body { overflow: hidden; }

body {
  margin: 0;
  min-height: var(--vh);
  color: var(--ink);
  font-family: var(--serif);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Linen tablecloth the envelope and cards rest on; fixed so it never stretches with the page.
   Images hidden under the closed envelope wait for .is-ready, so the envelope's own layers load first. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--linen) center / cover;
}

.is-ready::before { background-image: url("assets/linen.jpg"); }

/* ---------- Cards ---------- */

.sheet {
  position: relative;
  z-index: 1;
  /* Letterpress: the upper wall of each impression falls into shadow and the lower lip catches the light */
  text-shadow:
    0 -.5px .4px rgba(45, 28, 12, .3),
    0 1px .4px rgba(255, 255, 255, .9);
  width: var(--col);
  margin: 0 auto;
  container-type: inline-size;
  box-shadow: 0 0 90px rgba(20, 14, 8, .35);
}

/* Each card is a photographed sheet of the envelope's cotton stock, blind-embossed with peonies in a different place */
.page {
  position: relative;
  min-height: var(--vh);
  background: var(--paper) center / cover no-repeat;
}

.page--cover {
  /* Anchored to the bottom left so any crop falls on the top and right, pushing the peonies further into their corner */
  background-position: left bottom;
}

.is-ready .page--cover { background-image: url("assets/card-invitation.jpg"); }

/* Shorter screens crop a little more off the top so the peonies stay clear of the first line */
@media (max-height: 800px) {
  .page--cover { background-size: max(100%, calc(var(--vh) * .6)) auto; }
}

@media (max-height: 700px) {
  .page--cover { background-size: max(100%, calc(var(--vh) * .66)) auto; }
}

/* The details card is printed on the same sheet as the cover, peonies at the top right and a bud at the bottom left:
   the two corners its paintings leave free. Isolated so the paintings can be multiplied into this sheet alone. */
.page--details {
  /* The unit the paintings are laid out in: a hundredth of the card's width, grown on taller screens until the
     paintings' solid paint almost touches the words between them (about 90px + 35cqw tall, with 6px either side),
     but never past 1.3 times. 123.4 is how much of the card's height the two paintings' solid paint takes, in these
     units. */
  --k: min(1.3cqw, max(1cqw, (var(--vh) - 102px - 35cqw) / 123.4));
  /* The walkway's own unit: 1.12 times the shared one, but on tall screens no larger than it was before that
     enlargement (1.25cqw), so there the words settle back where they were */
  --kw: min(var(--k) * 1.12, 1.25cqw);
  background-image: url("assets/card-invitation.jpg");
  background-position: center top;
  isolation: isolate;
}

.page--closing {
  background-image: url("assets/card-closing.jpg");
  background-position: center top;
}

/* Each following card's edge casts a soft shadow, as if laid over the one before */
.rest .page {
  box-shadow:
    0 -1px 0 rgba(120, 95, 60, .14),
    0 -16px 28px -20px rgba(60, 40, 20, .45);
}

.caps {
  margin: 0;
  padding-left: .3em;
  font-size: max(11.5px, min(3.3cqw, 14.5px));
  font-weight: 500;
  letter-spacing: .3em;
  line-height: 1.75;
  font-variant-numeric: lining-nums;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---------- Cover: the first full screen ---------- */

.page--cover {
  min-height: max(var(--vh), 600px);
  transform-origin: 50% 50%;
}

.cover-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 1.3svh, 14px);
  min-height: max(var(--vh), 600px);
  padding: 28px 22px calc(10px + env(safe-area-inset-bottom));
  text-align: center;
}

/* The space above the headline and below the button is shared equally.
   "We are / getting married" is set close over the names, as their lead-in. */
.intro {
  margin-top: auto;
  padding-left: .24em;
  font-size: max(13px, min(4cqw, 17px));
  letter-spacing: .24em;
  line-height: 1.32;
}

.cover-cta { margin-bottom: auto; }

/* Until the portrait is revealed the button is invisible, so it must not take a stray tap */
.page--cover:not(.is-revealed) .cover-cta { pointer-events: none; }

.names {
  margin: calc(-1 * clamp(4px, 1.1svh, 10px)) 0 0;
  font-family: var(--display);
  font-size: min(10.4cqw, 6svh, 46px);
  font-style: italic;
  font-weight: 400;
  line-height: 1.15;
  white-space: nowrap;
  color: var(--ink);
}

/* Large type sits deeper in the paper */
.names,
.bigday-day,
.bigday-time,
.venue,
.sentiment {
  text-shadow:
    0 -1px .8px rgba(45, 28, 12, .3),
    0 1.4px .5px rgba(255, 255, 255, .92);
}

/* Cameo: an oval portrait between the names and the date */
.medallion-frame {
  position: relative;
  flex: none;
  width: min(56cqw, calc((var(--vh) - 420px) * .75), 250px);
  aspect-ratio: 3 / 4;
  margin: clamp(10px, 2svh, 20px) 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Two foil-stamped rings around the oval: a foil fill masked down to its padding */
.medallion-frame::before,
.medallion-frame::after {
  content: "";
  position: absolute;
  padding: 1.2px;
  border-radius: 50%;
  background: var(--gold) center / cover;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}

.is-ready .medallion-frame::before,
.is-ready .medallion-frame::after { background-image: url("assets/foil.jpg"); }

.medallion-frame::before { inset: -13px; }
.medallion-frame::after { inset: -5px; padding: 1px; }

.medallion {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  box-shadow:
    inset 1px 1.5px 2px rgba(110, 80, 46, .2),
    inset -1px -1px 1px rgba(255, 255, 255, .9);
}

/* While the foil is on, it sits on the paper like an applied seal */
.page--cover:not(.is-revealed) .medallion {
  box-shadow:
    0 1px 1.5px rgba(70, 48, 22, .35),
    0 7px 16px -7px rgba(70, 48, 22, .45);
}

.medallion img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 28%;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* The photo sits in a debossed well: shadow along the upper rim, light along the lower */
.medallion::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow:
    inset 1.5px 2.5px 4px rgba(60, 40, 18, .35),
    inset -1px -1.5px 1.5px rgba(255, 255, 255, .55);
  pointer-events: none;
}

.foil { z-index: 1; }

/* Confetti falling inside the portrait, under the well's rim shadow */
.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.foil {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: opacity 1.1s var(--ease-out);
}

.foil.is-cleared { opacity: 0; }
.foil:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 12px; border-radius: 50%; }

.is-open .page--cover:not(.is-revealed) .medallion-frame {
  touch-action: none;
  cursor: pointer;
}

.reveal {
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 1.4s var(--ease-out) var(--d, 0ms),
    transform 1.4s var(--ease-out) var(--d, 0ms);
}

.is-revealed .reveal {
  opacity: 1;
  transform: none;
}

/* ---------- Date and time on the cover: the day as one large numeral ---------- */

/* Saturday above; MAY, a large 8 and 2027 on one line, with gold hairlines running out toward the card's edges;
   the hour below */
.bigday {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 400px);
  margin: 0 0 clamp(4px, 1.4svh, 12px);
}

.bigday-weekday {
  letter-spacing: .36em;
  color: var(--ink);
}

.bigday-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto 1fr;
  align-items: center;
  gap: 0 clamp(14px, 4.6cqw, 24px);
  width: 100%;
  margin: -.1em 0 -.06em;
}

.bigday-row::before,
.bigday-row::after {
  content: "";
  height: 1px;
  background: linear-gradient(90deg, rgba(176, 138, 82, 0), rgba(176, 138, 82, .85));
}

.bigday-row::after { background: linear-gradient(90deg, rgba(176, 138, 82, .85), rgba(176, 138, 82, 0)); }

.bigday-side {
  padding-left: .22em;
  font-size: max(17px, min(6.2cqw, 27px));
  font-weight: 500;
  letter-spacing: .22em;
  line-height: 1.2;
  color: var(--ink);
}

.bigday-day,
.bigday-time {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  color: var(--ink);
}

/* Shrinks a little on short screens so the portrait keeps its size */
.bigday-day {
  padding: 0 .06em;
  font-size: min(21cqw, 92px, 11svh);
  line-height: 1;
}

.bigday-time {
  margin: 0;
  font-size: min(5.6cqw, 24px);
  line-height: 1.25;
}

/* ---------- "Click here": a gold arrow centred under a button, pointing at it, for guests who would not think to tap ---------- */

.btn-cue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(5px, 1.1svh, 9px);
}

.tap-cue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 18px;
  color: #54443a;
  font-size: min(4.2cqw, 17px);
  font-style: italic;
  font-weight: 500;
  line-height: 1.15;
  text-decoration: none;
}

/* A thin gold ring around a chevron, drawn like the rings around the portrait */
.tap-arrow {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(176, 138, 82, .8);
  border-radius: 50%;
}

.tap-arrow::before {
  content: "";
  width: 7px;
  height: 7px;
  border-top: 1.4px solid var(--gold);
  border-left: 1.4px solid var(--gold);
  transform: translateY(2px) rotate(45deg);
}

/* Every three seconds the arrow pushes up toward its button and a soft light then runs across the button, like light
   catching its lacquer. The light stays inside the button. On the cover it starts once the portrait is revealed. */
.btn-cue .btn { overflow: hidden; }

.btn-cue .btn::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 38%;
  background: linear-gradient(90deg, rgba(255, 236, 196, 0), rgba(255, 236, 196, .3) 50%, rgba(255, 236, 196, 0));
  transform: translateX(-130%) skewX(-22deg);
  pointer-events: none;
  animation: btn-sheen 3s ease-in-out 2.4s infinite;
}

.btn-cue .tap-arrow { animation: tap-nudge 3s ease-in-out 2.4s infinite; }

.page--cover:not(.is-revealed) .btn-cue .btn::after,
.page--cover:not(.is-revealed) .btn-cue .tap-arrow { animation: none; }

@keyframes tap-nudge {
  0%, 10%, 52%, 100% { transform: translateY(0); }
  28% { transform: translateY(-5px); }
}

@keyframes btn-sheen {
  0%, 26% { transform: translateX(-130%) skewX(-22deg); }
  66%, 100% { transform: translateX(320%) skewX(-22deg); }
}

/* On the details card "View Map" takes the exact place the card's button always had, so the words and the paintings
   stay where they are. "One Last Note" and its cue hang just below it, out of the card's flow, over the coast painting. */
.details-actions { position: relative; }

.details-actions .btn-cue {
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  width: max-content;
  translate: -50% 0;
}

/* Over the watercolour, the arrow and "Click here" get the paper back behind them: a soft wash of the card's own
   colour that fades out at its edges, so they stay legible (the padding is cancelled by the margins) */
.details-actions .tap-cue {
  margin: -10px 0 -14px;
  padding: 10px 34px 14px;
  background: radial-gradient(closest-side, rgba(211, 205, 192, .96) 50%, rgba(211, 205, 192, .75) 72%, rgba(211, 205, 192, 0));
  color: var(--ink);
}

/* ---------- Buttons ---------- */

/* Buttons carry a thin gold inner ring, like the rings around the portrait */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
  min-height: 52px;
  padding: 0 2.4em 0 calc(2.4em + .26em);
  border: 1px solid rgba(132, 102, 60, .75);
  border-radius: 999px;
  background: rgba(255, 252, 244, .28);
  color: var(--ink);
  font: 600 max(11.5px, min(3cqw, 13.5px)) / 1 var(--serif);
  letter-spacing: .26em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .7), inset 0 1px 1px rgba(110, 80, 46, .12);
  transition: background-color .25s, box-shadow .25s, transform .15s;
}

.btn::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(176, 138, 82, .55);
  border-radius: inherit;
  pointer-events: none;
}

.btn:hover { background-color: rgba(255, 252, 244, .55); }
.btn:active { transform: translateY(1px); }

.btn--solid {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
  text-shadow: none;
  box-shadow:
    0 1px 1.5px rgba(40, 26, 12, .3),
    0 10px 20px -10px rgba(40, 26, 12, .6);
}

.btn--solid::before { border-color: rgba(214, 186, 130, .65); }
.btn--solid:hover { background-color: #2b2019; }
.btn--solid:active { box-shadow: 0 1px 1px rgba(40, 26, 12, .3), 0 4px 10px -6px rgba(40, 26, 12, .5); }

.btn:focus-visible {
  outline: 1.5px solid var(--gold);
  outline-offset: 3px;
}

/* ---------- Details ---------- */

.rest {
  opacity: 0;
  transition: opacity 1.2s var(--ease-out) .8s;
}

.rest.is-visible { opacity: 1; }

.page-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: var(--vh);
  padding: 64px 36px;
  text-align: center;
}

/* The details card follows the couple's layout: the walkway into the chapel fills the top left corner and the coast
   from above the bottom right, both running off the card's edges, with the venue and the button between them.
   The padding stops at the walkway's lower edge and the coast's upper edge; the words stay centred between the two,
   and where a short screen leaves too little room they overlap the paintings, in front of them. */
.page--details .page-inner {
  height: 100%;
  /* measured to where each painting's solid paint ends, about 5% inside its edge; the words may sit over that pale rim */
  padding-top: calc(var(--kw) * 57.34 + 6px);
  padding-bottom: calc(var(--k) * 59.2 + 6px);
}

/* Both paintings, as one layer behind the words, multiplied over the photographed paper so the paint sits in the
   sheet's grain and the white around it disappears into the card. Clipped to the card, as if printed to its edge. */
.paintings {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.painting {
  position: absolute;
  height: auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Sizes and offsets in --k, as in the couple's mockup; each painting grows out of its own corner */
.painting--walkway { top: calc(var(--kw) * -4); left: calc(var(--kw) * -12); width: calc(var(--kw) * 86.5); }
.painting--coast { right: calc(var(--k) * -15.7); bottom: calc(var(--k) * -5.3); width: calc(var(--k) * 91); }

.venue {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  color: var(--ink);
}


.rule {
  width: 1px;
  height: 34px;
  margin: 26px 0;
  background: url("assets/foil.jpg") center / cover;
}

.venue {
  margin: 10px 0 0;
  font-size: min(9.4cqw, 42px);
  line-height: 1.12;
}

.venue-area { margin: 8px 0 30px; }

/* Short screens: the details sit a little closer together, so they overlap the paintings less */
@media (max-height: 700px) {
  .page--details .venue-area { margin-bottom: 22px; }
}

/* Closing card: two polaroids laid over the peonies, the couple's note under them signed with their hashtag,
   and the practical lines at the foot like a printed footnote */
.closing {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: var(--vh);
  padding: max(4svh, 22px) 36px max(9svh, 56px);
  text-align: center;
}

/* The pair is as big as the screen allows, and its top-right corner (the back print) never slips under the
   music button fixed in the card's top right corner:
   --fit        widest that leaves the note and the foot their room (the screen's height, as a width),
                and at most 82% of the card
   --clear-top  widest at which the pair's top still sits below the button (on tall screens: always)
   Wider than that, the pair may only reach the button's left edge (100cqw - 92px wide at most), sliding
   left just enough to stay clear of it. */
.polaroids {
  --fit: min(82cqw, 400px, calc((var(--vh) * .844 - 42.4cqw - 88px) / 1.069));
  --clear-top: calc((var(--vh) * .924 - 42.4cqw - 185px) * .96);
  --w: max(min(var(--fit), 100cqw - 92px), min(var(--fit), var(--clear-top)));
  position: relative;
  flex: none;
  width: max(50cqw, var(--w));
  aspect-ratio: .96;
  margin-top: auto;
  translate: calc(-1 * clamp(0px, var(--w) / 2 - 50cqw + 59px, (var(--w) - var(--clear-top)) * 100)) 0;
}

.polaroid {
  position: absolute;
  width: 55.5%;
  height: auto;
  pointer-events: none;
  -webkit-user-drag: none;
  /* Lying on the card: a tight contact shadow and a soft one where the print lifts off the paper */
  filter:
    drop-shadow(0 1px 1px rgba(50, 34, 18, .3))
    drop-shadow(0 7px 12px rgba(50, 34, 18, .22));
}

.polaroid--proposal {
  top: 0;
  right: 0;
  rotate: 1.5deg;
}

.polaroid--celebration {
  bottom: 0;
  left: 0;
  rotate: -6deg;
}

/* The same Z&P seal the guest broke to open the envelope, pressed into the corner where the two prints meet:
   about 2% of the pair's width below the back print and 3% beside the front one's slanted edge.
   Wax stands proud of the paper: a hard shadow where it meets the card and a soft one around it */
.wax-seal {
  position: absolute;
  left: 59.5%;
  top: 66%;
  width: 26%;
  height: auto;
  rotate: -8deg;
  pointer-events: none;
  -webkit-user-drag: none;
  filter:
    drop-shadow(0 1px 1px rgba(50, 34, 18, .4))
    drop-shadow(0 4px 6px rgba(50, 34, 18, .22));
}

.closing-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: clamp(16px, 2.6svh, 26px) 0 auto;
}

.sentiment {
  margin: 0;
  font-family: var(--display);
  font-size: min(7.2cqw, 32px);
  font-style: italic;
  font-weight: 400;
  line-height: 1.22;
  white-space: nowrap;
  color: var(--ink);
}

.closing-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.place-date {
  display: flex;
  align-items: center;
  gap: 13px;
  letter-spacing: .25em;
}

.place-date .bar {
  width: 1px;
  height: 13px;
  background: rgba(176, 138, 82, .8);
}

.footnote {
  margin: 0;
  font-size: min(4.2cqw, 17px);
  font-style: italic;
  color: var(--ink-soft);
}

/* Foil-stamped hashtag, kept on one line so guests read and copy it whole.
   The foil only paints inside the box, so padding makes room for the italic overhang.
   Set heavier than the note above it: Playfair's hairlines are too thin to carry foil at this size. */
.hashtag {
  margin: calc(20px - .3em) 0 -.3em;
  padding: .3em .4em;
  font-family: var(--display);
  font-size: min(6.6cqw, 29px);
  font-style: italic;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
  color: transparent;
  text-shadow: none;
  /* One sheet of foil across the whole line (a repeating tile shows its seam on a line this long),
     cut from the photo's lower right, where the gold is even and has no pale sheen */
  background: url("assets/foil.jpg") right 85% / 170% auto;
  -webkit-background-clip: text;
  background-clip: text;
  /* The foil photo is a pale champagne that nearly matches the paper: deepen it to a richer gold,
     then press it in with a highlight below and a shadow above */
  filter:
    saturate(1.35) contrast(1.2) brightness(.8)
    drop-shadow(0 1px 0 rgba(255, 255, 255, .8))
    drop-shadow(0 -.5px .3px rgba(70, 48, 22, .45));
}

/* ---------- Loading: shown until every layer of the envelope is ready, so no guest sees it half-built ---------- */

.loader {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(70% 55% at 50% 45%, #c4b8a8, var(--linen));
  transition: opacity .9s var(--ease-out), visibility 0s .9s;
}

.is-ready .loader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-mono {
  margin: 0;
  font-family: var(--display);
  font-size: 34px;
  font-style: italic;
  color: rgba(59, 46, 37, .62);
}

.loader-line {
  width: 72px;
  height: 1px;
  overflow: hidden;
  background: rgba(59, 46, 37, .16);
}

.loader-line span {
  display: block;
  height: 100%;
  background: var(--ink-soft);
  transform: scaleX(var(--loaded, 0));
  transform-origin: left;
  transition: transform .5s var(--ease-out);
}

/* ---------- Envelope: photographed layers, opened by script.js ---------- */

/* --env-w is set by script.js: the envelope's width when it fills the screen */
.env-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.env-back { z-index: 0; }
.env-front { z-index: 2; }

.envelope {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--env-w, 150vh);
  aspect-ratio: 1.5;
  margin: calc(var(--env-w, 150vh) / -3) 0 0 calc(var(--env-w, 150vh) / -2);
  perspective: calc(var(--env-w, 150vh) * 1.1);
  perspective-origin: 50% 45%;
  will-change: transform;
}

.env-back .envelope {
  border-radius: 3px;
  box-shadow:
    0 1px 2px rgba(40, 28, 15, .25),
    0 22px 40px -14px rgba(40, 28, 15, .5);
}

/* The inside, seen through the opening: the liner, deeper in shadow */
.env-inside {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background: linear-gradient(rgba(58, 40, 20, .16), rgba(58, 40, 20, .34)) #e6d6c0;
}

.is-ready .env-inside {
  background:
    linear-gradient(rgba(58, 40, 20, .16), rgba(58, 40, 20, .34)),
    url("assets/env-liner.jpg") center / cover;
}

.opening-shade,
.pocket,
.flap-shadow,
.flap,
.flap-open {
  position: absolute;
  left: 0;
  width: 100%;
  background: 0 0 / 100% 100% no-repeat;
  pointer-events: none;
}

.opening-shade {
  top: 0;
  height: 100%;
}

.is-ready .opening-shade { background-image: url("assets/env-opening-shade.webp"); }

.pocket {
  top: 0;
  height: 100%;
  background-image: url("assets/env-pocket.webp");
}

/* Cast by the flap and seal: a contact shadow at rest that stretches and softens as the flap lifts */
.flap-shadow {
  top: 0;
  aspect-ratio: 2400 / 1330;
  background: rgb(66, 44, 22);
  -webkit-mask: url("assets/env-flap-shadow.webp") 0 0 / 100% 100%;
  mask: url("assets/env-flap-shadow.webp") 0 0 / 100% 100%;
  transform-origin: 50% 0;
  opacity: .62;
}

/* Hinged along the envelope's top edge */
.flap {
  top: 0;
  aspect-ratio: 2400 / 1251;
  background-image: url("assets/env-flap.webp");
  transform-origin: 50% 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Inside of the flap with its liner, lying open above the envelope */
.flap-open {
  bottom: 100%;
  aspect-ratio: 2400 / 1251;
  transform-origin: 50% 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  visibility: hidden;
}

/* Light falls off as each face of the flap turns away from it */
.flap::after,
.flap-open::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgb(92, 66, 38);
  -webkit-mask: var(--face) 0 0 / 100% 100%;
  mask: var(--face) 0 0 / 100% 100%;
  opacity: var(--shade, 0);
}

.flap { --face: url("assets/env-flap.webp"); }
.is-ready .flap-open {
  --face: url("assets/env-flap-inside.webp");
  background-image: url("assets/env-flap-inside.webp");
}

/* Sits over the wax seal in the photograph */
.seal {
  position: absolute;
  top: 63.75%;
  left: 49.17%;
  z-index: 1;
  width: 17.8%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  translate: -50% -50%;
  cursor: pointer;
}

.seal:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 8px; }
.is-opening .seal { visibility: hidden; }

.seal::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 1px solid rgba(176, 138, 82, .7);
  border-radius: 50%;
  opacity: 0;
  animation: beckon 3.4s var(--ease-out) 1.8s infinite;
}

.seal:disabled::after { animation: none; }

@keyframes beckon {
  0% { transform: scale(.94); opacity: 0; }
  15% { opacity: .9; }
  70%, 100% { transform: scale(1.32); opacity: 0; }
}

.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(38px + env(safe-area-inset-bottom));
  text-align: center;
  transition: opacity .5s;
}

.is-opening .hint { opacity: 0; }

.is-open .env-layer { display: none; }

/* A card's shadow while it is handled: close against the envelope, then lifted */
.page::before,
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.page::before {
  box-shadow: 0 1px 2px rgba(40, 28, 15, .3), 0 3px 8px rgba(40, 28, 15, .18);
  opacity: var(--near-shadow, 0);
}

.page::after {
  box-shadow: 0 18px 36px -6px rgba(40, 28, 15, .4), 0 40px 80px -20px rgba(40, 28, 15, .35);
  opacity: var(--far-shadow, 0);
}

.is-sealed .sheet,
.is-opening .sheet { box-shadow: none; }

/* ---------- The cards as a stack, turned one at a time by script.js ---------- */

.is-deck { overscroll-behavior: none; }

.is-deck .sheet {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  margin: 0;
  translate: -50% 0;
  touch-action: none;
  box-shadow: none;
}

.is-deck .rest { display: contents; }

.is-deck .page {
  position: absolute;
  inset: 0;
  min-height: 0;
  transform-origin: 50% 100%;
  will-change: transform;
}

.is-deck .rest .page { box-shadow: none; }

/* Darkens a card while another lies over it */
.page-shade {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: rgb(38, 26, 14);
  opacity: 0;
  pointer-events: none;
}

.deck-dots { display: none; }

.is-deck .deck-dots {
  position: absolute;
  top: 50%;
  right: max(14px, env(safe-area-inset-right));
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 11px;
  translate: 0 -50%;
}

.deck-dots span {
  width: 5px;
  height: 5px;
  border: 1px solid rgba(176, 138, 82, .85);
  transform: rotate(45deg);
  transition: background-color .5s;
}

.deck-dots .is-current { background: var(--gold); }

/* ---------- Music: starts with the seal; the little button in the upper right corner turns it off and on ---------- */

/* A small paper roundel with the buttons' gold inner ring. On a phone it sits in the card's upper right corner, which
   is the screen's. --box is what takes the tap; --disc is the roundel drawn inside it. */
.music-toggle {
  --box: 44px;
  --disc: 34px;
  --icon: 17px;
  --ring: 3px;    /* from the roundel's edge in to its gold ring */
  --edge: 10px;
  position: fixed;
  top: calc(var(--edge) + env(safe-area-inset-top));
  right: max(var(--edge) + env(safe-area-inset-right), (100% - var(--col)) / 2 + var(--edge));
  z-index: 3;
  display: grid;
  place-items: center;
  width: var(--box);
  height: var(--box);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink);
  cursor: pointer;
  animation: music-in 1s var(--ease-out) .8s both;
}

.music-toggle::before,
.music-toggle::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

/* A disc of the cards' own photographed cotton stock, cut from the plain middle of the sheet at the cards' grain.
   It lies on the card or the linen, so the light from the upper left casts its shadow down and to the right. */
.music-toggle::before {
  inset: calc((var(--box) - var(--disc)) / 2);
  border: 1px solid rgba(132, 102, 60, .6);
  background: var(--paper) url("assets/card-invitation.jpg") 50% 50% / 510px auto;
  box-shadow:
    0 1px 1.5px rgba(40, 26, 12, .3),
    1px 4px 9px -3px rgba(40, 26, 12, .4);
  transition: filter .25s, transform .15s;
}

.music-toggle::after {
  inset: calc((var(--box) - var(--disc)) / 2 + var(--ring));
  border: 1px solid rgba(176, 138, 82, .5);
}

/* Pressed into the paper, like the lettering */
.music-toggle svg {
  position: relative;
  width: var(--icon);
  height: var(--icon);
  filter: drop-shadow(0 .8px 0 rgba(255, 255, 255, .85));
}

.music-toggle:hover::before { filter: brightness(1.05); }
.music-toggle:active::before { transform: scale(.95); }

.music-toggle:focus-visible {
  outline: 1.5px solid var(--gold);
  outline-offset: calc((var(--disc) - var(--box)) / 2 + 2px);
}

/* On a computer or a tablet the card is a column in the middle of the screen, so the button is bigger and goes to the
   screen's own upper right corner, out on the linen. A phone on its side (under 600px tall) keeps the small one. */
@media (min-width: 700px) and (min-height: 600px) {
  .music-toggle {
    --box: 68px;
    --disc: 56px;
    --icon: 28px;
    --ring: 4px;
    --edge: 22px;
    right: calc(var(--edge) + env(safe-area-inset-right));
  }
}

/* Muted, the sound waves give way to a small cross */
.music-waves,
.music-off { transition: opacity .25s; }

.music-toggle[aria-pressed="true"] .music-waves,
.music-toggle[aria-pressed="false"] .music-off { opacity: 0; }

@keyframes music-in {
  from { opacity: 0; transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0ms !important;
  }
}
