:root {
  --paper: oklch(0.955 0.02 85);
  --paper-deep: oklch(0.91 0.032 82);
  --ink: oklch(0.31 0.038 52);
  --ink-soft: oklch(0.48 0.03 55);
  --gold: oklch(0.71 0.108 82);
  --gold-deep: oklch(0.57 0.12 75);
  --wax: oklch(0.42 0.13 25);
  --wax-light: oklch(0.5 0.12 28);
  --flame: oklch(0.78 0.15 58);
  --smoke: oklch(0.78 0.01 80);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --font-display: "Fraunces", "Iowan Old Style", serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --safe-top: max(20px, env(safe-area-inset-top));
  --safe-bottom: max(24px, env(safe-area-inset-bottom));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

img {
  max-width: 100%;
  display: block;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.045;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#app {
  position: relative;
  z-index: 2;
  height: 100dvh;
  overflow: hidden;
}

.screen {
  position: relative;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: var(--safe-top) 22px var(--safe-bottom);
}

.screen[hidden] {
  display: none !important;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

.display {
  margin: 0.15em 0 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(3.4rem, 16vw, 5.6rem);
  line-height: 0.88;
  letter-spacing: -0.03em;
  font-optical-sizing: auto;
}

.display--sm {
  font-size: clamp(2.1rem, 10vw, 3.2rem);
  line-height: 0.95;
}

.hub-mast {
  display: grid;
  justify-items: center;
  text-align: center;
}

.hub-lockup {
  display: grid;
  justify-items: center;
}

.hub-age {
  margin: 0.02em 0 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(6.4rem, 34vw, 10.5rem);
  line-height: 0.76;
  letter-spacing: -0.06em;
  color: var(--ink);
  font-optical-sizing: auto;
}

.keepsakes {
  list-style: none;
  margin: 2.4rem 0 0;
  padding: 0;
  display: flex;
  gap: 0.7rem;
  min-height: 2.6rem;
}

.keepsakes li {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  background: var(--paper-deep);
  display: grid;
  place-items: center;
  color: var(--gold-deep);
  opacity: 0;
  transform: translateY(8px) scale(0.92);
}

.keepsakes li.is-in {
  opacity: 1;
  transform: none;
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}

.keepsakes i {
  font-size: 1.15rem;
  line-height: 1;
}

#hub.screen {
  display: flex;
  flex-direction: column;
}

.hub-action {
  margin-top: auto;
  padding-top: 2rem;
  display: grid;
  justify-items: center;
  gap: 0.7rem;
  position: relative;
  z-index: 2;
}

.hub-whisper {
  margin: 0;
  text-align: center;
  color: var(--ink-soft);
  max-width: 28ch;
  min-height: 2.6em;
  font-size: 0.95rem;
  line-height: 1.4;
}

.hub-cta {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--wax);
}

.wax-seal {
  position: relative;
  width: 6.4rem;
  height: 6.4rem;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, oklch(0.58 0.12 28), var(--wax) 58%, oklch(0.34 0.1 22));
  color: oklch(0.93 0.04 85);
  box-shadow:
    inset 0 1px 0 oklch(0.72 0.08 30 / 0.45),
    0 18px 30px oklch(0.42 0.13 25 / 0.28);
}

.wax-seal:active {
  transform: scale(0.98);
}

.wax-seal__ring {
  position: absolute;
  inset: 7px;
  border: 1px solid oklch(0.82 0.05 85 / 0.35);
  border-radius: 50%;
}

.wax-seal__mark {
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 650;
}

.ghost-back {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 0;
  margin: 0 0 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

#game-root {
  min-height: 0;
}

.game-shell {
  display: grid;
  align-content: start;
  gap: 1.1rem;
  animation: rise 0.7s var(--ease) both;
}

.game-kicker {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

.game-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 8vw, 2.45rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
  max-width: 16ch;
}

.game-copy {
  margin: 0;
  color: var(--ink-soft);
  max-width: 34ch;
  line-height: 1.45;
}

.pill {
  border: 0;
  border-radius: 999px;
  padding: 0.95rem 1.4rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 500;
}

.pill:active {
  transform: scale(0.98);
}

.pill--ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px oklch(0.31 0.038 52 / 0.18);
}

.pill--gold {
  background: var(--gold-deep);
  color: var(--paper);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-7px);
  }
  40% {
    transform: translateX(7px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(5px);
  }
}

@keyframes flicker {
  0%,
  100% {
    transform: scale(1) rotate(-4deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.08) rotate(6deg);
    opacity: 0.86;
  }
}

/* Dodge */
.dodge-stage {
  position: relative;
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 4rem);
}

.dodge-yes {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  transform-origin: center bottom;
  transition: transform 180ms ease-out;
  z-index: 2;
  min-width: 7.2rem;
}

.dodge-no {
  position: absolute;
  z-index: 3;
  transition: top 180ms ease-out, left 180ms ease-out, transform 180ms ease-out;
  will-change: top, left, transform;
}

.dodge-no.is-tiny {
  transform: scale(0.4);
}

/* Memory */
.memory-track {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  height: 0.42rem;
  border-radius: 999px;
  overflow: hidden;
  background: var(--paper-deep);
}

.memory-cell {
  background: oklch(0.31 0.038 52 / 0.28);
  transition: background 0.45s var(--ease);
}

.memory-cell.is-open {
  background: var(--gold);
}

.memory-hint {
  margin: 0;
  color: var(--gold-deep);
  font-size: 0.95rem;
  line-height: 1.4;
  max-width: 28ch;
}

.memory-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.card {
  position: relative;
  width: 100%;
  border: 0;
  padding: 0;
  border-radius: 1.05rem;
  background: var(--gold-deep);
  -webkit-perspective: 800px;
  perspective: 800px;
  -webkit-tap-highlight-color: transparent;
}

.card::before {
  content: "";
  display: block;
  padding-bottom: 100%;
}

.card-inner {
  position: absolute;
  inset: 0;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 0.55s var(--ease);
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 1.05rem;
  display: grid;
  place-items: center;
}

.card-back {
  background: var(--gold-deep);
  background-image: radial-gradient(circle at 30% 18%, oklch(0.78 0.1 82), var(--gold-deep) 62%);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 650;
}

.card-front {
  -webkit-transform: rotateY(180deg) translateZ(1px);
  transform: rotateY(180deg) translateZ(1px);
  background-color: var(--paper-deep);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.card-back i {
  font-size: 1.7rem;
  line-height: 1;
}

.memory-skip {
  justify-self: start;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  padding: 0.55rem 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.72rem;
  box-shadow: inset 0 0 0 1px oklch(0.31 0.038 52 / 0.22);
}

/* Quiz */
.quiz-options {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.4rem;
}

.quiz-option {
  text-align: left;
  border: 0;
  border-radius: 1.15rem;
  padding: 1rem 1.05rem;
  background: var(--paper-deep);
  color: var(--ink);
}

.quiz-option.is-shake {
  animation: shake 0.42s var(--ease);
  background: oklch(0.88 0.05 25);
}

.quiz-tease {
  min-height: 1.4em;
  margin: 0;
  color: var(--wax);
  font-size: 0.92rem;
}

.quiz-count {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Scratch */
.scratch-frame {
  position: relative;
  border-radius: 1.4rem;
  overflow: hidden;
  background: var(--paper-deep);
  aspect-ratio: 3 / 4;
}

.scratch-letter {
  position: absolute;
  inset: 0;
  padding: 1.5rem 1.3rem;
  display: grid;
  align-content: start;
  gap: 0.7rem;
}

.scratch-letter p {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  line-height: 1.35;
}

.scratch-letter small {
  color: var(--ink-soft);
  font-family: var(--font-body);
}

.scratch-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Candles */
.candle-field {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.35rem 0.2rem;
  justify-items: center;
  width: min(100%, 16rem);
  margin: 0 auto;
}

.candle-field .candle {
  font-size: 1.45rem;
  line-height: 1;
  color: var(--gold);
  animation: flicker 0.9s ease-out infinite;
}

.candle-field .candle:nth-child(3n) {
  animation-delay: 0.12s;
}

.candle-field .candle:nth-child(3n + 1) {
  animation-delay: 0.28s;
}

.candle-field .candle.is-out {
  color: var(--ink-soft);
  opacity: 0.38;
  animation: none;
}

.blow-wrap {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.6rem;
}

.blow-bar {
  height: 0.55rem;
  border-radius: 999px;
  background: oklch(0.31 0.038 52 / 0.1);
  overflow: hidden;
}

.blow-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--gold);
  transform-origin: left center;
}

.blow-hold {
  width: 100%;
}

/* Story */
.story {
  position: fixed;
  inset: 0;
  background: oklch(0.22 0.03 50);
  color: oklch(0.95 0.02 85);
  z-index: 20;
  padding: var(--safe-top) 0 0;
  touch-action: none;
}

.story-bars {
  display: flex;
  gap: 4px;
  padding: 0 10px;
}

.story-bar {
  flex: 1;
  height: 3px;
  border-radius: 99px;
  background: oklch(0.95 0.02 85 / 0.22);
  overflow: hidden;
}

.story-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 100%;
  background: oklch(0.95 0.02 85);
  transform: scaleX(0);
  transform-origin: left center;
}

.story-bar.is-done::after {
  transform: scaleX(1);
  animation: none;
}

.story-bar.is-active::after {
  animation: story-fill var(--dur, 3s) linear forwards;
}

.story-bar.is-paused::after {
  animation-play-state: paused;
}

@keyframes story-fill {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

.story-frame {
  position: relative;
  height: calc(100dvh - var(--safe-top) - 18px);
  display: grid;
  place-items: center;
}

.story-visual {
  position: absolute;
  inset: 0;
  background: oklch(0.28 0.04 55);
}

.story-visual img,
.story-visual video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.story-caption {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: calc(var(--safe-bottom) + 28px);
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  line-height: 1.25;
  text-shadow: 0 10px 24px oklch(0.2 0.03 50 / 0.6);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s var(--ease) 0.4s, transform 0.5s var(--ease) 0.4s;
}

.story-caption.is-in {
  opacity: 1;
  transform: none;
}

.story-hit {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
}

.story-hit--next {
  right: 0;
  width: 70%;
}

.story-count {
  position: absolute;
  top: 14px;
  right: 14px;
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: oklch(0.95 0.02 85 / 0.7);
}

.story-end {
  position: relative;
  z-index: 5;
  display: grid;
  gap: 1rem;
  justify-items: stretch;
  justify-content: center;
  align-content: center;
  text-align: center;
  width: min(22rem, 100%);
  margin: 0 auto;
  min-height: 100%;
  padding: 2rem 1.4rem calc(var(--safe-bottom) + 1.5rem);
}

.story-end .eyebrow {
  justify-self: center;
}

.story-end .pill--ghost {
  color: oklch(0.95 0.02 85);
  box-shadow: inset 0 0 0 1px oklch(0.95 0.02 85 / 0.3);
}

.story-end h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.6rem;
  line-height: 0.95;
}

.story-end p {
  margin: 0;
  color: oklch(0.95 0.02 85 / 0.75);
}

.story-end .pill {
  width: 100%;
}

.chapter {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: end;
  padding: 2rem 1.4rem calc(var(--safe-bottom) + 4.5rem);
  background:
    radial-gradient(circle at 20% 15%, oklch(0.45 0.08 75 / 0.45), transparent 40%),
    linear-gradient(180deg, oklch(0.32 0.05 55), oklch(0.22 0.03 48));
}

.chapter .eyebrow {
  color: var(--gold);
}

.chapter h3 {
  margin: 0.3rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  line-height: 0.95;
}

/* Album */
.album-head {
  margin-bottom: 1.2rem;
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 4px;
}

.album-grid button {
  position: relative;
  padding: 0;
  border: 0;
  background: var(--paper-deep);
  aspect-ratio: 1;
  overflow: hidden;
  touch-action: pan-y;
}

.album-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-grid button.is-video::after {
  content: "";
  position: absolute;
  z-index: 1;
  right: 7px;
  bottom: 7px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent oklch(0.97 0.02 85);
  filter: drop-shadow(0 1px 2px oklch(0.2 0.03 50 / 0.55));
}

.album-grid button.is-video::before {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: oklch(0.2 0.03 50 / 0.45);
}

.album-empty {
  color: var(--ink-soft);
  line-height: 1.5;
}

.album-empty code {
  font-size: 0.85em;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: oklch(0.22 0.03 50);
  padding: var(--safe-top) 0 var(--safe-bottom);
  touch-action: none;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-media {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.lightbox img,
.lightbox video {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

.lightbox-count {
  position: absolute;
  top: var(--safe-top);
  left: 18px;
  z-index: 3;
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: oklch(0.95 0.02 85 / 0.7);
}

.lightbox-close {
  position: absolute;
  top: var(--safe-top);
  right: 18px;
  z-index: 3;
  border: 0;
  background: transparent;
  color: oklch(0.95 0.02 85);
}

.lightbox-hit {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  width: 30%;
}

.lightbox-hit--next {
  left: auto;
  right: 0;
  width: 70%;
}

.lightbox--video-controls .lightbox-hit {
  bottom: 56px;
}

.finale {
  display: grid;
  gap: 1.1rem;
  padding-bottom: 1rem;
}

.finale h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 11vw, 3.6rem);
  line-height: 0.92;
  max-width: 12ch;
}

.finale p {
  margin: 0;
  color: var(--ink-soft);
  max-width: 34ch;
  line-height: 1.5;
}

.video-slot {
  border-radius: 1.3rem;
  overflow: hidden;
  background: var(--paper-deep);
  aspect-ratio: 16 / 9;
}

.video-slot iframe,
.video-slot video {
  width: 100%;
  height: 100%;
  border: 0;
}

.finale-actions {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.4rem;
}

@media (min-width: 720px) {
  .screen {
    max-width: 430px;
    margin: 0 auto;
    box-shadow: 0 0 0 1px oklch(0.31 0.038 52 / 0.06);
  }

  .story,
  .lightbox {
    max-width: 430px;
    left: 50%;
    transform: translateX(-50%);
  }
}

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