/* 3D Pacman Game Styles */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
  overflow: hidden;
  /* Stop iOS rubber-band overscroll and Android pull-to-refresh from
     fighting with in-canvas drag controls in Birds-Eye Follow mode. */
  overscroll-behavior: none;
}

html {
  overscroll-behavior: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  /* Defence in depth — JS also sets touchAction on the canvas, but this
     ensures even an early touch (before the canvas exists) doesn't pan
     the page on mobile. */
  touch-action: none;
}

#game-container canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* HUD Styles */
#hud {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

#hud > div:first-child {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid rgba(251, 191, 36, 0.3);
}

/* Strong text shadow for yellow score text */
#score,
#high-score {
  text-shadow: 
    2px 2px 0 #000,
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000,
    0 0 10px #000,
    0 0 20px rgba(251, 191, 36, 0.5);
}

/* Improve readability of camera mode text */
#camera-mode {
  text-shadow: 
    1px 1px 0 #000,
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    0 0 8px #000;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 8px;
  border-radius: 6px;
}

/* Retro glow effect for text */
.glow-text {
  text-shadow: 0 0 5px currentColor, 0 0 10px currentColor, 0 0 20px currentColor;
}

/* Overlay animations */
#start-screen h1 {
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%,
  100% {
    text-shadow: 0 0 10px #fbbf24, 0 0 20px #fbbf24, 0 0 30px #fbbf24;
  }
  50% {
    text-shadow: 0 0 20px #fbbf24, 0 0 40px #fbbf24, 0 0 60px #fbbf24;
  }
}

/* Button styles */
button {
  cursor: pointer;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 4px 15px rgba(251, 191, 36, 0.4);
}

button:hover {
  box-shadow: 0 6px 25px rgba(251, 191, 36, 0.6);
}

/*
 * Start menu — primary vs secondary action.
 * Primary = the "obvious" thing to do (NEW GAME when fresh, big yellow).
 * Secondary = the de-emphasised alternative (NEW GAME when CONTINUE is
 * showing — slimmer, outlined, low-contrast so it doesn't compete with
 * CONTINUE for the player's attention).
 */
.btn-primary {
  background-color: #eab308;
  color: #000;
}
.btn-primary:hover {
  background-color: #facc15;
}
.btn-secondary {
  background-color: transparent;
  color: #9ca3af;
  font-size: 0.95rem;
  padding: 0.5rem 1.25rem;
  border: 1px solid #4b5563;
  box-shadow: none;
}
.btn-secondary:hover {
  background-color: rgba(75, 85, 99, 0.3);
  color: #d1d5db;
  box-shadow: none;
}

/*
 * DASH HUD readout (Tier 5). The text inside #dash-status flips
 * between READY / DASH! / "1.4s" depending on phase; tier classes on
 * #dash-status drive the colour + pulse:
 *   • default (no class)   → cyan "READY"
 *   • .dash-active         → bright white "DASH!" with fast scale pulse
 *   • .dash-cooldown       → dim grey "Ns" countdown, no pulse
 * The pulse is on the inline span (not the line) so the "Dash:" label
 * doesn't bounce around with it.
 */
#dash-status {
  display: inline-block;
  transition: color 120ms ease-out;
  transform-origin: 50% 50%;
}
#dash-status.dash-active {
  color: #ffffff;
  text-shadow: 0 0 6px #22d3ee, 0 0 12px #06b6d4;
  animation: dash-active-pulse 0.3s ease-in-out infinite;
}
#dash-status.dash-cooldown {
  color: #6b7280;
}
@keyframes dash-active-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.75;
  }
}

/*
 * DASH charge bar. Lives inline after the status text so the entire
 * dash readout fits on a single HUD row alongside Far/Mult/Streak.
 * The container is a fixed-width track; the inner #dash-bar element
 * scales horizontally via `transform: scaleX(var(--dash-frac))` so
 * the GPU compositor handles the per-frame width change without a
 * relayout.
 *
 * Tier classes on the *bar* (not the status text) drive the colour:
 *   • default (.dash-charge)  → cyan "ready" tint
 *   • .dash-active            → hot white burst with cyan glow
 *   • .dash-cooldown          → dim cyan refill
 * scaleX(0) leaves an empty track; scaleX(1) fills it. Transform
 * origin is the left edge so the bar drains/refills from the left.
 */
.dash-line {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dash-bar-container {
  flex: 0 0 auto;
  width: 56px;
  height: 6px;
  background: rgba(75, 85, 99, 0.45);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.dash-bar {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #22d3ee, #67e8f9);
  border-radius: 3px;
  transform-origin: 0% 50%;
  transform: scaleX(var(--dash-frac, 1));
  transition: background-color 120ms ease-out;
  will-change: transform;
}
.dash-bar.dash-active {
  background: linear-gradient(90deg, #ffffff, #67e8f9);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.85);
}
.dash-bar.dash-cooldown {
  background: linear-gradient(90deg, #155e75, #22d3ee);
  opacity: 0.7;
}

/*
 * Power-mode HUD bar (Phase 3).
 * The fill colour transitions from pink → yellow → red as the timer
 * runs down. JS sets `--power-frac` on #power-timer-bar each frame; the
 * background colour is interpolated via CSS for free.
 */
#power-timer-bar {
  background: linear-gradient(
    90deg,
    #ff80ff 0%,
    #ffaa00 60%,
    #ff3030 100%
  );
}

/* Final-frame "about to expire" pulse on the power bar. */
@keyframes power-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
#power-timer.expiring #power-timer-bar {
  animation: power-pulse 0.3s ease-in-out infinite;
}

/*
 * Hunger meter (Minecraft-style food bar).
 * Default is a green→yellow gradient that becomes more red as the bar
 * shrinks (the gradient is on the bar's full width, but as `width`
 * decreases the visible portion is from the lush-green left). When
 * food drops below FOOD_LOW_THRESHOLD the JS toggles `.low` on the
 * meter and the bar pulses red as a "you are starving" warning.
 */
#food-bar {
  background: linear-gradient(
    90deg,
    #ff5050 0%,
    #ffaa00 30%,
    #82e000 70%,
    #50ff50 100%
  );
}
@keyframes food-low-pulse {
  0%, 100% { background: #ff3030; box-shadow: 0 0 6px #ff3030; }
  50% { background: #ff7070; box-shadow: 0 0 10px #ff5050; }
}
#food-meter.low #food-bar {
  animation: food-low-pulse 0.6s ease-in-out infinite;
}

/*
 * Difficulty pills on the start menu.
 * The .difficulty-active class is toggled via JS — it bumps the pill's
 * background to a saturated tint so it reads as "selected" at a glance.
 * Each colour stays scoped to the pill's family (cyan/yellow/red) so we
 * keep the easy/normal/hard semantics colour-coded.
 */
.difficulty-btn.difficulty-active {
  font-weight: 700;
  transform: scale(1.05);
  box-shadow: 0 0 0 2px currentColor inset;
}
.difficulty-btn[data-difficulty='easy'].difficulty-active {
  background: rgba(34, 211, 238, 0.25);
}
.difficulty-btn[data-difficulty='normal'].difficulty-active {
  background: rgba(250, 204, 21, 0.25);
}
.difficulty-btn[data-difficulty='hard'].difficulty-active {
  background: rgba(248, 113, 113, 0.25);
}

/*
 * Ghost-flee glow — a pulsing blue ring that JS toggles by adding the
 * `.ghost-flee-glow` class to the renderer's parent during power mode.
 * Cheap visual feedback that doesn't depend on per-ghost shader work.
 */
.ghost-flee-glow {
  box-shadow: inset 0 0 60px rgba(48, 96, 255, 0.35);
}

/*
 * On-screen ghost proximity markers. One element per nearby threat,
 * pooled in #ghost-indicators (full-viewport overlay). Each marker is
 * an arrow glyph rotated to point AT the ghost; positioning is via a
 * single transform string (`translate(x,y) rotate(deg)`) per frame so
 * the GPU can hand off the layout cheaply.
 *
 * Three tiers based on per-ghost world-tile distance to Pacman:
 *   • warn-watch    —  8–12 tiles: yellow, no pulse
 *   • warn-danger   —   5–8 tiles: orange, slow pulse
 *   • warn-imminent —  ≤5 tiles (DANGER_WARNING_RADIUS): red, fast pulse
 *
 * Note: the pulse animates `scale` on the marker. The rotation that
 * points at the ghost is set on the marker's own transform string and
 * gets overwritten each frame, so we use a CSS variable + composite
 * transform — `--marker-rot` carries the pointing angle, and the
 * keyframe layers `scale()` on top of it via `transform`.
 */
.ghost-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  user-select: none;
  /* `--marker-x/y` are pixel positions of the indicator's centre;
     `--marker-rot` is the rotation that aims the arrow at the ghost.
     Centre the box on the anchor point with the -50% offset. JS only
     touches the variables, never `transform` directly, so the keyframe
     animation can compose its scale on top.

     A 4-corner black text-shadow wraps the glyph in a hard outline so
     it stays legible against bright sky, dark walls, and dot fields
     alike. The two larger glow shadows underneath that paint the
     coloured halo for the tier. */
  transform: translate(calc(var(--marker-x, 0px) - 50%), calc(var(--marker-y, 0px) - 50%))
    rotate(var(--marker-rot, 0deg));
  transform-origin: 50% 50%;
  text-shadow:
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000,
    2px 2px 0 #000,
    0 0 10px currentColor,
    0 0 18px currentColor;
}
.ghost-marker.warn-watch {
  color: #fde047; /* yellow-300 */
}
.ghost-marker.warn-danger {
  color: #fb923c; /* orange-400 */
  animation: ghost-marker-pulse 0.8s ease-in-out infinite;
}
.ghost-marker.warn-imminent {
  color: #f87171; /* red-400 */
  font-size: 40px;
  animation: ghost-marker-pulse 0.35s ease-in-out infinite;
}
/* Pulse keeps a high min-opacity (0.78) so the arrow is always
   readable; the pulse is meant to draw the eye, not to flash on/off.
   Each keyframe re-emits the full transform string because `transform`
   is a single property — JS sets x/y/rot via custom properties and the
   keyframe layers a `scale()` on top. */
@keyframes ghost-marker-pulse {
  0%,
  100% {
    transform: translate(calc(var(--marker-x, 0px) - 50%), calc(var(--marker-y, 0px) - 50%))
      rotate(var(--marker-rot, 0deg)) scale(1);
    opacity: 1;
  }
  50% {
    transform: translate(calc(var(--marker-x, 0px) - 50%), calc(var(--marker-y, 0px) - 50%))
      rotate(var(--marker-rot, 0deg)) scale(1.22);
    opacity: 0.78;
  }
}

/*
 * GAME OVER screen (Phase 3) — same look-and-feel as the start screen
 * (matching #pulse-glow + glow text), recoloured red so it reads as a
 * fail-state rather than a menu.
 */
#game-over-screen h2 {
  animation: pulse-glow-red 1.5s ease-in-out infinite;
}
@keyframes pulse-glow-red {
  0%, 100% { text-shadow: 0 0 10px #ef4444, 0 0 20px #ef4444, 0 0 30px #ef4444; }
  50%      { text-shadow: 0 0 20px #ef4444, 0 0 40px #ef4444, 0 0 60px #ef4444; }
}

/* Lives display */
#lives span {
  filter: drop-shadow(0 0 5px #fbbf24);
}

/* Control hints */
#controls-help {
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 12px;
  border-radius: 8px;
}

/* Screen transitions */
.screen-overlay {
  transition: opacity 0.3s ease-in-out;
}

.screen-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Mobile responsive */
@media (max-width: 768px) {
  #hud {
    padding: 8px;
    /* Leave room for the global Back button (left: 8-12px in compact
       mode, ~90px wide once the "← Back" text is rendered). Without
       this clearance the HUD's score box slides under the Back pill
       on phones. */
    padding-left: 108px;
    flex-direction: column;
    gap: 8px;
  }

  #hud .text-2xl {
    font-size: 1rem;
  }

  #hud .text-sm {
    font-size: 0.7rem;
  }

  #hud .text-xs {
    font-size: 0.6rem;
  }

  #controls-help {
    display: none;
  }

  #start-screen h1 {
    font-size: 1.5rem;
    padding: 0 16px;
    text-align: center;
  }

  #start-screen button {
    padding: 12px 24px;
    font-size: 1rem;
  }

  /* Smaller lives icons on mobile */
  #lives span {
    font-size: 1.2rem !important;
  }

  /* Make camera mode display more compact */
  #camera-mode {
    display: block;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Adjust minimap size for mobile */
  #minimap {
    width: 100px !important;
    height: 100px !important;
  }

  /* Game over/win screens */
  #game-over-screen h2,
  #win-screen h2 {
    font-size: 2rem;
  }

  #game-over-screen p,
  #win-screen p {
    font-size: 1.2rem;
  }
}

/* Very small screens (iPhone SE, etc) */
@media (max-width: 375px) {
  #hud .text-2xl {
    font-size: 0.875rem;
  }

  #start-screen h1 {
    font-size: 1.25rem;
  }

  .touch-dpad {
    grid-template-columns: 50px 50px 50px !important;
    grid-template-rows: 50px 50px 50px !important;
  }

  .touch-btn,
  .touch-action-btn {
    width: 50px !important;
    height: 50px !important;
    font-size: 20px !important;
  }
}

/* Loading indicator */
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 1.5rem;
}

.loading::after {
  content: '';
  animation: loading-dots 1.5s infinite;
}

@keyframes loading-dots {
  0% {
    content: '.';
  }
  33% {
    content: '..';
  }
  66% {
    content: '...';
  }
}

/* Ghost scared animation */
@keyframes ghost-scared {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.ghost-scared {
  animation: ghost-scared 0.3s ease-in-out infinite;
}

/* Dot collection effect */
@keyframes dot-collect {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}

/* Power pill pulsing */
@keyframes power-pill-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
}
