@font-face { font-family: "Courier Prime"; src: url("/fonts/CourierPrime-Regular.ttf") format("truetype"); font-display: block; }
@font-face { font-family: "Special Elite"; src: url("/fonts/SpecialElite-Regular.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "Typekin Stamps A"; src: url("/fonts/TypekinStampsA.ttf") format("truetype"); font-display: block; }
@font-face { font-family: "Typekin Stamps B"; src: url("/fonts/TypekinStampsB.ttf") format("truetype"); font-display: block; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #120d0b;
  color: #f2e9dc;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: pre-wrap; border: 0;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #f6d58a; outline-offset: 3px; }

/* ---------- Landing page ---------- */
body.home { display: flex; align-items: center; justify-content: center; padding: 32px; text-align: center; }
body.home main { max-width: 520px; }
body.home h1 { margin: 0 0 16px; font-family: "Special Elite", "Courier New", monospace; font-weight: 400; font-size: 48px; }
body.home .lede { margin: 0 0 24px; font-size: 18px; line-height: 1.5; color: #e6dacb; }
body.home .soon { margin: 0; font-size: 16px; font-weight: 600; color: #cdbfae; }

/* ---------- Letter page ---------- */
body.letter main {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 38%, #3a2c24, #120d0b 75%);
}

.intro {
  position: absolute; left: 0; right: 0; top: 14%;
  padding: 0 24px; text-align: center;
  transition: opacity 400ms ease-out;
}
.intro h1 { margin: 0; font-family: "Special Elite", "Courier New", monospace; font-weight: 400; font-size: 30px; }
.intro p { margin: 10px 0 0; font-size: 15px; font-weight: 500; color: #cdbfae; }
main:not([data-phase="sealed"]) .intro { opacity: 0; pointer-events: none; }

.envelope {
  position: absolute; left: 50%; top: 50%;
  width: 300px; height: 200px; margin: -70px 0 0 -150px;
  padding: 0; border: 0; background: none; cursor: pointer;
  transition: opacity 600ms ease-in, transform 600ms ease-in;
}
.envelope > span { position: absolute; display: block; }
.env-back { inset: 0; border-radius: 8px; background: #d9c8ac; box-shadow: 0 24px 40px rgba(0, 0, 0, 0.55); }
.env-flap-back {
  left: 0; top: 0; width: 300px; height: 112px;
  background: #cdbb9c; clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0; transform: perspective(700px) rotateX(-90deg);
  transition: transform 380ms ease-out 360ms;
}
.env-note {
  left: 22px; right: 22px; top: 16px; height: 160px; border-radius: 4px;
  background:
    repeating-linear-gradient(#f0e7e0 0 13px, rgba(35, 38, 43, 0.28) 13px 14px, #f0e7e0 14px 22px) 18px 22px / 150px 96px no-repeat,
    #f0e7e0;
  transition: transform 700ms cubic-bezier(0.2, 0.8, 0.2, 1) 620ms;
}
.env-front { inset: 0; border-radius: 8px; background: linear-gradient(#efe3cf, #e4d5bb); clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%); }
.env-pocket { inset: 0; border-radius: 8px; background: #e9dbc3; clip-path: polygon(0 100%, 50% 44%, 100% 100%); }
.env-flap {
  left: 0; top: 0; width: 300px; height: 112px;
  transform-origin: 50% 0; transform: perspective(700px) rotateX(0deg);
  transition: transform 360ms ease-in;
}
.env-flap::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(#e6d7bd, #dccbae); clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.env-seal {
  position: absolute; left: 127px; top: 72px; width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 38% 32%, #c2413b, #8e1f1f);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  font-family: "Typekin Stamps A", sans-serif; font-size: 20px; color: #f6d9d2;
}
main[data-phase="sealed"] .envelope:active { transform: scale(0.98); }
main:not([data-phase="sealed"]):not([data-phase="loading"]) .env-flap { transform: perspective(700px) rotateX(-90deg); }
main:not([data-phase="sealed"]):not([data-phase="loading"]) .env-flap-back { transform: perspective(700px) rotateX(-180deg); }
main:not([data-phase="sealed"]):not([data-phase="loading"]) .env-note { transform: translateY(-92px); }
main[data-phase="rising"] .envelope,
main[data-phase="typing"] .envelope,
main[data-phase="done"] .envelope { opacity: 0; transform: translateY(160px) scale(0.9); pointer-events: none; }

.hint {
  position: absolute; left: 0; right: 0; top: calc(50% + 160px); margin: 0;
  padding: 12px 0;
  text-align: center; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: opacity 300ms ease-out;
}
main:not([data-phase="sealed"]) .hint { opacity: 0; pointer-events: none; }

/* The typewriter tilts up into view from below, like something being set down in front of you. */
.stage {
  position: absolute; inset: 0; overflow: hidden;
  opacity: 0; pointer-events: none;
  transform-origin: 50% 100%;
  transform: perspective(1100px) rotateX(42deg) translateY(34%) scale(0.8);
  transition: transform 1000ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 500ms ease-out;
}
main[data-phase="rising"] .stage,
main[data-phase="typing"] .stage,
main[data-phase="done"] .stage { opacity: 1; transform: none; }

.machine { position: absolute; transform-origin: 50% 100%; transition: transform 900ms cubic-bezier(0.2, 0.8, 0.2, 1); }
.art-clip { position: absolute; left: 0; top: 0; overflow: hidden; border-radius: 0 0 18px 18px; }
.art-clip img { position: absolute; left: 0; top: 0; display: block; }
.sheet { position: absolute; background: #f0e7e0; transition: top 220ms ease-out, height 220ms ease-out; }
.line { position: absolute; white-space: pre; overflow: hidden; transition: top 220ms ease-out; }
.u { display: inline-block; text-align: center; }
.u.stamp-a { font-family: "Typekin Stamps A", sans-serif; }
.u.stamp-b { font-family: "Typekin Stamps B", sans-serif; }
.u.new { animation: pop 140ms ease-out; }
@keyframes pop { from { opacity: 0.1; transform: translateY(-4px) scale(1.4); } to { opacity: 1; transform: none; } }

.cap { position: absolute; }
.cap .skirt { position: absolute; left: 0; right: 0; bottom: 0; }
.cap .face {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: "Special Elite", "Courier New", monospace; line-height: 1;
  transition: transform 60ms ease-out, filter 60ms ease-out;
}
.cap.down .face { transform: translateY(var(--travel)); filter: brightness(0.88); }

.bar-pivot { position: absolute; transform-origin: 50% 0; pointer-events: none; }
.bar { width: 100%; height: 100%; opacity: 0; transform-origin: 50% 100%; }
.bar.swing { animation: swing 150ms ease-out; }
@keyframes swing {
  0% { opacity: 0; transform: scaleY(0.2); }
  25% { opacity: 1; }
  50% { opacity: 1; transform: scaleY(1); }
  100% { opacity: 0; transform: scaleY(0.2); }
}

.controls {
  position: absolute; right: 12px; top: calc(12px + env(safe-area-inset-top));
  display: flex; gap: 8px;
  transition: opacity 300ms ease-out;
}
.controls button {
  min-height: 44px; padding: 0 14px; border-radius: 22px;
  border: 1px solid rgba(242, 233, 220, 0.45); background: rgba(18, 13, 11, 0.7);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
main[data-phase="done"] .controls #skip { display: none; }

.end {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 16px 24px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; align-items: stretch;
  max-width: 480px; margin: 0 auto;
  opacity: 0; transition: opacity 500ms ease-out 400ms;
}
main[data-phase="done"] .end { opacity: 1; }
.end p { margin: 0; text-align: center; font-size: 14px; font-weight: 500; color: #cdbfae; }
.primary, .secondary {
  display: flex; align-items: center; justify-content: center;
  border-radius: 26px; text-decoration: none; cursor: pointer;
}
.primary { min-height: 52px; background: #f2e9dc; color: #1a1310; font-size: 17px; font-weight: 700; border: 0; }
.secondary { min-height: 44px; background: transparent; color: #f2e9dc; font-size: 15px; font-weight: 600; border: 1px solid #6e5f52; }

.problem {
  position: absolute; inset: 0; padding: 32px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  text-align: center;
}
.problem h1 { margin: 0; font-family: "Special Elite", "Courier New", monospace; font-weight: 400; font-size: 26px; }
.problem p { margin: 0; max-width: 320px; font-size: 16px; line-height: 1.5; color: #e6dacb; }
.problem .primary { padding: 0 28px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; transition-delay: 0ms !important; }
}
