* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a3d2e;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  color: #fff;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
}

.hidden {
  display: none !important;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: env(safe-area-inset-top, 12px);
  left: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding-top: 12px;
  pointer-events: none;
  z-index: 10;
}

#stage-label {
  font-size: 22px;
  font-weight: 800;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
  letter-spacing: 1px;
}

#growth-bar {
  width: min(60vw, 280px);
  height: 18px;
  background: rgba(0, 0, 0, 0.5);
  border: 3px solid #fff;
  border-radius: 12px;
  overflow: hidden;
}

#growth-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd24a, #ff6a3d);
  transition: width 0.25s ease-out;
}

#score {
  font-size: 16px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #000;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 10px;
  border-radius: 10px;
}

/* ---------- Title screen ---------- */
#title-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #4fb3e0 0%, #87d676 60%, #5fae5c 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Scroll the whole screen as one column so nothing is clipped on
     small phones — centering is only used when content fits. */
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px
           calc(env(safe-area-inset-bottom, 0px) + 24px);
  z-index: 100;
}

#title-screen h1 {
  font-size: clamp(40px, 10vw, 88px);
  font-weight: 900;
  color: #fff;
  text-shadow: 4px 4px 0 #2a5a3a, 8px 8px 0 rgba(0, 0, 0, 0.2);
  letter-spacing: 2px;
  margin-bottom: 4px;
  text-align: center;
}

#title-screen .subtitle {
  font-size: clamp(14px, 3.5vw, 22px);
  color: #fff;
  text-shadow: 2px 2px 0 #2a5a3a;
  margin-bottom: 16px;
  font-weight: 700;
  text-align: center;
}

#title-screen .prompt {
  font-size: clamp(13px, 3.2vw, 18px);
  color: #2a5a3a;
  margin-bottom: 8px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---------- Level picker ---------- */
#level-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(94vw, 480px);
  margin-bottom: 14px;
}

@media (min-width: 560px) {
  #level-picker {
    grid-template-columns: repeat(6, 1fr);
  }
}

.level-choice {
  background: #fff;
  border: 3px solid #2a5a3a;
  border-radius: 14px;
  padding: 8px 6px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}

.level-choice:active {
  transform: scale(0.95);
}

.level-choice.selected {
  background: #ffd24a;
  border-color: #ffaa44;
  box-shadow: 0 0 12px rgba(255, 210, 74, 0.7);
}

.level-icon {
  font-size: 24px;
  line-height: 1;
}

.level-name {
  font-size: 11px;
  font-weight: 900;
  color: #2a5a3a;
  letter-spacing: 0.2px;
  text-align: center;
  line-height: 1.1;
}

/* Descriptions add height; hide on the level cards to keep the grid compact */
.level-desc {
  display: none;
}

/* ---------- Settings toggles ---------- */
#settings {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 8px 16px;
  justify-content: center;
  margin-bottom: 16px;
  padding: 0 8px;
}

@media (min-width: 560px) {
  #settings {
    grid-template-columns: repeat(3, auto);
  }
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: relative;
  width: 46px;
  height: 26px;
  background: #2a5a3a;
  border: 3px solid #fff;
  border-radius: 26px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.toggle input:checked + .toggle-slider {
  background: #ffaa44;
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  text-shadow: 2px 2px 0 #2a5a3a;
  letter-spacing: 0.5px;
}

.toggle.locked {
  filter: grayscale(0.85) opacity(0.55);
  pointer-events: none;
}
.toggle.locked .toggle-label::before { content: '🔒 '; }
.toggle.locked .lock-hint {
  display: block;
  font-size: 10px;
  color: #fff;
  text-shadow: 1px 1px 0 #2a5a3a;
  font-weight: 600;
  opacity: 0.9;
  letter-spacing: 0.3px;
}
.lock-hint { display: none; }

/* ---------- Invincible HUD indicator ---------- */
#invincible-indicator {
  display: inline-block;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #88ddff;
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 14px;
  color: #cef0ff;
  text-shadow: 1px 1px 0 #000;
  animation: invinciblePulse 1.2s ease-in-out infinite alternate;
}

@keyframes invinciblePulse {
  from { box-shadow: 0 0 4px rgba(136, 221, 255, 0.5); }
  to   { box-shadow: 0 0 16px rgba(136, 221, 255, 1); }
}

/* ---------- Home indicator ---------- */
#home-indicator {
  display: inline-block;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #ffd28a;
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 14px;
  color: #fff4d0;
  text-shadow: 1px 1px 0 #000;
  animation: homePulse 1.5s ease-in-out infinite alternate;
}

@keyframes homePulse {
  from { box-shadow: 0 0 4px rgba(255, 232, 138, 0.5); }
  to   { box-shadow: 0 0 14px rgba(255, 232, 138, 0.95); }
}

/* ---------- Menu / Pause buttons (top-right) ---------- */
#menu-btn, #pause-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  z-index: 15;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 14px;
  cursor: pointer;
  text-shadow: 1px 1px 0 #000;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
#menu-btn  { right: 12px; }
#pause-btn { right: 96px; padding: 8px 12px; font-size: 18px; }

#menu-btn:active, #pause-btn:active {
  transform: scale(0.92);
}

/* ---------- Homeward compass ---------- */
#compass {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 58px);
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  z-index: 11;
}

#compass-arrow {
  font-size: 32px;
  color: #ffd24a;
  text-shadow: 2px 2px 0 #000, 0 0 8px rgba(255, 210, 74, 0.6);
  line-height: 1;
}

#compass-label {
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  background: rgba(0, 0, 0, 0.45);
  padding: 2px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

#picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(94vw, 520px);
}

@media (min-width: 560px) {
  #picker {
    grid-template-columns: repeat(4, 1fr);
  }
}

.dino-choice {
  background: #fff;
  border: 3px solid #2a5a3a;
  border-radius: 14px;
  padding: 8px 4px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: transform 0.1s;
}

.dino-choice:active {
  transform: scale(0.95);
}

.dino-preview {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  box-shadow: inset -5px -6px 0 rgba(0, 0, 0, 0.2);
}

.dino-name {
  font-size: 11px;
  font-weight: 900;
  color: #2a5a3a;
  letter-spacing: 0.2px;
  text-align: center;
  line-height: 1.05;
}

.dino-desc {
  font-size: 9px;
  color: #5a7a3a;
  font-weight: 600;
  text-align: center;
  line-height: 1.05;
}

/* ---------- Touch controls ---------- */
#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

/* Invisible joystick zone covering the left half of the screen (below
   the HUD strip). Tapping anywhere here spawns the floating joystick. */
#joystick-zone {
  position: absolute;
  left: 0;
  top: 100px;
  width: 55vw;
  bottom: 0;
  pointer-events: auto;
  touch-action: none;
}

#joystick {
  position: fixed;
  /* left/top set dynamically by controls.js when the user touches */
  width: 130px;
  height: 130px;
  background: rgba(255, 255, 255, 0.18);
  border: 4px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  pointer-events: none;
  touch-action: none;
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#chomp-btn {
  position: absolute;
  right: calc(env(safe-area-inset-right, 0px) + 24px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 48px);
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: radial-gradient(circle at 35% 35%, #ff8a5a, #d44a2a);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
  font-family: inherit;
  text-shadow: 2px 2px 0 #6a1a0a;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}

#chomp-btn:active {
  transform: scale(0.92);
}

#blast-btn {
  position: absolute;
  right: calc(env(safe-area-inset-right, 0px) + 150px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: radial-gradient(circle at 35% 35%, #8ad8ff, #2a6ad4);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  font-family: inherit;
  text-shadow: 2px 2px 0 #0a2a6a;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(120, 200, 255, 0.8);
}

#blast-btn:active {
  transform: scale(0.92);
}

#blast-btn.cooldown {
  background: radial-gradient(circle at 35% 35%, #667, #334);
  box-shadow: none;
  opacity: 0.6;
}

/* ---------- Stage up popup ---------- */
#stage-up {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 50;
  animation: stageUpAnim 1.8s ease-out forwards;
}

#stage-up-text {
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 900;
  color: #ffd24a;
  text-shadow: 3px 3px 0 #000, 6px 6px 0 rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
}

#stage-up-name {
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 900;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  margin-top: 8px;
}

@keyframes stageUpAnim {
  0%   { opacity: 0; transform: scale(0.5); }
  20%  { opacity: 1; transform: scale(1.1); }
  30%  { transform: scale(1); }
  80%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.2); }
}

/* ---------- Game over ---------- */
#game-over {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 90;
  padding: 24px;
  text-align: center;
}

#game-over h2 {
  font-size: clamp(28px, 7vw, 44px);
  text-shadow: 3px 3px 0 #5a1a1a;
}

#game-over p {
  font-size: 18px;
  opacity: 0.9;
}

#respawn-btn {
  margin-top: 16px;
  padding: 16px 32px;
  font-size: 20px;
  font-weight: 900;
  font-family: inherit;
  background: #ffd24a;
  color: #2a5a3a;
  border: 4px solid #fff;
  border-radius: 16px;
  cursor: pointer;
  letter-spacing: 1px;
}

#respawn-btn:active {
  transform: scale(0.95);
}

/* ---------- Power-up indicator ---------- */
#powerup-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #ffd24a;
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 14px;
  color: #ffd24a;
  text-shadow: 1px 1px 0 #000;
  animation: powerupPulse 0.8s ease-in-out infinite alternate;
}

#powerup-icon {
  font-size: 18px;
}

#powerup-timer {
  background: rgba(255, 210, 74, 0.25);
  padding: 1px 8px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

@keyframes powerupPulse {
  from { box-shadow: 0 0 4px rgba(255, 210, 74, 0.5); }
  to   { box-shadow: 0 0 14px rgba(255, 210, 74, 0.95); }
}

/* ---------- Atomic Charge meter (Titan) ---------- */
#atomic-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid #66e6ff;
  border-radius: 16px;
  padding: 4px 10px 4px 8px;
  font-weight: 800;
  font-size: 12px;
  color: #cff5ff;
  text-shadow: 1px 1px 0 #000;
  letter-spacing: 1px;
}
#atomic-indicator.full {
  animation: atomicFullPulse 0.7s ease-in-out infinite alternate;
  border-color: #ffffff;
  color: #ffffff;
}
#atomic-icon { font-size: 16px; filter: drop-shadow(0 0 4px #66e6ff); }
#atomic-bar {
  width: 120px;
  height: 10px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(102, 230, 255, 0.6);
  border-radius: 6px;
  overflow: hidden;
}
#atomic-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #1a6fa0, #66e6ff, #c8f7ff);
  box-shadow: 0 0 6px rgba(102, 230, 255, 0.8) inset;
  transition: width 0.18s ease-out;
}
#atomic-indicator.full #atomic-fill {
  background: linear-gradient(90deg, #c8f7ff, #ffffff, #c8f7ff);
}
@keyframes atomicFullPulse {
  from { box-shadow: 0 0 6px rgba(102, 230, 255, 0.6); }
  to   { box-shadow: 0 0 22px rgba(200, 247, 255, 1.0); }
}

/* ---------- Baby indicator ---------- */
#baby-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #ffaadd;
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 14px;
  color: #ffd6ec;
  text-shadow: 1px 1px 0 #000;
}

.baby-icon {
  font-size: 18px;
}

#baby-timer {
  background: rgba(255, 170, 221, 0.25);
  padding: 1px 8px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Egg hatch prompt ---------- */
#egg-prompt {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 200px);
  transform: translateX(-50%);
  z-index: 25;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: eggPromptBob 0.6s ease-in-out infinite alternate;
}

#egg-progress {
  width: 180px;
  height: 14px;
  background: rgba(0, 0, 0, 0.55);
  border: 3px solid #fff4d0;
  border-radius: 10px;
  overflow: hidden;
}

#egg-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #fff4d0, #ffd24a);
  transition: width 0.15s ease-out;
}

.egg-prompt-text {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
  text-shadow: 2px 2px 0 #6a4a2a, 0 0 8px rgba(255, 232, 154, 0.8);
  letter-spacing: 1px;
  background: rgba(106, 74, 42, 0.7);
  padding: 4px 12px;
  border-radius: 10px;
}

@keyframes eggPromptBob {
  from { transform: translate(-50%, 0); }
  to   { transform: translate(-50%, -6px); }
}

/* ---------- Fact toast ---------- */
#fact-toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 170px);
  transform: translateX(-50%);
  background: #2a5a3a;
  color: #fff;
  padding: 12px 18px;
  border: 4px solid #ffd24a;
  border-radius: 16px;
  font-weight: 700;
  font-size: 15px;
  max-width: min(85vw, 420px);
  text-align: center;
  z-index: 30;
  pointer-events: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  animation: factToast 4s ease-out forwards;
}

#fact-toast::before {
  content: "🦕 ";
}

@keyframes factToast {
  0%   { opacity: 0; transform: translate(-50%, 20px); }
  10%  { opacity: 1; transform: translate(-50%, 0); }
  85%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

/* ---------- Win screen ---------- */
#win-screen {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(255, 210, 74, 0.4) 0%, transparent 60%),
    rgba(20, 60, 40, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 95;
  padding: 24px;
  text-align: center;
}

#win-screen h2 {
  font-size: clamp(28px, 8vw, 56px);
  font-weight: 900;
  color: #ffd24a;
  text-shadow: 4px 4px 0 #5a3a0a, 8px 8px 0 rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
  animation: winTitle 1.5s ease-out;
}

.win-sub {
  font-size: clamp(16px, 4vw, 22px);
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  font-weight: 700;
}

#win-score {
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 900;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 24px;
  border-radius: 16px;
}

#win-continue {
  margin-top: 12px;
  padding: 16px 32px;
  font-size: 20px;
  font-weight: 900;
  font-family: inherit;
  background: #ffd24a;
  color: #2a5a3a;
  border: 4px solid #fff;
  border-radius: 16px;
  cursor: pointer;
  letter-spacing: 1px;
}

#win-continue:active {
  transform: scale(0.95);
}

@keyframes winTitle {
  0%   { opacity: 0; transform: scale(0.3) rotate(-10deg); }
  50%  { transform: scale(1.2) rotate(5deg); }
  70%  { transform: scale(0.95) rotate(-2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

/* ---------- Error banner ---------- */
#error-banner {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  background: #d44a2a;
  color: #fff;
  padding: 12px 16px;
  font-family: monospace;
  font-size: 13px;
  z-index: 1000;
  border-bottom: 3px solid #6a1a0a;
  pointer-events: none;
  max-height: 50vh;
  overflow: auto;
}

#error-banner strong {
  display: block;
  font-family: -apple-system, sans-serif;
  font-size: 15px;
  margin-bottom: 6px;
}

#error-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  margin: 0;
}

/* ---------- Model status (title screen) ---------- */
.model-status {
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
  color: #2a5a3a;
  background: rgba(255, 255, 255, 0.7);
  padding: 4px 12px;
  border-radius: 10px;
  letter-spacing: 0.5px;
}
.model-status.glb {
  background: rgba(255, 210, 74, 0.85);
  color: #5a3a0a;
}

/* ---------- Boss health bar ---------- */
#boss-bar {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  left: 50%;
  transform: translateX(-50%);
  width: min(88vw, 420px);
  z-index: 14;
  text-align: center;
  pointer-events: none;
}
#boss-name {
  font-size: 14px;
  font-weight: 900;
  color: #ffdf6a;
  text-shadow: 2px 2px 0 #000, 0 0 8px rgba(255, 90, 60, 0.7);
  letter-spacing: 2px;
  margin-bottom: 4px;
}
#boss-hp-bar {
  height: 14px;
  background: rgba(0,0,0,0.6);
  border: 3px solid #ffdf6a;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(255, 90, 60, 0.5);
}
#boss-hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff3a5a, #ff8a3a);
  transition: width 0.2s ease-out;
}

/* ---------- Tutorial bubble (first-run hints) ---------- */
#tutorial-bubble {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 200px);
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: #2a5a3a;
  border: 4px solid #2a5a3a;
  border-radius: 18px;
  padding: 14px 18px;
  max-width: 86vw;
  text-align: center;
  z-index: 50;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25);
}

#tutorial-text {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 10px;
}

#tutorial-next {
  padding: 8px 18px;
  background: #ffd24a;
  border: 3px solid #2a5a3a;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 900;
  color: #2a5a3a;
  cursor: pointer;
}

#tutorial-bubble::after {
  content: '';
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 14px solid #2a5a3a;
}

/* ---------- Objective toast ---------- */
#objective-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid #ffd24a;
  border-radius: 14px;
  padding: 6px 14px;
  color: #fff4d0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 0 #000;
  z-index: 14;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#objective-progress {
  background: rgba(255, 210, 74, 0.25);
  padding: 1px 8px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Stats panel on title screen ---------- */
#stats-toggle {
  margin-top: 14px;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid #2a5a3a;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 800;
  color: #2a5a3a;
  cursor: pointer;
}

#stats-toggle:active {
  transform: scale(0.95);
}

#stats-panel {
  margin-top: 14px;
  width: min(94vw, 480px);
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #2a5a3a;
  border-radius: 16px;
  padding: 14px;
  color: #2a5a3a;
}

#stats-panel h3 {
  font-size: 16px;
  font-weight: 900;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

#stats-panel h4 {
  font-size: 13px;
  font-weight: 900;
  margin: 10px 0 6px;
}

#stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.stat-level-card {
  background: #fff;
  border: 2px solid #2a5a3a;
  border-radius: 10px;
  padding: 6px 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}

.stat-level-card .stat-icon {
  font-size: 20px;
  line-height: 1;
}

.stat-level-card.completed {
  border-color: #ffaa44;
  background: #fff4d0;
}

.stat-level-card .stat-score {
  font-size: 10px;
  color: #5a7a3a;
  margin-top: 2px;
}

#stats-ach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 120px;
  overflow-y: auto;
}

.ach-chip {
  font-size: 18px;
  background: #fff;
  border: 2px solid #2a5a3a;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: grayscale(0.85) opacity(0.5);
}

.ach-chip.unlocked {
  filter: none;
  border-color: #ffaa44;
  background: #fff4d0;
}

/* ---------- Level clear screen ---------- */
#level-clear {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(255, 210, 74, 0.5) 0%, transparent 60%),
    rgba(20, 60, 40, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 96;
  padding: 24px;
  text-align: center;
}

#level-clear h2 {
  font-size: clamp(28px, 8vw, 56px);
  font-weight: 900;
  color: #ffd24a;
  text-shadow: 4px 4px 0 #5a3a0a, 8px 8px 0 rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
  animation: winTitle 1.2s ease-out;
}

#level-clear-sub {
  font-size: clamp(14px, 4vw, 20px);
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  font-weight: 700;
}

#level-clear-score {
  font-size: clamp(18px, 5vw, 26px);
  font-weight: 900;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 24px;
  border-radius: 16px;
}

#level-clear-best {
  font-size: 18px;
  font-weight: 900;
  color: #ffd24a;
  text-shadow: 2px 2px 0 #5a3a0a;
  animation: bestPulse 1s ease-in-out infinite alternate;
}

@keyframes bestPulse {
  from { transform: scale(1); }
  to   { transform: scale(1.08); }
}

.level-clear-btns {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

#level-clear-continue, #level-clear-menu {
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 900;
  font-family: inherit;
  border: 4px solid #fff;
  border-radius: 16px;
  cursor: pointer;
  letter-spacing: 1px;
}

#level-clear-continue { background: #ffd24a; color: #2a5a3a; }
#level-clear-menu    { background: #fff;    color: #2a5a3a; }

/* ---------- Pause overlay ---------- */
#pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 88;
  padding: 24px;
  text-align: center;
}

#pause-overlay h2 {
  font-size: clamp(36px, 10vw, 64px);
  color: #fff;
  text-shadow: 4px 4px 0 #000;
  letter-spacing: 4px;
}

.pause-btns {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

#resume-btn, #pause-menu-btn {
  padding: 14px 26px;
  font-size: 18px;
  font-weight: 900;
  font-family: inherit;
  border: 4px solid #fff;
  border-radius: 16px;
  cursor: pointer;
  letter-spacing: 1px;
}

#resume-btn      { background: #ffd24a; color: #2a5a3a; }
#pause-menu-btn  { background: #fff;    color: #2a5a3a; }

/* ---------- Achievement toast ---------- */
#achievement-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 60px);
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #ffd24a 0%, #ffaa44 100%);
  border: 4px solid #fff;
  border-radius: 18px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 60;
  pointer-events: none;
  max-width: 92vw;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  animation: achToast 4s ease-out forwards;
}

#ach-icon {
  font-size: 32px;
  line-height: 1;
}

.ach-title {
  font-size: 11px;
  font-weight: 900;
  color: #5a3a0a;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#ach-name {
  font-size: 16px;
  font-weight: 900;
  color: #2a5a3a;
  letter-spacing: 0.5px;
}

#ach-desc {
  font-size: 12px;
  color: #2a5a3a;
  opacity: 0.85;
}

@keyframes achToast {
  0%   { opacity: 0; transform: translate(-50%, -16px); }
  10%  { opacity: 1; transform: translate(-50%, 0); }
  85%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}
