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

body {
  background: #000;
  overflow: hidden;
  font-family: Orbitron, monospace;
  /* no flex — JS positions .game via position:fixed */
}

/* ── Game container ── */
.game {
  /* content-box so the 500×620 content area is exact; border sits outside */
  box-sizing: content-box;
  width: 500px;
  height: 620px;
  /* JS sets left / top / transform — keep origin top-left for predictable maths */
  position: fixed;
  transform-origin: top left;
  background: linear-gradient(to bottom, #6ec6ff 0%, #9ad9ff 40%, #ccecff 70%, #ffffff 100%);
  border: 8px solid #8b5cf6;
  overflow: hidden;
  user-select: none;
  transition: background 2s ease;
}

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
}
.overlay.hidden { display: none; }

.overlay-box {
  background: rgba(5,5,20,0.97);
  border: 2px solid #8b5cf6;
  border-radius: 16px;
  padding: 28px 38px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: popIn 0.2s ease-out;
  color: #fff;
  min-width: 240px;
}
@keyframes popIn {
  from { opacity:0; transform: scale(0.85); }
  to   { opacity:1; transform: scale(1); }
}

.game-title {
  font-size: 2.4rem;
  color: #a78bfa;
  letter-spacing: 6px;
  line-height: 1.1;
  text-shadow: 0 0 20px #7c3aed, 0 0 40px #4c1d95;
  animation: glow 2s ease-in-out infinite;
}
@keyframes glow {
  0%,100% { text-shadow: 0 0 20px #7c3aed, 0 0 40px #4c1d95; }
  50%     { text-shadow: 0 0 40px #a78bfa, 0 0 80px #7c3aed; }
}
.over-title { font-size: 2rem; color: #f87171; letter-spacing: 4px; }
.best-label { color: #fbbf24; font-size: 0.85rem; letter-spacing: 2px; }
.stat-row   { color: #c4b5fd; font-size: 1rem; letter-spacing: 1px; }
.hint-text  { color: #6b7280; font-size: 0.65rem; letter-spacing: 1px; }

.big-btn {
  background: #7c3aed;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: Orbitron, monospace;
  font-size: 1rem;
  letter-spacing: 3px;
  padding: 12px 32px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 4px;
}
.big-btn:hover { background: #8b5cf6; box-shadow: 0 0 14px #7c3aed; transform: scale(1.04); }

.small-btn {
  background: transparent;
  border: 1px solid #4c1d95;
  border-radius: 6px;
  color: #9ca3af;
  font-family: Orbitron, monospace;
  font-size: 0.72rem;
  letter-spacing: 2px;
  padding: 7px 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.small-btn:hover { background: #1f1235; color: #c4b5fd; }

/* ── HUD ── */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: rgba(0,0,0,0.5);
  z-index: 30;
  font-size: 13px;
  color: #fff;
}
#hud-lives { display: flex; gap: 3px; font-size: 15px; min-width: 48px; }
#hud-center { display: flex; align-items: baseline; gap: 4px; }
.hud-label  { font-size: 0.6rem; color: #9ca3af; letter-spacing: 2px; }
#level { font-size: 1.2rem; color: #a78bfa; }
#hud-right { display: flex; align-items: center; gap: 8px; }
#score { font-size: 1.2rem; color: #fbbf24; }

#btn-pause {
  background: transparent;
  border: 1px solid rgba(139,92,246,0.5);
  border-radius: 4px;
  color: #a78bfa;
  font-size: 0.8rem;
  width: 26px; height: 22px;
  cursor: pointer;
  padding: 0;
  font-family: Orbitron, monospace;
  transition: all 0.15s;
}
#btn-pause:hover { background: rgba(139,92,246,0.3); }

/* ── Combo banner ── */
#combo-banner {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(251,191,36,0.92);
  color: #000;
  font-size: 1rem;
  letter-spacing: 3px;
  padding: 6px 18px;
  border-radius: 20px;
  z-index: 35;
  pointer-events: none;
  animation: comboPop 0.2s ease-out;
}
#combo-banner.hidden { display: none; }
@keyframes comboPop {
  from { transform: translateX(-50%) scale(0.7); opacity: 0; }
  to   { transform: translateX(-50%) scale(1);   opacity: 1; }
}

/* Portal power-up indicator */
.powerup-indicator {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(139,92,246,0.95);
  padding: 8px 18px;
  border-radius: 20px;
  color: #fff;
  font-size: 0.75rem;
  letter-spacing: 1px;
  animation: pulse 0.5s infinite;
  z-index: 100;
}
@keyframes pulse {
  0%,100% { opacity: 1; transform: translateX(-50%) scale(1); }
  50%      { opacity: 0.8; transform: translateX(-50%) scale(1.05); }
}

/* ── Clouds ── */
#clouds {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 52%;   /* proportional to new 620px game height */
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}
.cloud {
  position: absolute;
  background: rgba(255,255,255,0.85);
  border-radius: 50px;
  animation: cloudDrift linear infinite;
}
.cloud::before,
.cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}
.cloud::before { width: 55%; height: 160%; top: -50%; left: 15%; }
.cloud::after  { width: 45%; height: 140%; top: -40%; left: 50%; }

@keyframes cloudDrift {
  from { right: -220px; }
  to   { right: 110%;  }
}

/* ── 3D Scene ── */
#scene {
  position: relative;
  width: 500px;
  height: 620px;   /* matches game content height */
  left: 0;
  top: 0;
  perspective: 600px;
  perspective-origin: 50% 0%;
  transform-style: preserve-3d;
  z-index: 5;
}

#road {
  position: absolute;
  width: 400px;
  margin-left: -200px;
  height: 2500px;
  left: 50%;
  bottom: 0;
  transform-origin: bottom center;
  transform: rotateX(60deg);
  background: url('road.png') repeat-y;
  background-size: contain;
  z-index: 6;
}

#runner {
  width: 184px;
  height: 244px;
  position: absolute;
  left: 50%;
  top: 0;
  margin-left: -92px;
  margin-top: -122px;
  background: url('runner.png') no-repeat;
  animation: run 0.3s steps(4) infinite;
  z-index: 10;
  /* default transform-origin (50% 50%) keeps scale centred — prevents bottom clip */
}

#runner.dead {
  animation: death 0.8s ease-out forwards;
}
@keyframes death {
  0%   { filter: none; }
  100% { filter: saturate(0) brightness(0.5); }
}

#runner.hurt {
  animation: hurtFlash 0.15s steps(1) infinite, run 0.3s steps(4) infinite;
}
@keyframes hurtFlash {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.2; filter: brightness(2) saturate(0); }
}

@keyframes run {
  from { background-position: 0 0; }
  to   { background-position: -736px 0; }
}

/* Portal invincible */
#runner.invincible {
  filter: hue-rotate(200deg) brightness(1.3);
  animation: invincibleGlow 0.5s infinite, run 0.3s steps(4) infinite;
}
@keyframes invincibleGlow {
  0%,100% { filter: hue-rotate(200deg) brightness(1.3); }
  50%     { filter: hue-rotate(200deg) brightness(1.6) drop-shadow(0 0 10px #8b5cf6); }
}

/* ── Entity base ── */
#bomb-blueprint,
#coin-blueprint {
  display: none;
}

.coin {
  position: absolute;
  left: 50%;
  top: 0;
  width: 26px;
  height: 26px;
  margin-left: -13px;
  line-height: 26px;
  text-align: center;
  background: radial-gradient(circle at 35% 35%, #ffe066 30%, #f59e0b 100%);
  border: 2px solid #f59e0b;
  border-radius: 50%;
  font-size: 13px;
  box-shadow: 0 0 8px rgba(251,191,36,0.6);
  z-index: 8;
}
.coin::after { content: '●'; color: #fbbf24; }

.coin.magnet {
  filter: hue-rotate(200deg) brightness(1.5);
  animation: magnetPulse 0.3s infinite;
}
@keyframes magnetPulse {
  0%,100% { transform: scale(1); }
  50%     { transform: scale(1.3); }
}

.bomb {
  position: absolute;
  left: 50%;
  top: 0;
  width: 32px;
  height: 32px;
  line-height: 32px;
  margin-left: -16px;
  text-align: center;
  font-size: 22px;
  z-index: 8;
  filter: drop-shadow(0 0 4px rgba(239,68,68,0.8));
}
.bomb::after { content: '💣'; }

/* Wall obstacle — must jump over */
.wall {
  position: absolute;
  left: 50%;
  top: 0;
  width: 58px;
  height: 28px;
  margin-left: -29px;
  background: linear-gradient(to bottom, #92400e 0%, #78350f 50%, #451a03 100%);
  border: 2px solid #451a03;
  border-radius: 4px;
  box-shadow: 0 4px 0 #1c0701, inset 0 2px 0 rgba(255,180,100,0.2);
  z-index: 8;
}
.wall::before {
  content: '';
  position: absolute;
  top: 6px; left: 8px; right: 8px;
  height: 2px;
  background: rgba(255,200,120,0.25);
  border-radius: 1px;
}

/* Bird obstacle — must duck under */
.bird {
  position: absolute;
  left: 50%;
  top: 0;
  width: 36px;
  height: 28px;
  margin-left: -18px;
  font-size: 24px;
  text-align: center;
  line-height: 28px;
  animation: birdFlap 0.18s steps(2) infinite;
  z-index: 8;
  filter: drop-shadow(0 0 3px rgba(100,200,255,0.6));
}
.bird::after { content: '🦅'; }
@keyframes birdFlap {
  0%   { transform: scaleY(1); }
  50%  { transform: scaleY(0.65); }
  100% { transform: scaleY(1); }
}

/* ── Particles ── */
.particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 200;
  animation: particleBurst 0.55s ease-out forwards;
}
.p-coin {
  width: 7px; height: 7px;
  background: #fbbf24;
  box-shadow: 0 0 4px #fbbf24;
}
.p-hit {
  width: 9px; height: 9px;
  background: #ef4444;
  box-shadow: 0 0 5px #ef4444;
}
.p-star {
  width: 5px; height: 5px;
  background: #fff;
}
@keyframes particleBurst {
  0%   { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0.2); }
}

/* ── Level-up flash ── */
.levelup-flash {
  position: absolute;
  inset: 0;
  background: rgba(139,92,246,0.35);
  z-index: 40;
  pointer-events: none;
  animation: flashFade 0.5s ease-out forwards;
}
@keyframes flashFade {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}
