* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  overflow: hidden;
  font-family: Arial, sans-serif;
  background-color: #000;
  touch-action: none; /* Prevents browser default touch actions */
}

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.loader {
  width: 60px;
  height: 60px;
  border: 8px solid rgba(255, 255, 255, 0.3);
  border-top: 8px solid #ff0000;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* Disable default touch behaviors like pinch-zoom */
}

#minimap-container {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 150px;
  height: 150px;
  background-color: rgba(0, 0, 0, 0.5);
  border: 2px solid #fff;
}

#minimap {
  width: 100%;
  height: 100%;
}

#hud {
  position: absolute;
  bottom: 20px;
  left: 20px;
  padding: 10px;
  color: white;
}

#health-bar {
  width: 200px;
  height: 20px;
  background-color: rgba(0, 0, 0, 0.5);
  border: 2px solid #fff;
  margin-bottom: 10px;
}

#health-bar-fill {
  height: 100%;
  width: 100%;
  background-color: #00ff00;
  transition: width 0.3s;
}

#weapon-info {
  font-size: 18px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  padding: 5px;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  display: inline-block;
}

#mobile-controls {
  position: absolute;
  bottom: 80px;  /* Increased from 30px to 80px for much better visibility */
  left: 0;
  width: 100%;
  height: 200px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 100;
  touch-action: none;
  padding-bottom: env(safe-area-inset-bottom, 10px); /* Add safe area for modern devices */
}

#mobile-controls.hidden {
  display: none;
}

#joystick-area {
  position: absolute;
  bottom: 70px;  /* Increased from 50px to 70px */
  left: 30px;
  width: 120px;
  height: 120px;
  pointer-events: auto;
  z-index: 110;
  touch-action: none;
}

#joystick-base {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 60px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
}

#joystick-thumb {
  width: 60px;
  height: 60px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.8);
  touch-action: none;
}

#action-buttons {
  position: absolute;
  bottom: 70px;  /* Increased from 50px to 70px */
  right: 30px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 15px;
  pointer-events: auto;
  z-index: 110;
  touch-action: none;
}

#action-buttons button {
  width: 70px;
  height: 70px;
  border-radius: 35px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: white;
  font-weight: bold;
  font-size: 14px;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#action-buttons button:active {
  background: rgba(255, 255, 255, 0.4);
}

#camera-toggle-btn {
  position: absolute;
  top: -60px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: white;
  font-weight: bold;
  pointer-events: auto;
  touch-action: none;
}

#mobile-instructions {
  position: fixed;
  top: 10px;
  left: 10px;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 10px;
  border-radius: 5px;
  max-width: 80%;
  font-size: 12px;
  display: none;
  z-index: 200;
}

/* Add a stamina indicator for sprint */
#stamina-indicator {
  position: absolute;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  width: 150px;
  height: 8px;
  background-color: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 4px;
  overflow: hidden;
  pointer-events: none;
  display: none;
}

#stamina-bar {
  height: 100%;
  width: 100%;
  background-color: rgba(255, 255, 0, 0.6);
  transition: width 0.2s;
}

/* Instructions panel */
#instructions-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 20px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  z-index: 1000;
  max-width: 90%;
  text-align: center;
  transition: opacity 0.5s;
}

#instructions-panel h2 {
  margin-bottom: 15px;
  color: #ff0000;
}

#instructions-panel p {
  margin: 8px 0;
  font-size: 16px;
}

#instructions-panel .dismiss {
  margin-top: 20px;
  font-style: italic;
  color: #aaaaaa;
}

/* Player message styles */
#player-message {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
  font-size: 18px;
  text-align: center;
  z-index: 1000;
  transition: opacity 0.3s;
  pointer-events: none;
}

/* Game Over Overlay */
#game-over-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.game-over-content {
  text-align: center;
  color: #ffffff;
  max-width: 80%;
  padding: 30px;
  background-color: rgba(50, 50, 50, 0.8);
  border-radius: 10px;
  border: 2px solid #ff0000;
  animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.game-over-content h1 {
  font-size: 48px;
  margin-bottom: 20px;
  color: #ff0000;
  text-shadow: 0 0 10px rgba(255, 0, 0, 0.7);
}

.game-over-content p {
  font-size: 24px;
  margin-bottom: 30px;
}

#restart-button {
  background-color: #ff0000;
  color: white;
  border: none;
  padding: 15px 30px;
  font-size: 24px;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.2s;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#restart-button:hover {
  background-color: #ff3333;
  transform: scale(1.05);
}

#restart-button:active {
  transform: scale(0.98);
}

/* Mobile adjustments for game over screen */
@media (max-width: 768px) {
  .game-over-content h1 {
    font-size: 36px;
  }
  
  .game-over-content p {
    font-size: 18px;
  }
  
  #restart-button {
    padding: 12px 24px;
    font-size: 20px;
  }
}

@media (max-width: 768px) {
  #mobile-controls {
      display: flex !important;
  }

  #mobile-instructions {
      display: block;
  }
  
  #stamina-indicator {
      display: block;
  }
  
  /* Scale HUD elements for better mobile visibility */
  #health-bar {
      height: 15px;
      width: 150px;
  }
  
  #minimap-container {
      width: 100px;
      height: 100px;
  }
  
  /* Add additional responsive adjustments for very small screens */
  @media (max-height: 600px) {
    #mobile-controls {
      bottom: 40px; /* Increased from 10px to 40px */
    }
    
    #joystick-area {
      bottom: 30px; /* Increased from 20px to 30px */
    }
    
    #action-buttons {
      bottom: 30px; /* Increased from 20px to 30px */
    }
    
    #action-buttons button {
      width: 60px;
      height: 60px;
    }
  }
  
  #player-message {
    bottom: 170px; /* Higher position on mobile */
    font-size: 16px;
    max-width: 80%;
  }
}