@font-face {
  font-family: 'Card Serif';
  src: url('assets/serif.ttf') format('truetype');
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: 'Card Hand';
  src: url('assets/handwriting.ttf') format('truetype');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --night: #142735;
  --paper: #f5eedc;
  --ink: #172a38;
  --annotation: #7d2f28;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100svh;
  background: radial-gradient(ellipse at 35% 15%, #243b49 0%, var(--night) 55%, #10212e 100%);
  color: var(--paper);
  font-family: system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .12;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath fill='%23fff' filter='url(%23n)' opacity='.22' d='M0 0h180v180H0z'/%3E%3C/svg%3E");
}

.masthead {
  min-height: 72px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 27px 40px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  letter-spacing: 1.7px;
  color: #eee7d5bd;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #f5eedc24;
  border-radius: 3px;
  color: var(--paper);
  background: transparent;
  font-size: 11px;
  letter-spacing: .3px;
}

.sound-toggle:hover { background: #ffffff08; }
.sound-muted { display: none; }
.sound-toggle[aria-pressed='false'] .sound-muted { display: initial; }
.sound-toggle[aria-pressed='false'] .sound-waves { display: none; }

main {
  display: grid;
  align-content: center;
  min-height: calc(100svh - 112px);
  padding: 0 24px 84px;
}

.stationery {
  position: relative;
  width: min(100%, 1050px);
  aspect-ratio: 3 / 2;
  margin: 0 auto;
  isolation: isolate;
}

.scene {
  position: absolute;
  inset: 0;
  color: var(--ink);
}

.paper-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.envelope-view h1 {
  position: absolute;
  inset: 42% 12% auto;
  margin: 0;
  text-align: center;
  font: 500 clamp(32px, 5.4vw, 67px) / 1.2 'Card Serif', Georgia, serif;
  letter-spacing: -.025em;
  pointer-events: none;
}

button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid #f5eedc; outline-offset: 6px; }

.open-card {
  position: absolute;
  inset: 17% 7% 17%;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--paper);
}

.open-label {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 36px);
  padding: 13px 0;
  font-size: 15px;
  letter-spacing: .35px;
  white-space: nowrap;
}

.open-label span { display: inline-block; margin-left: 10px; transition: transform .25s; }
.open-card:hover .open-label span { transform: translate(3px, -3px); }
.envelope-view:has(.open-card:hover) .paper-image { filter: brightness(1.025); }
.envelope-view.leaving { animation: envelope-away .65s ease-in both; pointer-events: none; }
.envelope-view.leaving .open-label { opacity: 0; }
.greeting-view { animation: card-arrives .95s cubic-bezier(.2, .65, .25, 1) both; }

.greeting-view h2 {
  position: absolute;
  top: 50.5%;
  left: 12%;
  right: 12%;
  margin: 0;
  font: 500 clamp(21px, 4.3vw, 49px) / 1.1 'Card Serif', Georgia, serif;
  letter-spacing: -.018em;
  text-align: center;
}

.greeting-view h2 span { display: block; }
.greeting-view h2:focus { outline: none; }

.marginal-note {
  position: absolute;
  top: 79.5%;
  right: 13%;
  margin: 0;
  padding: 0 12px 5px;
  font: 500 clamp(24px, 4vw, 48px) / 1.2 'Card Hand', cursive;
  color: var(--annotation);
  transform: rotate(-7deg);
  clip-path: inset(0 100% 0 0);
  animation: ink-appears 1.4s linear forwards;
}

.restart-card {
  position: absolute;
  top: 102%;
  left: 50%;
  transform: translateX(-50%);
  min-height: 44px;
  padding: 12px 16px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #eee7d5bd;
  font-size: 12px;
  white-space: nowrap;
}

.restart-card span { margin-left: 7px; }
.restart-card:hover { color: var(--paper); }

.greeting-actions {
  position: absolute;
  top: 102%;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
}

.greeting-actions .restart-card { position: static; transform: none; }
.marginal-note.visited { animation: none; clip-path: none; }

.reading-action {
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid #f5eedc66;
  border-radius: 0;
  padding: 12px 8px;
  background: transparent;
  color: var(--paper);
  font-size: 13px;
  letter-spacing: .2px;
}

.reading-action span { margin-left: 12px; }
.reading-action:hover { border-color: var(--paper); }
.reading-action.secondary { color: #eee7d5bd; border-bottom-color: transparent; }
.reading-action.secondary:hover { color: var(--paper); }

.inside-mode .masthead { position: sticky; top: 0; z-index: 5; background: #142735ed; backdrop-filter: blur(12px); }
.inside-mode main { align-content: start; padding-top: 24px; padding-bottom: 48px; }
.inside-view { width: min(100%, 1160px); margin: 0 auto; color: var(--ink); }
.inside-spread { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); position: relative; }
.inside-spread::after { content: ''; position: absolute; top: 4%; bottom: 4%; left: calc(50% - 10px); width: 20px; background: linear-gradient(90deg, transparent, #63482a17, transparent); pointer-events: none; }
.inside-page { position: relative; min-height: 560px; padding: 60px 44px 62px; }
.inside-page + .inside-page { margin-left: -6.5%; }
.page-surface { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; user-select: none; }
.page-content { position: relative; }
.page-content h2 { margin: 8px 0 54px; font: 500 clamp(36px, 4vw, 48px)/1.1 'Card Serif', Georgia, serif; letter-spacing: -.015em; }
.page-content h2:focus { outline: none; }
.page-content p { font: 500 clamp(25px, 2.7vw, 33px)/1.3 'Card Serif', Georgia, serif; margin: 0; }
.page-content .inside-note { margin-top: 45px; padding: 3px 3px 8px 13px; font: 500 clamp(25px, 2.6vw, 34px)/1.1 'Card Hand', cursive; color: var(--annotation); transform: rotate(-5deg); clip-path: inset(-36px 100% -8px -8px); animation: inner-ink-appears 1.4s linear forwards; }
.page-content .second-note { margin-top: 16px; margin-left: 30%; }
.age-challenge { margin-top: 42px; }
.age-challenge p { font-size: clamp(25px, 2.3vw, 29px); }
.age-challenge p + p { margin-top: 18px; }
.page-content [tabindex='-1'] { scroll-margin-top: 110px; }
.page-content p:focus { outline: none; }
.inside-note::before { content: ''; position: absolute; width: 18px; height: 31px; border-left: 1px solid currentColor; border-radius: 50%; left: -4px; top: -30px; transform: rotate(15deg); }
.inside-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 20px 20px 0; }

.ending-view { width: min(100%, 1080px); margin: 0 auto; color: var(--ink); }
.ending-sheet { position: relative; min-height: 620px; padding: 64px 78px 68px; }
.ending-copy { position: relative; max-width: 840px; }
.ending-copy h2 { margin: 0 0 32px; font: 500 clamp(32px, 3.3vw, 42px)/1.2 'Card Serif', Georgia, serif; letter-spacing: -.015em; }
.ending-copy h2:focus { outline: none; }
.ending-copy p { margin: 0 0 26px; max-width: 760px; font: 500 clamp(25px, 2.6vw, 33px)/1.33 'Card Serif', Georgia, serif; }
.ending-copy .signature { margin: 12px 0 0; font: 500 50px/1.15 'Card Hand', cursive; }

.media-status, .noscript {
  margin: 55px auto 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
  color: #eee7d5bd;
}

@keyframes envelope-away {
  to { opacity: 0; transform: translateY(18px) rotateX(12deg) scale(.97); }
}

@keyframes card-arrives {
  from { opacity: 0; transform: translateY(35px) scale(.97); }
  to { opacity: 1; transform: none; }
}

@keyframes ink-appears { to { clip-path: inset(0 0 0 0); } }
@keyframes inner-ink-appears { to { clip-path: inset(-36px -8px -8px -8px); } }

@media (max-width: 600px) {
  .masthead { min-height: 64px; padding: 22px 24px 10px; font-size: 10px; letter-spacing: 1.2px; }
  main { min-height: calc(100svh - 100px); padding: 0 4px 80px; }
  .stationery { width: 100%; }
  .envelope-view h1 { top: 41%; font-size: clamp(29px, 8vw, 45px); }
  .open-label { top: calc(100% + 25px); font-size: 14px; }
  .greeting-view h2 { top: 49%; left: 11%; right: 11%; font-size: clamp(20px, 5.7vw, 34px); }
  .marginal-note { top: 80.5%; right: 12%; font-size: clamp(24px, 6.6vw, 36px); }
  .greeting-actions { gap: 12px; }
  .inside-mode main { padding: 8px 4px 28px; }
  .inside-spread { display: block; }
  .inside-spread::after { display: none; }
  .inside-page { min-height: 400px; padding: 44px 34px 54px; }
  .inside-page + .inside-page { margin-left: 0; margin-top: 6px; }
  .inside-page.awaiting { display: none; }
  .page-content h2 { font-size: 39px; margin-bottom: 38px; }
  .page-content p { font-size: 28px; }
  .page-content .inside-note { font-size: 30px; margin-top: 38px; }
  .page-content .second-note { margin-top: 15px; margin-left: 15%; }
  .inside-actions { margin: 16px 18px 0; }
  .ending-sheet { min-height: 0; padding: 44px 34px 54px; }
  .ending-copy h2 { font-size: 32px; margin-bottom: 28px; }
  .ending-copy p { font-size: 28px; margin-bottom: 24px; }
  .ending-copy .signature { font-size: 46px; margin-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; }
  .marginal-note { clip-path: none; }
  .inside-note { clip-path: none; }
}
