/* ===========================================================================
   Juno's Park Dash — a little endless-runner game for Paws & Chores Torfaen.
   Self-contained: this file + game.js are the whole feature. It deliberately
   reuses the site's palette (--green / --cream / --coral) so it feels native,
   but defines its own scoped classes so it never collides with styles.css.
   =========================================================================== */

/* ---- Floating "Play Now" button (shown on every page except the game) ---- */
.play-now-fab {
  position: fixed;
  right: clamp(14px, 4vw, 28px);
  bottom: clamp(14px, 4vw, 28px);
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--coral, #d95f70), var(--coral-deep, #c84f61));
  color: #fff7f3;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.95rem, 1.4vw, 1.05rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  box-shadow: 0 14px 30px rgba(200, 79, 97, 0.38), 0 2px 6px rgba(52, 67, 57, 0.18);
  border: 2px solid rgba(255, 247, 243, 0.55);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 220ms ease;
  animation: fab-bob 2.6s ease-in-out infinite;
}

.play-now-fab:hover,
.play-now-fab:focus-visible {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 20px 38px rgba(200, 79, 97, 0.46), 0 3px 8px rgba(52, 67, 57, 0.22);
  outline: none;
}

.play-now-fab:focus-visible {
  outline: 3px solid var(--green, #2f5d42);
  outline-offset: 3px;
}

.play-now-fab.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.9);
}

/* Tucked away while the page is being scrolled (phones only) so it never sits
   over the text being read; slides back when scrolling stops. */
.play-now-fab.is-scroll-tuck {
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px) scale(0.92);
  animation: none;
}

@keyframes fab-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@media (prefers-reduced-motion: reduce) {
  .play-now-fab { animation: none; }
}

/* Compact + tucked into the corner on phones so it doesn't sit over content. */
@media (max-width: 760px) {
  .play-now-fab {
    right: 10px;
    bottom: 10px;
    padding: 8px 15px;
    font-size: 0.86rem;
    box-shadow: 0 10px 22px rgba(200, 79, 97, 0.34), 0 2px 5px rgba(52, 67, 57, 0.16);
  }
}

/* ---- Game page layout ---------------------------------------------------- */
.page.is-current[data-page="game"] {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: calc(100svh - 132px);
  padding: clamp(16px, 3vw, 40px) clamp(12px, 3vw, 28px);
}

.game-shell {
  width: 100%;
  max-width: 1140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 2.2vw, 22px);
}

.game-head {
  text-align: center;
  max-width: 560px;
}

.game-head .game-kicker {
  display: inline-block;
  font-family: "Segoe Script", "Brush Script MT", cursive;
  color: var(--coral-deep, #c84f61);
  font-size: 1.25rem;
  margin-bottom: 2px;
}

.game-head h2 {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--green-deep, #244933);
  font-size: clamp(1.7rem, 4.6vw, 2.5rem);
  margin: 0 0 8px;
  text-shadow: 2px 2px 0 #f2c7cd;
}

.game-head p {
  color: var(--muted, #66746a);
  font-size: clamp(0.95rem, 1.8vw, 1.05rem);
  line-height: 1.5;
  margin: 0;
}

/* ---- The play stage (canvas + overlays) ---------------------------------- */
.runner-stage {
  position: relative;
  width: 100%;
  max-width: 1080px;
  aspect-ratio: 16 / 9;
  max-height: min(76vh, 660px);
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(#eaf5ef 0%, #f6efe2 100%);
  border: 3px solid rgba(47, 93, 66, 0.22);
  box-shadow: var(--shadow, 0 20px 50px rgba(52, 67, 57, 0.12));
  touch-action: manipulation;
  user-select: none;
}

.runner-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* HUD */
.runner-hud {
  position: absolute;
  inset: 12px 14px auto 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  color: var(--green-deep, #244933);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.runner-hud .runner-distance {
  font-size: clamp(1.05rem, 3vw, 1.5rem);
}

.runner-hud .runner-bones {
  font-size: clamp(0.95rem, 2.6vw, 1.25rem);
  background: rgba(255, 250, 243, 0.78);
  border-radius: 999px;
  padding: 2px 12px;
}

.runner-hud .runner-level {
  font-size: clamp(0.9rem, 2.4vw, 1.15rem);
  background: rgba(47, 93, 66, 0.82);
  color: #fff8f0;
  border-radius: 999px;
  padding: 2px 14px;
  text-shadow: none;
}

/* Juno's mood meter — fills as she collects bones without a mishap, and the
   little face cheers up tier by tier. Sits just under the bones counter. */
.runner-hud-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.runner-mood {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 250, 243, 0.78);
  border-radius: 999px;
  padding: 2px 9px 2px 7px;
}

.runner-mood-face {
  font-size: clamp(0.95rem, 2.4vw, 1.2rem);
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(40, 60, 48, 0.25));
}

.runner-mood-bar {
  position: relative;
  width: clamp(48px, 12vw, 84px);
  height: 7px;
  border-radius: 999px;
  background: rgba(47, 93, 66, 0.22);
  overflow: hidden;
}

.runner-mood-bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 35%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff9ec0, #ffd24e);
  transition: width 0.18s ease-out;
}

/* Active power-up icons, centred just under the HUD (empty when none active) */
.runner-powerups {
  position: absolute;
  top: clamp(34px, 8%, 52px);
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  letter-spacing: 0.18em;
  filter: drop-shadow(0 2px 3px rgba(40, 60, 48, 0.4));
}

/* "Level N" banner that flashes on each level change */
.runner-levelup {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  pointer-events: none;
  opacity: 0;
}

.runner-levelup strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 8vw, 3.4rem);
  color: #fff8f0;
  text-shadow: 0 3px 0 rgba(40, 60, 48, 0.55), 0 0 18px rgba(217, 95, 112, 0.6);
}

.runner-levelup span {
  font-family: "Segoe Script", "Brush Script MT", cursive;
  font-size: clamp(1.1rem, 3.4vw, 1.7rem);
  color: #ffe2a8;
  text-shadow: 0 2px 6px rgba(40, 60, 48, 0.6);
}

.runner-levelup.is-shown {
  animation: levelup-pop 2.2s ease forwards;
}

@keyframes levelup-pop {
  0%   { opacity: 0; transform: scale(0.6); }
  16%  { opacity: 1; transform: scale(1.08); }
  26%  { transform: scale(1); }
  72%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.04); }
}

@media (prefers-reduced-motion: reduce) {
  .runner-levelup.is-shown { animation-duration: 1.4s; }
}

/* Overlays (start / game over) */
.runner-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  text-align: center;
  background: rgba(34, 56, 44, 0.46);
  backdrop-filter: blur(2px);
  color: #fff8f0;
}

.runner-overlay[hidden] { display: none; }

.runner-overlay h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  margin: 0;
  text-shadow: 2px 2px 0 rgba(40, 60, 48, 0.55);
}

.runner-overlay p {
  margin: 0;
  font-size: clamp(0.95rem, 2.4vw, 1.1rem);
}

.runner-overlay .runner-final-score { font-size: 1.3em; color: #ffe2a8; }

.runner-overlay kbd {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--green-deep, #244933);
  font-family: inherit;
  font-weight: 700;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.runner-btn {
  margin-top: 4px;
  padding: 11px 26px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--coral, #d95f70), var(--coral-deep, #c84f61));
  color: #fff7f3;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(200, 79, 97, 0.42);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.runner-btn:hover,
.runner-btn:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 30px rgba(200, 79, 97, 0.5);
  outline: none;
}

.runner-btn:focus-visible { outline: 3px solid #fff8f0; outline-offset: 2px; }

.runner-overlay .runner-best { opacity: 0.92; font-size: 0.95rem; }

/* ---- Juno's Wardrobe (paw-print trail shop) --------------------------- */
.runner-wallet { opacity: 0.95; font-size: 0.95rem; margin: 2px 0 0; }
.runner-wallet-value { color: #ffe2a8; font-weight: 700; }

.runner-wardrobe {
  margin-top: 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.9rem, 2.4vw, 1.05rem);
  font-weight: 700;
  color: #2f5d42;
  background: rgba(255, 250, 243, 0.92);
  border: 2px solid rgba(47, 93, 66, 0.4);
  border-radius: 999px;
  padding: 7px 18px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.runner-wardrobe:hover { background: #fff; }
.runner-wardrobe:active { transform: translateY(1px); }
.runner-wardrobe:focus-visible { outline: 3px solid #fff8f0; outline-offset: 2px; }

.runner-shop {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 8px;
  background: rgba(34, 56, 44, 0.66);
  backdrop-filter: blur(3px);
  color: #fff8f0;
}
.runner-shop[hidden] { display: none; }

.runner-shop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.runner-shop-head h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.05rem, 3.2vw, 1.5rem);
  margin: 0;
}
.runner-shop-wallet {
  background: rgba(255, 250, 243, 0.92);
  color: #2f5d42;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  margin-left: auto;
}
.runner-shop-close {
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 250, 243, 0.92);
  color: #2f5d42;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.runner-shop-sub {
  margin: 0;
  opacity: 0.85;
  font-size: 0.9rem;
}
.runner-shop-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
  align-content: start;
  padding-right: 2px;
}

.trail-card {
  background: rgba(255, 250, 243, 0.96);
  color: #2f5d42;
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  box-shadow: 0 3px 8px rgba(20, 40, 30, 0.18);
}
.trail-card.is-equipped { outline: 3px solid #ffd24e; }

.trail-swatch {
  width: 100%;
  height: 34px;
  border-radius: 8px;
  background: rgba(47, 93, 66, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.sw-dot { width: 12px; height: 9px; border-radius: 50%; display: inline-block; }
.sw-glyph { font-size: 1.15rem; line-height: 1; }
.sw-spark { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }

.trail-name { font-weight: 700; font-size: 0.92rem; text-align: center; line-height: 1.15; }

.trail-btn {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 0.85rem;
  border: none;
  border-radius: 999px;
  padding: 5px 15px;
  cursor: pointer;
  background: #2f5d42;
  color: #fff8f0;
}
.trail-btn.buy { background: #d95f70; }
.trail-btn.is-on { background: #ffd24e; color: #5a4a1e; cursor: default; }
.trail-btn.is-broke { background: #b9b2a8; color: #fff; cursor: not-allowed; }

.game-controls-hint {
  color: var(--muted, #66746a);
  font-size: 0.9rem;
  text-align: center;
  margin: 0;
}

.game-controls-hint kbd {
  display: inline-block;
  padding: 0 6px;
  border-radius: 5px;
  background: rgba(47, 93, 66, 0.1);
  color: var(--green-deep, #244933);
  font-family: inherit;
  font-weight: 700;
}

/* Bone counter pop when a bone is collected */
.runner-hud .runner-bones.pop {
  animation: bone-pop 0.3s ease;
}

@keyframes bone-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); color: #c98a1a; }
  100% { transform: scale(1); }
}

/* Screen shake after a collision (transforms the canvas bitmap only) */
.runner-stage canvas.is-shake {
  animation: stage-shake 0.4s ease;
}

@keyframes stage-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 3px); }
  40% { transform: translate(5px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 2px); }
}

/* Polished game-over screen */
.runner-over .runner-medal {
  font-size: clamp(2.6rem, 9vw, 4rem);
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(40, 60, 48, 0.45));
}

.runner-over h3 { margin: 0; }

.runner-over .runner-title {
  font-family: "Segoe Script", "Brush Script MT", cursive;
  color: #ffe2a8;
  font-size: clamp(1.1rem, 3.4vw, 1.6rem);
  margin: 0;
}

.runner-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 22px;
  margin: 4px 0 2px;
}

.runner-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.runner-stats dt {
  font-size: clamp(0.7rem, 2vw, 0.82rem);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.runner-stats dd {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: clamp(1.1rem, 3.2vw, 1.5rem);
  color: #fff8f0;
}

@media (prefers-reduced-motion: reduce) {
  .runner-stage canvas.is-shake { animation: none; }
}

@media (max-width: 540px) {
  .runner-stage { max-height: 64vh; border-radius: 16px; }
}
