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

body {
  background: #0a0a1a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  font-family: 'Silkscreen', monospace;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#game-wrapper {
  position: relative;
  width: 800px;
  max-width: 100vw;
}

#rainbow-border {
  position: absolute;
  inset: -4px;
  border-radius: 8px;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.5s;
  background: conic-gradient(from var(--angle, 0deg), #ff0000, #ff8800, #ffff00, #00ff00, #0088ff, #8800ff, #ff0000);
  animation: spin-border 2s linear infinite;
}

@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

@keyframes spin-border {
  to { --angle: 360deg; }
}

#rainbow-border.active {
  opacity: 1;
}

canvas {
  display: block;
  width: 800px;
  max-width: 100vw;
  height: auto;
  aspect-ratio: 800 / 500;
  background: #0d0d2b;
  border-radius: 4px;
  position: relative;
  z-index: 1;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 12px;
  z-index: 2;
  pointer-events: none;
  font-size: 11px;
}

#hud-left { text-align: left; }
#hud-center { text-align: center; flex: 1; }
#hud-right { text-align: right; }

#score-display {
  color: #f8d878;
  text-shadow: 1px 1px 0 #000, 2px 2px 4px rgba(248,216,120,0.3);
  font-size: 12px;
  letter-spacing: 1px;
}

#health-display {
  margin-top: 4px;
  font-size: 16px;
  filter: drop-shadow(1px 1px 2px #000);
}

#status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 10px;
  letter-spacing: 2px;
  background: rgba(80,0,0,0.7);
  color: #ff4444;
  border: 1px solid #ff4444;
  text-shadow: 0 0 6px #ff0000;
}

#status-badge.invincible {
  background: rgba(80,60,0,0.7);
  color: #ffd700;
  border-color: #ffd700;
  text-shadow: 0 0 8px #ffd700;
  animation: badge-pulse 1s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

#timer-display {
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  font-weight: 700;
  color: #555;
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 #000;
}

#timer-display.active {
  color: #ffd700;
  text-shadow: 0 0 10px #ffd700, 0 0 20px #ffaa00;
  animation: timer-glow 1.5s ease-in-out infinite;
}

@keyframes timer-glow {
  0%, 100% { text-shadow: 0 0 10px #ffd700, 0 0 20px #ffaa00; }
  50% { text-shadow: 0 0 15px #ffd700, 0 0 30px #ffaa00, 0 0 40px #ff8800; }
}

#controls-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 2;
  pointer-events: none;
  font-size: 9px;
  color: rgba(255,255,255,0.25);
  letter-spacing: 1px;
  display: flex;
  gap: 20px;
  justify-content: center;
}

#mobile-controls {
  display: none;
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  z-index: 3;
  padding: 0 16px;
}

.touch-btn {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.4);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active, .touch-btn.pressed {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.4);
}

#btn-left { bottom: 0; left: 16px; }
#btn-right { bottom: 0; left: 90px; }
#btn-jump { bottom: 0; right: 16px; width: 70px; height: 70px; }

@media (hover: none) and (pointer: coarse), (max-width: 600px) {
  #mobile-controls { display: block; }
  #controls-hint { display: none; }
}

#welcome-back {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  background: rgba(0,0,0,0.85);
  border: 2px solid #ffd700;
  border-radius: 8px;
  padding: 20px 30px;
  text-align: center;
  color: #ffd700;
  font-size: 14px;
  line-height: 1.8;
  box-shadow: 0 0 40px rgba(255,215,0,0.3);
  animation: wb-in 0.5s ease-out;
}

#welcome-back.hidden { display: none; }

@keyframes wb-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

#stats-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 5;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.5;
  transition: opacity 0.2s;
}
#stats-btn:hover { opacity: 1; }

#stats-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  background: #111122;
  border: 2px solid #3344aa;
  border-radius: 8px;
  padding: 20px;
  color: #aabbff;
  font-size: 11px;
  line-height: 1.8;
  min-width: 240px;
  text-align: center;
}
#stats-panel.hidden { display: none; }
#stats-panel h3 { color: #6688ff; margin-bottom: 10px; font-size: 12px; letter-spacing: 2px; }
#stats-close {
  margin-top: 12px;
  background: #2233aa;
  color: #fff;
  border: none;
  padding: 6px 16px;
  font-family: 'Silkscreen', monospace;
  font-size: 10px;
  cursor: pointer;
  border-radius: 3px;
}

footer {
  margin-top: 12px;
  z-index: 1;
}
footer a {
  color: #4455aa;
  text-decoration: none;
  font-family: 'Silkscreen', monospace;
  font-size: 10px;
  letter-spacing: 1px;
}
footer a:hover { color: #6688ff; text-decoration: underline; }

.hidden { display: none !important; }