@font-face {
  font-family: "Fredoka";
  src: url("/fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

/* Palette from the game's ART_RULES anchors */
:root {
  --ink: #302b38;
  --cream: #e9dec6;
  --cream-deep: #d6c7a6;
  --petrol: #456b75;
  --night: #1f3b45;
  --night-deep: #142a32;
  --timber: #a77b5a;
  --timber-deep: #6f4b33;
  --vermilion: #bc5c4a;
  --mustard: #e3b54e;
  --mustard-deep: #b5852c;
  --sage: #7c8b71;
  --lamp: #f2cf86;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--night-deep);
  color: var(--cream);
  font-family: "Fredoka", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  overflow-x: hidden;
}
img { display: block; max-width: 100%; height: auto; }
html, body { overflow-x: clip; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.1; font-weight: 600; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--mustard); outline-offset: 3px; border-radius: 10px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; inset: max(10px, env(safe-area-inset-top)) 12px auto 12px;
  display: flex; align-items: center; justify-content: space-between;
  z-index: 40; pointer-events: none;
}
.hud-btn {
  pointer-events: auto; width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: #2b4c57; border: 3px solid #3d6673; box-shadow: 0 3px 0 #16303a;
  transition: transform .12s, background .2s;
}
.hud-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #16303a; }
.hud-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--cream); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#lightBtn[aria-pressed="true"] { background: #6a5a33; border-color: #8e7843; box-shadow: 0 3px 0 #3f3418, 0 0 18px rgba(242, 207, 134, .35); }
#lightBtn[aria-pressed="true"] svg { stroke: var(--lamp); fill: rgba(242, 207, 134, .35); }
#musicBtn .slash { stroke: var(--vermilion); }
#musicBtn[aria-pressed="true"] .slash { display: none; }
#musicBtn[aria-pressed="true"] { background: #355f4d; border-color: #4b7d67; }
.hud-score {
  pointer-events: auto; display: flex; align-items: center; gap: 6px;
  padding: 6px 14px 6px 10px; border-radius: 999px; font-weight: 600;
  background: #2b4c57; border: 3px solid #3d6673;
}
.hud-score.bump { animation: bump .35s; }

/* ---------- Hero scene ---------- */
.scene {
  position: relative; height: 100svh; min-height: 640px; max-height: 1300px;
  overflow: hidden; background: var(--night);
  isolation: isolate;
}
/* The stage keeps the art's 16:9 so hotspots stay put; it covers the hero and anchors to the floor. */
.stage {
  --w: max(100vw, calc(clamp(640px, 100svh, 1300px) * 16 / 9));
  --fx: .3;
  position: absolute; bottom: 0; width: var(--w); aspect-ratio: 16 / 9;
  left: calc((100vw - var(--w)) * var(--fx));
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  transition: transform .6s cubic-bezier(.2, .7, .2, 1);
}
@media (min-width: 900px) { .stage { --fx: .5; } }
.stage-bg { width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; }
.lamp-hit {
  position: absolute; left: 0; top: 25%; width: 7.5%; height: 22%;
  background: none; border: 0; border-radius: 40%; cursor: pointer;
}

.keepers { position: absolute; inset: 0; pointer-events: none; }
.hero-keeper {
  position: absolute; bottom: 5%; height: 37%; padding: 0; border: 0; background: none;
  pointer-events: auto; cursor: pointer; transform-origin: 50% 100%;
  filter: drop-shadow(0 .6vh 0 rgba(20, 30, 36, .35));
  animation: land .7s cubic-bezier(.3, 1.5, .5, 1) both;
}
.hero-keeper img { height: 100%; width: auto; }
.hero-keeper:hover img, .hero-keeper:focus-visible img { animation: wobble .5s; }
.hero-keeper.talk img { animation: hop .45s; }
.k-maeve { left: 21.5%; animation-delay: .35s; }
.k-avery { left: 28.5%; height: 39%; z-index: 2; animation-delay: .2s; }
.k-tilly { left: 37.5%; animation-delay: .5s; }

.bubble {
  position: absolute; z-index: 5; max-width: min(320px, 70vw);
  padding: 12px 16px; border-radius: 18px; color: var(--ink);
  background: var(--cream); border: 3px solid var(--cream-deep);
  font-weight: 500; line-height: 1.3; transform: translate(-50%, -100%);
  animation: pop .25s cubic-bezier(.3, 1.6, .5, 1) both;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -12px; margin-left: -10px;
  border: 10px solid transparent; border-top-color: var(--cream); border-bottom: 0;
}

.hero-copy {
  position: relative; z-index: 10; width: min(640px, 100% - 32px); margin: 0 auto;
  padding-top: max(70px, 8svh); text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.logo-wrap { margin: 0; }
.logo {
  width: clamp(250px, 34vw, 460px); height: auto; cursor: pointer;
  filter: drop-shadow(0 6px 0 rgba(10, 22, 28, .45));
  animation: drop .8s cubic-bezier(.3, 1.4, .5, 1) both;
}
.logo.spin { animation: windup .9s ease-in-out; }
.hero-line {
  margin-top: 14px; font-size: clamp(1.45rem, 3.1vw, 2.2rem); font-weight: 600;
  text-shadow: 0 2px 0 rgba(10, 22, 28, .55), 0 0 24px rgba(10, 22, 28, .6);
}
.hero-sub {
  margin-top: 8px; max-width: 34em; font-size: clamp(1rem, 1.5vw, 1.125rem);
  text-shadow: 0 1px 0 rgba(10, 22, 28, .6), 0 0 18px rgba(10, 22, 28, .8);
}

.play-btn {
  margin-top: 20px; display: inline-flex; align-items: center; gap: 12px;
  padding: 10px 26px 10px 20px; border-radius: 18px; cursor: pointer;
  color: #3a2a12; background: var(--mustard);
  border: 3px solid #f0cd7a; border-bottom-color: var(--mustard-deep);
  box-shadow: 0 5px 0 #8c6420, 0 10px 20px rgba(8, 18, 22, .35);
  text-align: left; transition: transform .1s, box-shadow .1s;
}
.play-btn:hover { background: #ebc15c; }
.play-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #8c6420, 0 4px 10px rgba(8, 18, 22, .35); }
.play-btn svg { width: 30px; height: 30px; fill: #3a2a12; }
.play-btn span { display: flex; flex-direction: column; font-size: 1.35rem; font-weight: 700; line-height: 1.05; }
.play-btn small { font-size: .78rem; font-weight: 500; }
.play-btn.nope { animation: nope .4s; }
.toast {
  min-height: 1.5em; margin-top: 12px; font-weight: 500; opacity: 0; transition: opacity .25s;
  text-shadow: 0 1px 0 rgba(10, 22, 28, .7);
}
.toast.on { opacity: 1; }
.tip {
  position: absolute; z-index: 10; right: 16px; bottom: 14px; font-size: .9rem;
  padding: 4px 12px; border-radius: 999px; background: rgba(20, 42, 50, .7); color: var(--cream);
}

/* Lights Out */
.dark {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .5s;
  background: radial-gradient(circle at 25% 80%, rgba(242, 207, 134, .12) 0, rgba(8, 14, 22, .72) 9%, rgba(5, 9, 15, .93) 30%);
}
body.lights-out .dark { opacity: 1; }
body.lights-out .hero-copy, body.lights-out .tip { opacity: .35; transition: opacity .5s; }
.creepers { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.creeper {
  position: absolute; bottom: 9%; height: 21%; aspect-ratio: 261 / 360;
  padding: 0; border: 0; background: none; pointer-events: auto; cursor: pointer;
  transform-origin: 50% 100%;
}
.creeper img { width: 100%; height: 100%; }
.creeper.walking img { animation: tiptoe .5s ease-in-out infinite alternate; }
.creeper.frozen img { animation: freeze .3s; filter: saturate(.75); }
.creeper.frozen::after {
  content: "!"; position: absolute; left: 50%; top: -18%; transform: translateX(-50%);
  font-weight: 700; font-size: clamp(16px, 2.2vw, 30px); color: var(--mustard);
  text-shadow: 0 2px 0 var(--ink);
}
.shard {
  position: absolute; width: clamp(12px, 1.6vw, 22px); pointer-events: none; z-index: 6;
  animation: shard .8s cubic-bezier(.2, .6, .4, 1) forwards;
}

/* ---------- Story ---------- */
/* The garden stays pinned while the captions scroll over it, like turning picture-book pages. */
.story { position: relative; background: #182c35; }
.story-art {
  position: sticky; top: 0; height: 100svh; overflow: hidden;
  background: url("/img/garden-1280.webp") 72% center / cover no-repeat;
}
@media (min-width: 1300px) { .story-art { background-image: url("/img/garden-2048.webp"); } }
.story-art::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(16, 30, 38, .92) 0, rgba(16, 30, 38, .72) 40%, rgba(16, 30, 38, .1) 75%),
              linear-gradient(180deg, var(--night) 0, transparent 14%, transparent 86%, #2a4952 100%);
}
.rain {
  position: absolute; inset: 0; z-index: 1; opacity: .35; pointer-events: none;
  background-image: repeating-linear-gradient(103deg, transparent 0 22px, rgba(190, 210, 220, .5) 22px 23px, transparent 23px 61px);
  background-size: 140px 220px; animation: rain .6s linear infinite;
}
.captions {
  position: relative; list-style: none; margin: 0; padding: 0 20px;
  width: min(560px, 100% - max(16px, 8vw)); margin: -100svh 0 0 max(16px, 8vw); padding: 40svh 16px 45svh 0;
  display: grid; gap: 34svh;
}
.captions li {
  font-size: clamp(1.6rem, 3.6vw, 2.6rem); font-weight: 600; line-height: 1.2;
  text-shadow: 0 2px 0 rgba(8, 18, 24, .6);
  opacity: .18; transform: translateY(14px); transition: opacity .7s, transform .7s;
}
.captions li.on { opacity: 1; transform: none; }

/* ---------- How to play (the board: a rug on floorboards) ---------- */
.howto {
  padding: 90px 16px 100px; text-align: center;
  background:
    repeating-linear-gradient(0deg, transparent 0 58px, rgba(60, 38, 24, .35) 58px 61px),
    var(--timber-deep);
}
.howto h2, .select h2 { font-size: clamp(2rem, 4.4vw, 3rem); text-shadow: 0 3px 0 rgba(20, 14, 8, .45); }
.howto-grid {
  margin: 40px auto 0; max-width: 1080px; display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.tile {
  text-align: left; color: var(--ink); background: var(--cream); border-radius: 22px;
  border: 4px solid #f5ecd9; border-bottom-color: var(--cream-deep);
  box-shadow: 0 6px 0 #4e3423; overflow: hidden; padding-bottom: 22px;
}
.tile h3 { margin: 18px 22px 6px; font-size: 1.5rem; }
.tile p { margin: 0 22px; }
.tile-art {
  height: 170px; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--petrol); border-bottom: 4px solid #3a5b64;
}
.art-blocks img { width: 64px; }
.art-blocks img:nth-child(2) { transform: translateY(-14px); }
.art-merge img { width: 66px; }
.art-merge img.big { width: 96px; }
.art-merge span { font-size: 1.8rem; font-weight: 700; color: var(--cream); }
.art-keeper { position: relative; align-items: flex-end; }
.art-keeper img { height: 156px; width: auto; }
.super {
  position: absolute; right: 18px; top: 18px; padding: 4px 14px; border-radius: 999px;
  font-weight: 700; color: #3a2a12; background: var(--mustard); border: 3px solid #f0cd7a;
  animation: glow 1.6s ease-in-out infinite alternate;
}

/* ---------- Keeper select ---------- */
.select {
  padding: 90px 16px 100px; text-align: center;
  background: radial-gradient(ellipse at 50% 30%, #3e6670 0, var(--night) 70%);
}
.select-sub { margin-top: 10px; }
.select-wrap {
  margin: 36px auto 0; max-width: 1040px; display: grid; gap: 28px; align-items: center;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
}
.podium { margin: 0; position: relative; display: flex; flex-direction: column; align-items: center; }
.podium::before {
  content: ""; position: absolute; bottom: 116px; width: 64%; height: 46px; border-radius: 50%;
  background: #2b4f59; border: 4px solid #4c7884; box-shadow: 0 8px 0 #1a343c;
}
.podium img {
  position: relative; height: min(52vh, 460px); width: auto;
  filter: drop-shadow(0 6px 0 rgba(10, 22, 28, .4));
}
.podium img.swap { animation: hop .45s; }
.podium figcaption { margin-top: 26px; display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 116px; }
.podium-name { font-size: 2rem; font-weight: 700; }
.podium-tag { font-size: .95rem; padding: 2px 12px; border-radius: 999px; background: #2b4c57; border: 2px solid #3d6673; }
.podium-quote { max-width: 26em; font-size: 1.1rem; font-style: normal; }
.podium-quote:empty { display: none; }
.roster { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.slot {
  position: relative; aspect-ratio: 3 / 4; padding: 0; border-radius: 18px; cursor: pointer; overflow: hidden;
  background: #2d5561; border: 4px solid #3f6c78; box-shadow: 0 4px 0 #17323a;
  transition: transform .12s;
}
.slot img { position: absolute; left: 50%; top: 6%; height: 190%; width: auto; max-width: none; transform: translateX(-50%); }
.slot span {
  position: absolute; inset: auto 0 0; padding: 4px 0 6px; font-size: .9rem; font-weight: 600;
  background: linear-gradient(transparent, rgba(16, 32, 38, .9) 45%);
}
.slot:hover { transform: translateY(-3px); }
.slot[aria-pressed="true"] { border-color: var(--mustard); box-shadow: 0 4px 0 var(--mustard-deep), 0 0 0 3px rgba(227, 181, 78, .3); }

/* ---------- Gnome Book ---------- */
.book { padding: 90px 16px 100px; background: #2a2531; }
.book-page {
  max-width: 760px; margin: 0 auto; padding: 40px clamp(20px, 5vw, 56px) 44px;
  color: var(--ink); background: var(--cream); border-radius: 10px 22px 22px 10px;
  border-left: 14px solid var(--vermilion); box-shadow: 0 8px 0 #1b1720;
}
.book h2 { font-size: clamp(2rem, 4.4vw, 2.8rem); }
.book-sub { margin-top: 6px; color: #5b5262; }
.entries { list-style: none; margin: 26px 0 0; padding: 0; display: grid; gap: 4px; }
.entry { display: grid; grid-template-columns: 52px 1fr; gap: 16px; align-items: center; padding: 14px 0; border-top: 2px dashed #cdbd99; }
.entry img { width: 44px; height: auto; }
.entry h3 { font-size: 1.2rem; }
.entry p { margin-top: 2px; }
.entry.locked img { filter: brightness(0) opacity(.35); }
.entry.locked h3, .entry.locked p { color: #8a7f8f; }
.entry.fresh { animation: unlock .8s; }

/* ---------- Finale ---------- */
.finale {
  position: relative; padding: 120px 16px 90px; text-align: center; overflow: hidden;
  background: linear-gradient(180deg, #2a2531 0, var(--night) 100%);
}
.finale h2 { font-size: clamp(2rem, 4.6vw, 3.2rem); }
.finale p { margin-top: 10px; }
.finale-gnome {
  position: absolute; width: 120px; left: 50%; top: 0; transform: translate(-50%, -62%);
  transition: transform .5s cubic-bezier(.3, 1.4, .5, 1);
}
.finale.peek .finale-gnome { transform: translate(-50%, -18%); }

.foot { padding: 26px 16px 40px; text-align: center; font-size: .9rem; color: #a9b7ba; background: var(--night); }
.foot p + p { margin-top: 4px; }

/* Idle sneaker and storm */
.sneaker { position: fixed; z-index: 30; right: -140px; bottom: 0; width: 110px; animation: sneak 7s ease-in-out forwards; }
.sneaker button { padding: 0; border: 0; background: none; cursor: pointer; width: 100%; }
.sneaker img { width: 100%; }
.flash { position: fixed; inset: 0; z-index: 50; pointer-events: none; background: #e8f1ff; opacity: 0; }
.flash.on { animation: flash 1.1s; }
body.storm .hero-keeper img, body.storm .slot img { animation: hop .45s 3; }

/* ---------- Keyframes ---------- */
@keyframes land { from { transform: translateY(-60vh) rotate(-8deg); } }
@keyframes drop { from { transform: translateY(-40px) scale(.85); opacity: 0; } }
@keyframes wobble { 30% { transform: rotate(-4deg); } 60% { transform: rotate(3deg); } }
@keyframes hop { 40% { transform: translateY(-9%) scaleY(1.04); } 70% { transform: translateY(0) scaleY(.96); } }
@keyframes pop { from { transform: translate(-50%, -80%) scale(.6); opacity: 0; } }
@keyframes windup { 0% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 50% { transform: rotate(5deg); } 75% { transform: rotate(-3deg); } }
@keyframes nope { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes tiptoe { from { transform: translateY(0) rotate(-3deg); } to { transform: translateY(-5%) rotate(3deg); } }
@keyframes freeze { 50% { transform: scale(1.06, .94); } }
@keyframes shard { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }
@keyframes rain { to { background-position: -40px 220px; } }
@keyframes glow { to { box-shadow: 0 0 18px rgba(227, 181, 78, .7); } }
@keyframes unlock { 0% { background: rgba(227, 181, 78, .5); } 100% { background: transparent; } }
@keyframes sneak { 0% { right: -140px; } 35%, 70% { right: 8px; } 100% { right: -140px; } }
@keyframes flash { 0%, 18%, 40% { opacity: 0; } 8%, 30% { opacity: .85; } 100% { opacity: 0; } }
@keyframes bump { 50% { transform: scale(1.2); } }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  .select-wrap { grid-template-columns: 1fr; }
  .podium img { height: 340px; }
  .podium::before { bottom: 112px; }
  .roster { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
  .slot { border-radius: 14px; border-width: 3px; }
  .slot span { font-size: .75rem; }
  .captions { gap: 30svh; }
  .story-art::after { background: linear-gradient(180deg, rgba(16, 30, 38, .55), rgba(16, 30, 38, .75)); }
  .tip { left: 50%; right: auto; transform: translateX(-50%); white-space: nowrap; }
}
@media (max-height: 700px) and (max-width: 760px) {
  .hero-sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .rain { display: none; }
  .captions li { opacity: 1; transform: none; }
}
