/* styles/main.css */

/* Page backdrop so the gutters are not white */
html,
body {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  height: 100%;
  margin: 0;
  background-color: var(--bg-core, #030302);
  background-image: radial-gradient(circle at 15% 20%, rgba(255, 217, 122, 0.22), transparent 45%),
    radial-gradient(circle at 85% 5%, rgba(255, 255, 255, 0.12), transparent 60%),
    linear-gradient(180deg, #050505 0%, #0b0603 55%, #020202 100%),
    url('../assets/img/IntroOne.webp');
  background-size: auto, auto, auto, cover;
  background-position: center, center, center, center;
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
  color: #f8f5ec;
  overflow-x: hidden;
  font-family: 'Press Start 2P', system-ui, sans-serif;
}

/* mild vignette around the gameplay canvas */
#game {
  position: fixed;
  z-index: 1;
  display: block;
}
#vignetteOverlay {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 50%;
  transform: translateX(-50%);
  width: var(--gameWpx, 900px);
  height: var(--gameHpx, 1200px);
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(
    ellipse at 50% 80%,
    rgba(0, 0, 0, 0) 48%,
    rgba(0, 0, 0, 0.24) 70%,
    rgba(0, 0, 0, 0.48) 100%
  );
  box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.45), inset 0 0 220px rgba(0, 0, 0, 0.3);
}
/* Remove vignette during intro to avoid darkening the tutorial art */
body[data-game-state='intro'] #vignetteOverlay {
  display: none;
}
/* Hide the game canvas during intro to avoid its black backdrop showing through */
body[data-game-state='intro'] #game {
  display: none;
}
/* Fallback: paint the tutorial art on the body during intro in case overlay sizing misses */
body[data-game-state='intro'] {
  background-image: none;
}

/* Two background images: left = silver-haired, right = hoary */
:root {
  --gameWpx: 1000px; /* fallback before JS runs */
  --title-gap: clamp(0px, 0.18vw, 6px);
  --title-offset: clamp(10px, 5vh, 90px);
  --title-logo-max: calc(70vh - 140px);
  --title-tag-max: 110px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --gutterFocusPad: 0px; /* how far from the inner edge to center the crop */
  --bg-core: #030302;
  --bg-deep: #060503;
  --surface-border: rgba(255, 255, 255, 0.12);
  --surface-highlight: rgba(255, 255, 255, 0.35);
  --canvas-shadow: 0 40px 90px rgba(0, 0, 0, 0.85);
  --accent-gold: #ffd86c;
}

/* Left and right “gutters” that fill & crop like cover */
body::before,
body::after {
  content: '';
  position: fixed;
  top: 0;
  bottom: 0;
  width: max(0px, calc((100vw - var(--gameWpx)) / 2));
  background-size: cover; /* fill each gutter */
  background-repeat: no-repeat;
  pointer-events: none; /* never block clicks */
  z-index: 0; /* behind the game */
  filter: brightness(0.92) contrast(1.05);
}

/* LEFT image (silver-haired) — bias toward the canvas edge */
body::before {
  left: 0;
  background-image: url('../assets/img/Silver1.webp');
  background-position: calc(100% - var(--gutterFocusPad)) center;
}

/* RIGHT image (hoary) — bias toward the canvas edge */
body::after {
  right: 0;
  background-image: url('../assets/img/Hoary1.webp');
  background-position: calc(0% + var(--gutterFocusPad)) center;
}

/* Hide gutters on narrow screens */
@media (max-width: 1100px) {
  body::before,
  body::after {
    display: none;
  }
}

/* Keep the canvas crisp and capped, as you have */
canvas {
  position: fixed;
  max-width: 1200px;
  max-height: 100vh;
  max-height: 100svh;
  max-height: 100dvh;
  border-radius: 0px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background-color: #020202;
  box-shadow: var(--canvas-shadow);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto;
  touch-action: none;
}
canvas:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 6px;
}
canvas:hover {
  box-shadow: 0 48px 120px rgba(0, 0, 0, 0.95);
}
/* Ensure title overlay clicks aren't intercepted by the canvas */
body[data-game-state='menu'] #game {
  pointer-events: none;
}

@supports (image-rendering: crisp-edges) {
  canvas {
    image-rendering: crisp-edges;
  }
}

.mobile {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 12px);
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 18px 12px;
  pointer-events: none;
  z-index: 24;
  gap: 12px;
}
.joystick {
  width: 150px;
  height: 150px;
  position: relative;
  opacity: 0.98;
  pointer-events: auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.08), rgba(18, 11, 8, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.75), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  touch-action: none;
}
.joystick-ring {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ffd86c, #c98f2f 65%, #7a5520);
  border: 2px solid rgba(255, 255, 255, 0.45);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 18px 38px rgba(0, 0, 0, 0.55);
  transform: translate(-50%, -50%);
  transition: transform 80ms ease-out;
}
.joystick.active .joystick-thumb {
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.32), 0 10px 26px rgba(0, 0, 0, 0.6);
}

.fire {
  pointer-events: auto;
  min-width: 108px;
  height: 108px;
  padding: 0 12px;
  border-radius: 50%;
  background: radial-gradient(
      circle at 30% 32%,
      rgba(255, 240, 200, 0.75),
      rgba(255, 196, 104, 0.9) 36%,
      rgba(160, 96, 28, 0.92) 70%,
      rgba(48, 24, 8, 0.95)
    ),
    linear-gradient(145deg, rgba(255, 210, 128, 0.25), transparent 55%);
  color: #1a0f08;
  border: 2px solid rgba(255, 223, 160, 0.7);
  font-weight: bold;
  letter-spacing: 1px;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  text-transform: uppercase;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -4px 0 rgba(56, 32, 12, 0.6),
    0 18px 38px rgba(0, 0, 0, 0.55), 0 0 12px rgba(255, 180, 90, 0.45);
  transition: transform 0.1s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.fire:active {
  transform: scale(0.95);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.24), inset 0 -3px 0 rgba(56, 32, 12, 0.7),
    0 12px 26px rgba(0, 0, 0, 0.55), 0 0 10px rgba(255, 170, 70, 0.36);
  filter: brightness(0.96);
}

/* Title art stack (allows the logo + tagline to fill vertical space) */
.title-art {
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  image-rendering: auto;
}
.title-art-stack {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--title-gap);
  padding: 0;
  margin-top: clamp(8px, 3vh, 32px);
  margin-bottom: clamp(6px, 1vh, 14px); /* small breathing room to buttons */
}
.title-logo {
  width: min(640px, 92vw);
  height: auto;
  max-height: var(--title-logo-max);
  object-fit: contain;
  margin-bottom: clamp(-10px, -1.2vw, -4px); /* slight tuck */
  position: relative;
}
.title-tag {
  width: min(420px, 86vw);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  max-height: var(--title-tag-max); /* reduce if tag still feels oversized */
  object-fit: contain;
  margin-top: clamp(-12px, -1.4vw, -4px); /* bring close without overlap */
  margin-bottom: clamp(8px, 1.2vh, 14px);
}

.title-art-stack::after {
  content: '';
  position: absolute;
  left: -8%;
  right: -8%;
  bottom: -6%;
  top: auto;
  height: 32%;
  background: linear-gradient(
    90deg,
    transparent 30%,
    rgba(255, 236, 180, 0.85) 46%,
    rgba(255, 255, 255, 0.9) 50%,
    rgba(255, 236, 180, 0.85) 54%,
    transparent 70%
  );
  background-size: 260% 100%;
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
  animation: logoShimmer 16s ease-in-out infinite;
}

@media (max-width: 480px) {
  .title-logo {
    width: clamp(240px, 62vw, 440px);
  }
  .title-tag {
    width: clamp(260px, 88vw, 560px);
  }
}

@keyframes logoShimmer {
  0%,
  82% {
    opacity: 0;
    background-position: -120% 0;
  }
  86% {
    opacity: 0.9;
    background-position: 0% 0;
  }
  92% {
    opacity: 0.75;
    background-position: 120% 0;
  }
  100% {
    opacity: 0;
    background-position: 120% 0;
  }
}

/* === Hud (indie panels) === */
.hud {
  position: fixed;
  color: #fdf9e7;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
body[data-game-state='play'] .hud {
  opacity: 1;
  transform: translateY(0);
}
.hud-scoreboard {
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: calc(50% - (var(--gameWpx) / 2) + 16px);
  display: flex;
  align-items: center;
  gap: 8px;
}
.hud-score {
  font-size: 0.75rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
}
.hud-score span {
  color: #ffe7a5;
  font-family: 'Press Start 2P', sans-serif;
  letter-spacing: 0.35em;
}
#uiScore {
  font-family: 'Press Start 2P', sans-serif;
}
.hud-bars-panel {
  top: calc(env(safe-area-inset-top, 0px) + var(--gameHpx, 1200px) - 36px);
  left: calc(50% - (var(--gameWpx) / 2) + 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hud-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hud-bar-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hud-label {
  font-size: 0.55rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
}
.hud-bar {
  width: clamp(140px, 18vw, 220px);
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
  position: relative;
}
.hud-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(255, 108, 108, 0.95), rgba(220, 32, 32, 0.9));
  box-shadow: 0 0 12px rgba(255, 64, 64, 0.6);
}
.hud-bar span.flash-white {
  animation: hudHealthFlashWhite 0.45s ease;
}
.hud-bar--energy span {
  background: linear-gradient(90deg, rgba(255, 178, 112, 0.95), rgba(255, 111, 170, 0.9));
  box-shadow: 0 0 12px rgba(255, 127, 167, 0.65);
}
.hud-distance {
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: calc(50% - (var(--gameWpx) / 2) + 16px);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.65rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
}
.hud-distance span {
  color: #fff;
  font-family: 'Press Start 2P', sans-serif;
  font-size: 0.65rem;
}
.hud.paused .hud-bar span {
  filter: saturate(0.5) brightness(0.85);
}
.hud-score #uiScore {
  display: inline-block;
}
.hud-score #uiScore.pulse {
  animation: hudScorePulse 0.35s ease;
}
.hud-bar #uiHealth.flash-white {
  animation: hudHealthFlashWhite 0.45s ease;
}
@keyframes hudHealthFlashWhite {
  0% {
    background: linear-gradient(90deg, rgba(255, 108, 108, 0.95), rgba(220, 32, 32, 0.9));
    box-shadow: 0 0 12px rgba(255, 64, 64, 0.6);
  }
  18% {
    background: #fff;
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.92);
  }
  60% {
    background: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
  }
  100% {
    background: linear-gradient(90deg, rgba(255, 108, 108, 0.95), rgba(220, 32, 32, 0.9));
    box-shadow: 0 0 12px rgba(255, 64, 64, 0.6);
  }
}
@keyframes hudScorePulse {
  0% {
    transform: scale(1);
    text-shadow: none;
  }
  25% {
    transform: scale(1.12);
    text-shadow: 0 0 10px rgba(255, 232, 170, 0.85);
  }
  60% {
    transform: scale(1.05);
    text-shadow: 0 0 6px rgba(255, 232, 170, 0.55);
  }
  100% {
    transform: scale(1);
    text-shadow: none;
  }
}
@media (max-width: 768px) {
  .hud-scoreboard,
  .hud-bars-panel {
    left: 16px;
  }
  .hud-distance {
    right: 16px;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }
  .hud-scoreboard {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .hud-score {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  #uiScore {
    display: block;
    min-width: 0;
    padding: 2px 0;
  }
  .hud-bar {
    height: 5px;
  }
}

@media (max-width: 768px) {
  .hud {
    height: 52px;
    padding: 0 12px;
    font-size: 14px;
  }
  .hud .bar {
    width: 180px;
    height: 14px;
  }
  #uiScore {
    min-width: 0;
    padding: 2px 0;
  }
  
  /* Expand canvas to fill horizontal space on mobile */
  canvas {
    max-width: 100vw;
    width: 100%;
    max-height: calc(100vh - env(safe-area-inset-bottom, 0px) - 180px);
    max-height: calc(100svh - env(safe-area-inset-bottom, 0px) - 180px);
    max-height: calc(100dvh - env(safe-area-inset-bottom, 0px) - 180px);
    aspect-ratio: 900 / 1200;
  }
}

.overlay {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(var(--gameWpx), 100vw);
  max-width: var(--gameWpx);
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 18px) env(safe-area-inset-right, 16px)
    env(safe-area-inset-bottom, 18px) env(safe-area-inset-left, 16px);
  background-color: transparent;
  color: #ffd36a;
  font-family: 'Press Start 2P', sans-serif;
  z-index: 8;
  overflow-x: hidden;
  overflow-y: auto;
  isolation: isolate;
  box-sizing: border-box;
}
.overlay#titleOverlay {
  align-items: center; /* center title content vertically */
  z-index: 12;
  pointer-events: auto;
  overflow: visible;
  position: relative;
}
.hidden {
  display: none !important;
} /* global helper */
.overlay.hidden {
  display: none;
} /* also fine */
.overlay#overOverlay.win {
  background-image: url('../assets/img/IntroOne.webp');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent;
  box-shadow: inset 0 0 0 2000px rgba(0, 0, 0, 0.2);
  width: 100vw;
  left: 50%;
  transform: translateX(-50%);
}
.overlay#overOverlay.win .start-card {
  background: rgba(0, 0, 0, 0.65);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.4);
}
#overOverlay {
  background-image: url('../assets/img/BatDeathEnding.webp');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent;
  box-shadow: inset 0 0 0 2000px rgba(0, 0, 0, 0.35);
  width: 100vw;
  left: 50%;
  transform: translateX(-50%);
}
#introOverlay {
  background-color: transparent;
  pointer-events: auto;
  isolation: isolate;
  z-index: 9;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(var(--gameWpx), 100vw);
  max-width: var(--gameWpx);
  padding: 0;
  align-items: stretch;
}
#introOverlay::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(var(--gameWpx), 100vw);
  height: min(var(--gameHpx, 1200px), 100vh);
  background: url('../assets/img/TutorialBg.webp') center/cover no-repeat;
  opacity: var(--intro-bg-opacity, 1);
  transition: opacity 0.8s ease;
  z-index: -2;
  pointer-events: none;
}
#introOverlay::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(var(--gameWpx), 100vw);
  height: min(var(--gameHpx, 1200px), 100vh);
  background: url('../assets/img/HoaryBatIntro.webp') center/cover no-repeat; /* image fallback */
  opacity: var(--intro-hero-opacity, 0);
  transition: opacity 0.9s ease;
  z-index: -1;
  pointer-events: none;
}

/* Video used as intro hero background (autoplay muted). Controlled via --intro-hero-opacity */
.intro-video {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(var(--gameWpx), 100vw);
  height: min(var(--gameHpx, 1200px), 100vh);
  object-fit: cover;
  opacity: var(--intro-hero-opacity, 0);
  transition: opacity 0.9s ease;
  z-index: 1;
  pointer-events: none;
  background: transparent;
}
#introOverlay.intro-tutorial-mode {
  width: min(var(--gameWpx), 100vw);
  max-width: var(--gameWpx);
  left: 50%;
  transform: translateX(-50%);
  overflow: visible;
}
#introOverlay.intro-tutorial-mode .intro-panel {
  width: 100%;
  max-width: 100%;
}
#introOverlay .intro-panel {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-align: center;
}

/* # intro overlay text */
#introOverlay .intro-text {
  letter-spacing: 0.45em;
  text-transform: uppercase;
  font-size: clamp(18px, 2.6vw, 32px);
  color: #ffcc33;
  max-width: min(720px, 90vw);
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1vw, 12px);
}

/* Tutorial text (dynamically created during tutorial) */
.intro-tutorial__text {
  letter-spacing: 0.45em;
  text-transform: uppercase;
  font-size: clamp(18px, 2.6vw, 32px);
  color: #ffcc33;
  max-width: min(480px, 70vw);
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1vw, 12px);
  text-align: center;
}

.intro-line {
  display: block;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.intro-line.visible {
  opacity: 1;
  transform: translateY(0);
}
.intro-line.intro-line--delay.visible {
  transition-delay: 0.25s;
}

.over-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

.fact-line {
  color: #ffd987;
  font-family: 'Press Start 2P', system-ui, sans-serif;
  font-size: clamp(13px, 2.6vw, 20px);
  letter-spacing: 0.06em;
  line-height: 1.4;
  max-width: min(760px, 88vw);
  margin: 0 auto;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  text-align: center;
}
.fact-line.visible {
  opacity: 1;
  transform: translateY(0);
}
#factOverlay {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  text-align: center;
}
#factOverlay.hidden {
  display: none;
}

/* Level transition overlay */
#levelTransition {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(255, 216, 108, 0.12), transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(115, 170, 255, 0.12), transparent 50%),
    rgba(3, 2, 2, 0.9);
}
#levelTransition.hidden {
  display: none;
}
.level-transition__map {
  position: relative;
  width: min(960px, 92vw);
  height: min(380px, 48vh);
  background: linear-gradient(180deg, rgba(36, 64, 96, 0.3), rgba(10, 16, 24, 0.7)),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.06),
      rgba(255, 255, 255, 0.06) 1px,
      transparent 1px,
      transparent 32px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.05),
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 32px
    ),
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 40%);
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  overflow: hidden;
}
.level-transition__bat {
  position: absolute;
  top: 20%;
  left: 0;
  width: 80px;
  height: 80px;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.45));
  will-change: transform;
}
.level-transition__bat img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#introOverlay .intro-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 1s ease, transform 1s ease;
  z-index: 1;
}
#introOverlay .intro-image.visible {
  opacity: 1;
  transform: scale(1);
}
#introOverlay .intro-bat {
  position: absolute;
  right: max(2vw, 16px);
  bottom: clamp(30px, 8vh, 120px);
  height: clamp(180px, 40vh, 360px);
  width: auto;
  object-fit: contain;
  opacity: 0;
  transform: translateX(140%);
  transition: transform 0.9s ease, opacity 0.9s ease;
  z-index: 3;
  filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.45));
}
#introOverlay .intro-bat.visible {
  opacity: 1;
  transform: translateX(0);
}
#introOverlay .intro-typing {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(80vw, var(--gameWpx, 900px));
  max-width: min(720px, var(--gameWpx, 900px));
  color: #fce9c2;
  font-size: clamp(18px, 3vw, 26px);
  letter-spacing: 0.08em;
  text-align: center;
  text-shadow: 0 0 16px rgba(0, 0, 0, 0.55);
  z-index: 4;
  font-family: 'Press Start 2P', system-ui, sans-serif;
  opacity: 0;
  display: none;
}
#introOverlay.intro-tutorial-mode .intro-panel > *:not(.intro-tutorial) {
  display: none !important;
}
.intro-tutorial {
  position: absolute;
  inset: 0;
  background: none;
  color: #fce9c2;
  font-family: 'Press Start 2P', system-ui, sans-serif;
  text-align: center;
  padding: 0 18px;
  overflow: hidden;
}
.intro-tutorial > :not(.intro-tutorial__canvas) {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
}
.intro-tutorial__text {
  top: 46%;
  white-space: pre-line;
  letter-spacing: 0.06em;
  line-height: 1.4;
  font-size: clamp(12px, 1.8vw, 16px);
  width: min(82vw, var(--gameWpx, 900px));
  padding: 0 18px;
  opacity: 0;
  transition: opacity 0.35s ease;
}
.intro-tutorial__text.show {
  opacity: 1;
}
.intro-tutorial__insects {
  top: 40%;
  width: min(320px, 70vw);
  height: min(240px, 52vh);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  transition: opacity 0.35s ease;
  visibility: hidden; /* canvas handles visuals; this is only used for state */
  transform: translate(-50%, -40%);
}
.intro-tutorial__insects.visible {
  opacity: 1;
}
.intro-tutorial__bug {
  position: relative;
  width: clamp(24px, 8vw, 48px);
  height: clamp(24px, 8vw, 48px);
  animation: bugWiggle var(--wiggle-dur, 1.8s) ease-in-out infinite alternate,
    bugBob var(--bob-dur, 2s) ease-in-out infinite alternate;
}
.intro-tutorial__bug img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
}
.intro-tutorial__bug img.frame2 {
  opacity: 0;
  animation: bugFlap 0.35s steps(1) infinite;
}
@keyframes bugWiggle {
  0% {
    transform: translate(calc(var(--wiggle-amp, 4px) * -1), 0);
  }
  50% {
    transform: translate(0, calc(var(--bob-amp, 3px) * -0.4));
  }
  100% {
    transform: translate(calc(var(--wiggle-amp, 4px)), 0);
  }
}
@keyframes bugBob {
  0% {
    transform: translateY(calc(var(--bob-amp, 3px) * -1));
  }
  100% {
    transform: translateY(calc(var(--bob-amp, 3px)));
  }
}
@keyframes bugFlap {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
.intro-tutorial__prompt {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border: 2px solid rgba(255, 233, 180, 0.75);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  color: #ffe7b0;
  letter-spacing: 0.12em;
  font-size: clamp(10px, 2vw, 12px);
}
.intro-tutorial__prompt.hidden {
  display: none;
}
.intro-tutorial__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  background: transparent; /* don't cover the tutorial art */
  border: none; /* avoid inheriting the game canvas outline */
  box-shadow: none;
}
#introOverlay .intro-typing::after {
  content: '';
  display: inline-block;
  width: 0.6em;
  border-bottom: 2px solid #fce9c2;
  animation: blink 1s steps(1) infinite;
  margin-left: 6px;
  vertical-align: baseline;
}
#introOverlay .intro-typing.visible {
  opacity: 1;
  display: block;
}
#introOverlay .intro-typing.done::after {
  opacity: 0;
  animation: none;
}

@keyframes blink {
  0%,
  50% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}
#titleOverlay::before,
#titleOverlay::after,
#overOverlay::before {
  background: none;
  display: none;
}

.title-stars {
  position: absolute;
  inset: 0;
  height: 52%;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
  background: transparent;
  filter: none;
}
.title-stars::before,
.title-stars::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0) 70%),
    radial-gradient(circle, rgba(255, 233, 180, 0.7) 0%, rgba(255, 233, 180, 0) 70%),
    radial-gradient(circle, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0) 70%),
    radial-gradient(circle, rgba(255, 220, 150, 0.6) 0%, rgba(255, 220, 150, 0) 70%),
    radial-gradient(circle, rgba(255, 255, 255, 0.75) 0%, rgba(255, 255, 255, 0) 70%),
    radial-gradient(circle, rgba(255, 233, 180, 0.6) 0%, rgba(255, 233, 180, 0) 70%),
    radial-gradient(circle, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0) 70%),
    radial-gradient(circle, rgba(255, 220, 150, 0.55) 0%, rgba(255, 220, 150, 0) 70%);
  background-repeat: no-repeat;
  background-size: 3px 3px, 2px 2px, 2px 2px, 3px 3px, 2px 2px, 2px 2px, 3px 3px, 2px 2px;
  background-position: 8% 12%, 18% 6%, 26% 18%, 38% 10%, 52% 16%, 64% 8%, 78% 14%, 90% 6%;
}
.title-stars::after {
  animation: twinkleDrift 7s ease-in-out infinite alternate;
  opacity: 0.75;
}
.title-stars::before {
  animation: twinkleDrift 9s ease-in-out infinite alternate-reverse;
  opacity: 0.55;
}

@keyframes twinkleDrift {
  0% {
    transform: translateY(0px);
    opacity: 0.4;
  }
  50% {
    transform: translateY(1px);
    opacity: 0.85;
  }
  100% {
    transform: translateY(-1px);
    opacity: 0.5;
  }
}

/* Mobile overlay centering fixes */
@media (max-width: 1100px) {
  #titleOverlay,
  #howOverlay {
    width: 100vw;
    max-width: 100vw;
    left: 0;
    transform: none;
  }
}
/* Title overlay panel stacks art/buttons to fill the full height */
/* Title overlay panel stacks art/buttons to fill the full height */
.title-panel {
  width: min(640px, var(--gameWpx));
  max-width: 640px;
  margin: 0 auto;
  height: auto;
  max-height: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, 0.6vw, 10px);
  justify-content: center;
  overflow: hidden;
  padding: 0;
  position: relative;
  z-index: 1;
}

/* Button row constrained so controls stay readable near bottom */
.title-buttons {
  width: min(420px, 92%);
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: clamp(0px, 0.6vh, 8px) auto clamp(6px, 1vh, 12px);
}
.title-buttons .btn {
  flex: 1 1 140px;
  min-width: 120px;
  max-width: 180px;
  padding: 0.55rem 1rem;
}
#titleOverlay .title-panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0; /* vertical position handled by title stack offset */
  justify-content: center;
  pointer-events: auto;
}
.start-card--wide {
  max-width: 700px;
}
.start-card--guide {
  max-width: 720px;
  position: relative;
}
.overlay-footer {
  margin-top: 12px;
}
.overlay-footer--compact {
  margin-top: 10px;
}
.start-card {
  text-align: center;
  padding: clamp(20px, 3vw, 32px);
  background: rgba(6, 6, 6, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.85), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  max-width: min(90vw, 720px);
  width: 100%;
  position: relative;
  z-index: 1;
  margin-left: auto;
  margin-right: auto;
}
.start-card--guide {
  max-width: 620px;
  background: rgba(6, 6, 6, 0.86);
  border-color: rgba(255, 255, 255, 0.14);
}
@media (max-width: 900px) {
  .start-card--guide {
    max-width: min(92vw, 600px);
  }
}

/* Game Over card: transparent background and no border/shadow */
#overOverlay .start-card {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: clamp(18px, 3vw, 26px) clamp(18px, 3vw, 26px) clamp(26px, 3.4vw, 32px);
}
/* Keep breathing room between text and buttons on the win/lose card */
#overOverlay .start-card p {
  margin: 10px 0;
}

/* Title card overrides: strip padding/background so art + tagline/buttons sit tighter */
.start-card.title-panel {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  height: auto;
  max-height: none;
  gap: clamp(4px, 0.6vw, 10px);
}
.how-card {
  background: rgba(10, 10, 12, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.how-lede {
  color: #f7eabf;
  font-size: clamp(14px, 2vw, 18px);
  margin-bottom: clamp(12px, 2vw, 20px);
  line-height: 1.5;
}
.how-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: clamp(12px, 2vh, 24px);
  margin-bottom: clamp(16px, 3vh, 26px);
}
.how-panel {
  background: rgba(18, 18, 18, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: clamp(12px, 2vw, 20px);
  border-radius: 8px;
  text-align: left;
  color: #f1e9cf;
  min-height: 180px;
}
.how-panel h3 {
  margin-top: 0;
  font-size: 1rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #ffd36a;
}
.how-panel ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  line-height: 1.4;
}
.how-panel li + li {
  margin-top: 6px;
}
.how-note {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: clamp(8px, 2vh, 16px);
}
.start-card h1 {
  font-size: clamp(28px, 3vw, 42px);
  margin-bottom: 20px;
  color: #f6d27a;
  text-shadow: 0 2px 0 #2b1d13, 0 0 12px rgba(245, 177, 94, 0.35);
  letter-spacing: 0.05em;
}
.pause-card {
  max-width: 520px;
  padding: clamp(24px, 4vw, 48px);
  gap: 16px;
  text-align: center;
}
.pause-settings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.pause-card .overlay-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
}
.pause-volume {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pause-text,
.pause-help {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #ffe8b0;
  line-height: 1.4;
}
.pause-help {
  margin-bottom: 8px;
}
/* Title background */
#titleOverlay,
#howOverlay,
#fieldOverlay {
  background-color: transparent;
  background-image: url('../assets/img/TitleOpen.webp');
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}
#fieldOverlay {
  /* Lightly dim the field guide backdrop while keeping the art visible */
  background-image: url('../assets/img/TitleOpen.webp');
  background-blend-mode: normal;
  overflow-x: hidden;
  left: 50%;
  transform: translateX(-50%);
}
#fieldOverlay .start-card h1 {
  font-size: clamp(22px, 2.4vw, 28px);
  margin-bottom: 10px;
}

#howOverlay .start-card,
#overOverlay .start-card {
  margin: auto; /* keep how/over cards centered inside their overlays */
}

.coming-card {
  max-width: 540px;
  text-align: center;
}
.coming-lede {
  color: #f6d27a;
  margin: 0 0 12px;
  letter-spacing: 0.04em;
}
.coming-body {
  margin: 0;
  color: rgba(255, 245, 228, 0.86);
  line-height: 1.5;
}

.btn {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(18, 18, 18, 0.9));
  color: #f8f4ec;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.65);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.25), rgba(33, 33, 33, 0.95));
}
.btn:active {
  transform: translateY(0);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}
@media (max-width: 768px) {
  .mobile {
    bottom: calc(var(--safe-bottom) + 14px);
    padding: 0 18px 12px;
    gap: 10px;
  }
  .joystick {
    width: 136px;
    height: 136px;
  }
  .joystick-thumb {
    width: 62px;
    height: 62px;
  }
  .fire {
    min-width: 102px;
    height: 102px;
    font-size: 11px;
  }
}

@media (orientation: portrait) {
  .overlay {
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
  }
  .overlay .start-card {
    margin-top: clamp(16px, 5vh, 60px);
  }
  .mobile {
    gap: 18px;
  }
  .mobile .fire {
    order: -1;
    margin-left: auto;
  }
}

/* Allow overlays to scroll on smaller viewports and keep cards within the screen */
@media (max-width: 900px), (max-height: 780px) {
  .overlay {
    overflow-y: auto;
  }
  .start-card {
    max-height: min(
      calc(100svh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 36px),
      calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 36px)
    );
    overflow-y: auto;
  }
  #fieldOverlay .start-card,
  #howOverlay .start-card {
    max-height: min(
      calc(100svh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 28px),
      calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 28px)
    );
  }
}

/* === Field Guide (shared background, sprite on top) === */
.fg-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 5px;
  row-gap: 5px;
  column-gap: 5px;
  justify-items: center;
  align-items: start;
  margin: 4px auto 0;
  max-width: min(440px, 100%);
  width: 100%;
  justify-content: center;
}

.fg-tile {
  width: 100px;
  height: 100px;
  border-radius: 0px;
  overflow: hidden;
  position: relative;
  background: url('../assets/img/FieldTileBg.webp') center/cover no-repeat;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(246, 210, 122, 0.15);
  cursor: pointer;
  display: block;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.fg-tile:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.fg-tile[data-id='fox'] {
  order: 999; /* push placeholder fox tile to the bottom-right of the grid */
}

/* faint center halo to lift dark sprites */
.fg-tile::before {
  content: '';
  position: absolute;
  inset: 0; /* covers the whole tile */
  display: block;
  background: radial-gradient(
    circle at center,
    rgba(255, 245, 200, 0.35) 0%,
    rgba(255, 245, 200, 0.1) 45%,
    rgba(0, 0, 0, 0) 75%
  );
  pointer-events: none; /* doesn’t block clicks */
  z-index: 0; /* sits under the image */
}

.fg-tile img {
  position: relative;
  z-index: 1;
  width: 80%;
  height: 80%;
  object-fit: contain; /* was cover; contain is better so assets don't crop */
}

/* the species sprite only (no baked background) */
.fg-tile img.fg-sprite {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.25));
}

@supports (image-rendering: crisp-edges) {
  .fg-tile img.fg-sprite {
    image-rendering: crisp-edges;
  }
}

.fg-tile.locked::after {
  content: 'Locked';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  color: #ffd36a;
  font-weight: 700;
  text-shadow: 0 1px 0 #2b1d13;
}

.fg-card .fg-img {
  width: clamp(150px, 34vw, 200px);
  aspect-ratio: 1 / 1;
  margin: 2px auto 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 50%, rgba(255, 245, 200, 0.08), rgba(0, 0, 0, 0) 65%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  overflow: hidden;
}
.fg-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Field Guide detail layout */
.fg-card {
  width: clamp(280px, 58vw, 450px);
  padding: 10px 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  box-shadow: none;
}
.fg-meta {
  width: 100%;
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.fg-meta h3 {
  margin: 0;
  font-size: 13px;
}
.fg-meta p {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
}
.fg-nav {
  width: 100%;
  max-width: 300px;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 6px auto 8px;
}

/* Field Guide attribute list */
.fg-attrs {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.fg-attrs li {
  position: relative;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 10px;
  line-height: 1.3;
  color: #f8f5ec;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.fg-attrs li::after {
  display: none;
  content: '';
}
.fg-attrs .effect-pickup {
  background: rgba(65, 214, 151, 0.14);
  border-color: rgba(104, 255, 193, 0.4);
}
.fg-attrs .effect-poison {
  background: rgba(255, 102, 102, 0.14);
  border-color: rgba(255, 153, 153, 0.4);
}
.fg-attrs .effect-hazard {
  background: rgba(255, 180, 64, 0.14);
  border-color: rgba(255, 206, 140, 0.45);
}
.fg-attrs .effect-player,
.fg-attrs .effect-planned {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
}

@media (max-width: 600px) {
  .fg-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 4px;
    row-gap: 4px;
    column-gap: 4px;
    max-width: min(240px, 100%);
    width: 100%;
    margin: 4px auto 0;
    justify-content: center;
  }
  .fg-tile {
    width: 96px;
    height: 96px;
  }
}

/* Make form controls inherit the parent font */
button,
input,
select,
textarea {
  font: inherit; /* includes family, size, weight, line-height */
}

/* Explicitly set the arcade font on all overlay buttons */
.start-card button,
#titleOverlay .btn,
#fieldOverlay .btn,
#howOverlay .btn {
  font-family: 'Press Start 2P', system-ui, sans-serif;
}

/* iOS/Safari: remove native control styling that can fight fonts */
button {
  -webkit-appearance: none;
  appearance: none;
}

/* Title screen buttons ONLY */
#titleOverlay .title-panel .btn,
#titleOverlay .title-panel button {
  font-family: 'Press Start 2P', system-ui, sans-serif;
  font-size: 14px; /* change this without touching card text */
  color: #fddf56;
  background: #002a25;
  border: 1px solid #1a120c;
}
#titleOverlay .title-panel .btn:hover {
  filter: brightness(0.95);
}

/* Soften title overlay button shadow (mellow bottom edge) */
#titleOverlay .title-panel .btn,
#titleOverlay .title-panel button {
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45), 0 4px 12px rgba(0, 0, 0, 0.25);
  border-radius: 12px;
}
