:root {
  --olive-900: #1f2612;
  --olive-800: #2c3619;
  --olive-700: #3d4a23;
  --olive-600: #4f5d2c;
  --olive-500: #6b7a3a;
  --moss: #8a9a5b;
  --khaki: #bdb76b;
  --sand: #c3b091;
  --cream: #f4efdf;
  --gold: #e6cf7a;
  --pink: #f2a7b5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: "Cormorant Garamond", Georgia, serif;
  color: var(--cream);
  background:
    radial-gradient(ellipse at 20% 10%, rgba(189, 183, 107, 0.25), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(138, 154, 91, 0.3), transparent 60%),
    linear-gradient(160deg, var(--olive-700) 0%, var(--olive-800) 45%, var(--olive-900) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}

body.locked { overflow: hidden; }

#fireflies {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

#floaters {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.floater {
  position: absolute;
  bottom: -40px;
  animation: floatUp linear forwards;
  opacity: 0;
  filter: drop-shadow(0 0 6px rgba(230, 207, 122, 0.5));
}

@keyframes floatUp {
  0% { transform: translateY(0) translateX(0) rotate(0); opacity: 0; }
  10% { opacity: 0.9; }
  50% { transform: translateY(-55vh) translateX(var(--drift)) rotate(20deg); }
  90% { opacity: 0.7; }
  100% { transform: translateY(-110vh) translateX(0) rotate(-15deg); opacity: 0; }
}

/* ---------- Pixel art ---------- */
canvas.pixel {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.pixel-heart {
  width: 49px;
  height: 42px;
  margin: 0 1.2rem;
  align-self: center;
  position: relative;
}

.pixel-heart::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 7px;
  height: 7px;
  color: #e85b7a;
  background: transparent;
  box-shadow:
    7px 0 0 currentColor, 14px 0 0 currentColor, 28px 0 0 currentColor, 35px 0 0 currentColor,
    0 7px 0 currentColor, 7px 7px 0 currentColor, 14px 7px 0 currentColor, 21px 7px 0 currentColor, 28px 7px 0 currentColor, 35px 7px 0 currentColor, 42px 7px 0 currentColor,
    0 14px 0 currentColor, 7px 14px 0 currentColor, 14px 14px 0 currentColor, 21px 14px 0 currentColor, 28px 14px 0 currentColor, 35px 14px 0 currentColor, 42px 14px 0 currentColor,
    7px 21px 0 currentColor, 14px 21px 0 currentColor, 21px 21px 0 currentColor, 28px 21px 0 currentColor, 35px 21px 0 currentColor,
    14px 28px 0 currentColor, 21px 28px 0 currentColor, 28px 28px 0 currentColor,
    21px 35px 0 currentColor;
}

.beat { animation: beat 1.1s ease-in-out infinite; }

@keyframes beat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.18); }
  30% { transform: scale(1); }
  45% { transform: scale(1.12); }
}

/* ---------- Lock ---------- */
#lock {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(189, 183, 107, 0.22), transparent 60%),
    linear-gradient(160deg, var(--olive-700), var(--olive-900));
  transition: opacity 1s ease, visibility 1s ease, transform 1s ease;
}

#lock.hide { opacity: 0; visibility: hidden; transform: scale(1.08); pointer-events: none; }

.lock-inner { text-align: center; padding: 1.5rem; }

.lock-cat { animation: hop 2.4s ease-in-out infinite; margin-bottom: 0.8rem; }

.lock-title {
  font-family: "Dancing Script", cursive;
  font-size: 2.6rem;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(230, 207, 122, 0.4);
}

.lock-sub { font-style: italic; opacity: 0.75; font-size: 1.1rem; margin-bottom: 1.4rem; }

.pin-dots { display: flex; justify-content: center; gap: 1rem; }

.pin-dots i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--khaki);
  transition: background 0.2s, transform 0.2s;
}

.pin-dots i.on { background: var(--gold); transform: scale(1.15); box-shadow: 0 0 12px rgba(230, 207, 122, 0.7); }
.pin-dots.shake { animation: shake 0.45s; }
.pin-dots.ok i { background: #9fd17a; border-color: #9fd17a; }

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

.lock-msg { min-height: 1.6em; margin: 0.8rem 0 1rem; font-size: 1.1rem; color: var(--pink); }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  gap: 0.9rem;
  justify-content: center;
}

.keypad button {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid rgba(244, 239, 223, 0.3);
  background: rgba(255, 255, 255, 0.07);
  color: var(--cream);
  font-family: "Cormorant Garamond", serif;
  font-size: 1.7rem;
  font-weight: 600;
  font-variant-numeric: lining-nums;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.1s;
}

.keypad button:hover { background: rgba(189, 183, 107, 0.25); }
.keypad button:active { transform: scale(0.92); background: rgba(230, 207, 122, 0.4); }
.keypad .k-alt { font-size: 1.4rem; }

/* ---------- Intro ---------- */
#intro {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(189, 183, 107, 0.25), transparent 60%),
    linear-gradient(160deg, var(--olive-700), var(--olive-900));
  transition: opacity 1.4s ease, visibility 1.4s ease;
}

#intro.hide { opacity: 0; visibility: hidden; }

.intro-inner { text-align: center; padding: 2rem; }

.intro-pets {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.8rem;
}

.intro-pets canvas { animation: hop 2.4s ease-in-out infinite; }
.intro-pets canvas:last-child { animation-delay: 0.6s; }

@keyframes hop {
  0%, 60%, 100% { transform: translateY(0); }
  70% { transform: translateY(-10px); }
  80% { transform: translateY(0); }
}

.intro-small {
  font-style: italic;
  font-size: 1.25rem;
  opacity: 0.8;
  letter-spacing: 0.5px;
}

.intro-name {
  font-family: "Dancing Script", cursive;
  font-size: clamp(4rem, 14vw, 7.5rem);
  color: var(--gold);
  text-shadow: 0 0 25px rgba(230, 207, 122, 0.45);
  margin: 0.2rem 0 1.4rem;
  animation: glow 3s ease-in-out infinite;
}

.intro-hint { margin-top: 1rem; font-size: 0.95rem; opacity: 0.6; }

@keyframes glow {
  0%, 100% { text-shadow: 0 0 18px rgba(230, 207, 122, 0.35); }
  50% { text-shadow: 0 0 38px rgba(230, 207, 122, 0.75), 0 0 70px rgba(189, 183, 107, 0.4); }
}

/* ---------- Buttons ---------- */
.btn-glow, .btn-ghost {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.35rem;
  font-weight: 600;
  padding: 0.85rem 2.2rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s;
}

.btn-glow {
  border: 1px solid rgba(244, 239, 223, 0.5);
  color: var(--olive-900);
  background: linear-gradient(135deg, var(--gold), var(--khaki));
  box-shadow: 0 0 0 0 rgba(230, 207, 122, 0.6);
  animation: pulse 2s infinite;
}

.btn-glow:hover { transform: scale(1.06); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(230, 207, 122, 0.55); }
  70% { box-shadow: 0 0 0 22px rgba(230, 207, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(230, 207, 122, 0); }
}

.btn-ghost {
  border: 1px solid rgba(244, 239, 223, 0.4);
  background: rgba(255, 255, 255, 0.05);
  color: var(--cream);
}

/* ---------- Layout ---------- */
main {
  position: relative;
  z-index: 2;
}

section {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 1.5rem;
  text-align: center;
}

.section-title {
  font-family: "Dancing Script", cursive;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  color: var(--gold);
  margin-bottom: 2.5rem;
  text-shadow: 0 0 20px rgba(230, 207, 122, 0.35);
}

.section-title.big { font-size: clamp(2.8rem, 8vw, 5rem); }

.reveal {
  opacity: 0;
  transform: translateY(40px);
  filter: blur(6px);
  transition: opacity 1.1s ease, transform 1.1s cubic-bezier(.2,.8,.2,1), filter 1.1s ease;
}

.reveal.visible { opacity: 1; transform: none; filter: none; }

/* ---------- Hero ---------- */
.eyebrow {
  font-style: italic;
  font-size: 1.5rem;
  opacity: 0.85;
  margin-bottom: 0.5rem;
}

.title { display: flex; flex-direction: column; align-items: center; }

.title-name {
  font-family: "Dancing Script", cursive;
  font-size: clamp(5rem, 18vw, 10rem);
  line-height: 1;
  color: var(--gold);
  animation: glow 3s ease-in-out infinite;
}

.title-sub {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 400;
  font-style: italic;
  min-height: 1.3em;
  margin-top: 1rem;
  letter-spacing: 1px;
}

.title-sub::after {
  content: "|";
  margin-left: 2px;
  animation: caret 0.9s steps(1) infinite;
  color: var(--khaki);
}

@keyframes caret { 50% { opacity: 0; } }

.scroll-hint {
  margin-top: 5rem;
  font-size: 1rem;
  opacity: 0.6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.arrow {
  width: 14px;
  height: 14px;
  border-right: 2px solid var(--cream);
  border-bottom: 2px solid var(--cream);
  transform: rotate(45deg);
  animation: bounce 1.6s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(45deg); }
  50% { transform: translateY(8px) rotate(45deg); }
}

/* ---------- Eyes ---------- */
.eyes {
  display: flex;
  gap: clamp(1rem, 5vw, 3.5rem);
  margin-bottom: 3rem;
}

.eye {
  width: clamp(130px, 28vw, 230px);
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 0 25px rgba(154, 160, 74, 0.45));
}

.eye .iris-group { transition: transform 0.15s ease-out; }
.eye .lid { transition: transform 0.12s ease-in; }
.eye.blink .lid { transform: translateY(128px); }

.eye-lines p {
  font-size: clamp(1.25rem, 3vw, 1.65rem);
  max-width: 640px;
  margin: 0 auto 1.4rem;
  line-height: 1.6;
}

.eye-lines p:last-child { font-style: italic; color: var(--khaki); }

/* ---------- Envelope ---------- */
.envelope {
  position: relative;
  width: min(420px, 88vw);
  height: calc(min(420px, 88vw) * 0.62);
  cursor: pointer;
  margin-top: 1rem;
  transition: margin 1s ease;
}

.envelope.open { margin-top: 10rem; cursor: default; }

.env-back, .env-front, .env-flap {
  position: absolute;
  inset: 0;
}

.env-back {
  background: #b8ae7c;
  border-radius: 6px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.35);
}

.env-front {
  background:
    linear-gradient(to top right, #d3c895 50%, transparent 50.5%) left / 50% 100% no-repeat,
    linear-gradient(to top left, #d3c895 50%, transparent 50.5%) right / 50% 100% no-repeat;
  z-index: 3;
  border-radius: 0 0 6px 6px;
}

.env-flap {
  z-index: 4;
  height: 60%;
  background: linear-gradient(to bottom, #c8bd88, #bfb47f);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  transition: transform 0.8s ease, z-index 0s 0.4s;
}

.envelope.open .env-flap { transform: rotateX(180deg); z-index: 1; }

.env-seal {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  background: radial-gradient(circle, #7d2f3e, #5a1f2b);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  transition: opacity 0.4s, transform 0.4s;
}

.envelope.open .env-seal { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }

.letter {
  position: absolute;
  z-index: 2;
  left: 6%;
  width: 88%;
  bottom: 6%;
  height: 85%;
  background:
    repeating-linear-gradient(to bottom, transparent 0 23px, rgba(107, 122, 58, 0.2) 23px 24px),
    #fbf7ea;
  border-radius: 4px;
  display: flex;
  justify-content: center;
  padding-top: 0.9rem;
  font-family: "Dancing Script", cursive;
  font-size: 1.7rem;
  color: var(--olive-600);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  transition: transform 1.1s cubic-bezier(.2,.8,.2,1) 0.5s;
}

.envelope.open .letter { transform: translateY(-58%); }

.letter-full {
  width: min(620px, 92vw);
  margin-top: 2rem;
  background:
    radial-gradient(ellipse at top left, rgba(189, 183, 107, 0.18), transparent 60%),
    #fbf7ea;
  border-left: 4px solid var(--moss);
  color: #2c3619;
  text-align: left;
  padding: 2.2rem 2.2rem 1.6rem;
  border-radius: 6px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  display: none;
  transform-origin: top center;
}

.letter-full.show {
  display: block;
  animation: unfold 1.3s cubic-bezier(.2,.8,.2,1) both;
}

@keyframes unfold {
  from { opacity: 0; transform: perspective(900px) rotateX(-70deg) translateY(-30px); }
  to { opacity: 1; transform: none; }
}

.letter-full p {
  font-size: 1.25rem;
  line-height: 1.6;
  margin-bottom: 0.9rem;
  opacity: 0;
  animation: lineIn 0.9s ease forwards;
}

.letter-full.show p:nth-child(1) { animation-delay: 0.8s; }
.letter-full.show p:nth-child(2) { animation-delay: 1.4s; }
.letter-full.show p:nth-child(3) { animation-delay: 2.1s; }
.letter-full.show p:nth-child(4) { animation-delay: 2.9s; }
.letter-full.show p:nth-child(5) { animation-delay: 3.6s; }
.letter-full.show p:nth-child(6) { animation-delay: 4.4s; }
.letter-full.show p:nth-child(7) { animation-delay: 5.2s; }

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

.letter-hello, .letter-sign {
  font-family: "Dancing Script", cursive;
  font-size: 1.6rem !important;
  color: var(--olive-600);
}

.letter-sign { text-align: right; line-height: 1.3 !important; }

.tap-hint, .cards-hint {
  margin-top: 1.4rem;
  opacity: 0.6;
  font-style: italic;
}

/* ---------- Cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 200px));
  gap: 1.3rem;
}

.card {
  height: 200px;
  perspective: 900px;
  cursor: pointer;
}

.card:nth-child(2) { transition-delay: 0.1s; }
.card:nth-child(3) { transition-delay: 0.2s; }
.card:nth-child(4) { transition-delay: 0.3s; }
.card:nth-child(5) { transition-delay: 0.4s; }
.card:nth-child(6) { transition-delay: 0.5s; }

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.8s cubic-bezier(.3,.9,.3,1.1);
  transform-style: preserve-3d;
}

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

.card-front, .card-back {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  border: 1px solid rgba(244, 239, 223, 0.2);
}

.card-front {
  font-size: 3.2rem;
  background: linear-gradient(145deg, rgba(138, 154, 91, 0.35), rgba(61, 74, 35, 0.6));
  backdrop-filter: blur(6px);
  box-shadow: inset 0 0 30px rgba(230, 207, 122, 0.12), 0 15px 30px rgba(0, 0, 0, 0.25);
}

.card-back {
  transform: rotateY(180deg);
  background: linear-gradient(145deg, var(--khaki), var(--moss));
  color: var(--olive-900);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.4;
}

/* ---------- Pets ---------- */
.pets {
  display: flex;
  gap: clamp(1.5rem, 6vw, 5rem);
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
}

.pet {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  position: relative;
}

.pet:nth-child(2) { transition-delay: 0.2s; }
.pet:nth-child(3) { transition-delay: 0.4s; }

.pet-sprite { animation: idle 1.8s ease-in-out infinite; }
.pet:nth-child(2) .pet-sprite { animation-delay: 0.3s; }
.pet:nth-child(3) .pet-sprite { animation-delay: 0.6s; }
.pet.jump .pet-sprite { animation: jump 0.5s ease; }

@keyframes idle {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.96) translateY(2px); }
}

@keyframes jump {
  0% { transform: translateY(0); }
  40% { transform: translateY(-30px) scale(1.05); }
  100% { transform: translateY(0); }
}

.bubble {
  background: var(--cream);
  color: var(--olive-800);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  max-width: 190px;
  margin-bottom: 1rem;
  position: relative;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
  border: 3px solid var(--olive-900);
}

.bubble::after {
  content: "";
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  border: 9px solid transparent;
  border-top-color: var(--olive-900);
  border-bottom: 0;
}

.pet-name {
  font-family: "Press Start 2P", monospace;
  font-size: 0.7rem;
  margin-top: 0.8rem;
  color: var(--khaki);
  letter-spacing: 1px;
}

.walkers {
  position: fixed;
  bottom: 6px;
  left: 0;
  width: 100%;
  height: 80px;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity 1s 1s;
}

body.started .walkers { opacity: 0.95; }

.walker { position: absolute; bottom: 0; }

.w1 { animation: walk 26s linear infinite; }
.w2 { animation: walk 26s linear infinite; animation-delay: -1.6s; }

@keyframes walk {
  0% { left: -90px; transform: scaleX(1); }
  49.9% { left: calc(100% + 30px); transform: scaleX(1); }
  50% { left: calc(100% + 30px); transform: scaleX(-1); }
  99.9% { left: -90px; transform: scaleX(-1); }
  100% { left: -90px; transform: scaleX(1); }
}

/* ---------- Question ---------- */
.q-buttons {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

#noBtn { position: relative; transition: transform 0.25s, left 0.3s, top 0.3s; }
#noBtn.fleeing { position: fixed; z-index: 30; }

/* ---------- Final ---------- */
.final-section { display: none; }
.final-section.show { display: flex; }

.final-inner { animation: finalIn 1.6s cubic-bezier(.2,.8,.2,1) both; }

@keyframes finalIn {
  from { opacity: 0; transform: scale(0.85); filter: blur(10px); }
  to { opacity: 1; transform: none; filter: none; }
}

.final-title {
  font-family: "Dancing Script", cursive;
  font-size: clamp(3rem, 9vw, 5.5rem);
  color: var(--gold);
  animation: glow 3s ease-in-out infinite;
  margin-bottom: 1.5rem;
}

.final-text {
  font-size: clamp(1.3rem, 3vw, 1.7rem);
  max-width: 620px;
  margin: 0 auto 1rem;
  line-height: 1.6;
}

.final-text.small { font-style: italic; color: var(--khaki); }

footer {
  text-align: center;
  padding: 2rem 1rem 7rem;
  opacity: 0.55;
  font-style: italic;
}

/* ---------- Music button ---------- */
.music-btn {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 40;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid rgba(244, 239, 223, 0.4);
  background: rgba(31, 38, 18, 0.55);
  backdrop-filter: blur(6px);
  cursor: pointer;
  display: none;
  place-items: center;
}

body.started .music-btn { display: grid; }

.eq { display: flex; gap: 3px; align-items: flex-end; height: 18px; }
.eq i {
  width: 3px;
  background: var(--gold);
  border-radius: 2px;
  animation: eq 0.9s ease-in-out infinite;
}
.eq i:nth-child(1) { animation-delay: -0.2s; }
.eq i:nth-child(2) { animation-delay: -0.5s; }
.eq i:nth-child(3) { animation-delay: -0.1s; }
.eq i:nth-child(4) { animation-delay: -0.7s; }
.music-btn.paused .eq i { animation-play-state: paused; height: 4px; }

@keyframes eq {
  0%, 100% { height: 4px; }
  50% { height: 18px; }
}

#ytHolder {
  position: fixed;
  width: 1px;
  height: 1px;
  left: -10px;
  bottom: 0;
  opacity: 0;
  pointer-events: none;
}

.burst {
  position: fixed;
  pointer-events: none;
  z-index: 60;
  font-size: 1.5rem;
  animation: burst 1.4s ease-out forwards;
}

@keyframes burst {
  0% { transform: translate(0, 0) scale(0.4); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.2) rotate(var(--rot)); opacity: 0; }
}

@media (max-width: 680px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 160px)); }
  .card { height: 170px; }
  .card-back { font-size: 1.02rem; }
  .envelope.open { margin-top: 5rem; }
  .letter-full { padding: 1.6rem 1.3rem 1.2rem; }
  .letter-full p { font-size: 1.1rem; }
}
