@font-face { font-family: "Cinzel Decorative"; font-weight: 700; font-display: swap; src: url(fonts/cinzel-decorative-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 400; font-display: swap; src: url(fonts/eb-garamond-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 400; font-style: italic; font-display: swap; src: url(fonts/eb-garamond-latin-400-italic.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 600; font-display: swap; src: url(fonts/eb-garamond-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Pinyon Script"; font-weight: 400; font-display: swap; src: url(fonts/pinyon-script-latin-400-normal.woff2) format("woff2"); }

:root {
  --red-1: #8e1119;
  --red-2: #5e0910;
  --red-3: #33040a;
  --gold: #d9ae52;
  --gold-hi: #f6dc8e;
  --gold-lo: #9c7326;
  --paper: #f5ead0;
  --paper-hi: #fbf5e4;
  --paper-lo: #e4d1a8;
  --ink: #2c160f;
  --ink-red: #7c1016;
  --script: "Pinyon Script", "Snell Roundhand", cursive;
  --serif: "EB Garamond", Garamond, Georgia, serif;
  --display: "Cinzel Decorative", "Trajan Pro", Georgia, serif;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .35 0 0 0 0 .2 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  --frame-inset: clamp(7px, 1.4vmin, 14px);
  --corner: clamp(40px, 8vmin, 84px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  overflow: hidden;
  background: var(--red-3);
  color: var(--paper);
  font-family: var(--serif);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

/* ---------- the room: velvet, damask lattice, gold dust ---------- */
.room {
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, rgba(196, 34, 44, .55), transparent 70%),
    radial-gradient(ellipse 120% 90% at 50% 50%, transparent 55%, rgba(10, 0, 2, .65)),
    repeating-linear-gradient(45deg, transparent 0 46px, rgba(217, 174, 82, .07) 46px 47px),
    repeating-linear-gradient(-45deg, transparent 0 46px, rgba(217, 174, 82, .07) 46px 47px),
    radial-gradient(circle at 50% 50%, rgba(217, 174, 82, .13) 0 2px, transparent 2.5px) 0 0 / 66.5px 66.5px,
    linear-gradient(180deg, var(--red-1), var(--red-2) 60%, var(--red-3));
  transition: filter .8s ease;
}
.room::after {
  content: ""; position: absolute; inset: 0;
  background-image: var(--noise); opacity: .35; mix-blend-mode: multiply;
}
.dust { position: absolute; inset: 0; overflow: hidden; }
.dust i {
  position: absolute; bottom: -10px; width: var(--s); height: var(--s); border-radius: 50%;
  background: radial-gradient(circle, var(--gold-hi), rgba(217, 174, 82, 0) 70%);
  opacity: 0; animation: rise var(--d) linear var(--delay) infinite;
}
@keyframes rise {
  0% { transform: translate(0, 0); opacity: 0; }
  15% { opacity: var(--o); }
  85% { opacity: var(--o); }
  100% { transform: translate(var(--drift), -105vh); opacity: 0; }
}

/* ---------- gold frame ---------- */
.frame {
  position: fixed; inset: var(--frame-inset); pointer-events: none;
  border: 1.5px solid rgba(217, 174, 82, .65);
  box-shadow: inset 0 0 0 4px rgba(51, 4, 10, .5), inset 0 0 0 5px rgba(217, 174, 82, .35);
  transition: filter .8s ease, opacity .8s ease;
}
.corner { position: absolute; width: var(--corner); height: var(--corner); overflow: visible; }
.corner.tl { top: -4px; left: -4px; }
.corner.tr { top: -4px; right: -4px; transform: scaleX(-1); }
.corner.bl { bottom: -4px; left: -4px; transform: scaleY(-1); }
.corner.br { bottom: -4px; right: -4px; transform: scale(-1, -1); }

/* ---------- header ---------- */
.scroller {
  position: fixed; inset: 0; z-index: 3; overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.scroller::-webkit-scrollbar { display: none; }
body.focused .scroller { overflow-y: hidden; }
.intro {
  position: relative; z-index: 2;
  padding: calc(var(--frame-inset) + clamp(14px, 3.2vh, 40px)) 24px 0;
  text-align: center; pointer-events: none;
  transition: filter .8s ease, opacity .8s ease;
}
.intro__kicker {
  margin: 0; font-size: clamp(11px, 1.7vh, 15px); letter-spacing: .32em; text-transform: uppercase;
  color: var(--gold); font-weight: 600;
}
.intro__title {
  margin: .18em 0 .12em; font-family: var(--display); font-weight: 700;
  font-size: clamp(28px, min(8.4vw, 7.2vh), 72px); line-height: 1.05;
  background: linear-gradient(180deg, var(--gold-hi) 15%, var(--gold) 55%, var(--gold-lo) 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 rgba(40, 3, 8, .8)) drop-shadow(0 0 18px rgba(246, 220, 142, .18));
}
.intro__hint { margin: 0; font-style: italic; font-size: clamp(16px, 2.3vh, 21px); color: rgba(251, 245, 228, .88); }
.intro__hint::before, .intro__hint::after { content: "\2766"; font-style: normal; color: var(--gold); margin: 0 .55em; font-size: .85em; }
.intro__hint::before { display: inline-block; transform: scaleX(-1); }

@media (max-height: 520px) {
  .intro { display: flex; align-items: baseline; justify-content: center; gap: 1em; padding-top: calc(var(--frame-inset) + 8px); }
  .intro__kicker { display: none; }
  .intro__title { font-size: clamp(22px, 7vh, 34px); margin: 0; }
  .intro__hint { font-size: 15px; }
}

/* ---------- the pile of envelopes ---------- */
.pile { position: relative; z-index: 3; }
.pile__msg {
  position: absolute; inset: 40% 10% auto; text-align: center; font-size: 20px; font-style: italic;
}
.envelope {
  position: absolute; padding: 0; margin: 0; border: 0; background: none; cursor: pointer;
  transition: transform 1s cubic-bezier(.5, 0, .2, 1) var(--away-delay, 0s), opacity .9s ease var(--away-delay, 0s), visibility 0s linear 0s;
  touch-action: manipulation;
}
.envelope:focus { outline: none; }
.envelope:focus-visible .env-face { outline: 3px solid var(--gold-hi); outline-offset: 5px; border-radius: 3px; }
.envelope.is-away {
  transform: translate(var(--ax), var(--ay)) rotate(var(--ar));
  opacity: 0; visibility: hidden;
  transition: transform 1s cubic-bezier(.5, 0, .2, 1) var(--away-delay, 0s), opacity .9s ease var(--away-delay, 0s), visibility 0s linear calc(1s + var(--away-delay, 0s));
}
.envelope.is-picked { visibility: hidden; opacity: 0; transition: none; }
.env-float {
  position: absolute; inset: 0; display: block;
  transform: rotate(var(--r0));
  animation: float var(--dur) ease-in-out var(--delay) infinite alternate;
  transition: scale .25s ease;
}
@media (hover: hover) { .envelope:hover .env-float { scale: 1.045; } }
.envelope:active .env-float { scale: .97; }
@keyframes float {
  from { transform: translate(0, 0) rotate(var(--r0)); }
  to { transform: translate(var(--fx), var(--fy)) rotate(var(--r1)); }
}
.envelope.is-settling .env-float { animation: settle .9s cubic-bezier(.2, .9, .3, 1.2) both, float var(--dur) ease-in-out .9s infinite alternate; }
@keyframes settle {
  from { transform: translate(0, -18px) rotate(var(--r0)) scale(1.12); opacity: 0; }
  to { transform: translate(0, 0) rotate(var(--r0)) scale(1); opacity: 1; }
}

/* ---------- envelope front (shared by pile and stage) ---------- */
.env-face {
  position: absolute; inset: 0; display: block;
  container-type: size;
  filter: drop-shadow(0 1.2cqh 1.6cqh rgba(20, 0, 3, .45)) drop-shadow(0 .3cqh .3cqh rgba(20, 0, 3, .35));
}
.env-paper {
  position: absolute; inset: 0; display: block; overflow: hidden; border-radius: .8cqw;
  background:
    radial-gradient(ellipse 80% 70% at 40% 35%, var(--paper-hi), transparent 70%),
    linear-gradient(160deg, var(--paper) 0%, var(--paper-lo) 100%);
}
.env-paper::after, .letter::after, .sheet::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--noise); opacity: .3; mix-blend-mode: multiply; border-radius: inherit;
}
.env-sender {
  position: absolute; left: 6cqw; top: 7cqh; text-align: left;
  font-style: italic; font-size: 4.3cqw; line-height: 1.25; color: rgba(44, 22, 15, .78);
}
.env-sender b { font-style: normal; font-weight: 600; font-size: .8em; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-red); }
.env-stamp { position: absolute; right: 5cqw; top: 6cqh; width: 15cqw; height: 18cqw; transform: rotate(3deg); }
.env-postmark { position: absolute; right: 13cqw; top: 9cqh; width: 22cqw; height: 22cqw; opacity: .62; transform: rotate(-14deg); }
.env-address {
  position: absolute; left: 12cqw; right: 12cqw; top: 46cqh; bottom: 12cqh; display: block;
}
.env-to {
  display: block; font-size: 4.2cqw; letter-spacing: .25em; text-transform: uppercase; font-weight: 600;
  color: rgba(124, 16, 22, .75);
}
.envelope__name {
  display: block; overflow: hidden; white-space: nowrap; text-align: center;
  font-family: var(--script); font-size: var(--name-size, 15cqw); line-height: 1.3;
  color: var(--ink); padding: 0 .1em;
  border-bottom: .35cqw dotted rgba(44, 22, 15, .35);
}
.env-peek {
  position: absolute; left: 8cqw; right: 8cqw; top: -9cqh; height: 40cqh; display: none;
  background: linear-gradient(180deg, #fffdf6, #f3ead5); border-radius: .6cqw;
  box-shadow: 0 0 .8cqw rgba(0, 0, 0, .25);
}
.env-opened {
  position: absolute; right: 6cqw; bottom: 8cqh; display: none;
  padding: .5cqw 1.8cqw; border: .7cqw double rgba(150, 18, 28, .72); border-radius: 1cqw;
  font-weight: 600; font-size: 4.4cqw; letter-spacing: .2em; text-transform: uppercase;
  color: rgba(150, 18, 28, .78); transform: rotate(-11deg);
  mix-blend-mode: multiply;
}
.is-opened .env-peek, [data-opened="true"] .env-peek { display: block; }
.is-opened .env-opened, [data-opened="true"] .env-opened { display: block; }
[data-opened="true"] .env-float { filter: saturate(.9); }

/* ---------- the stage: the one envelope that comes forward ---------- */
.veil {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(40, 2, 8, .35), rgba(12, 0, 3, .72));
  opacity: 0; transition: opacity .8s ease;
}
body.focused .veil { opacity: 1; }
body.focused .room, body.focused .frame, body.focused .intro { filter: blur(9px); }
body.focused .intro { opacity: .5; }

.stage { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.big { position: absolute; perspective: 1600px; }
.big__flipper { position: absolute; inset: 0; transform-style: preserve-3d; }
.big__front, .big__back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.big__back { transform: rotateY(180deg); perspective: 1400px; }
.big__inside {
  position: absolute; inset: 0; border-radius: .8%;
  background: linear-gradient(180deg, #b49a6a, #d8c294 40%, #cdb584);
  box-shadow: 0 18px 30px rgba(10, 0, 2, .45);
}
.letter {
  position: absolute; left: 6%; right: 6%; top: 7%; height: 86%;
  background:
    linear-gradient(180deg, transparent 32.8%, rgba(120, 95, 50, .18) 33.3%, transparent 34%, transparent 66.2%, rgba(120, 95, 50, .16) 66.6%, transparent 67.2%),
    linear-gradient(180deg, #fffdf6, #f4ecd8);
  border-radius: 1.2% / 1.8%;
  box-shadow: 0 2px 6px rgba(40, 20, 0, .25);
  container-type: size;
}
.letter__for {
  position: absolute; left: 0; right: 0; top: 8cqh; text-align: center;
  font-family: var(--script); font-size: 9cqw; color: var(--ink-red); white-space: nowrap; overflow: hidden;
}
.letter__lines {
  position: absolute; left: 14%; right: 14%; top: 32cqh; bottom: 12cqh;
  background: repeating-linear-gradient(180deg, transparent 0 7cqh, rgba(44, 22, 15, .16) 7cqh calc(7cqh + 1.5px));
  -webkit-mask: linear-gradient(90deg, #000 70%, transparent);
  mask: linear-gradient(90deg, #000 70%, transparent);
}
.big__panel { position: absolute; inset: 0; }
.big__panel > svg.body { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.big__inside { z-index: 0; } .letter { z-index: 1; } .big__panel { z-index: 2; } .big__flap { z-index: 3; } .seal-body { z-index: 4; }
.big__flap.is-behind { z-index: 0; }

/* The flap is two hinged pieces, so the tip can lift first and the paper seems to bend. */
.big__flap {
  position: absolute; left: 0; top: 0; width: 100%; height: 60%;
  transform-origin: 50% 0; transform-style: preserve-3d;
}
.flap-piece { position: absolute; inset: 0; transform-style: preserve-3d; }
.flap-tip { transform-origin: 50% 55%; }
.flap-tip .seal--top { translate: -50% -50% 1px; }
.flap-piece .face { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.flap-piece .face.out { backface-visibility: hidden; -webkit-backface-visibility: hidden; filter: drop-shadow(0 3px 2px rgba(60, 35, 0, .28)); }
.flap-piece .face.in { transform: translateZ(-.6px); }

.seal-body { position: absolute; inset: 0; pointer-events: none; }
.seal { position: absolute; left: 50%; top: 93%; width: 17%; aspect-ratio: 1; translate: -50% -50%; }
.seal-body .seal { top: 55.8%; }
.seal > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.seal--top > svg, .seal--bottom > svg { filter: drop-shadow(0 1px 1.5px rgba(40, 0, 4, .45)); }
.seal-crack { opacity: 0; }
.seal-crack polyline { fill: none; stroke: #250206; stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.seal-crack polyline + polyline { stroke: #f07a83; stroke-width: 1; opacity: .5; transform: translate(.8px, 1.2px); }
.crumb {
  position: absolute; width: 1.5%; aspect-ratio: 1.3; z-index: 6;
  background: radial-gradient(circle at 35% 30%, #d0343e, #7a0912);
  border-radius: 40% 60% 45% 55%;
}

/* ---------- the poem sheet ---------- */
.reader { position: fixed; inset: 0; z-index: 6; display: grid; place-items: center; padding: 3dvh 3vw; }
.reader[hidden] { display: none; }
.sheet {
  position: relative; display: flex; flex-direction: column;
  width: min(94vw, 760px); height: min(92vh, 92dvh, 1060px);
  padding: clamp(18px, 3.4vmin, 44px) clamp(18px, 5vmin, 64px) clamp(14px, 2.4vmin, 30px);
  color: var(--ink); border-radius: 4px;
  background:
    linear-gradient(180deg, transparent 32.9%, rgba(120, 95, 50, .09) 33.3%, transparent 33.9%, transparent 66.3%, rgba(120, 95, 50, .08) 66.6%, transparent 67.1%),
    radial-gradient(ellipse 85% 75% at 50% 40%, #fffcf2, transparent 75%),
    linear-gradient(170deg, #f9f1dc, #ead9b3);
  box-shadow: 0 30px 80px rgba(10, 0, 2, .6), 0 0 0 1px rgba(156, 115, 38, .4);
  transform-origin: 0 0;
}
.sheet::before {
  content: ""; position: absolute; inset: clamp(8px, 1.4vmin, 14px); pointer-events: none;
  border: 1.5px solid rgba(178, 132, 48, .7);
  box-shadow: inset 0 0 0 3px rgba(249, 241, 220, .9), inset 0 0 0 4px rgba(178, 132, 48, .45);
}
.sheet__corner { position: absolute; width: clamp(38px, 7vmin, 70px); height: clamp(38px, 7vmin, 70px); pointer-events: none; }
.sheet__corner.tl { top: 4px; left: 4px; }
.sheet__corner.tr { top: 4px; right: 4px; transform: scaleX(-1); }
.sheet__corner.bl { bottom: 4px; left: 4px; transform: scaleY(-1); }
.sheet__corner.br { bottom: 4px; right: 4px; transform: scale(-1, -1); }
.sheet__close {
  position: absolute; top: clamp(14px, 2.6vmin, 26px); right: clamp(14px, 2.6vmin, 26px); z-index: 2;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(124, 16, 22, .35);
  background: rgba(255, 252, 242, .85); color: var(--ink-red); font-size: 28px; line-height: 1; cursor: pointer;
}
.sheet__head { text-align: center; flex: none; }
.sheet__mitre { width: clamp(30px, 5.5vmin, 48px); height: clamp(30px, 5.5vmin, 48px); display: block; margin: 0 auto -2px; }
.sheet__for { margin: 0; font-size: clamp(12px, 1.8vmin, 15px); letter-spacing: .35em; text-transform: uppercase; font-weight: 600; color: rgba(124, 16, 22, .8); }
.sheet__name {
  margin: 0 0 .1em; font-family: var(--script); font-weight: 400; color: var(--ink-red);
  font-size: clamp(38px, 8vmin, 76px); line-height: 1.15;
  overflow-wrap: anywhere;
}
.sheet__name::after {
  content: ""; display: block; width: 38%; height: 10px; margin: .1em auto 0;
  background: radial-gradient(circle, var(--gold) 0 3px, transparent 3.5px) 50% 50% / 10px 10px no-repeat,
              linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold) 42%, transparent 44% 56%, var(--gold) 58%, var(--gold) 80%, transparent) 50% 50% / 100% 1.5px no-repeat;
}
.sheet__scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column;
  outline: none; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 0 4px;
}
.sheet__scroll.is-scrollable:not(.at-end) {
  -webkit-mask: linear-gradient(180deg, #000 85%, transparent);
  mask: linear-gradient(180deg, #000 85%, transparent);
}
.sheet__poem {
  margin: auto; padding: .6em 0 1em; max-width: 100%;
  font-size: 22px; line-height: 1.5; text-wrap: pretty;
}
.sheet__poem .line { margin: 0; padding-left: 1.1em; text-indent: -1.1em; overflow-wrap: anywhere; }
.sheet__poem .gap { height: .8em; }
.sheet__foot { flex: none; text-align: center; padding-top: clamp(8px, 1.6vmin, 16px); }
.sheet__back {
  min-height: 44px; padding: .45em 1.4em; cursor: pointer; border-radius: 999px;
  border: 1px solid var(--gold-lo); color: var(--paper-hi); font-size: clamp(16px, 2.2vmin, 19px); letter-spacing: .04em;
  background: linear-gradient(180deg, #a3141e, #6e0a12);
  box-shadow: inset 0 1px 0 rgba(255, 220, 180, .35), 0 3px 8px rgba(60, 0, 5, .35);
}
.sheet__back:hover { background: linear-gradient(180deg, #b31823, #7a0b14); }
.sheet__back:focus-visible, .sheet__close:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.noscript { position: fixed; inset: 40% 10% auto; text-align: center; z-index: 9; }

@media (prefers-reduced-motion: reduce) {
  .env-float, .dust i { animation: none !important; }
  .envelope, .envelope.is-away { transition-duration: .2s !important; transition-delay: 0s !important; }
}
