:root {
  --theme-main: #c68a3a;
  --theme-dark: #8b5e24;
  --theme-light: #e7b873;
  --theme-medium: #a9742f;
  --theme-darkest: #5a3a14;
  --theme-rgb: 198, 138, 58;

  --petal-color: rgba(var(--theme-rgb), .58);

  --font-main: "Cormorant Garamond", serif;
  --font-accent: "Cinzel", serif;

  --fs-hint: 15px;
  --fs-ornament: 14px;
  --fs-lead: 12px;
  --fs-names: clamp(34px, 5vw, 44px);
  --fs-details: 13px;
  --fs-date: 15px;
  --fs-place: 17px;
  --fs-button: 16px;
  --fs-seal: 12px;

  --fs-names-mobile: 34px;
  --fs-lead-mobile: 10px;
  --fs-details-mobile: 11px;
  --fs-date-mobile: 13px;
  --fs-place-mobile: 15px;
  --fs-seal-mobile: 10px;

  --ls-hint: .14em;
  --ls-ornament: 5px;
  --ls-lead: .24em;
  --ls-details: .06em;
  --ls-date: .18em;
  --ls-button: .1em;
  --ls-seal: .08em;

  --bg: #f6f0e7;
  --paper: #fffdf8;
  --paper-line: rgba(var(--theme-rgb), .18);
  --env-back: #f4eee3;
  --env-front: #efe5d5;
  --env-front-2: #e8dbc6;
  --text: #2c2416;
  --muted: #8f7658;
  --place-color: #6e5a3e;

  --scene-w: 520px;
  --env-w: 520px;
  --env-h: 330px;
  --card-w: 454px;
  --card-h: 278px;
  --card-bottom: 18px;

  --seal-size: 54px;
  --seal-hitbox: 58px;
  --seal-size-mobile: 46px;
  --seal-hitbox-mobile: 50px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(var(--theme-rgb), .08), transparent 25%),
    radial-gradient(circle at 80% 80%, rgba(var(--theme-rgb), .06), transparent 22%),
    linear-gradient(180deg, #f8f3eb 0%, var(--bg) 100%);
  color: var(--text);
  font-family: var(--font-main);
}

.scene {
  position: relative;
  z-index: 2;
  width: min(92vw, var(--scene-w));
  display: grid;
  justify-items: center;
  gap: 24px;
  perspective: 1800px;
}

.hint {
  color: var(--theme-main);
  font-size: var(--fs-hint);
  font-style: italic;
  letter-spacing: var(--ls-hint);
  text-align: center;
  user-select: none;
  transition: opacity .35s ease, transform .35s ease;
}

.hint.hidden {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.envelope-wrap {
  position: relative;
  width: min(92vw, var(--env-w));
  height: calc(var(--env-h) + 72px);
  display: grid;
  place-items: center;
  transform-style: preserve-3d;
}

.envelope {
  position: relative;
  width: var(--env-w);
  max-width: 100%;
  height: var(--env-h);
  transform-style: preserve-3d;
  filter: drop-shadow(0 28px 40px rgba(44, 36, 22, .12));
  transition: transform .35s ease;
  user-select: none;
  isolation: isolate;
}

.envelope:not(.open):hover {
  transform: translateY(-6px);
}

.envelope.open {
  transform: translateY(-2px) rotateX(7deg);
}

.shadow {
  position: absolute;
  inset: auto 8% -26px;
  height: 38px;
  background: radial-gradient(ellipse at center, rgba(31, 24, 13, .18), rgba(31, 24, 13, 0));
  filter: blur(8px);
  transform: translateZ(-80px);
  pointer-events: none;
}

.env-back {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  border-radius: 4px;
  background: linear-gradient(180deg, #f7f1e7 0%, var(--env-back) 100%);
  box-shadow: inset 0 0 0 1px rgba(var(--theme-rgb), .11);
  transform: translateZ(0);
}

.env-back::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .7), transparent 18%),
    radial-gradient(circle at 50% 115%, rgba(0, 0, 0, .08), transparent 26%);
  pointer-events: none;
}

.inner-fold-left,
.inner-fold-right,
.inner-fold-bottom {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.inner-fold-left {
  clip-path: polygon(0 0, 0 100%, 50% 50%);
  background: linear-gradient(90deg, rgba(0, 0, 0, .07), rgba(255, 255, 255, .05));
}

.inner-fold-right {
  clip-path: polygon(100% 0, 100% 100%, 50% 50%);
  background: linear-gradient(270deg, rgba(0, 0, 0, .09), rgba(255, 255, 255, .05));
}

.inner-fold-bottom {
  clip-path: polygon(0 100%, 100% 100%, 50% 50%);
  background: linear-gradient(180deg, rgba(255, 255, 255, .02), rgba(0, 0, 0, .12));
}

.card-rail {
  position: absolute;
  left: 50%;
  bottom: var(--card-bottom);
  z-index: 3;
  width: var(--card-w);
  height: calc(var(--env-h) - var(--card-bottom) - 10px);
  transform: translateX(-50%) translateZ(8px);
  pointer-events: none;
}

.card {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 3;
  width: 100%;
  height: var(--card-h);
  overflow: hidden;
  border-radius: 2px;
  background: linear-gradient(180deg, #fffefb 0%, var(--paper) 100%);
  box-shadow: 0 6px 24px rgba(44, 36, 22, .12);
  transform: translateY(0) translateZ(0) rotateX(0deg);
  transform-origin: center bottom;
  transition:
    transform 1.25s cubic-bezier(.22, 1, .18, 1),
    box-shadow .8s ease;
  backface-visibility: hidden;
  will-change: transform;
}

.envelope.card-front .card {
  z-index: 8;
}

.envelope.open .card {
  box-shadow: 0 10px 28px rgba(44, 36, 22, .14);
}

.envelope.card-out .card {
  transform: translateY(-188px) translateZ(10px) rotateX(-1deg);
  box-shadow: 0 18px 36px rgba(44, 36, 22, .16);
}

.card::before,
.card::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid var(--paper-line);
  pointer-events: none;
}

.card::after {
  inset: 13px;
  border-color: rgba(var(--theme-rgb), .1);
}

.card-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
  padding: 22px 34px;
  text-align: center;
}

.ornament {
  margin-bottom: 4px;
  color: var(--theme-main);
  font-size: var(--fs-ornament);
  letter-spacing: var(--ls-ornament);
  opacity: .72;
}

.lead {
  color: var(--muted);
  font-size: var(--fs-lead);
  text-transform: uppercase;
  letter-spacing: var(--ls-lead);
  font-style: italic;
}

.name {
  font-size: var(--fs-names);
  line-height: .95;
  font-weight: 300;
  font-style: italic;
}

.divider {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin: 10px 0 4px;
}

.divider::before,
.divider::after {
  content: "";
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(var(--theme-rgb), .65), transparent);
}

.divider span {
  color: var(--theme-main);
  font-size: 8px;
}

.details {
  max-width: 34ch;
  color: var(--muted);
  font-size: var(--fs-details);
  line-height: 1.55;
  letter-spacing: var(--ls-details);
  font-style: italic;
}

.date {
  margin-top: 2px;
  font-family: var(--font-accent);
  font-size: var(--fs-date);
  letter-spacing: var(--ls-date);
}

.place {
  color: var(--place-color);
  font-size: var(--fs-place);
  line-height: 1.28;
  font-style: italic;
}

.front {
  position: absolute;
  inset: 0;
  z-index: 5;
  transform-style: preserve-3d;
  pointer-events: none;
}

.front-left,
.front-right,
.front-bottom {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.front-left {
  clip-path: polygon(0 0, 0 100%, 50% 50%);
  background: linear-gradient(120deg, #f4eadb 0%, var(--env-front) 55%, #e2d1ba 100%);
}

.front-right {
  clip-path: polygon(100% 0, 100% 100%, 50% 50%);
  background: linear-gradient(240deg, #f4eadb 0%, var(--env-front) 55%, #e0cfb7 100%);
}

.front-bottom {
  clip-path: polygon(0 100%, 100% 100%, 50% 50%);
  background: linear-gradient(180deg, #efe2cf 0%, var(--env-front-2) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45);
}

.front-bottom::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(0 100%, 100% 100%, 50% 50%);
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(0, 0, 0, .05));
}

.top-flap {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 7;
  width: 100%;
  height: 51%;
  overflow: visible;
  transform: translateZ(2px) rotateX(0deg);
  transform-origin: 50% 0%;
  transform-style: preserve-3d;
  transition: transform 1s cubic-bezier(.4, 0, .18, 1);
  pointer-events: none;
  will-change: transform;
}

.envelope.open .top-flap {
  transform: translateZ(2px) rotateX(-178deg);
}

.envelope.flap-behind .top-flap {
  z-index: 2;
}

.top-flap .face {
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, .55);
  backface-visibility: hidden;
}

.top-flap .face.front {
  background: linear-gradient(155deg, var(--theme-light) 0%, var(--theme-main) 48%, var(--theme-dark) 100%);
  transform: rotateX(0deg) translateZ(1px);
}

.top-flap .face.front::after,
.top-flap .face.back::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.top-flap .face.front::after {
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(180deg, rgba(255, 255, 255, .24), transparent 55%);
}

.top-flap .face.back {
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
  background: linear-gradient(155deg, var(--theme-light) 0%, var(--theme-medium) 48%, var(--theme-darkest) 100%);
  transform: rotateX(180deg) translateZ(1px);
}

.top-flap .face.back::after {
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
  background: linear-gradient(180deg, rgba(255, 255, 255, .16), transparent 58%);
}

.seal-button {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 9;
  width: var(--seal-hitbox);
  height: var(--seal-hitbox);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%) translateZ(28px);
}

.seal-button:focus-visible {
  outline: 2px solid rgba(var(--theme-rgb), .75);
  outline-offset: 4px;
}

.seal {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--seal-size);
  height: var(--seal-size);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 30% 30%, var(--theme-light) 0%, var(--theme-main) 55%, var(--theme-dark) 100%);
  box-shadow:
    0 4px 14px rgba(var(--theme-rgb), .4),
    inset 0 1px 3px rgba(255, 255, 255, .45);
  color: #fff;
  font-family: var(--font-accent);
  font-size: var(--fs-seal);
  letter-spacing: var(--ls-seal);
  transform: translate(-50%, -50%);
  transition: opacity .25s ease, transform .35s ease;
  pointer-events: none;
  backface-visibility: hidden;
}

.seal-button:hover .seal {
  transform: translate(-50%, -50%) scale(1.04);
}

.envelope.open .seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.9);
}

.actions {
  display: flex;
  justify-content: center;
}

.btn {
  border: 1px solid rgba(var(--theme-rgb), .4);
  background: rgba(255, 255, 255, .38);
  color: var(--theme-dark);
  font-family: var(--font-main);
  font-size: var(--fs-button);
  letter-spacing: var(--ls-button);
  padding: 8px 18px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .3s ease, transform .3s ease, background .2s ease;
  text-decoration: none;
  pointer-events: none;
}

.btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.btn:hover {
  background: rgba(var(--theme-rgb), .08);
}

.petals {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.petal {
  position: absolute;
  top: -24px;
  left: var(--x);
  width: 12px;
  height: 14px;
  border-radius: 70% 12% 70% 20%;
  background: var(--petal-color);
  opacity: 0;
  transform-origin: center;
  animation: fall var(--duration) linear var(--delay) infinite;
}

.petal-1 { --x: 4vw; --duration: 12s; --delay: .2s; --scale: .7; --rotation: 12deg; --drift: 36px; }
.petal-2 { --x: 11vw; --duration: 18s; --delay: 4s; --scale: 1.1; --rotation: 44deg; --drift: 62px; }
.petal-3 { --x: 18vw; --duration: 14s; --delay: 7s; --scale: .8; --rotation: 75deg; --drift: 48px; }
.petal-4 { --x: 25vw; --duration: 20s; --delay: 2s; --scale: 1.3; --rotation: 25deg; --drift: 70px; }
.petal-5 { --x: 32vw; --duration: 13s; --delay: 10s; --scale: .65; --rotation: 66deg; --drift: 34px; }
.petal-6 { --x: 39vw; --duration: 17s; --delay: 5s; --scale: 1; --rotation: 5deg; --drift: 55px; }
.petal-7 { --x: 46vw; --duration: 21s; --delay: 1s; --scale: 1.25; --rotation: 88deg; --drift: 44px; }
.petal-8 { --x: 53vw; --duration: 15s; --delay: 8s; --scale: .85; --rotation: 32deg; --drift: 68px; }
.petal-9 { --x: 60vw; --duration: 19s; --delay: 3s; --scale: 1.15; --rotation: 58deg; --drift: 40px; }
.petal-10 { --x: 67vw; --duration: 16s; --delay: 11s; --scale: .75; --rotation: 18deg; --drift: 59px; }
.petal-11 { --x: 74vw; --duration: 22s; --delay: 6s; --scale: 1.35; --rotation: 83deg; --drift: 72px; }
.petal-12 { --x: 81vw; --duration: 14s; --delay: 9s; --scale: .9; --rotation: 47deg; --drift: 38px; }
.petal-13 { --x: 88vw; --duration: 18s; --delay: 12s; --scale: 1.05; --rotation: 70deg; --drift: 64px; }
.petal-14 { --x: 94vw; --duration: 20s; --delay: 4.5s; --scale: .72; --rotation: 15deg; --drift: 42px; }
.petal-15 { --x: 7vw; --duration: 23s; --delay: 13s; --scale: 1.2; --rotation: 39deg; --drift: 74px; }
.petal-16 { --x: 57vw; --duration: 16s; --delay: 14s; --scale: .95; --rotation: 61deg; --drift: 52px; }

@keyframes fall {
  0% {
    transform: translate3d(0, -20px, 0) rotate(var(--rotation)) scale(var(--scale));
    opacity: 0;
  }

  10% {
    opacity: .55;
  }

  85% {
    opacity: .28;
  }

  100% {
    transform: translate3d(var(--drift), 110vh, 0) rotate(calc(var(--rotation) + 360deg)) scale(var(--scale));
    opacity: 0;
  }
}

@media (max-width: 620px) {
  :root {
    --env-w: 92vw;
    --env-h: 58vw;
    --card-w: 81vw;
    --card-h: 50vw;
  }

  .card-content {
    padding: 18px 26px;
    gap: 4px;
  }

  .name {
    font-size: var(--fs-names-mobile);
  }

  .lead {
    font-size: var(--fs-lead-mobile);
  }

  .details {
    font-size: var(--fs-details-mobile);
  }

  .date {
    font-size: var(--fs-date-mobile);
  }

  .place {
    font-size: var(--fs-place-mobile);
  }

  .seal-button {
    width: var(--seal-hitbox-mobile);
    height: var(--seal-hitbox-mobile);
  }

  .seal {
    width: var(--seal-size-mobile);
    height: var(--seal-size-mobile);
    font-size: var(--fs-seal-mobile);
  }

  .envelope.card-out .card {
    transform: translateY(-36vw) translateZ(10px) rotateX(-1deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}