@font-face {
  font-family: "Ma Shan Zheng";
  src: url("fonts/MaShanZheng-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "LXGW WenKai Lite";
  src: url("fonts/LXGWWenKaiLite-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #31272a;
  --letter-cream: #f9eddf;
  --serif: "Noto Serif SC", "Source Han Serif SC", "SimSun", "STSong", serif;
}

* { box-sizing: border-box; }

body,
body.reveal-viewport {
  margin: 0;
  background: #160f15;
  color: var(--letter-cream);
  font-family: var(--serif);
}

.reveal {
  height: 100vh;
  height: 100dvh;
}

.reveal .slides { background: #eddbdb; }

.reveal .slides > section {
  height: 100%;
  padding: 0;
  text-align: center;
  background: radial-gradient(ellipse at 50% 42%, var(--light) 0%, var(--dark) 72%);
}

.wine {
  --dark: #ebcbd3;
  --light: #fff5ed;
  --liner: #673644;
  --envelope: #a46e76;
  --envelope-front: #b97f88;
  --flap: #c88d95;
  --seal: #803c4d;
  --accent: #7e4252;
}

.blue {
  --dark: #d9dce9;
  --light: #fff6ed;
  --liner: #3d5367;
  --envelope: #678298;
  --envelope-front: #7d99ac;
  --flap: #96aebd;
  --seal: #435c73;
  --accent: #415b71;
}

.blush {
  --dark: #f1d6dc;
  --light: #fff8ef;
}

.cover { color: #4f263b; }

.cover-title {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-size: 140px;
  font-weight: 400;
  letter-spacing: .08em;
  transition: opacity .22s ease;
}

.cover-title button,
.cover-title button:not(:disabled):hover {
  padding: 0;
  border: 0;
  color: inherit;
  letter-spacing: inherit;
  background: transparent;
}

.cover-title button:focus-visible { outline-color: #703b54; }

.petals {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  transition: opacity .22s ease;
}

.cover:not(.present) :is(.cover-title, .petals) { opacity: 0; }

.petals i {
  position: absolute;
  top: 0;
  left: var(--x);
  width: var(--size);
  height: calc(var(--size) * .72);
  border-radius: 86% 20% 82% 27%;
  background: linear-gradient(135deg, #e6a2b7, #cb6c8c);
  opacity: .52;
  animation: fall var(--duration) var(--delay) linear infinite paused;
}

.cover.present .petals i {
  animation-play-state: running;
}

@keyframes fall {
  from { transform: translate(-70px, -60px) rotate(-20deg); }
  to { transform: translate(145px, 1130px) rotate(380deg); }
}

.photo-layout {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
}

.photo-print {
  display: block;
  width: auto;
  height: auto;
  max-width: 1480px;
  max-height: 906px;
  padding: 20px 20px 48px;
  object-fit: contain;
  background: #fffcf7;
  box-shadow: 0 34px 86px #6e43573b, 0 4px 10px #6e43571d;
  transition: opacity .22s ease;
}

.photo-slide:not(.present) .photo-print { opacity: 0; }
.photo-slide.present .photo-print { transition: opacity .38s .18s ease; }

.opening .envelope-trigger,
.opening .envelope-trigger:not(:disabled):hover {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 530px;
  height: 315px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  transform: translate(-50%, -50%);
}

.envelope-trigger:focus-visible { outline-color: var(--accent); }

.envelope {
  position: absolute;
  inset: 0;
  perspective: 1100px;
  isolation: isolate;
}

.envelope > div { position: absolute; }

.envelope-back {
  inset: 0;
  z-index: 0;
  border-radius: 12px;
  background: var(--liner);
  box-shadow: 0 34px 95px #5030444d;
}

.envelope-paper {
  inset: 22px 40px 18px;
  z-index: 2;
  border-radius: 4px;
  background: linear-gradient(140deg, #fff8ed, #e9d9c4);
  box-shadow: 0 9px 32px #28172238;
  transition: transform .58s .33s ease;
}

.envelope-paper::after {
  position: absolute;
  inset: 24px;
  content: "";
  border: 1px solid #b3906a80;
}

.envelope-front {
  inset: 0;
  z-index: 3;
  border-radius: 0 0 12px 12px;
  background:
    linear-gradient(147deg, var(--envelope) 0 48%, transparent 48.3%) left / 50% 100% no-repeat,
    linear-gradient(213deg, var(--envelope) 0 48%, transparent 48.3%) right / 50% 100% no-repeat,
    var(--envelope-front);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
}

.envelope-flap {
  inset: 0 0 auto;
  z-index: 4;
  height: 192px;
  background: linear-gradient(var(--envelope), var(--flap));
  clip-path: polygon(0 0, 100% 0, 52% 97%, 48% 97%);
  transform-origin: top;
  transition: transform .5s .12s ease, z-index 0s .36s;
}

.envelope-seal {
  display: grid;
  z-index: 5;
  place-items: center;
  left: calc(50% - 29px);
  top: 155px;
  width: 58px;
  height: 58px;
  border-radius: 48% 54% 46% 55%;
  background: var(--seal);
  color: #f8e7d9;
  border: 3px double #f8e7d96b;
  box-shadow: 0 5px 9px #13070f59;
  font: 25px Georgia, serif;
  transition: opacity .22s ease, transform .22s ease;
}

.unsealed .envelope-seal { opacity: 0; transform: scale(1.3); }
.unsealed .envelope-flap { z-index: 1; transform: rotateX(165deg); }
.unsealed .envelope-paper { transform: translateY(-144px); }

.paper {
  position: absolute;
  inset: 124px 253px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 100px 132px;
  color: var(--ink);
  background: radial-gradient(ellipse at 39% 35%, #fff9ef, #f4e6d5 87%);
  box-shadow: 0 30px 90px #50304433;
}

.paper::before {
  position: absolute;
  inset: 32px;
  border: 1px solid #a1846273;
  content: "";
  pointer-events: none;
}

.letter-body {
  display: grid;
  gap: 23px;
  font-family: "Ma Shan Zheng", "LXGW WenKai Lite", "KaiTi", "STKaiti", var(--serif);
}

.letter-body p {
  margin: 0;
  text-align: left;
  text-indent: 2em;
  font-size: 49px;
  font-weight: 400;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.salutation .letter-body p:first-child {
  color: var(--accent);
  font-size: 57px;
  text-indent: 0;
}

.salutation .letter-body p:nth-child(3):last-child {
  color: var(--accent);
  text-indent: 0;
}

.closing .letter-body p {
  color: var(--accent);
  font-size: 72px;
  text-align: center;
  text-indent: 0;
}

button {
  color: var(--letter-cream);
  cursor: pointer;
  font: inherit;
  border: 1px solid #ecd8ca70;
  background: #231722;
}

button:not(:disabled):hover { background: #503444; }
button:disabled { opacity: .38; cursor: default; }
button:focus-visible { outline: 2px solid #fff0d8; outline-offset: 4px; }

.controls {
  position: fixed;
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
  inset: auto 12px 12px;
  z-index: 3;
  transition: opacity .18s;
}

.controls button {
  border-radius: 4px;
  padding: 8px 10px;
  font: 14px system-ui, sans-serif;
}

:fullscreen .controls:not(:hover):not(:focus-within) { opacity: 0; }

@media (max-width: 650px) and (orientation: portrait) {
  .paper { inset-inline: 83px; padding-inline: 90px; }
  .letter-body p { font-size: 56px; line-height: 1.45; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; transition-delay: 0s !important; }
  .petals { display: none; }
}
