:root {
  color-scheme: dark;
  --pink: #ff3ca6;
  --cyan: #3cf0ff;
  --violet: #9b6bff;
  --gold: #ffd23c;
  --ink: #f0f0f5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Chakra Petch", system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Inside the OS shell, the shell chrome owns volume + fullscreen + home. */
html.in-shell .mute-btn,
html.in-shell .fs-btn,
html.in-shell .back-link {
  display: none;
}

.back-link {
  position: absolute;
  top: 1.25rem;
  left: 1.5rem;
  z-index: 6;
  color: #8f8fb0;
  text-decoration: none;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
  text-transform: uppercase;
}
.back-link:hover { color: var(--cyan); }

.arena {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 0.7rem;
  padding: 1rem;
}

/* HUD row above the tunnel */
.hudbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(86vw, 118vh);
  min-width: 300px;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 0.95rem;
}
.hud-score { color: var(--cyan); text-shadow: 0 0 12px rgba(60, 240, 255, 0.6); }
.hud-score span { color: #eafcff; }
.hud-best {
  color: #b6a6e0;
  font-size: 0.8rem;
  /* Sit beside SCORE on the left instead of centered over the synthwave
     sun, where it was unreadable; dark halo keeps it legible regardless. */
  margin-right: auto;
  text-shadow: 0 0 6px rgba(5, 3, 12, 0.9), 0 0 14px rgba(5, 3, 12, 0.9);
}
.hud-best span { color: #e7dcff; }
/* Cyan pixel hearts (layout + glow come from the shared .gh-heart rules). */
.hud-shields { color: var(--cyan); }

.stage {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  line-height: 0;
  /* Reserve the canvas's FINAL size up front so the stage doesn't visibly grow
     from a small placeholder to the full game area when three.js finishes
     booting (~1–2s) and mounts its canvas. This mirrors sizeRenderer() in
     script.js exactly: w = min(86vw, 120vh, 1280px), h = 0.6·w. Keep the two in
     sync — a mismatch reintroduces the load-in reflow. */
  width: min(86vw, 120vh, 1280px);
  height: min(51.6vw, 72vh, 768px);
}
#mount { line-height: 0; }
#mount canvas {
  display: block;
  touch-action: none;
  cursor: grab;
}
#mount canvas:active { cursor: grabbing; }

/* ---------- shield force-field countdown (post-hit invulnerability) ----------
   Same convention as Neon Breakout's power-up bars: a glowing pill with a
   draining bar + seconds, blinking a warning as it runs out. */
.shield-timer {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 9px;
  border-radius: 12px;
  background: rgba(4, 8, 20, 0.72);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 14px rgba(60, 240, 255, 0.45), inset 0 0 12px rgba(60, 240, 255, 0.12);
  font-family: "Orbitron", sans-serif;
  line-height: 1;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.shield-timer.show { opacity: 1; transform: translateY(0); }
.shield-timer .st-icon { width: 17px; height: 17px; fill: var(--cyan); filter: drop-shadow(0 0 4px var(--cyan)); }
.shield-timer .st-label { font-weight: 800; font-size: 11px; letter-spacing: 0.12em; color: #eafcff; }
.shield-timer .st-secs { font-weight: 700; font-size: 11px; color: var(--cyan); min-width: 16px; }
.shield-timer .st-bar {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 4px;
  height: 3px;
  border-radius: 2px;
  background: rgba(60, 240, 255, 0.16);
  overflow: hidden;
}
.shield-timer .st-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
  transform-origin: left center;
  /* width is set per-frame in JS to the fraction remaining */
}
/* under ~0.7s left: pulse the whole pill red-hot as a "about to drop" warning */
.shield-timer.ending {
  border-color: #ffd23c;
  box-shadow: 0 0 16px rgba(255, 210, 60, 0.6);
  animation: shield-warn 0.36s steps(2, end) infinite;
}
.shield-timer.ending .st-icon,
.shield-timer.ending .st-secs { fill: #ffd23c; color: #ffd23c; }
.shield-timer.ending .st-bar i { background: #ffd23c; box-shadow: 0 0 6px #ffd23c; }
@keyframes shield-warn { 0% { opacity: 1; } 100% { opacity: 0.45; } }

/* ---------- red edge-flash when a life is lost ---------- */
.hit-flash {
  position: absolute;
  inset: 0;
  z-index: 2; /* above the canvas, below the callout/pause/overlay */
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse 78% 70% at 50% 50%, transparent 45%, rgba(255, 40, 40, 0.6) 100%);
}
.hit-flash.show { animation: hit-flash 0.45s ease-out; }
@keyframes hit-flash {
  0% { opacity: 0; }
  12% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- big milestone callouts (WARP 2! / LIGHT SPEED!) ---------- */
.callout {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  letter-spacing: 0.1em;
  color: #fff;
  opacity: 0;
  line-height: 1.4;
}
.callout.show {
  animation: hyper-callout 1.6s ease-out forwards;
}
@keyframes hyper-callout {
  0% { opacity: 0; transform: scale(0.6); }
  12% { opacity: 1; transform: scale(1.15); }
  24% { transform: scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05); }
}
.callout span {
  text-shadow:
    0 0 14px var(--cyan),
    0 0 34px rgba(60, 240, 255, 0.7),
    3px 3px 0 rgba(255, 60, 166, 0.55),
    -3px -3px 0 rgba(77, 210, 255, 0.55);
}

/* ---------- Pause (P key, the ⏸ chip, or switching tabs) ---------- */
.pause-btn {
  position: absolute;
  /* bottom-right, matching the other games so pause is always in one place */
  right: 12px;
  bottom: 12px;
  z-index: 4;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 19, 0.6);
  border: 2px solid rgba(155, 107, 255, 0.45);
  border-radius: 11px;
  color: #b6a6e0;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.pause-btn svg { width: 20px; height: 20px; }
.pause-btn:hover { border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 14px rgba(60, 240, 255, 0.4); }
.pause-btn:active { transform: scale(0.92); }

.pause-veil {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  text-align: center;
  line-height: 1.4; /* the .stage zeroes line-height for the canvas — reset it */
  background: rgba(8, 5, 20, 0.74);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  cursor: pointer;
}
.pause-veil.show { opacity: 1; pointer-events: auto; }
.pause-veil .pv-title {
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 2.2rem;
  letter-spacing: 0.14em;
  color: #eafcff;
  text-shadow: 0 0 18px rgba(60, 240, 255, 0.75), 0 0 40px rgba(155, 107, 255, 0.5);
}
.pause-veil .pv-sub { color: #b6a6e0; font-size: 0.85rem; letter-spacing: 0.04em; }
.pause-veil .pv-sub b { color: var(--cyan); }

/* ---------- Title card / result overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 6; /* above the pause chip + veil */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 1.5rem;
  text-align: center;
  line-height: 1.4;
  background:
    radial-gradient(ellipse 90% 55% at 50% 8%, rgba(155, 107, 255, 0.14), transparent 60%),
    rgba(6, 5, 18, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.3s ease;
}
/* While hidden (during play) skip the blur too — no reason to composite a
   backdrop-filter for an invisible layer on every canvas repaint. */
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* NEON HYPERDRIVE wordmark — NEON in cyan over a stretched, speeding
   HYPERDRIVE in pink italics, like it's already halfway down the tunnel. */
.overlay-logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.08em;
  font-family: "Audiowide", "Orbitron", sans-serif;
  font-weight: 400;
  line-height: 1;
}
.wm-neon {
  font-size: clamp(1rem, 4vw, 1.5rem);
  letter-spacing: 0.55em;
  margin-left: 0.55em; /* visually recenter the tracked-out text */
  color: #eafcff;
  text-shadow: 0 0 10px var(--cyan), 0 0 26px rgba(60, 240, 255, 0.7);
}
.wm-hyper {
  font-size: clamp(1.7rem, 7.5vw, 3rem);
  font-style: italic;
  letter-spacing: 0.02em;
  transform: scaleX(1.08) skewX(-6deg);
  background: linear-gradient(180deg, #ffe9f5 0%, var(--pink) 55%, #8d1d63 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 60, 166, 0.6));
}
.overlay-tag {
  margin: 0.1rem 0;
  max-width: 92%;
  color: #c4c4e0;
  font-size: 0.86rem;
  line-height: 1.5;
}
.overlay-tag .c-red { color: #ff6a5a; }
.overlay-tag .c-gold { color: var(--gold); }
.overlay-tag .c-cuke { color: #8fe34a; }
.overlay-tag .c-shield { color: var(--cyan); }
.overlay-tag .c-mon { color: #c58bff; }
.overlay-best {
  margin: 0.3rem 0 0;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.03em;
}
.overlay-best:empty { display: none; }
.overlay-result {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 1.5rem;
  letter-spacing: 0.03em;
  background: linear-gradient(90deg, #4dd2ff, #b06bff, #ff4ec7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(155, 107, 255, 0.55));
}
.overlay-result:empty { display: none; }
.overlay-sub { margin: 0; color: #d8ccff; font-size: 0.95rem; min-height: 1.1em; }
.overlay-sub:empty { display: none; }
.overlay-hint { margin: 0.2rem 0 0; color: #8b86ae; font-size: 0.75rem; }

.overlay-btn {
  margin-top: 0.3rem;
  padding: 0.6rem 2rem;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 0.95rem;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(90deg, #7c5cff, #ff4ec7);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(155, 107, 255, 0.55);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.overlay-btn:hover { transform: scale(1.05); box-shadow: 0 0 32px rgba(255, 78, 199, 0.75); }
.overlay-btn:active { transform: scale(0.98); }

/* Corner buttons (hidden inside the shell) */
.mute-btn,
.fs-btn {
  position: fixed;
  top: 14px;
  z-index: 80;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 19, 0.7);
  border: 2px solid rgba(155, 107, 255, 0.55);
  border-radius: 11px;
  color: var(--cyan);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.mute-btn { right: 14px; }
.fs-btn { right: 62px; color: #ffd23c; border-color: rgba(255, 210, 60, 0.55); }
.mute-btn svg,
.fs-btn svg { width: 21px; height: 21px; filter: drop-shadow(0 0 5px currentColor); }
.mute-btn:hover { border-color: var(--cyan); box-shadow: 0 0 16px rgba(60, 240, 255, 0.5); }
.fs-btn:hover { border-color: #ffd23c; box-shadow: 0 0 16px rgba(255, 210, 60, 0.5); }
.mute-btn:active,
.fs-btn:active { transform: scale(0.92); }
.mute-btn.muted { color: var(--pink); border-color: rgba(255, 60, 166, 0.6); }

/* On phones the wide stage is short — let the title card use the whole
   screen so the button and hint aren't clipped. */
@media (max-width: 640px) {
  .overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    overflow-y: auto;
    background:
      radial-gradient(ellipse 90% 45% at 50% 8%, rgba(155, 107, 255, 0.14), transparent 60%),
      rgba(6, 5, 18, 0.95);
  }
}


/* ---------- watchdog fallback (3D engine failed to boot) ---------- */
.load-fail {
  position: absolute;
  inset: 0;
  z-index: 7; /* above everything — if this shows, nothing else works anyway */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  text-align: center;
  line-height: 1.4;
  background: rgba(6, 5, 18, 0.92);
}
.load-fail[hidden] { display: none; }
.load-fail .lf-title {
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: 0.14em;
  color: #ff6a5a;
  text-shadow: 0 0 18px rgba(255, 106, 90, 0.6);
}
.load-fail .lf-sub { color: #b6a6e0; font-size: 0.9rem; }

/* ---------- floating "+10" pops at the coin you just grabbed ---------- */
.score-pop {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
  font-family: "Orbitron", sans-serif;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 210, 60, 0.8), 0 1px 0 rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  line-height: 1;
}
.score-pop.show {
  animation: pop-rise 0.8s ease-out forwards;
}
@keyframes pop-rise {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -62%) scale(1.15); }
  30% { transform: translate(-50%, -74%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(0.95); }
}
