:root {
  --paper: #fffaf0;
  --paper-strong: #fff4d8;
  --ink: #1e2930;
  --muted: #66757d;
  --line: #e7dac2;
  --mint: #b9ead6;
  --mint-dark: #168869;
  --coral: #ff7c66;
  --coral-dark: #b84232;
  --blue: #8fc7ff;
  --violet: #7f6ad8;
  --shadow: 0 24px 80px rgba(65, 48, 25, 0.13);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(rgba(30, 41, 48, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30, 41, 48, 0.03) 1px, transparent 1px),
    radial-gradient(circle at 16% 8%, rgba(185, 234, 214, 0.9), transparent 26rem),
    radial-gradient(circle at 86% 18%, rgba(255, 124, 102, 0.22), transparent 25rem),
    linear-gradient(135deg, #fffaf0 0%, #fff7e7 45%, #f8fbf2 100%);
  background-size: 42px 42px, 42px 42px, auto, auto, auto;
  overflow-x: clip;
}

body.final-gift-running .quest-topbar,
body.final-gift-running .quest-stage {
  filter: blur(7px);
  transform: scale(0.992);
  transition: filter 420ms ease, transform 420ms ease;
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.quest-topbar {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 420px);
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
  border: 1px solid rgba(30, 41, 48, 0.1);
  border-radius: 14px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 16px 48px rgba(65, 48, 25, 0.08);
  backdrop-filter: blur(14px);
}

.quest-topbar strong {
  display: block;
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 800;
}

.eyebrow,
.section-kicker,
.scene-count {
  margin: 0 0 10px;
  color: var(--coral-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.progress-area {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
  text-align: right;
}

.progress-track {
  height: 12px;
  border: 1px solid rgba(30, 41, 48, 0.15);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint-dark), var(--coral));
  transition: width 260ms ease;
}

.quest-stage {
  position: relative;
  min-height: 660px;
  perspective: 1400px;
}

.quest-stage::before {
  position: absolute;
  top: 26px;
  left: 56%;
  width: 170px;
  height: 170px;
  border: 2px dashed rgba(30, 41, 48, 0.15);
  content: "";
  pointer-events: none;
  transform: rotate(14deg);
}

.quest-stage::after {
  position: absolute;
  right: 8%;
  bottom: 40px;
  width: 220px;
  height: 14px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 11px, transparent 11px 20px);
  content: "";
  opacity: 0.12;
  pointer-events: none;
  transform: rotate(-6deg);
}

.scene {
  display: none;
  min-height: 660px;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 1.05fr);
  gap: 36px;
  align-items: center;
  transform-origin: 50% 45%;
  animation: pageIn 560ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.scene.active {
  display: grid;
}

.scene.leaving {
  position: absolute;
  inset: 0;
  display: grid;
  pointer-events: none;
  animation: pageOut 520ms cubic-bezier(0.45, 0, 0.2, 1) both;
}

@keyframes pageIn {
  from {
    opacity: 0;
    filter: blur(10px);
    transform: translateX(34px) rotateY(-7deg) scale(0.985);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: translateX(0) rotateY(0) scale(1);
  }
}

@keyframes pageOut {
  from {
    opacity: 1;
    filter: blur(0);
    transform: translateX(0) rotateY(0) scale(1);
  }
  to {
    opacity: 0;
    filter: blur(9px);
    transform: translateX(-42px) rotateY(8deg) scale(0.985);
  }
}

@keyframes wordReveal {
  0% {
    transform: translateY(8px) scale(0.96);
    box-shadow: 0 0 0 rgba(22, 136, 105, 0);
  }
  55% {
    transform: translateY(-4px) scale(1.035);
    box-shadow: 0 16px 32px rgba(22, 136, 105, 0.2);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: none;
  }
}

@keyframes burstDot {
  to {
    opacity: 0;
    transform:
      translate(calc(-50% + var(--x)), calc(-50% + var(--y)))
      rotate(var(--r))
      scale(0.65);
  }
}

@keyframes burstRing {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.32);
  }
  24% {
    opacity: 0.45;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.45);
  }
}

@keyframes burstSpark {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--r)) scaleX(0.2);
  }
  22% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform:
      translate(calc(-50% + var(--x)), calc(-50% + var(--y)))
      rotate(var(--r))
      scaleX(0.8);
  }
}

.scene-copy {
  position: relative;
  z-index: 1;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 720px;
  font-size: clamp(4.1rem, 13vw, 9rem);
  line-height: 0.82;
  font-weight: 800;
}

h2 {
  font-size: clamp(2.6rem, 7vw, 6rem);
  line-height: 0.92;
  font-weight: 800;
}

.scene-copy p:not(.eyebrow):not(.scene-count):not(.form-message) {
  max-width: 650px;
  margin: 26px 0 0;
  color: #435058;
  font-size: clamp(1.06rem, 2vw, 1.28rem);
  line-height: 1.65;
}

.button {
  display: inline-flex;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 0 20px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.button:hover {
  transform: translateY(-2px);
}

.button:disabled {
  cursor: default;
  opacity: 0.58;
  transform: none;
  box-shadow: none;
}

.button.primary {
  margin-top: 32px;
  background: var(--ink);
  color: #fffaf0;
  box-shadow: 8px 8px 0 var(--mint);
}

.intro-visual {
  position: relative;
  min-height: 520px;
}

.button.ghost {
  background: rgba(255, 255, 255, 0.54);
}

.seed-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(30, 41, 48, 0.12);
  border-radius: 18px 18px 6px 18px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: var(--shadow);
  transform: rotate(3deg);
  backdrop-filter: blur(16px);
}

.intro-visual .seed-board {
  position: absolute;
  inset: 64px 0 auto auto;
  width: min(600px, 100%);
}

.seed-token {
  display: grid;
  min-height: 78px;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--paper);
}

.seed-token.revealed {
  animation: wordReveal 520ms ease both;
}

.seed-token span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.seed-token b {
  overflow-wrap: anywhere;
  font-size: 0.93rem;
}

.seed-token.locked b {
  color: transparent;
  text-shadow: 0 0 10px rgba(30, 41, 48, 0.38);
}

.seed-token.offline {
  border-style: dashed;
  background: #f4fff9;
}

.seed-token.offline b {
  color: var(--mint-dark);
}

.qr-card,
.words-unlocked {
  border: 1px solid rgba(30, 41, 48, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.qr-card {
  display: grid;
  grid-template-columns: minmax(210px, 300px) 1fr;
  gap: 22px;
  align-items: end;
  padding: 26px;
  transform: rotate(-2deg);
}

.qr-code {
  aspect-ratio: 1;
  border: 8px solid var(--ink);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.qr-code svg,
.qr-code img {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-note {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.qr-note strong {
  color: var(--ink);
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  line-height: 0.95;
}

.qr-unlock {
  display: grid;
  gap: 12px;
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

#qrUnlockWord {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.answer-form {
  display: grid;
  max-width: 520px;
  gap: 12px;
  margin-top: 30px;
}

.answer-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.answer-form input {
  width: 100%;
  border: 1px solid #d9cdb6;
  border-radius: 8px;
  padding: 14px 15px;
  background: #fffdf8;
  color: var(--ink);
  outline: none;
}

.answer-form input:focus {
  border-color: var(--mint-dark);
  box-shadow: 0 0 0 3px rgba(22, 136, 105, 0.12);
}

.answer-form input[aria-invalid="true"] {
  border-color: var(--coral-dark);
}

.form-message {
  min-height: 24px;
  margin: 0;
  color: var(--coral-dark);
  font-weight: 800;
}

.question-scene {
  align-self: stretch;
  display: grid;
  align-content: center;
}

.words-unlocked {
  display: grid;
  align-content: center;
  gap: 12px;
  min-height: 280px;
  padding: 26px;
  transform: rotate(2deg);
}

#currentUnlocks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
}

.next-step {
  justify-self: start;
  margin-top: 8px;
}

.next-step[hidden] {
  display: none;
}

.map-art {
  position: relative;
  min-height: 430px;
  border: 1px solid rgba(30, 41, 48, 0.13);
  border-radius: 8px;
  background: #dce5d7;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.actual-map {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  min-height: 430px;
}

.map-focus {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  border: 2px solid #fff;
  background: var(--coral);
  border-radius: 999px;
  box-shadow: 0 0 0 12px rgba(255, 124, 102, 0.2), 0 14px 28px rgba(30, 41, 48, 0.24);
  transform: translate(-50%, -50%);
}

.place-readout {
  border: 1px solid rgba(30, 41, 48, 0.11);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink) !important;
  font-weight: 800;
}

.final-copy .button {
  margin-top: 30px;
}

[data-scene="final"] {
  grid-template-columns: minmax(0, 0.78fr) minmax(420px, 1.22fr);
  gap: 54px;
}

[data-scene="final"] h1 {
  max-width: 520px;
  font-size: clamp(4rem, 8.5vw, 6.25rem);
  line-height: 0.88;
}

[data-scene="final"] .scene-copy p:not(.eyebrow):not(.scene-count):not(.form-message) {
  max-width: 560px;
  font-size: clamp(1.08rem, 1.8vw, 1.22rem);
}

.final-visual .seed-board {
  inset: 34px 0 auto auto;
  width: min(650px, 100%);
  transform: rotate(-1.6deg);
}

.final-reward {
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: -36px;
  color: var(--mint-dark);
  font-size: clamp(3.8rem, 12vw, 8.5rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: 0;
  opacity: 0;
  text-shadow: 0 18px 46px rgba(22, 136, 105, 0.18);
  transform: translateY(-24px) scale(0.94);
  transition: opacity 520ms ease, transform 720ms cubic-bezier(0.2, 0.85, 0.2, 1);
}

.final-reward.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.word-chip {
  border: 1px solid rgba(30, 41, 48, 0.18);
  border-radius: 999px;
  padding: 8px 11px;
  background: #fffaf0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.word-chip.open {
  background: var(--ink);
  color: #fffaf0;
}

.word-chip.revealed {
  animation: wordReveal 520ms ease both;
}

.word-chip.offline {
  border-style: dashed;
  background: #f4fff9;
  color: var(--mint-dark);
}

.success-burst {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, rgba(185, 234, 214, 0.18), transparent 34%);
}

.burst-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 230px;
  height: 230px;
  border: 1px solid rgba(22, 136, 105, 0.34);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  animation: burstRing 900ms cubic-bezier(0.2, 0.85, 0.2, 1) forwards;
}

.burst-ring.coral {
  width: 170px;
  height: 170px;
  border-color: rgba(255, 124, 102, 0.34);
  animation-delay: 90ms;
}

.burst-spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(30, 41, 48, 0.42), transparent);
  transform-origin: center;
  animation: burstSpark 820ms cubic-bezier(0.2, 0.85, 0.2, 1) forwards;
  animation-delay: var(--delay);
}

.gift-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(255, 250, 240, 0.28), transparent 45%);
  animation: giftOverlayOut 3300ms ease forwards;
}

.birthday-note-overlay {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(255, 250, 240, 0.58);
  backdrop-filter: blur(10px);
  animation: noteOverlayIn 360ms ease both;
}

.birthday-note-overlay.closing {
  animation: noteOverlayOut 260ms ease both;
}

.birthday-note {
  position: relative;
  width: min(700px, 100%);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid rgba(65, 48, 25, 0.18);
  border-radius: 8px;
  padding: clamp(20px, 3vw, 32px);
  background:
    linear-gradient(rgba(65, 48, 25, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #fffaf0, #fff1d0);
  background-size: 100% 34px, auto;
  box-shadow: 0 34px 110px rgba(65, 48, 25, 0.24);
  transform: rotate(-1deg);
}

.birthday-note::before {
  position: absolute;
  inset: 14px;
  border: 1px dashed rgba(184, 66, 50, 0.22);
  border-radius: 6px;
  content: "";
  pointer-events: none;
}

.note-kicker {
  margin: 0 0 8px;
  color: var(--coral-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.birthday-note h2 {
  margin: 0 0 10px;
  font-family: Caveat, cursive;
  font-size: clamp(2.45rem, 5.8vw, 4.1rem);
  line-height: 0.9;
}

.note-text {
  display: grid;
  gap: 9px;
  color: #263239;
  font-family: Caveat, cursive;
  font-size: clamp(1.18rem, 2.15vw, 1.58rem);
  font-weight: 600;
  line-height: 1.16;
}

.note-text p {
  margin: 0;
}

.note-close {
  min-height: 42px;
  margin-top: 16px;
}

@keyframes noteOverlayIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes noteOverlayOut {
  to {
    opacity: 0;
  }
}

.gift-stage {
  position: relative;
  width: min(360px, 78vw);
  height: 360px;
  display: grid;
  place-items: end center;
}

.gift-box {
  position: relative;
  width: 210px;
  height: 154px;
  border: 1px solid rgba(30, 41, 48, 0.32);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.22), transparent 34%),
    linear-gradient(90deg, transparent 0 43%, rgba(255, 250, 240, 0.84) 43% 57%, transparent 57%),
    linear-gradient(135deg, #ff977f 0%, #ff6f59 48%, #df5140 100%);
  box-shadow:
    inset -18px -18px 32px rgba(130, 42, 31, 0.18),
    inset 16px 14px 28px rgba(255, 255, 255, 0.18),
    0 28px 70px rgba(65, 48, 25, 0.24);
  animation: giftBoxSettle 3600ms cubic-bezier(0.2, 0.85, 0.2, 1) forwards;
}

.gift-lid {
  position: absolute;
  left: -15px;
  top: -42px;
  width: 240px;
  height: 48px;
  border: 1px solid rgba(30, 41, 48, 0.32);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.28), transparent 38%),
    linear-gradient(90deg, transparent 0 43%, rgba(255, 250, 240, 0.9) 43% 57%, transparent 57%),
    linear-gradient(135deg, #ffad9a, #ff725e);
  box-shadow: 0 14px 34px rgba(65, 48, 25, 0.18);
  transform-origin: 18% 100%;
  animation: giftLidOpen 3600ms cubic-bezier(0.2, 0.85, 0.2, 1) forwards;
}

.gift-ribbon {
  position: absolute;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.38), transparent 34%),
    rgba(255, 250, 240, 0.86);
}

.gift-ribbon.vertical {
  inset: 0 auto 0 50%;
  width: 26px;
  transform: translateX(-50%);
}

.gift-ribbon.horizontal {
  left: 0;
  right: 0;
  top: 58px;
  height: 24px;
}

.gift-bow {
  position: absolute;
  z-index: 3;
  top: -34px;
  width: 76px;
  height: 44px;
  border: 1px solid rgba(30, 41, 48, 0.24);
  background:
    radial-gradient(circle at 32% 34%, rgba(255, 255, 255, 0.52), transparent 18px),
    linear-gradient(135deg, #fff7df, #f5d78b);
  box-shadow: 0 12px 24px rgba(65, 48, 25, 0.14);
}

.gift-bow.left {
  left: 44px;
  border-radius: 72% 42% 48% 68%;
  transform: rotate(18deg) skewX(-8deg);
  transform-origin: 100% 100%;
}

.gift-bow.right {
  right: 44px;
  border-radius: 42% 72% 68% 48%;
  transform: rotate(-18deg) skewX(8deg);
  transform-origin: 0 100%;
}

.gift-knot {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: -22px;
  width: 34px;
  height: 28px;
  border: 1px solid rgba(30, 41, 48, 0.24);
  border-radius: 50%;
  background: linear-gradient(135deg, #fff8df, #eecf78);
  box-shadow: 0 8px 18px rgba(65, 48, 25, 0.16);
  transform: translateX(-50%);
}

.gift-reward {
  position: absolute;
  left: 50%;
  top: 158px;
  z-index: 2;
  color: var(--mint-dark);
  font-size: clamp(3.4rem, 12vw, 7rem);
  font-weight: 800;
  line-height: 0.9;
  text-shadow: 0 16px 40px rgba(22, 136, 105, 0.22);
  opacity: 0;
  transform: translate(-50%, 28px) scale(0.72);
  animation: giftRewardFly 3600ms cubic-bezier(0.18, 0.92, 0.2, 1) forwards;
}

@keyframes giftLidOpen {
  0%,
  20% {
    transform: translateY(0) rotate(0);
  }
  42%,
  100% {
    transform: translate(-28px, -44px) rotate(-18deg);
  }
}

@keyframes giftRewardFly {
  0%,
  22% {
    opacity: 0;
    transform: translate(-50%, 30px) scale(0.72);
  }
  42% {
    opacity: 1;
    transform: translate(-50%, -116px) scale(1.08);
  }
  68% {
    opacity: 1;
    transform: translate(-50%, -116px) scale(1.08);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, 236px) scale(1);
  }
}


@keyframes giftBoxSettle {
  0% {
    transform: translateY(18px) scale(0.94);
  }
  20%,
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes giftOverlayOut {
  0%,
  82% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 900px) {
  .quest-topbar,
  .scene {
    grid-template-columns: 1fr;
  }

  .quest-topbar {
    align-items: start;
  }

  .progress-area {
    text-align: left;
  }

  .quest-stage,
  .scene {
    min-height: auto;
  }

  .seed-board,
  .intro-visual .seed-board,
  .qr-card,
  .words-unlocked {
    position: static;
    transform: none;
  }

  .intro-visual {
    min-height: auto;
  }

}

@media (max-width: 640px) {
  .page-shell {
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    padding-top: 14px;
    overflow: hidden;
  }

  .quest-stage::before {
    right: -48px;
    left: auto;
    width: 140px;
    height: 140px;
  }

  .quest-stage::after {
    display: none;
  }

  h1 {
    font-size: clamp(3.5rem, 20vw, 5.2rem);
  }

  h2 {
    font-size: clamp(2.8rem, 16vw, 4.8rem);
  }

  .scene {
    gap: 24px;
    padding-top: 14px;
  }

  .scene-copy,
  .scene-copy p,
  .qr-card,
  .map-art,
  .final-copy {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .button {
    width: 100%;
  }

  .seed-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .qr-card {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .map-art,
  .actual-map {
    min-height: 360px;
  }

  .final-copy {
    padding: 22px;
  }

  .final-reward {
    margin-top: 8px;
  }
}
