@font-face { font-family: "Cormorant"; src: url(fonts/cormorant-garamond-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Caveat"; src: url(fonts/caveat-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Goudy"; src: url(fonts/sorts-mill-goudy-latin-400-normal.woff2) format("woff2"); font-style: normal; font-display: swap; }
@font-face { font-family: "Goudy"; src: url(fonts/sorts-mill-goudy-latin-400-italic.woff2) format("woff2"); font-style: italic; font-display: swap; }

:root {
  --cream: #f8ebdf;
  --paper: #fffaf2;
  --rose: #c97f8d;
  --mauve: #7c5570;
  --plum: #54303f;
  --gold: #b98b3f;
  --velvet: #320f17;
  --display: "Cormorant", "Iowan Old Style", Georgia, serif;
  --hand: "Caveat", "Segoe Print", cursive;
  --body: "Goudy", Georgia, serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }

body {
  position: fixed;
  inset: 0;
  color: var(--plum);
  background: linear-gradient(rgba(255, 246, 237, .58), rgba(255, 246, 237, .58)), url(art/backdrop.jpg) center / cover, var(--cream);
  font: 400 1.08rem/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* A fine gilded edge around the page, and the velvet that rises for the question. */
body::before {
  content: "";
  position: fixed;
  z-index: 1;
  inset: max(7px, env(safe-area-inset-top)) 7px max(7px, env(safe-area-inset-bottom));
  border: 1px solid rgba(185, 139, 63, .6);
  border-radius: 14px;
  pointer-events: none;
  transition: border-color 1.4s ease;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--velvet);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.4s ease;
}
body.velvet { color: var(--paper); }
body.velvet::after { opacity: 1; }
body.velvet::before { border-color: rgba(232, 191, 115, .45); }

#stage {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  padding: max(16px, calc(env(safe-area-inset-top) + 6px)) 22px max(18px, calc(env(safe-area-inset-bottom) + 8px));
}

.top { display: flex; align-items: center; gap: 12px; min-height: 40px; flex: none; }

.progress { display: flex; gap: 5px; margin: 0; padding: 0; list-style: none; }
.progress[hidden] { display: none; }
.progress svg { display: block; width: 19px; height: 19px; fill: none; stroke: var(--rose); stroke-width: 1.5; transition: fill .5s, stroke .5s; }
.progress .now svg { stroke: var(--gold); stroke-width: 2.2; }
.progress .lit svg { fill: var(--gold); stroke: var(--gold); }

#chapter { flex: 1; min-height: 0; display: flex; flex-direction: column; }

h1 {
  margin: .12em 0 .14em;
  font: 500 clamp(2.25rem, 10.4vw, 3rem)/1 var(--display);
  letter-spacing: -.01em;
  text-align: center;
  text-wrap: balance;
  outline: none;
}

.intro { margin: 0 auto .2em; max-width: 34ch; color: var(--mauve); text-align: center; text-wrap: balance; }

.scene { position: relative; flex: 1; min-height: 0; display: flex; }
.scene > svg { flex: 1; width: 100%; height: 100%; display: block; overflow: visible; touch-action: none; }
.lab { fill: var(--plum); font: 500 21px var(--hand); text-anchor: middle; pointer-events: none; }
.can-grab, .item, .handle, .coin, .seal, .pot, .key { cursor: grab; }

.foot { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.status { margin: 0; min-height: 2.5em; max-width: 30ch; color: var(--mauve); font: 500 1.5rem/1.18 var(--hand); text-align: center; text-wrap: balance; }
.actions { display: flex; justify-content: center; align-items: center; gap: 16px; min-height: 56px; }

button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 8px; }

.paper {
  min-height: 48px;
  padding: .32em 1.5em .4em;
  color: var(--plum);
  background: var(--paper);
  border: 1px solid var(--gold);
  border-radius: 999px;
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px rgba(185, 139, 63, .7), 0 7px 14px rgba(84, 48, 63, .24);
  font: 500 1.5rem/1 var(--display);
}
.paper:active { transform: translateY(2px); }

.quiet {
  min-height: 44px;
  padding: 0 .7em;
  color: var(--mauve);
  background: none;
  border: 0;
  font-style: italic;
  text-decoration: underline;
  text-decoration-color: rgba(124, 85, 112, .5);
  text-underline-offset: .25em;
}

.sound { margin-left: auto; padding-right: 2px; font-size: .95rem; }
body.velvet .quiet { color: #f2d9cf; text-decoration-color: rgba(242, 217, 207, .55); }

.loading { margin: auto; color: var(--mauve); font: 500 1.6rem var(--hand); }

/* Cover */
.cover { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; }
.frame { position: relative; flex: 1; min-height: 0; aspect-ratio: 609 / 900; max-width: 100%; }
.frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.frame .inside { position: absolute; inset: 24% 22%; display: flex; align-items: center; justify-content: center; }
.frame h1 { margin: 0; font-size: clamp(2.5rem, min(12vw, 7dvh), 3.5rem); }
.cover .intro { margin-top: .7em; font-size: 1.14rem; }
.cover .actions { flex: none; flex-wrap: wrap; margin: .35em 0 .2em; }

/* Chapter art */
.liquid { transition: fill .5s; }
.rise { animation: rise 2.6s ease-in infinite; animation-delay: var(--d, 0s); }
@keyframes rise { from { transform: translateY(0); opacity: 0; } 20% { opacity: 1; } to { transform: translateY(-96px); opacity: 0; } }

.nudge { animation: nudge 1.7s ease-in-out infinite; }
@keyframes nudge { 50% { opacity: .35; } }

.plant { opacity: 0; transform: scale(.72); transform-origin: 0 0; transition: opacity .55s ease, transform .75s cubic-bezier(.3, 1.4, .5, 1); }
.pot[data-stage="0"] .s0, .pot[data-stage="1"] .s1, .pot[data-stage="2"] .s2 { opacity: 1; transform: none; }
.drops circle { animation: fall .5s linear infinite; animation-delay: var(--d, 0s); }
@keyframes fall { from { transform: translateY(0); opacity: 1; } to { transform: translateY(52px); opacity: .2; } }

.scratch {
  position: relative;
  width: 100%;
  aspect-ratio: 860 / 470;
  max-height: 100%;
  margin: auto;
  filter: drop-shadow(0 8px 12px rgba(84, 48, 63, .28));
}
.ticket {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1em 2.2em;
  color: var(--plum);
  background: url(art/card.webp) center / 100% 100% no-repeat;
  text-align: center;
}
.ticket p { margin: 0; max-width: 24ch; }
.ticket .big { margin-bottom: .12em; font: 500 clamp(1.9rem, 8.6vw, 2.5rem)/1 var(--display); }
.scratch canvas { position: absolute; inset: 3.2%; width: 93.6%; height: 93.6%; border-radius: 3px; touch-action: none; cursor: crosshair; transition: opacity .6s; }

.letter {
  position: absolute;
  inset: 10px 0 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 1.15em 1.35em 1.3em;
  color: var(--plum);
  background: var(--paper);
  border: 1px solid rgba(185, 139, 63, .75);
  outline: 3px solid var(--paper);
  border-radius: 4px;
  box-shadow: 0 0 0 4px rgba(185, 139, 63, .55), 0 12px 22px rgba(84, 48, 63, .25);
  font-size: 1.03rem;
  line-height: 1.5;
  -webkit-user-select: text;
  user-select: text;
}
.letter p { margin: 0 0 .8em; }
.letter .salute { font: 500 1.9rem/1.1 var(--display); }
.letter .sign { margin: 1em 0 0; font: 500 1.6rem/1.1 var(--hand); text-align: right; }
.letter:focus-visible { outline-color: var(--gold); }

/* The question */
.final { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 1.2dvh; }
.ring-wrap {
  flex: 0 1 auto;
  min-height: 150px;
  margin: 0 -22px;
  display: flex;
  justify-content: center;
  overflow: hidden;
  animation: appear 1.6s .5s ease-out both;
}
/* The photo melts into the page on every side, so it has no visible edge. */
.ring-photo {
  display: block;
  width: min(100%, 56dvh);
  aspect-ratio: 1;
  object-fit: cover;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 7%, #000 70%, transparent 98%), linear-gradient(to right, transparent, #000 9%, #000 91%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 7%, #000 70%, transparent 98%), linear-gradient(to right, transparent, #000 9%, #000 91%, transparent);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}
.final h1 { margin-top: .05em; color: var(--paper); font-size: clamp(2.2rem, 10.4vw, 3.2rem); animation: appear 1s 1.8s both; }
.final .foot { animation: appear 1s 2.4s both; }
.final .status { color: #f2d9cf; white-space: pre-line; }
.final .paper { min-width: 118px; }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }

#confetti { position: fixed; inset: 0; z-index: 5; width: 100%; height: 100%; pointer-events: none; }

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

@media (max-height: 700px) {
  body { font-size: 1rem; }
  h1 { font-size: clamp(1.9rem, 8.6vw, 2.4rem); }
  .status { font-size: 1.28rem; }
  .final h1 { font-size: clamp(2rem, 9.8vw, 2.4rem); }
}

/* A rotated phone: let the ring shrink so Yes and No stay on screen. */
@media (max-height: 460px) {
  .ring-wrap { min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
