/* ============================================================
   CRYPTO RUNNER — ENHANCEMENT LAYER v2 (juice overhaul)
   Adds heavy game-feel: screen shake, speed lines, lightning,
   combo-flames, particle bursts, lives HUD, dynamic backgrounds.
   ============================================================ */

/* ---------- Animated star/grid background ---------- */
.cr-bg-fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}
/* Ensure main content stacks above the bg-fx layer */
.container { position: relative; z-index: 1; }
.cr-bg-fx .cr-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,240,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,240,255,0.06) 1px, transparent 1px);
  background-size: 60px 60px;
  animation: cr-grid-drift 20s linear infinite;
  mask-image: radial-gradient(ellipse at center, #000 0%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 0%, transparent 70%);
}
@keyframes cr-grid-drift {
  from { transform: translate3d(0,0,0); }
  to   { transform: translate3d(60px,60px,0); }
}
.cr-bg-fx .cr-stars {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(2px 2px at 20% 30%, #ffd700 0%, transparent 100%),
    radial-gradient(1px 1px at 65% 60%, #00f0ff 0%, transparent 100%),
    radial-gradient(2px 2px at 80% 20%, #ff00d4 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 80%, #00ff9d 0%, transparent 100%),
    radial-gradient(1px 1px at 50% 90%, #ffd700 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 70%, #00f0ff 0%, transparent 100%),
    radial-gradient(2px 2px at 35% 15%, #ff00d4 0%, transparent 100%);
  background-size: 800px 800px;
  animation: cr-stars-pan 60s linear infinite;
  opacity: 0.55;
}
@keyframes cr-stars-pan {
  from { background-position: 0 0; }
  to   { background-position: 800px 800px; }
}

/* Body backdrop pulse during BULL_RUN */
body.cr-bullrun .cr-bg-fx::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(255,68,68,0.20), transparent 70%);
  animation: cr-bullrun-pulse 0.4s ease-in-out infinite alternate;
}
@keyframes cr-bullrun-pulse {
  from { opacity: 0.4; }
  to   { opacity: 0.85; }
}

/* DIAMOND_HANDS — green aura */
body.cr-diamond .cr-bg-fx::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,255,136,0.18), transparent 70%);
  animation: cr-diamond-pulse 0.8s ease-in-out infinite alternate;
}
@keyframes cr-diamond-pulse {
  from { opacity: 0.3; }
  to   { opacity: 0.7; }
}

/* AIRDROP — blue magnet aura */
body.cr-airdrop .cr-bg-fx::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,191,255,0.15), transparent 70%);
}

/* ---------- Screen shake (applied to game wrapper) ---------- */
.cr-shake-1 { animation: cr-shake1 0.18s ease-in-out; }
.cr-shake-2 { animation: cr-shake2 0.32s cubic-bezier(.36,.07,.19,.97); }
.cr-shake-3 { animation: cr-shake3 0.55s cubic-bezier(.36,.07,.19,.97); }
@keyframes cr-shake1 {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-3px, 1px); }
  75% { transform: translate(3px, -1px); }
}
@keyframes cr-shake2 {
  0%,100% { transform: translate(0,0); }
  10% { transform: translate(-6px, -2px) rotate(-0.4deg); }
  30% { transform: translate(7px, 1px) rotate(0.4deg); }
  50% { transform: translate(-4px, 2px) rotate(-0.3deg); }
  70% { transform: translate(5px, -1px) rotate(0.2deg); }
}
@keyframes cr-shake3 {
  0%,100% { transform: translate(0,0); }
  10% { transform: translate(-10px, -3px) rotate(-0.7deg); }
  20% { transform: translate(11px, 2px) rotate(0.7deg); }
  35% { transform: translate(-9px, 4px) rotate(-0.5deg); }
  50% { transform: translate(8px, -3px) rotate(0.5deg); }
  65% { transform: translate(-6px, 2px) rotate(-0.3deg); }
  80% { transform: translate(4px, -1px) rotate(0.2deg); }
}

/* ---------- Speed lines (during fast play / BULL_RUN) ---------- */
.cr-speedlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 19;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.35s;
}
.cr-speedlines.on { opacity: 0.45; }
.cr-speedlines.bull { opacity: 0.85; }
.cr-speedlines .line {
  position: absolute;
  height: 2px;
  background: linear-gradient(90deg, transparent, #fff, transparent);
  opacity: 0.9;
  filter: blur(0.5px);
}
.cr-speedlines.bull .line {
  background: linear-gradient(90deg, transparent, #ff4444, transparent);
  height: 3px;
}

/* ---------- Lightning flashes (BULL_RUN bursts) ---------- */
.cr-lightning {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.85), transparent 60%);
  pointer-events: none;
  z-index: 22;
  opacity: 0;
  mix-blend-mode: screen;
}
.cr-lightning.flash { animation: cr-lightning 0.18s ease-out; }
@keyframes cr-lightning {
  0%   { opacity: 0; }
  20%  { opacity: 0.95; }
  40%  { opacity: 0.2; }
  60%  { opacity: 0.85; }
  100% { opacity: 0; }
}

/* ---------- Combo flame counter ---------- */
.cr-combo {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  text-align: center;
  pointer-events: none;
  z-index: 26;
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1);
}
.cr-combo.show { transform: translateX(-50%) scale(1); }
.cr-combo .num {
  font-size: clamp(36px, 8vw, 64px);
  background: linear-gradient(180deg, #fff700, #ff8800, #ff0066);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(255,136,0,0.65);
  filter: drop-shadow(0 4px 8px rgba(255,68,0,0.6));
  line-height: 1;
}
.cr-combo .lbl {
  display: block;
  font-size: clamp(11px, 2.5vw, 14px);
  letter-spacing: 4px;
  color: #ffd700;
  margin-top: 2px;
  text-shadow: 0 0 12px rgba(255,215,0,0.6);
}
.cr-combo.pulse { animation: cr-combo-pulse 0.35s ease-out; }
@keyframes cr-combo-pulse {
  0%   { transform: translateX(-50%) scale(1); }
  40%  { transform: translateX(-50%) scale(1.35); }
  100% { transform: translateX(-50%) scale(1); }
}

/* ---------- Confetti / particle bursts (DOM particles) ---------- */
.cr-particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 24;
  overflow: hidden;
}
.cr-confetti {
  position: absolute;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: cr-confetti-fall 1.6s ease-out forwards;
}
@keyframes cr-confetti-fall {
  0%   { transform: translate3d(0,0,0) rotate(0deg);   opacity: 1; }
  100% { transform: translate3d(var(--dx,0), var(--dy,200px), 0) rotate(720deg); opacity: 0; }
}

.cr-spark {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
  will-change: transform, opacity;
  animation: cr-spark-out 0.7s ease-out forwards;
}
@keyframes cr-spark-out {
  0%   { transform: translate3d(0,0,0) scale(1); opacity: 1; }
  100% { transform: translate3d(var(--dx,0), var(--dy,0), 0) scale(0.2); opacity: 0; }
}

/* ---------- Floating score popups (+points) ---------- */
.cr-pop {
  position: fixed;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(16px, 3.5vw, 22px);
  pointer-events: none;
  z-index: 23;
  text-shadow: 0 2px 6px rgba(0,0,0,0.8);
  animation: cr-pop-rise 1.1s ease-out forwards;
  white-space: nowrap;
}
@keyframes cr-pop-rise {
  0%   { transform: translate(-50%, 0) scale(0.4); opacity: 0; }
  15%  { transform: translate(-50%, -10px) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -80px) scale(1); opacity: 0; }
}

/* ---------- Lives HUD (5 hearts row) ---------- */
.cr-lives-hud {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  gap: 4px;
  font-size: 22px;
  z-index: 21;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  font-family: 'Orbitron', sans-serif;
  background: rgba(0,0,0,0.35);
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,80,80,0.3);
}
.cr-lives-hud .heart {
  transition: transform 0.25s, opacity 0.25s, filter 0.25s;
  filter: drop-shadow(0 0 6px rgba(255,80,80,0.8));
}
.cr-lives-hud .heart.empty {
  opacity: 0.18;
  filter: grayscale(1);
}
.cr-lives-hud .heart.lost {
  animation: cr-heart-lost 0.6s ease-out;
}
.cr-lives-hud .heart.gain {
  animation: cr-heart-gain 0.6s cubic-bezier(.34,1.56,.64,1);
}
@keyframes cr-heart-lost {
  0%   { transform: scale(1.5) rotate(0deg); filter: drop-shadow(0 0 20px #ff0033); }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes cr-heart-gain {
  0%   { transform: scale(0); }
  50%  { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* ---------- Top-bar leaderboard button ---------- */
.cr-lb-btn {
  position: fixed;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(0,240,255,0.4);
  color: #fff;
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  z-index: 25;
  font-family: 'Orbitron', sans-serif;
  box-shadow: 0 0 14px rgba(0,240,255,0.25);
  transition: all 0.18s;
}
.cr-lb-btn:hover { background: rgba(0,240,255,0.18); transform: scale(1.05); }
.cr-lb-btn:active { transform: scale(0.96); }

/* ---------- Leaderboard popup ---------- */
.cr-leaderboard-popup {
  position: fixed;
  top: 56px;
  right: 8px;
  width: min(320px, 92vw);
  background: linear-gradient(180deg, rgba(12,10,46,0.98), rgba(6,6,26,0.98));
  border: 1px solid rgba(0,240,255,0.5);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5), 0 0 30px rgba(0,240,255,0.25);
  z-index: 30;
  overflow: hidden;
  font-family: 'Orbitron', sans-serif;
  animation: cr-popIn 0.22s ease-out;
}
.cr-leaderboard-popup.hide { display: none; }
@keyframes cr-popIn { 0% { opacity: 0; transform: scale(0.85); } 100% { opacity: 1; transform: scale(1); } }
.cr-lb-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.cr-lb-head h3 { margin: 0; font-size: 15px; letter-spacing: 2px; color: #ffd700; }
.cr-lb-head button { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; padding: 4px 8px; }
#cr-lb-content { max-height: 50vh; overflow-y: auto; padding: 8px 0; }
.cr-lb-row {
  display: grid;
  grid-template-columns: 32px 1fr 80px;
  align-items: center;
  padding: 8px 14px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: #fff;
}
.cr-lb-row .cr-lb-rank { font-weight: 800; color: #00f0ff; }
.cr-lb-row.top1 { background: linear-gradient(90deg, rgba(255,215,0,0.18), transparent); }
.cr-lb-row.top1 .cr-lb-rank { color: #ffd700; font-size: 16px; }
.cr-lb-row.top2 .cr-lb-rank { color: #c0c0c0; }
.cr-lb-row.top3 .cr-lb-rank { color: #cd7f32; }
.cr-lb-row .cr-lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: 'Inter', sans-serif; }
.cr-lb-row .cr-lb-dist { opacity: 0.55; font-size: 10px; margin-left: 4px; }
.cr-lb-row .cr-lb-pts { text-align: right; font-weight: 700; color: #ffd700; }
.cr-lb-empty { padding: 30px 20px; text-align: center; color: rgba(255,255,255,0.55); font-size: 13px; }

/* ---------- Rank-up banner ---------- */
.cr-rank-banner {
  position: fixed;
  top: 38%;
  left: 0; right: 0;
  text-align: center;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  pointer-events: none;
  z-index: 30;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.4s, transform 0.4s cubic-bezier(.34,1.56,.64,1);
}
.cr-rank-banner.show { opacity: 1; transform: scale(1); }
.cr-rank-title {
  font-size: clamp(28px, 7vw, 56px);
  letter-spacing: 3px;
  background: linear-gradient(90deg, #ffd700, #00f0ff, #ff00d4, #ffd700);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: cr-shine 2s linear infinite;
  text-shadow: 0 0 30px rgba(255,215,0,0.4);
  line-height: 1.05;
}
.cr-rank-sub {
  margin-top: 6px;
  font-size: clamp(14px, 3vw, 18px);
  color: #00ff9d;
  letter-spacing: 2px;
  font-weight: 700;
  text-shadow: 0 0 15px rgba(0,255,157,0.5);
}
@keyframes cr-shine {
  0%   { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

/* ---------- Achievement toast ---------- */
.cr-achievement-toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-160%);
  background: linear-gradient(135deg, #ffd700, #ff8800);
  color: #000;
  font-family: 'Orbitron', sans-serif;
  font-weight: 800;
  padding: 12px 22px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 0 30px rgba(255,215,0,0.5);
  z-index: 28;
  transition: transform 0.4s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
  white-space: nowrap;
  font-size: 15px;
  letter-spacing: 1px;
}
.cr-achievement-toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Screen flash overlay ---------- */
.cr-flash {
  position: fixed;
  inset: 0;
  background: transparent;
  pointer-events: none;
  z-index: 20;
  opacity: 0;
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 600px) {
  .cr-lb-btn { top: 6px; right: 6px; padding: 6px 9px; font-size: 16px; }
  .cr-leaderboard-popup { top: 50px; right: 4px; }
  .cr-lives-hud { top: 4px; left: 4px; font-size: 16px; gap: 2px; padding: 3px 6px; }
  .cr-combo { top: 70px; }
}
