:root {
  --ink: #1f3b2a;
  --panel: rgba(255, 252, 235, 0.92);
  --accent: #ff8a1f;
  --accent-dark: #c4620c;
  --good: #3cbf4a;
  --bad: #ef4444;
  --home-bg: #fff6dc;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: 'Fredoka', system-ui, sans-serif; color: var(--ink); }
body { background: var(--home-bg); }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

/* =========================================================
   Shared animal + scenery animation classes (used by scenes)
   Transform origin is each group's local (0,0).
   ========================================================= */
.animal {
  opacity: 0;
  transform: translate(var(--hx, 0px), var(--hy, 60px)) scale(.55);
  transition: transform .35s ease-in, opacity .3s ease-in;
  pointer-events: none;
}
.animal.out {
  opacity: 1;
  transform: none;
  transition: transform 2.2s cubic-bezier(.25, 1.4, .5, 1), opacity 1.8s ease-out;
}
.sway      { animation: sway 4s ease-in-out infinite; }
.sway-slow { animation: sway 7s ease-in-out infinite; }
@keyframes sway { 0%,100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
.bob   { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.blink { animation: blink 4.5s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes blink { 0%,92%,100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
.leap  { animation: leap 6s ease-in-out infinite; }
@keyframes leap {
  0%, 45% { transform: rotate(-70deg); opacity: 0; }
  48% { opacity: 1; }
  80% { transform: rotate(70deg); opacity: 1; }
  83%, 100% { transform: rotate(70deg); opacity: 0; }
}
.flap-l, .flap-r { animation: flap .25s ease-in-out infinite alternate; }
@keyframes flap { from { transform: scaleX(1); } to { transform: scaleX(.25); } }
.drift  { animation: drift 9s ease-in-out infinite; }
.drift2 { animation: drift 11s ease-in-out infinite reverse; }
@keyframes drift {
  0%,100% { transform: translate(0,0); } 25% { transform: translate(40px,-30px); }
  50% { transform: translate(80px,10px); } 75% { transform: translate(30px,30px); }
}
.tongue { animation: tongue 2.2s infinite; }
@keyframes tongue { 0%,70%,100% { transform: scaleX(0); } 75%,90% { transform: scaleX(1); } }
.tail { animation: tail 2s ease-in-out infinite; }
@keyframes tail { 0%,100% { transform: rotate(-10deg); } 50% { transform: rotate(14deg); } }
.wave { animation: wave 5s linear infinite; }
.wave.w2 { animation-duration: 7s; animation-direction: reverse; }
@keyframes wave { from { transform: translateX(0); } to { transform: translateX(-120px); } }
.cloud { animation: cloud 60s linear infinite; }
.cloud.c2 { animation-duration: 90s; }
@keyframes cloud { from { transform: translateX(-300px); } to { transform: translateX(1900px); } }
.leafsway { animation: sway 6s ease-in-out infinite; }
.shake .bush { animation: shake .12s linear 6; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px) rotate(-1deg); } 75% { transform: translateX(6px) rotate(1deg); } }

/* Thumbnails: show every animal, freeze motion */
.thumb .animal { opacity: 1; transform: none; transition: none; }
.thumb * { animation: none !important; }

/* =========================================================
   Home screen
   ========================================================= */
#home { min-height: 100%; padding: 24px 16px 40px; overflow-y: auto; height: 100%; }
.home-head { text-align: center; max-width: 900px; margin: 0 auto 24px; }
.home-head h1 { font-size: clamp(32px, 6vw, 56px); margin: 8px 0 4px; }
.home-head p { font-size: clamp(17px, 2.4vw, 22px); margin: 0; opacity: .85; }
.grid {
  display: grid; gap: 20px; max-width: 1500px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.tile {
  position: relative; display: flex; flex-direction: column; text-align: left; padding: 0; border: 0;
  background: #fff; border-radius: 22px; overflow: hidden; cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,.12); transition: transform .15s, box-shadow .15s;
}
.tile:hover, .tile:focus-visible { transform: translateY(-4px); box-shadow: 0 10px 0 rgba(0,0,0,.14); outline: none; }
.tile:focus-visible { box-shadow: 0 0 0 4px var(--accent), 0 10px 0 rgba(0,0,0,.14); }
.tile:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(0,0,0,.12); }
.thumb { aspect-ratio: 16 / 10; overflow: hidden; background: #cde; }
.thumb svg { width: 100%; height: 100%; display: block; }
.tile-info { padding: 12px 16px 14px; }
.tile-name { font-size: 21px; font-weight: 700; line-height: 1.15; }
.tile-place { font-size: 15px; opacity: .7; margin-top: 2px; }
.badge {
  position: absolute; top: 10px; right: 10px; padding: 5px 12px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.badge.visited { background: var(--good); color: #fff; }
.badge.new { background: #fff; color: var(--ink); }
/* Not visited yet: picture slightly faded */
.thumb svg { transition: opacity .2s, filter .2s; }
.tile.unvisited .thumb svg { opacity: .55; filter: saturate(.6); }
.tile.unvisited:hover .thumb svg, .tile.unvisited:focus-visible .thumb svg { opacity: .85; filter: none; }

/* Secret (11th) tile */
.tile.secret { background: linear-gradient(135deg, #3b1a6e, #1d0b40); color: #fff; box-shadow: 0 6px 0 #12062a, 0 0 0 3px #c78bff; }
.tile.secret .tile-place { opacity: .85; }
.tile.secret:not(.locked) { animation: secret-glow 2.4s ease-in-out infinite; }
@keyframes secret-glow { 0%,100% { box-shadow: 0 6px 0 #12062a, 0 0 0 3px #c78bff, 0 0 18px #c78bff; } 50% { box-shadow: 0 6px 0 #12062a, 0 0 0 3px #ffe96b, 0 0 34px #ffe96b; } }
.tile.locked { cursor: not-allowed; }
.tile.locked .thumb svg { filter: blur(7px) brightness(.35) saturate(.3); transform: scale(1.15); }
.tile.locked:hover { transform: none; }
.lock-overlay {
  position: absolute; top: 0; left: 0; right: 0; aspect-ratio: 16 / 10; display: grid; place-items: center;
  font-size: 56px; text-shadow: 0 4px 12px rgba(0,0,0,.5); pointer-events: none;
}
.tile.nope { animation: nope .4s; }
@keyframes nope { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.badge.unlocked { background: #ffe96b; color: #3b1a6e; }

#unlock { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(20, 8, 50, .7); backdrop-filter: blur(4px); }
#unlock .card { background: linear-gradient(160deg, #4a2390, #1d0b40); color: #fff; box-shadow: 0 10px 0 #12062a, 0 0 40px #c78bff; }
#unlock .rocket { font-size: 64px; display: inline-block; animation: bob 1.2s ease-in-out infinite; }
.text-btn { background: none; border: 0; color: inherit; opacity: .75; cursor: pointer; font-size: 17px; margin-top: 14px; display: block; width: 100%; }
.text-btn:hover { opacity: 1; }

.home-foot { display: flex; gap: 16px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 28px; font-size: 18px; }
.link-btn { background: none; border: 2px solid currentColor; border-radius: 999px; padding: 6px 16px; cursor: pointer; font-size: 15px; opacity: .7; }
.link-btn:hover { opacity: 1; }

/* =========================================================
   Scene view
   ========================================================= */
#sceneView { position: fixed; inset: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: absolute; z-index: 5; }
.pill { background: var(--panel); border-radius: 999px; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.top-left { top: 16px; left: 16px; display: flex; gap: 10px; align-items: center; max-width: calc(100% - 180px); }
.home-btn { border: 0; cursor: pointer; padding: 8px 16px; font-weight: 700; font-size: clamp(16px, 2.2vw, 22px); }
.home-btn:hover { background: #fff; }
.top-right { top: 16px; right: 16px; display: flex; gap: 10px; align-items: center; }
.sound-btn { border: 0; cursor: pointer; padding: 8px 14px; font-size: clamp(16px, 2.5vw, 24px); line-height: 1.2; }
.sound-btn:hover { background: #fff; }
.counter { padding: 8px 16px; font-weight: 600; font-size: clamp(16px, 2.5vw, 24px); }
.bubble {
  top: 12px; left: 50%; transform: translateX(-50%); background: #fff; padding: 12px 24px;
  border-radius: 24px; font-size: clamp(18px, 3.2vw, 32px); font-weight: 600; text-align: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.12); transition: transform .3s, background .3s, color .3s;
  max-width: calc(100% - 380px); width: max-content; text-wrap: balance;
}
.bubble.loud { background: var(--bad); color: #fff; transform: translateX(-50%) scale(1.12); }
.meter-wrap {
  bottom: 16px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 32px));
  background: var(--panel); border-radius: 20px; padding: 10px 16px 12px; box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.meter-label { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.meter { position: relative; height: 22px; background: #e4ecd9; border-radius: 999px; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--good); border-radius: 999px; transition: background .2s; }
.meter-fill.loud { background: var(--bad); }
.meter-limit { position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px; background: var(--ink); border-radius: 2px; }
.slider-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; }
.slider-row input { flex: 1; accent-color: var(--accent); }

/* ?debug */
.debug-only { display: none !important; }
body.debug .debug-only { display: flex !important; }
.debug-note { justify-content: center; margin-top: 10px !important; font-size: 16px !important; font-weight: 600; color: #b45309; opacity: 1 !important; }
.debug-bar { left: 16px; bottom: 16px; gap: 8px; align-items: center; font-size: 20px; }
.debug-bar button { border: 0; cursor: pointer; padding: 6px 14px; font-size: 14px; font-weight: 600; }
.debug-bar button:hover { background: #fff; }

#start {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(20, 50, 35, .55); backdrop-filter: blur(3px);
}
.card {
  background: #fffbe8; border-radius: 28px; padding: 28px 32px; text-align: center; max-width: 480px; margin: 16px;
  box-shadow: 0 10px 0 rgba(0,0,0,.18);
}
.card h2 { margin: 0 0 8px; font-size: clamp(28px, 6vw, 40px); }
.card p { font-size: 19px; line-height: 1.4; margin: 8px 0 18px; }
.big-btn {
  font-size: 24px; font-weight: 700; color: #fff; background: var(--accent); border: 0;
  padding: 14px 34px; border-radius: 999px; cursor: pointer; box-shadow: 0 6px 0 var(--accent-dark);
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); }
.card small { display: block; margin-top: 14px; opacity: .7; font-size: 14px; }

@media (max-width: 600px) {
  .bubble { white-space: normal; top: 70px; max-width: calc(100% - 32px); }
}
