/* Base */
body {
  margin: 0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: #111;
  color: #fff;
}

/* Road */
#road-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: repeating-linear-gradient(
    to bottom,
    #2a2a2a 0px,
    #2a2a2a 40px,
    #303030 40px,
    #303030 80px
  );
}

/* Canvas */
#game-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* UI Overlay */
#ui-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1rem;
}

#ui-overlay a,
#ui-overlay button {
  pointer-events: auto;
}

/* Top bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Back Button with Tooltip */
.back-btn {
  position: relative;
  background: rgba(55, 65, 81, 0.9);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: rgba(75, 85, 101, 1);
  transform: translateX(-3px);
}

.back-arrow {
  width: 16px;
  height: 16px;
  transition: transform 0.3s ease;
}

.back-btn:hover .back-arrow {
  transform: translateX(-3px);
}

/* Tooltip */
.tooltip {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 41, 55, 0.95);
  color: #fff;
  padding: 0.4rem 0.8rem;
  border-radius: 0.375rem;
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
  z-index: 100;
}

.tooltip::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: rgba(31, 41, 55, 0.95);
}

.back-btn:hover .tooltip {
  opacity: 1;
  visibility: visible;
}

/* Stats */
.stats {
  display: flex;
  gap: 0.75rem;
}

.stat {
  background: rgba(31, 41, 55, 0.8);
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-weight: 500;
}

/* Overlay screens */
.overlay-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.75);
}

.overlay-box {
  text-align: center;
  max-width: 400px;
  padding: 2rem;
  background: rgba(31, 41, 55, 0.3);
  border-radius: 1rem;
}

.hidden { 
  display: none !important; 
}

/* Titles */
.title {
  font-size: 3rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

/* Gradient text effect */
.title.gradient {
  background: linear-gradient(135deg, #facc15, #ef4444);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent;
}

/* Descriptions */
.desc { 
  margin: 1.5rem 0; 
  font-size: 1.1rem; 
  line-height: 1.6;
}

.bad { color: #ef4444; font-weight: bold; }
.good { color: #22c55e; font-weight: bold; }
.coin { color: #facc15; font-weight: bold; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.85rem 2.5rem;
  font-size: 1.2rem;
  font-weight: bold;
  border: none;
  border-radius: 9999px;
  cursor: pointer;
  color: white;
  background: linear-gradient(135deg, #22c55e, #3b82f6);
  transition: transform 0.2s ease;
}

.btn:hover { 
  transform: scale(1.05); 
}

.btn:active {
  transform: scale(0.98);
}

/* Difficulty */
.difficulty-select { 
  margin: 1.5rem 0; 
}

.diff-label { 
  margin-bottom: 0.75rem; 
  font-size: 1rem; 
  color: #d1d5db;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.diff-buttons { 
  display: flex; 
  justify-content: center; 
  gap: 0.75rem; 
}

.diff-btn {
  padding: 0.6rem 1.2rem;
  border-radius: 0.5rem;
  border: 2px solid transparent;
  font-weight: 600;
  cursor: pointer;
  background: rgba(55, 65, 81, 0.6);
  color: #fff;
  transition: all 0.3s ease;
}

.diff-btn:hover { 
  background: rgba(75, 85, 99, 0.8);
}

.diff-btn.active { 
  background: #3b82f6;
  border-color: #60a5fa;
}

/* Instructions */
.instructions {
  margin-top: 1.5rem;
  font-size: 0.9rem;
  color: #9ca3af;
  line-height: 1.5;
}

.instructions b {
  color: #fff;
  font-weight: 600;
}

/* Game Over box */
.score-box {
  background: rgba(55, 65, 81, 0.6);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.final-score {
  font-size: 2.5rem;
  font-weight: bold;
  color: #facc15;
}

.new-record {
  color: #22c55e;
  font-weight: bold;
  margin-top: 0.75rem;
  animation: pulse 1s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Mobile controls */
#mobile-controls {
  display: none;
  justify-content: center;
  gap: 3rem;
  position: fixed;
  bottom: 20px;
  left: 0;
  right: 0;
  z-index: 10;
  pointer-events: auto;
}

.control-btn {
  width: 75px;
  height: 75px;
  font-size: 2.2rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  border: 3px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.control-btn:active {
  background: rgba(255, 255, 255, 0.45);
  transform: scale(0.92);
  border-color: rgba(255, 255, 255, 0.8);
}

/* Show mobile controls on mobile devices */
@media (max-width: 767px) {
  #mobile-controls {
    display: flex;
  }
  
  .control-btn {
    width: 70px;
    height: 70px;
    font-size: 2rem;
  }
}

/* Score popup */
#score-popups {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.score-popup {
  position: absolute;
  font-weight: bold;
  font-size: 1.2rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
  animation: scoreFloat 1.2s ease-out forwards;
}

@keyframes scoreFloat {
  0% { 
    opacity: 1; 
    transform: translateY(0) scale(1); 
  }
  100% { 
    opacity: 0; 
    transform: translateY(-50px) scale(1.2); 
  }
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .title {
    font-size: 2.5rem;
  }
  
  .back-btn {
    font-size: 0.9rem;
    padding: 0.4rem 0.8rem;
  }
  
  .stats {
    font-size: 0.9rem;
  }
  
  .stat {
    padding: 0.25rem 0.6rem;
  }
}