/* ---- Sealed envelope ---- */
.cover { display: none; }
html.intro { overflow: hidden; }
html.intro .cover { position: fixed; inset: 0; z-index: 10; display: block; overflow: hidden; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cover:focus { outline: none; }

.env-back, .env-piece > div { background: var(--paper) url("../art/paper.webp") repeat; background-size: 480px 480px; }
.env-back { position: absolute; inset: 0; }

/* Portrait like an envelope held upright; centred with a soft edge on wide screens. */
.envelope { position: absolute; top: 0; bottom: 0; left: 50%; width: min(100%, 32rem); transform: translateX(-50%); pointer-events: none; }
@media (min-width: 33rem) { .env-inside { box-shadow: 0 0 34px rgb(110 78 48 / .24); } }
.env-front, .env-flap { position: absolute; inset: 0; }

/* The card inside. Its resting place after opening is exactly where the page's arch sits. */
.env-card {
  --width: min(100%, 680px);
  --tuck: .86;
  position: absolute;
  top: 0;
  left: calc(50% - var(--width) / 2);
  width: var(--width);
  height: 140%;
  container-type: inline-size;
  background: var(--paper) url("../art/paper.webp") repeat;
  background-size: 480px 480px;
  box-shadow: 0 -2px 18px rgb(90 62 36 / .26);
  transform-origin: 50% 0;
  transform: translateY(34%) scale(var(--tuck));
}
@media (min-width: 720px) { .env-card { --tuck: .66; top: 1.5rem; } }

/* The inside of the envelope: hidden by the flap until it lifts, and darker so the card stands out. */
.env-lining { position: absolute; inset: 0; clip-path: polygon(0 0, 100% 0, 100% 11%, 51% 54%, 49% 54%, 0 11%); background: linear-gradient(#cdbb9f, #a8906e 54%); }

/* The shadow sits on the wrapper, because the clipped child would cut its own shadow off. */
.env-piece { position: absolute; inset: 0; pointer-events: none; }
.env-piece > div { position: absolute; inset: 0; }
.env-left { filter: drop-shadow(3px 0 5px rgb(110 78 48 / .24)); }
.env-right { filter: drop-shadow(-3px 0 5px rgb(110 78 48 / .24)); }
.env-bottom { filter: drop-shadow(0 -3px 6px rgb(110 78 48 / .27)); }
.env-flap-paper { filter: drop-shadow(0 6px 9px rgb(110 78 48 / .33)); }
.env-left > div { clip-path: polygon(0 11%, 51% 54%, 0 95%); background-image: linear-gradient(90deg, rgb(255 249 241 / .2), rgb(217 198 173 / .26)), url("../art/paper.webp"); background-size: auto, 480px; }
.env-right > div { clip-path: polygon(100% 11%, 49% 54%, 100% 95%); background-image: linear-gradient(270deg, rgb(255 249 241 / .2), rgb(217 198 173 / .26)), url("../art/paper.webp"); background-size: auto, 480px; }
.env-bottom > div { clip-path: polygon(0 100%, 0 92.4%, 44% 55%, 47% 53.2%, 50% 52.6%, 53% 53.2%, 56% 55%, 100% 92.4%, 100% 100%); background-image: linear-gradient(rgb(255 250 243 / .4), rgb(255 250 243 / .15)), url("../art/paper.webp"); background-size: auto, 480px; }
.env-flap-paper > div { clip-path: polygon(0 0, 100% 0, 100% 18%, 57% 50%, 54% 52%, 50% 52.8%, 46% 52%, 43% 50%, 0 18%); background-image: linear-gradient(rgb(255 250 243 / .4), rgb(220 201 177 / .4) 53%), url("../art/paper.webp"); background-size: auto, 480px; }

.env-greeting { position: absolute; inset: 22% 1rem auto; text-align: center; font-family: var(--display); font-weight: 500; font-size: clamp(1.7rem, 4.4vh, 2.2rem); color: var(--brown); }
.env-hint { position: absolute; inset: 72% 1rem auto; text-align: center; font-size: 1.2rem; letter-spacing: .04em; color: var(--brown); }

.seal { --size: min(52vw, 26vh, 12.5rem); position: absolute; top: 52%; left: 50%; width: var(--size); height: var(--size); margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2); padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; pointer-events: auto; filter: drop-shadow(0 6px 6px rgb(60 38 20 / .38)); }
.seal:focus-visible { outline: 2px solid var(--brown); outline-offset: 4px; }
.seal svg { display: block; width: 100%; height: 100%; overflow: visible; }
.seal-text { font-family: var(--display); font-weight: 500; font-size: 32px; text-anchor: middle; fill: #e6d6ae; }
.seal-text-shade { fill: #2a200c; }

/* Opening, in order: the flap lifts with its seal, the card rises, then the card comes
   forward as the envelope's front moves down. Only transform and opacity move. */
.env-hint, .env-greeting { transition: opacity .3s ease; }
.opening .env-hint, .opening .env-greeting { opacity: 0; }
.env-flap { transition: transform 1.05s cubic-bezier(.55, 0, .35, 1) .15s; }
.opening .env-flap { transform: translateY(-82%); }
.opening .env-card { animation: card-rises 1.75s .7s forwards; }
@keyframes card-rises {
  0% { transform: translateY(34%) scale(var(--tuck)); animation-timing-function: cubic-bezier(.3, 0, .2, 1); }
  52% { transform: translateY(6%) scale(var(--tuck)); box-shadow: 0 -2px 18px rgb(90 62 36 / .26); animation-timing-function: cubic-bezier(.55, 0, .25, 1); }
  100% { transform: translateY(0) scale(1); box-shadow: 0 -2px 18px rgb(90 62 36 / 0); }
}
.env-front { transition: transform .85s cubic-bezier(.55, 0, .35, 1) 1.6s; }
.opening .env-front { transform: translateY(105%); }
.env-inside { transition: opacity .5s ease 1.6s; }
.opening.cover .env-inside { opacity: 0; }
html.intro .cover.opening { pointer-events: none; }

/* ---- Lines that draw themselves ---- */
html.motion .frame g.shade, html.motion .frame g.face, html.motion .frame g.light { stroke-dasharray: 1; }
html.motion .frame-top path, html.motion .frame-sides path, html.motion .frame-bottom path { stroke-dashoffset: 1; }
html.motion .relief, html.motion .groove { stroke-dasharray: 1; }
html.motion .frame .fleuron { stroke-dashoffset: 1; fill-opacity: 0; }

/* The arch grows out from the top ornament (its paths end there, so the dash runs backwards). */
html.motion.play .frame-top g path { animation: draw-back 1.5s cubic-bezier(.45, 0, .25, 1) .25s forwards; }
html.motion.play .frame-sides path { animation: draw 1.4s ease-out 1.55s forwards; }
html.motion.play .frame-top .fleuron { animation: draw 1.4s ease-in-out forwards, fill-in .9s ease .8s forwards; }
html.motion .frame-bottom.seen path { animation: draw 1.4s ease-in-out forwards; }
html.motion .frame-bottom.seen .fleuron { animation: draw 1.4s ease-in-out forwards, fill-in .9s ease .8s forwards; }

/* Dashed from -1 to 0 reveals a line from its far end. */
@keyframes draw-back { from { stroke-dashoffset: -1; } to { stroke-dashoffset: 0; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes fill-in { to { fill-opacity: 1; } }

/* The arch on the card in the envelope, and on the page it hands over to, is already complete. */
html.motion .cover .frame g.shade, html.motion .cover .frame g.face, html.motion .cover .frame g.light { stroke-dasharray: none; }
html.motion .cover .frame path { stroke-dashoffset: 0; }
html.motion .cover .frame .relief, html.motion .cover .frame .groove { stroke-dasharray: none; }
html.motion .cover .frame .fleuron { stroke-dashoffset: 0; fill-opacity: 1; }
html.motion.from-envelope main :is(.frame-top path, .frame-sides path) { animation: none; stroke-dashoffset: 0; }
html.motion.from-envelope main .frame-top .fleuron { animation: none; stroke-dashoffset: 0; fill-opacity: 1; }

/* ---- Reveals ---- */
/* Held back from the first paint, so nothing flashes before it is revealed. */
html.motion:not(.watching) .content > * { opacity: 0; }
html.motion .reveal:not(.frame-bottom) { opacity: 0; transform: translateY(14px); }
html.motion .reveal.seen:not(.frame-bottom) {
  opacity: 1;
  transform: none;
  transition: opacity .9s ease var(--delay, 0ms), transform .9s cubic-bezier(.2, .7, .2, 1) var(--delay, 0ms);
}

/* ---- Countdown ---- */
.countdown { margin-top: 1.75rem; }
.countdown dl { display: flex; justify-content: center; gap: clamp(.35rem, 2.5cqw, 1rem); }
.countdown dl[hidden] { display: none; }
.countdown dl div { min-width: 3.6rem; display: flex; flex-direction: column; align-items: center; }
.countdown dd { font-family: var(--display); font-weight: 500; font-size: clamp(1.9rem, 8cqw, 2.6rem); line-height: 1.1; font-variant-numeric: lining-nums tabular-nums; color: var(--brown); }
.countdown dt { font-size: .95rem; }
.countdown .countdown-done { font-size: 1.25rem; color: var(--brown); }

/* ---- Petals ---- */
.petals { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 5; }
.petal { position: absolute; top: 0; border-radius: 80% 15% 75% 20%; opacity: 0; will-change: transform, opacity; }
.petal-0 { background: linear-gradient(135deg, #f3ded5, #dcb5a6); }
.petal-1 { background: linear-gradient(135deg, #fffaf0, #e4d0ae); }
.petal-2 { background: linear-gradient(135deg, #ead9c6, #c8a98a); }

/* A safety net in case the setting changes while the page is open. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; transition-delay: 0ms !important; }
  .petals { display: none; }
}
