:root {
  --grass: #6ec24d;
  --yellow: #ffd23f;
  --orange: #ff8a3d;
  --pink: #ff6b9d;
  --brown: #5a3a1e;
  --cream: #fff8ec;
  --ink: #3a2418;
  --danger: #ff4d4d;
}

.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  z-index: 50;
  padding: 20px;
  text-align: center;
}
/* The canvas now renders a live "attract mode" scene (panning camera,
   swaying grass, wandering critters) behind these two screens instead of
   a flat color — see Game._updateAttract()/_draw(). A soft vignette keeps
   the loading screen's centered text readable over that busy scene; the
   menu screen needs no scrim of its own since its content sits inside the
   opaque .menu-card. */
#screen-loading {
  background: radial-gradient(ellipse at center, rgba(14,32,9,0.42) 0%, rgba(14,32,9,0.16) 55%, transparent 100%);
}
#screen-menu {
  background: transparent;
}
.screen.overlay {
  background: rgba(30, 40, 20, 0.55);
  backdrop-filter: blur(2px);
}

.logo-pig { font-size: 72px; filter: drop-shadow(0 6px 0 rgba(0,0,0,0.15)); }
.logo-pig.bounce { animation: pigBounce 1.6s ease-in-out infinite; }
@keyframes pigBounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-14px) rotate(3deg); }
}

.game-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(38px, 9vw, 56px);
  font-weight: 800;
  /* The title sits on the cream menu-card, not on the green page
     background — an earlier cream-on-cream fill made it nearly
     illegible (only the dark outline showed, everything inside each
     letter blended into the card). Found via a screenshot review, not
     just code reading: the outline looked fine in isolation, but the
     interior fill matched the card so closely it read as hollow text.
     Fixed with a saturated brand color that actually contrasts against
     the cream card. */
  color: var(--pink);
  -webkit-text-fill-color: var(--pink);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow:
    -2px -2px 0 var(--ink), 2px -2px 0 var(--ink),
    -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    0 3px 0 rgba(0,0,0,0.2);
  margin-top: 6px;
  letter-spacing: 1px;
}
.subtitle {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  /* Used on both the green loading screen and the cream menu-card — dark
     ink reads clearly against both, unlike the earlier cream-on-cream
     mismatch the title had (see .game-title comment). */
  color: var(--ink);
  opacity: 0.72;
  letter-spacing: 3px;
  margin-top: 4px;
  font-size: clamp(13px, 3vw, 16px);
}

.best-score-line {
  margin-top: 14px;
  color: var(--ink);
  font-weight: 800;
  background: var(--yellow);
  border: 2px solid var(--ink);
  padding: 6px 18px;
  border-radius: 999px;
  font-size: 14px;
}

.loading-bar {
  width: 220px; height: 14px;
  background: rgba(0,0,0,0.2);
  border-radius: 999px;
  margin-top: 26px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.5);
}
.loading-bar-fill {
  height: 100%; width: 0%;
  background: var(--yellow);
  border-radius: 999px;
  transition: width 0.2s ease;
}
.loading-text { margin-top: 10px; color: var(--cream); font-weight: 700; font-size: 13px; opacity: 0.9; }

.menu-card {
  background: var(--cream);
  border-radius: 28px;
  border: 5px solid var(--ink);
  box-shadow: 0 10px 0 rgba(0,0,0,0.18);
  padding: 28px 26px 22px;
  width: min(92vw, 380px);
  max-height: 88vh;
  overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

.section-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 24px; font-weight: 800;
  color: var(--ink);
  margin-bottom: 6px;
}

.btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 16px;
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  box-shadow: 0 5px 0 rgba(0,0,0,0.25);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  color: var(--ink);
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.btn-primary { background: var(--yellow); }
.btn-secondary { background: #fff; }
.btn-lg { font-size: 19px; padding: 16px 18px; }

.menu-footer {
  margin-top: 8px;
  display: flex; align-items: center; gap: 10px;
  color: #8a7a68; font-size: 12px; font-weight: 700;
}
.brand { opacity: 0.75; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  border: 3px solid var(--ink);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

.howto-list { text-align: left; width: 100%; display: flex; flex-direction: column; gap: 10px; margin: 6px 0 16px; }
.howto-list li { font-size: 14.5px; color: var(--ink); line-height: 1.4; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 30; pointer-events: none; }
.hud-top {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 16px 0;
  pointer-events: none;
}
.hud-pill {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  background: rgba(255,255,255,0.92);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 18px;
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}
.hud-level { background: var(--yellow); }
.hud-pause {
  position: absolute; right: 14px; top: 14px;
  pointer-events: auto;
}
.hud-fullscreen {
  position: absolute; right: 60px; top: 14px;
  pointer-events: auto;
  font-size: 15px;
}

.growth-bar-wrap { padding: 8px 20px 0; max-width: 420px; margin: 0 auto; }
.growth-bar {
  height: 12px;
  background: rgba(0,0,0,0.25);
  border: 2px solid rgba(255,255,255,0.6);
  border-radius: 999px;
  overflow: hidden;
}
.growth-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #ffd23f, #ff8a3d);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.combo-badge {
  position: absolute; top: 78px; left: 50%; transform: translateX(-50%);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  background: var(--pink);
  color: #fff;
  padding: 6px 16px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  font-size: 15px;
  animation: comboPop 0.25s ease;
}
@keyframes comboPop { from { transform: translateX(-50%) scale(0.6); } to { transform: translateX(-50%) scale(1); } }

/* ---------------- Game Over ---------------- */
.gameover-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 32px; font-weight: 800;
  color: var(--danger);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
}
.new-best-badge {
  font-weight: 800; color: #b8860b; background: #fff4c2;
  border: 2px solid #e0b400; border-radius: 999px;
  padding: 6px 14px; font-size: 13px;
}
.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  width: 100%; margin: 6px 0;
}
.stat-box {
  background: #fdf3e1; border: 2px solid #e7d3ae;
  border-radius: 12px; padding: 8px 10px;
  display: flex; flex-direction: column; align-items: center;
}
.stat-label { font-size: 10.5px; font-weight: 800; color: #a0876a; letter-spacing: 0.5px; }
.stat-value { font-family: 'Baloo 2', sans-serif; font-size: 19px; font-weight: 800; color: var(--ink); }

.rank-teaser { font-size: 13px; color: #6b5638; font-weight: 700; }

.nickname-form { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.nickname-input {
  width: 100%; padding: 12px 14px;
  border-radius: 12px; border: 3px solid var(--ink);
  font-size: 15px; font-weight: 700; text-align: center;
  color: var(--ink);
}
.nickname-error { color: var(--danger); font-size: 12px; font-weight: 700; }
.score-saved-msg { font-size: 13px; font-weight: 800; color: #2f8f4f; }

/* ---------------- Leaderboard ---------------- */
.lb-header, .lb-row {
  display: grid; grid-template-columns: 0.6fr 1.6fr 1fr 0.6fr;
  font-size: 12px; padding: 6px 4px;
}
.lb-header { font-weight: 800; color: #a0876a; border-bottom: 2px solid #eadfc7; }
.lb-list { width: 100%; max-height: 40vh; overflow-y: auto; margin-bottom: 10px; }
.lb-row { border-bottom: 1px solid #f1e8d4; font-weight: 700; color: var(--ink); align-items: center; }
.lb-row.me { background: #fff4c2; border-radius: 8px; }
.lb-rank { font-weight: 800; }
.lb-loading { padding: 20px; color: #a0876a; font-weight: 700; font-size: 13px; }

@media (max-width: 380px) {
  .menu-card { padding: 22px 16px 18px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
