:root {
  --forest: #12261d;
  --forest-2: #1f4e3d;
  --hero: #3f8f4f;
  --gold: #e6b422;
  --gold-light: #fff2b3;
  --parchment: #f3e6c4;
  --ink: #3b2a14;
  --heart: #e0383e;
  --sky: #7ec8e3;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: "EB Garamond", Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.65;
  color: var(--gold-light);
  background: radial-gradient(ellipse at top, #1d3d2f 0%, var(--forest) 55%, #0a1510 100%) fixed;
  overflow-x: hidden;
}

#sparkles { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
section, footer { position: relative; z-index: 1; }

h1, h2, h3 { font-family: "Cinzel", serif; font-weight: 700; }
.pixel { font-family: "Press Start 2P", monospace; font-size: .9rem; letter-spacing: .05em; }
.center { text-align: center; }
.light { color: var(--gold-light); }

/* ---------- Title ---------- */
.title-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem;
  background:
    radial-gradient(circle at 50% 35%, rgba(230,180,34,.18), transparent 45%),
    linear-gradient(180deg, #0c1c2b 0%, #16324a 45%, #1f4e3d 85%);
  overflow: hidden;
}
.crest { width: 130px; filter: drop-shadow(0 0 22px rgba(230,180,34,.55)); animation: float 4s ease-in-out infinite; }
.eyebrow { font-family: "Cinzel"; letter-spacing: .4em; text-transform: uppercase; color: var(--gold); margin-top: 1.2rem; font-size: .95rem; }
.title-screen h1 {
  font-family: "Cinzel Decorative", serif;
  font-size: clamp(3.2rem, 11vw, 7.5rem);
  line-height: 1;
  margin: .4rem 0;
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, #9c6b0f);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 4px 30px rgba(230,180,34,.25);
}
.title-screen h1 span { display: block; font-family: "Cinzel"; font-size: .28em; letter-spacing: .35em; margin-top: .6rem; }
.subtitle { font-style: italic; opacity: .85; }
.press-start {
  display: inline-block; margin-top: 2.4rem;
  font-family: "Press Start 2P"; font-size: .85rem;
  color: var(--gold-light); text-decoration: none;
  padding: 1rem 1.4rem; border: 3px solid var(--gold);
  background: rgba(0,0,0,.35);
  animation: blink 1.4s steps(2, start) infinite;
}
.press-start:hover { background: var(--gold); color: var(--forest); animation: none; }
.grass {
  position: absolute; left: 0; right: 0; bottom: 0; height: 70px;
  background:
    repeating-linear-gradient(100deg, transparent 0 12px, rgba(63,143,79,.9) 12px 16px, transparent 16px 26px),
    linear-gradient(transparent, #12261d 70%);
  mask: linear-gradient(transparent, #000 40%);
}

/* ---------- Panels ---------- */
.panel { padding: 6rem 1.5rem; max-width: 1100px; margin: 0 auto; }
.chapter { font-family: "Cinzel"; letter-spacing: .3em; text-transform: uppercase; color: var(--gold); font-size: .85rem; }
.panel > h2 { font-size: clamp(2rem, 5vw, 3rem); margin-bottom: 2.5rem; }

/* ---------- Hearts ---------- */
.hud { text-align: center; }
.hud h2.pixel { font-size: clamp(.9rem, 2.5vw, 1.25rem); color: var(--heart); margin-bottom: 1rem; }
.hud-text { opacity: .85; margin-bottom: 1.8rem; }
.heart-row { display: flex; flex-wrap: wrap; justify-content: center; gap: .45rem; max-width: 640px; margin: 0 auto; }
.heart {
  width: 34px; height: 34px; cursor: pointer; border: 0; background: none;
  transition: transform .15s;
}
.heart svg { width: 100%; height: 100%; }
.heart .fill { fill: transparent; transition: fill .2s; }
.heart.full .fill { fill: var(--heart); }
.heart:hover { transform: scale(1.2); }
.heart.full { animation: pop .3s; }
.hud-count { font-family: "Press Start 2P"; margin-top: 1.2rem; font-size: .8rem; color: var(--gold); }

/* ---------- Parchment ---------- */
.scroll-section { display: flex; justify-content: center; }
.parchment {
  position: relative;
  max-width: 760px; width: 100%;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.45), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(150,100,40,.25), transparent 45%),
    var(--parchment);
  padding: 3rem clamp(1.5rem, 5vw, 3.5rem);
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5), inset 0 0 60px rgba(120,80,20,.35);
}
.parchment::before, .parchment::after {
  content: ""; position: absolute; left: -14px; right: -14px; height: 26px;
  background: linear-gradient(180deg, #c9a467, #8a6328);
  border-radius: 13px; box-shadow: 0 4px 10px rgba(0,0,0,.4);
}
.parchment::before { top: -13px; }
.parchment::after { bottom: -13px; }
.parchment h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); color: var(--forest-2); margin: .2rem 0 1.2rem; }
.parchment .chapter { color: #8a6328; }
.parchment p + p { margin-top: 1rem; }
.parchment strong { color: var(--forest-2); }
blockquote {
  margin-top: 1.6rem; padding: 1rem 1.2rem;
  border-left: 4px solid var(--gold); background: rgba(31,78,61,.08);
  font-style: italic;
}

.stats { margin-top: 1.8rem; display: grid; gap: .6rem; font-size: 1rem; }
.stats > div { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 1rem; }
.stat-label { font-family: "Cinzel"; font-weight: 700; color: #8a6328; font-size: .85rem; letter-spacing: .1em; text-transform: uppercase; }
.stat-val { font-weight: 600; }
.bar { height: 14px; background: rgba(59,42,20,.15); border: 2px solid var(--ink); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--hero), #8fd694); transition: width 1.6s ease-out; }
.visible .bar i { width: var(--w); }

/* ---------- Quests ---------- */
.quest-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.4rem; }
.quest {
  background: linear-gradient(160deg, rgba(31,78,61,.85), rgba(12,28,43,.9));
  border: 2px solid rgba(230,180,34,.55); border-radius: 10px;
  padding: 1.8rem 1.4rem; text-align: center;
  transition: transform .25s, box-shadow .25s;
}
.quest:hover { transform: translateY(-6px); box-shadow: 0 12px 30px rgba(230,180,34,.25); }
.quest-icon { font-size: 2.6rem; margin-bottom: .6rem; }
.quest h3 { color: var(--gold); font-size: 1.15rem; margin-bottom: .5rem; }
.quest p { font-size: 1.05rem; opacity: .9; }

/* ---------- Collage ---------- */
.collage { columns: 3 240px; column-gap: 1rem; }
.polaroid {
  break-inside: avoid; margin-bottom: 1rem;
  background: #fbf6e9; padding: .6rem .6rem 2.2rem; border-radius: 3px;
  box-shadow: 0 10px 25px rgba(0,0,0,.45);
  transform: rotate(var(--r, 0deg));
  transition: transform .3s;
  position: relative;
}
.polaroid:hover { transform: rotate(0) scale(1.04); z-index: 2; }
.polaroid img { width: 100%; display: block; border-radius: 2px; }
.polaroid figcaption { position: absolute; bottom: .5rem; left: 0; right: 0; text-align: center; color: var(--ink); font-style: italic; font-size: 1rem; }
.polaroid.empty .slot {
  aspect-ratio: var(--ar, 4/5);
  display: grid; place-items: center; text-align: center;
  background: repeating-linear-gradient(45deg, #e9dcb8 0 12px, #e2d2a8 12px 24px);
  color: #8a6328; font-family: "Cinzel"; font-size: .9rem; padding: 1rem;
}

/* ---------- Poem ---------- */
.poem .verse p { font-style: italic; font-size: 1.25rem; line-height: 1.8; }
.poem .verse p + p { margin-top: 1.4rem; }
.signature { text-align: right; margin-top: 2rem !important; font-family: "Cinzel"; color: var(--forest-2); }

/* ---------- Finale chest ---------- */
.finale { text-align: center; min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.chest { position: relative; width: 180px; height: 150px; cursor: pointer; margin-bottom: 1.6rem; }
.chest-body {
  position: absolute; bottom: 0; left: 0; right: 0; height: 90px;
  background: linear-gradient(#8a5a2b, #5a3816); border: 5px solid var(--gold); border-radius: 6px;
}
.chest-body::after { content: ""; position: absolute; left: 50%; top: -6px; width: 26px; height: 30px; transform: translateX(-50%); background: var(--gold); border-radius: 4px; }
.chest-lid {
  position: absolute; top: 0; left: 0; right: 0; height: 64px; z-index: 2;
  background: linear-gradient(#a06a35, #6d4419); border: 5px solid var(--gold); border-radius: 60px 60px 6px 6px;
  transform-origin: bottom center; transition: transform .7s cubic-bezier(.3,1.6,.5,1);
}
.chest-glow { position: absolute; left: 50%; top: 40px; width: 10px; height: 10px; transform: translateX(-50%); border-radius: 50%; background: var(--gold-light); box-shadow: 0 0 0 0 rgba(255,242,179,.9); opacity: 0; transition: .8s; }
.chest.open .chest-lid { transform: translateY(-20px) rotateX(75deg) rotate(-12deg); }
.chest.open .chest-glow { opacity: 1; box-shadow: 0 0 120px 70px rgba(255,242,179,.75); }
.chest:not(.open) { animation: wiggle 2.5s ease-in-out infinite; }
.hint { color: var(--gold); animation: blink 1.4s steps(2, start) infinite; }
.reward h2 {
  font-family: "Cinzel Decorative"; font-size: clamp(2rem, 6vw, 3.6rem); margin: .6rem 0 1rem;
  background: linear-gradient(180deg, var(--gold-light), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.reward .small { font-size: .75rem; color: var(--gold); }
.reward:not([hidden]) { animation: rise .8s ease-out; }

footer { text-align: center; padding: 2rem; opacity: .6; font-size: .95rem; }

/* ---------- Reveal ---------- */
.reveal { opacity: 0; transform: translateY(40px); transition: opacity .9s, transform .9s; }
.reveal.visible { opacity: 1; transform: none; }

@keyframes float { 50% { transform: translateY(-10px); } }
@keyframes blink { to { visibility: hidden; } }
@keyframes pop { 50% { transform: scale(1.4); } }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-4deg); } 90% { transform: rotate(4deg); } 95% { transform: rotate(-2deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}
@media (max-width: 520px) {
  .stats > div { grid-template-columns: 1fr; gap: .2rem; }
  .heart { width: 28px; height: 28px; }
}

/* ---------- Lightbox ---------- */
.polaroid:not(.empty) { cursor: zoom-in; }
.polaroid:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }
body.lb-open { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  padding: 1rem; background: rgba(5, 12, 9, .92);
  backdrop-filter: blur(4px); animation: lbFade .25s ease;
}
.lightbox[hidden] { display: none; }
@keyframes lbFade { from { opacity: 0; } to { opacity: 1; } }
.lb-frame {
  background: #fbf6e9; padding: .75rem .75rem 0; border-radius: 4px;
  box-shadow: 0 0 0 3px var(--gold), 0 20px 60px rgba(0,0,0,.6);
  min-width: 0; max-width: min(90vw, 1100px);
}
.lb-frame img { display: block; max-width: 100%; max-height: 78vh; margin: 0 auto; border-radius: 2px; }
.lb-frame figcaption {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .6rem .2rem .75rem; color: var(--ink); font-style: italic;
}
.lb-count { font-style: normal; font-size: .6rem; color: var(--forest-2); white-space: nowrap; }
.lb-btn {
  flex: none; width: 3rem; height: 3rem; border-radius: 50%;
  border: 2px solid var(--gold); background: var(--forest); color: var(--gold-light);
  font-size: 1.1rem; cursor: pointer; transition: transform .15s, background .15s;
}
.lb-btn:hover, .lb-btn:focus-visible { background: var(--forest-2); transform: scale(1.1); outline: none; }
.lb-close { position: absolute; top: 1rem; right: 1rem; }
@media (max-width: 640px) {
  .lightbox { gap: 0; padding: 4.5rem .75rem 5.5rem; }
  .lb-frame { max-width: 100%; padding: .5rem .5rem 0; }
  .lb-prev, .lb-next { position: absolute; bottom: 1.25rem; }
  .lb-prev { left: 30%; } .lb-next { right: 30%; }
  .lb-frame img { max-height: 70vh; }
}
@media (prefers-reduced-motion: reduce) { .lightbox { animation: none; } }
