@font-face {
  font-family: "Zhi Mang Xing";
  src: url("assets/birthday-running-script.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #12100f;
  --gold: #e4c58b;
  --serif: "Songti SC", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  --handwriting: "Zhi Mang Xing", "Kaiti SC", KaiTi, STKaiti, cursive;
  --stationery-ratio: 1.68;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100svh;
  color: #e8d9bd;
  background: radial-gradient(ellipse at 49% 45%, #37312c 0%, #1d1917 43%, #0d0d0e 82%);
  font: 16px/1.5 system-ui, sans-serif;
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, .card-rotor:focus-visible { outline: 2px solid #ffe2a6; outline-offset: 6px; }
.experience {
  min-height: 100svh;
  width: min(100%, 900px);
  margin: auto;
  padding: clamp(36px, 8svh, 92px) 22px 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  isolation: isolate;
}
.dedication { text-align: center; }
h1 { font: 400 clamp(23px, 3vw, 37px)/1.25 var(--serif); letter-spacing: .16em; margin: 0; }
h1 span { color: #f0d8a8; }
.stage {
  position: relative;
  width: min(100%, 640px);
  height: clamp(230px, 58vw, 420px);
  margin-top: clamp(20px, 6svh, 55px);
  transition: height 1s cubic-bezier(.25,.65,.18,1), margin-top .8s;
}
.grain::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("assets/paper-grain.png") repeat;
  opacity: .49;
  mix-blend-mode: soft-light;
  pointer-events: none;
}
.envelope {
  --light-x: 36%;
  --light-y: 16%;
  --tilt-x: 4deg;
  --tilt-y: -4deg;
  --sheen-x: 34%;
  --open-angle: -8deg;
  --open-scale: .73;
  --mouth-height: clamp(11px, 2.3vw, 17px);
  --satin-outer: linear-gradient(128deg, #1d1d1e, #08080a 33%, #1b1b1e 57%, #060607 91%);
  --satin-light:
    radial-gradient(ellipse at var(--light-x) var(--light-y), #d4c9bb46, #c9c5c42b 24%, #fff0 64%),
    linear-gradient(123deg, #fff0 calc(var(--sheen-x) - 19%), #eae0d10c calc(var(--sheen-x) - 8%), #eae0d13b var(--sheen-x), #fff0 calc(var(--sheen-x) + 13%));
  position: absolute;
  width: 100%;
  aspect-ratio: var(--stationery-ratio);
  top: 50%;
  transform: translateY(-50%) perspective(1300px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y)) rotateZ(-3deg);
  transition: transform .62s cubic-bezier(.2,.76,.25,1), top 1s, opacity .8s;
  perspective: 1050px;
}
.envelope-back, .pocket, .lid { position: absolute; inset: 0; border-radius: 5px 5px 8px 8px; }
.envelope-back {
  background: linear-gradient(154deg, #2f2d2c, #09090b 65%, #222123);
  border: 1px solid #4f4945;
  box-shadow: 0 2px 0 #080809, 0 4px 0 #252223, 0 25px 40px #000b, 0 52px 80px -38px #000, inset 0 1px 8px #0008;
}
.pocket {
  isolation: isolate;
  overflow: hidden;
  background: var(--satin-outer);
  border: 1px solid #5b5552;
  border-bottom-color: #3c3635;
  box-shadow: inset 0 1px #d7c9b427, inset 0 -2px #0007;
}
.envelope .grain::after {
  background:
    repeating-linear-gradient(113deg, #fff2 0 1px, transparent 1px 3px),
    url("assets/paper-grain.png");
  opacity: .51;
}
.pocket-left, .pocket-right, .pocket-bottom { position: absolute; inset: 0; }
.pocket-left {
  clip-path: polygon(0 0, 58% 73%, 31% 100%, 0 100%);
  background: linear-gradient(39deg, #09090c, #17171a 42%, #26262a 65%, #0b0b0d);
}
.pocket-right {
  clip-path: polygon(100% 0, 40% 74%, 68% 100%, 100% 100%);
  background: linear-gradient(139deg, #101012, #1b1a1d 62%, #070709);
}
.pocket-bottom {
  clip-path: polygon(0 99%, 49.5% 42%, 50.5% 42%, 100% 99%, 100% 100%, 0 100%);
  background:
    linear-gradient(132deg, transparent 40%, #f5e4d620 51%, transparent 70%),
    linear-gradient(165deg, #252427, #111113 53%, #070709);
}
.pocket::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--satin-light);
}
.foil-border {
  position: absolute;
  z-index: 2;
  inset: 3% 2.1% 3.6%;
  border: 1px solid #8a704266;
  border-radius: 3px;
  box-shadow: inset 0 1px #f4dcb035, 0 1px #000b;
  background:
    linear-gradient(130deg, transparent 35%, #83643d75 37%, #e1bf7c9c 41%, transparent 44%) bottom left / 7% 16% no-repeat,
    linear-gradient(230deg, transparent 35%, #83643d75 37%, #e1bf7c9c 41%, transparent 44%) bottom right / 7% 16% no-repeat;
}
.foil-border::before {
  content: "";
  position: absolute;
  inset: 1.7% 1.05%;
  border-bottom: 1px solid #cfad6966;
  border-inline: 1px solid #cfad6947;
  border-radius: 2px;
}
.foil-diamond {
  position: absolute;
  bottom: 6%;
  left: 50%;
  width: clamp(8px, 1.5vw, 15px);
  aspect-ratio: 1;
  transform: translateX(-50%) rotate(45deg);
  background: linear-gradient(135deg, #fff0c5, #ad834a 54%, #e3c18a);
  border: 1px solid #8f6a3b;
  box-shadow: inset 0 0 0 2px #d7b77c, 0 1px #fff1c7;
}
.lid {
  z-index: 2;
  height: 58%;
  transform: rotateX(0);
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  transition: transform .9s cubic-bezier(.24,.71,.24,1) .27s;
  filter: drop-shadow(0 3px 1.5px #000c);
  pointer-events: none;
}
.lid-paper {
  position: absolute;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  border-radius: 5px 5px 0 0;
  clip-path: polygon(0 0, 100% 0, 99% 3%, 53% 94%, 51% 97%, 49% 97%, 47% 94%, 1% 3%);
  background: var(--satin-light), var(--satin-outer);
  box-shadow: inset 0 1px #f1e1cf58;
}
.lid-paper::before {
  content: "";
  position: absolute;
  inset: 0 1px 0;
  border-radius: inherit;
  clip-path: polygon(0 0, 49% 94%, 50% 95%, 51% 94%, 100% 0, 100% 1%, 51% 96%, 50% 98%, 49% 96%, 0 1%);
  background: linear-gradient(95deg, #b9afa18c, #514c4a 38%, #c9baaa8f 58%, #151315);
}
.flap-lines {
  position: absolute;
  inset: 6% 6% 13%;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(102deg, #a4834a7a, #d4b47c9e 38%, #80624456 74%, #cba9758c);
}
.flap-lines::after {
  content: "";
  position: absolute;
  inset: 1px 3px 3px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: var(--satin-light), var(--satin-outer);
}
.seal-button {
  --wax-size: clamp(55px, 13vw, 91px);
  display: grid;
  place-items: center;
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 55.4%;
  width: calc(var(--wax-size) + 10px);
  height: calc(var(--wax-size) + 10px);
  padding: 0;
  border: 0;
  border-radius: 49%;
  background: none;
  transform: translate(-50%, -50%) rotate(-9deg);
  transition: filter .25s, scale .23s;
}
.seal-button:hover { filter: brightness(1.12); scale: 1.035; }
.seal-button:active { scale: .96; }
.wax {
  position: absolute;
  width: var(--wax-size);
  height: var(--wax-size);
  display: grid;
  place-items: center;
  border-radius: 44% 50% 43% 49% / 49% 46% 55% 47%;
  background:
    radial-gradient(ellipse at 32% 17%, #cc7f88 0%, #a44454 23%, transparent 52%),
    radial-gradient(ellipse at 60% 68%, #863242, #651e30 70%, #330e1a);
  box-shadow: inset 2px 3px 4px #f4a7ad93, inset -4px -5px 9px #2b0818c9;
  filter: drop-shadow(1px 4px 3px #391424ad);
}
.wax-top { clip-path: polygon(-9% -9%,109% -9%,109% 52%,81% 49%,69% 56%,58% 46%,49% 56%,38% 44%,26% 52%,17% 46%,-9% 55%); }
.wax-bottom { clip-path: polygon(-9% 55%,17% 46%,26% 52%,38% 44%,49% 56%,58% 46%,69% 56%,81% 49%,109% 52%,109% 110%,-9% 110%); }
.wax-stamp {
  width: 76%;
  height: 76%;
  border: 1px solid #ecb0b284;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 400 clamp(28px, 6vw, 50px)/1 Georgia, serif;
  color: #ce8790;
  text-shadow: 0 2px #440e20, 0 -1px #f5abae9d;
  box-shadow: 0 0 0 2px #5b1e32aa, inset 0 2px 4px #451427b3, 0 2px 1px #e4989b8c;
}
.wax-crack {
  position: absolute;
  width: var(--wax-size);
  height: var(--wax-size);
  clip-path: polygon(0 52%,17% 45%,26% 51%,38% 43%,49% 55%,58% 45%,69% 55%,81% 48%,100% 50%,100% 53%,81% 51%,69% 58%,58% 48%,49% 58%,38% 46%,26% 54%,17% 48%,0 55%);
  background: #2d0e19;
  opacity: 0;
}
.opening .seal-button { pointer-events: none; scale: 1; }
.opening .wax-top { animation: wax-lift .73s .14s both; }
.opening .wax-bottom { animation: wax-break .58s .14s both; }
.opening .wax-crack { animation: wax-crack .43s .13s both; }
.opening .lid { transform: rotateX(166deg); }
.withdrawing .lid { z-index: 1; }
.withdrawing .pocket { z-index: 4; }
.mail-mouth {
  position: absolute;
  z-index: 1;
  top: 0;
  inset-inline: 3%;
  height: var(--mouth-height);
  background: linear-gradient(#252327 0%, #080809 24%, #010102 74%, #242225);
  border-bottom: 1px solid #8f81735c;
  border-radius: 6% 6% 43% 43% / 27% 27% 44% 44%;
  opacity: 0;
  transition: opacity .29s .53s;
  pointer-events: none;
}
.opening .mail-mouth { opacity: 1; }
.opening .pocket { clip-path: inset(var(--mouth-height) 0 0); }
.pocket-track {
  position: absolute;
  z-index: 2;
  top: var(--mouth-height);
  left: 50%;
  translate: -50% 0;
  pointer-events: none;
}
.pocket-track .letter { width: 100%; transform-origin: 50% 0; }
@keyframes wax-lift {
  0% { transform: none; }
  17% { transform: translate(-1px,-2px) rotate(-2deg); }
  33% { transform: translate(-2px,-4px) rotate(1deg); }
  100% { transform: translate(20px,-122px) rotate(-31deg) scale(.76); opacity: 0; }
}
@keyframes wax-break {
  0% { transform: none; }
  32% { transform: translate(1px,4px) rotate(3deg); }
  55%,100% { transform: translate(1px,3px) rotate(2deg); }
}
@keyframes wax-crack {
  0% { opacity: 0; }
  19%,58% { opacity: 1; }
  100% { opacity: 0; }
}
.open-hint { margin: 18px 0 0; color: #c0ab89; font-size: 14px; letter-spacing: .1em; }
.contents {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
}
.presenting .contents,
.opened .contents {
  opacity: 1;
}
.opened .contents {
  pointer-events: auto;
}
.opening:not(.opened) :is(.controls, .drag-hint) { visibility: hidden; }
.opening .stage { height: max(clamp(320px, 90vw, 465px), calc(min(51svh, 420px) + 16px)); margin-top: 32px; }
.opening .envelope { top: 64%; transform: translateY(-50%) rotate(var(--open-angle)) scale(var(--open-scale)); }
.opened .envelope { opacity: .84; }
.card-holder {
  --photo-height: min(51svh, 420px);
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 555px);
  height: 100%;
}
.card-rotor {
  position: relative;
  display: grid;
  width: max-content;
  max-width: 100%;
  transform: perspective(950px) rotateX(var(--pitch, 0deg)) rotateY(var(--yaw, 0deg));
  transition: transform .48s cubic-bezier(.2,.75,.27,1);
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.card-rotor.dragging { transition: none; cursor: grabbing; }
.card-rotor:has(.letter:not([hidden])) { width: min(100%, 545px); }
.card-rotor:has(.photograph.is-landscape:not([hidden])) {
  width: min(100%, calc(var(--photo-height) * 1.6229));
}
.paper {
  position: relative;
  margin: 0;
  border-radius: 2px;
  box-shadow: var(--edge-x, 0px) var(--edge-y, 0px) 0 1px var(--paper-edge), 0 3px 5px #000b, 0 19px 55px #000b;
}
.letter {
  --paper-edge: #5e5241;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: var(--stationery-ratio);
  container-type: inline-size;
  padding: 12px 16px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #7d633a;
  color: var(--gold);
  background:
    radial-gradient(ellipse at var(--glint-x, 35%) var(--glint-y, 18%), #d8cec747, #8f817221 30%, #fff0 61%),
    linear-gradient(var(--glint-angle, 122deg), #fff0 22%, #d1b9a21c var(--glint-x, 40%), #fff0 65%),
    linear-gradient(152deg, #1e1c1d, #101012 64%, #1e1a1a);
  box-shadow: var(--edge-x, 0px) var(--edge-y, 0px) 0 1px var(--paper-edge), inset 0 1px 1px #d0bb9b38, 0 19px 55px #000b;
}
.letter::before {
  position: absolute;
  content: "";
  inset: 10px;
  border: 1px solid #cba96966;
  box-shadow: 0 0 0 1px #050506, inset 0 1px #f6d69a10;
  border-radius: 1px;
  pointer-events: none;
}
.letter h2 {
  font: 400 4.6cqi/1.17 var(--handwriting);
  letter-spacing: .11em;
  margin: 2.25cqi 0 2.55cqi;
}
.letter h2, #birthday-message > span {
  z-index: 1;
  width: fit-content;
  color: #edce91;
}
@supports (background-clip: text) {
  .letter h2, #birthday-message > span {
    background: linear-gradient(var(--glint-angle, 122deg), #c59c5e, #e0bd7c 20%, #fff2cd clamp(24%, var(--glint-x, 40%), 70%), #d0a964 77%, #efd39b);
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 1px #5c432e);
  }
}
#birthday-message {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .55cqi;
  text-align: center;
  font: 400 11cqi/1.01 var(--handwriting);
  letter-spacing: .03em;
}
#birthday-message > span {
  display: block;
  padding: .04em .1em;
}
#birthday-message > span:nth-child(1) {
  transform: translateX(-4.6cqi) rotate(-3deg);
}
#birthday-message > span:nth-child(2) {
  transform: translateX(3.4cqi) rotate(1.4deg);
}
#birthday-message > span:nth-child(3) {
  transform: translateX(-.8cqi) rotate(-1.6deg);
}
.paper-rule {
  width: 8cqi;
  height: 1px;
  background: linear-gradient(90deg, #b6925400, #b69254, #b6925400);
}
.paper-rule-bottom { margin-top: 2.55cqi; }
.photograph {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  background: #0e0d0d;
  border: 0;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 9px 22px #000a, 0 22px 55px #0008;
}
.photograph::before,
.photograph::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}
.photograph::before {
  z-index: 1;
  background: url("assets/paper-grain.png") repeat;
  mix-blend-mode: soft-light;
  opacity: .17;
}
.photograph::after {
  z-index: 2;
  background:
    linear-gradient(var(--glint-angle, 122deg),
      #fff0 calc(var(--glint-x, 41%) - 24%),
      #f0e4d22e calc(var(--glint-x, 41%) - 11%),
      #fff0d594 var(--glint-x, 41%),
      #f0e4d238 calc(var(--glint-x, 41%) + 6%),
      #fff0 calc(var(--glint-x, 41%) + 24%)),
    radial-gradient(ellipse at var(--glint-x, 41%) var(--glint-y, 21%), #fffbefbd, #fff0 48%);
  mix-blend-mode: screen;
  mask-image: radial-gradient(ellipse closest-side, #000 77%, transparent);
  opacity: var(--gloss, .20);
}
.photograph img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: var(--photo-height);
  object-fit: contain;
}
.photograph.is-landscape { width: 100%; }
.photograph.is-landscape img { width: 100%; }
.drag-hint { margin: 11px 0 0; color: #c0ab89; font-size: 13px; letter-spacing: .1em; }
.card-rotor:has(.photograph:not([hidden])):focus-visible { outline: none; }
.experience:has(.card-rotor:focus-visible .photograph:not([hidden])) .drag-hint {
  color: #ffe2a6;
  outline: 1px solid currentColor;
  outline-offset: 4px;
}
.controls { position: relative; z-index: 6; display: flex; align-items: center; justify-content: center; gap: clamp(12px, 5vw, 35px); margin-top: 20px; }
.controls button {
  min-height: 44px;
  padding: 7px 15px;
  color: #e9cda0;
  background: #1d1812;
  border: 1px solid #856a495f;
  border-radius: 3px;
  font-size: 14px;
}
.controls button:enabled:hover { background: #33271a; }
.controls button:disabled { opacity: .36; cursor: default; }
#page-count { min-width: 100px; color: #d8c8ad; text-align: center; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 520px) {
  .experience { padding-inline: 16px; padding-top: 32px; }
  .stage { width: calc(100% - 8px); }
  .opening .stage { height: max(clamp(320px, 90vw, 465px), calc(min(48svh, 350px) + 16px)); margin-top: 20px; }
  .opening .envelope { top: 73%; }
  .card-holder { --photo-height: min(48svh, 350px); }
  .controls { margin-top: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; transition-delay: 0ms !important; }
  .opening .wax-top { opacity: 0; }
}
