* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #0d1b12; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; color: #f4f7f0;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }

#loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 22px; letter-spacing: .5px; color: #cfe8c4; z-index: 40;
  background: radial-gradient(circle at 50% 40%, #1c3a25, #0d1b12);
}
#errbox {
  display: none; position: fixed; left: 12px; top: 12px; right: 12px; z-index: 999;
  background: rgba(150, 20, 20, .95); color: #fff; padding: 14px 16px; border-radius: 8px;
  font-family: monospace; font-size: 13px; white-space: pre-wrap; max-height: 60vh; overflow: auto;
}

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#topbar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; }
.pill {
  pointer-events: auto; background: rgba(18, 40, 26, .62); backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, .16); color: #eef7e8; border-radius: 999px;
  padding: 7px 13px; font-size: 15px; font-weight: 700; line-height: 1; white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
}
button.btn, #playBtn, #complete button { cursor: pointer; font-family: inherit; }
button.btn:active { transform: translateY(1px); }
#menuBtn { margin-left: auto; }
#peekBtn[disabled] { opacity: .4; }

#minimap {
  position: absolute; top: 56px; right: 12px; width: 138px; height: 138px;
  background: rgba(12, 26, 17, .55); border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}

#compass {
  position: absolute; top: 56px; left: 12px; width: 60px; height: 60px; border-radius: 50%;
  background: rgba(12, 26, 17, .5); border: 1px solid rgba(255, 255, 255, .18);
  display: flex; align-items: center; justify-content: center; transition: opacity .5s;
}
#compassArrow {
  width: 0; height: 0; border-left: 11px solid transparent; border-right: 11px solid transparent;
  border-bottom: 26px solid #ffd873; filter: drop-shadow(0 0 4px rgba(255, 200, 90, .7));
  transform-origin: 50% 68%;
}

#toast {
  position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%);
  background: rgba(18, 40, 26, .8); padding: 9px 18px; border-radius: 999px; font-weight: 700;
  opacity: 0; transition: opacity .3s; font-size: 15px; border: 1px solid rgba(255, 255, 255, .15);
}
#toast.show { opacity: 1; }

/* ---------------- Mobile joystick ---------------- */
#joy {
  position: fixed; left: 22px; bottom: 22px; width: 128px; height: 128px; z-index: 25;
  border-radius: 50%; background: rgba(20, 44, 28, .35); border: 1px solid rgba(255, 255, 255, .18);
  touch-action: none;
}
#joyKnob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(210, 240, 200, .5); border: 1px solid rgba(255, 255, 255, .4);
}

/* ---------------- Overlays (menu / complete) ---------------- */
#menu, #complete {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(28, 58, 37, .78), rgba(8, 18, 12, .92));
  backdrop-filter: blur(3px); overflow: auto; padding: 20px;
}
.menu-inner {
  width: min(560px, 94vw); text-align: center;
  background: rgba(16, 34, 22, .72); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 20px; padding: 26px 24px 30px; box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
#menu h1 { font-size: clamp(26px, 6vw, 40px); letter-spacing: .5px; margin-bottom: 6px; }
#menu .sub { color: #bfe0b2; margin-bottom: 18px; font-size: 15px; }
.section-label { text-align: left; font-size: 12px; letter-spacing: 2px; text-transform: uppercase;
  color: #8fb98a; margin: 16px 4px 8px; }

#animalRow { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.animal-card {
  cursor: pointer; flex: 1 1 140px; max-width: 170px; background: rgba(10, 24, 15, .5);
  border: 2px solid transparent; border-radius: 14px; padding: 14px 10px; transition: .15s;
}
.animal-card:hover { background: rgba(20, 44, 28, .6); }
.animal-card.sel { border-color: #ffd873; background: rgba(30, 60, 38, .7); box-shadow: 0 0 18px rgba(255, 210, 100, .25); }
.animal-emoji { font-size: 40px; line-height: 1; }
.animal-name { font-weight: 800; margin-top: 6px; }
.animal-blurb { font-size: 12px; color: #a9cfa0; margin-top: 2px; }

#levelRow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.level-chip {
  cursor: pointer; aspect-ratio: 1; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(10, 24, 15, .5); display: flex; align-items: center; justify-content: center;
  flex-direction: column; font-weight: 800; font-size: 18px; transition: .12s;
}
.level-chip .lname { font-size: 9px; font-weight: 700; color: #9cc593; margin-top: 2px; letter-spacing: .3px; }
.level-chip:hover { background: rgba(20, 44, 28, .65); }
.level-chip.sel { border-color: #ffd873; background: rgba(30, 60, 38, .75); box-shadow: 0 0 14px rgba(255, 210, 100, .25); }
.level-chip.locked { opacity: .4; cursor: not-allowed; }
.level-chip .lock { font-size: 15px; }
.level-chip .best { font-size: 8px; color: #ffd873; margin-top: 1px; }

#playBtn {
  margin-top: 22px; background: linear-gradient(180deg, #7ec850, #4e9a34); color: #10240f;
  border: none; border-radius: 14px; padding: 14px 34px; font-size: 20px; font-weight: 900;
  box-shadow: 0 6px 0 #2f6a1f, 0 10px 20px rgba(0, 0, 0, .3); letter-spacing: .5px;
}
#playBtn:active { transform: translateY(3px); box-shadow: 0 3px 0 #2f6a1f; }
.hint { margin-top: 16px; font-size: 12px; color: #94b98d; line-height: 1.6; }

#complete h2 { font-size: clamp(24px, 5vw, 34px); margin-bottom: 14px; }
#completeStats { font-size: 16px; line-height: 1.9; margin-bottom: 18px; color: #dff0d6; }
#completeStats b { color: #ffd873; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#complete button {
  background: linear-gradient(180deg, #7ec850, #4e9a34); color: #10240f; border: none;
  border-radius: 12px; padding: 12px 22px; font-size: 17px; font-weight: 800;
  box-shadow: 0 5px 0 #2f6a1f;
}
#complete button:active { transform: translateY(2px); box-shadow: 0 3px 0 #2f6a1f; }
#complete button.ghost { background: rgba(255, 255, 255, .1); color: #eef7e8; box-shadow: none; border: 1px solid rgba(255, 255, 255, .2); }
