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

body {
  font-family: "Arial", sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

#container {
  text-align: center;
  position: relative;
}

h1 {
  font-size: 3em;
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#ui {
  margin-bottom: 20px;
}

#gameInfo {
  display: flex;
  justify-content: space-around;
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 10px;
  font-weight: bold;
}

#gameInfo div {
  margin: 0 10px;
}

#controls {
  background: rgba(0, 0, 0, 0.2);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 20px;
}

#controls p {
  margin: 5px 0;
  font-size: 0.9em;
}

#joinForm {
  background: rgba(255, 255, 255, 0.1);
  padding: 30px;
  border-radius: 15px;
  backdrop-filter: blur(10px);
  margin-bottom: 20px;
  display: block;
}

#joinForm.hidden {
  display: none;
}

#joinForm h2 {
  margin-bottom: 20px;
}

#nameInput {
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  margin-right: 10px;
  width: 200px;
  text-align: center;
  outline: none;
  background: white;
  color: #333;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#nameInput:focus {
  box-shadow: 0 0 0 2px #4caf50;
  background: #fff;
}

#joinButton {
  padding: 12px 24px;
  background: #4caf50;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.3s;
}

#joinButton:hover {
  background: #45a049;
}

#joinButton:disabled {
  background: #cccccc;
  cursor: not-allowed;
}

#errorMessage {
  color: #ff6b6b;
  margin-top: 10px;
  font-weight: bold;
}

#gameCanvas {
  border: 3px solid white;
  border-radius: 10px;
  background: #f0f8ff;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  display: none;
}

#gameCanvas.visible {
  display: block;
}

#gameMessages {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 300px;
  z-index: 1000;
}

.message {
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 15px;
  margin-bottom: 10px;
  border-radius: 8px;
  border-left: 4px solid #4caf50;
  animation: slideIn 0.3s ease-out;
}

.message.tagged {
  border-left-color: #ff6b6b;
  background: rgba(255, 107, 107, 0.9);
}

.message.star {
  border-left-color: #ffd700;
  background: rgba(255, 215, 0, 0.9);
  color: #000;
}

.message.success {
  border-left-color: #00ff00;
  background: rgba(0, 255, 0, 0.8);
  color: #000;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes glow {
  0%,
  100% {
    box-shadow: 0 0 20px rgba(255, 255, 0, 0.5);
  }
  50% {
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.8);
  }
}

.player-it {
  animation: glow 1s ease-in-out infinite;
}

/* Responsive design */
@media (max-width: 900px) {
  #gameCanvas {
    width: 90vw;
    height: calc(90vw * 0.75);
  }

  #gameInfo {
    flex-direction: column;
    gap: 5px;
  }

  h1 {
    font-size: 2em;
  }

  #nameInput {
    width: 100%;
    margin-bottom: 10px;
    margin-right: 0;
    padding: 16px;
    font-size: 18px;
    min-height: 48px; /* iOS/Android recommended touch target */
  }

  #joinButton {
    padding: 16px 32px;
    font-size: 18px;
    min-height: 48px; /* iOS/Android recommended touch target */
    width: 100%;
  }

  /* Hide desktop controls on mobile */
  #controls {
    display: none;
  }

  /* Show mobile controls */
  #mobileControls {
    display: block;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
  }
}

/* Mobile controls (hidden by default) */
#mobileControls {
  display: none;
}

/* Touch control overlay styles */
.touch-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 120px;
  height: 120px;
  pointer-events: none;
  z-index: 100;
}

.virtual-joystick {
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.1);
}

.joystick-knob {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  transition: all 0.1s ease;
}

/* Score and Leaderboard Styles */
#playerScore {
  font-size: 1.1em;
  font-weight: bold;
  color: #ffd700;
}

#leaderboard {
  background: rgba(0, 0, 0, 0.3);
  padding: 15px;
  border-radius: 10px;
  margin: 15px 0;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

#leaderboard h3 {
  margin-bottom: 10px;
  color: #ffd700;
  font-size: 1.2em;
}

#playerScores {
  text-align: left;
}

.score-entry {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
  margin: 3px 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  font-size: 0.9em;
}

.score-entry.my-score {
  background: rgba(255, 215, 0, 0.2);
  border: 1px solid rgba(255, 215, 0, 0.3);
}

.score-entry.it-player {
  background: rgba(255, 100, 100, 0.2);
  border: 1px solid rgba(255, 100, 100, 0.3);
}

.score-change {
  position: fixed;
  font-weight: bold;
  font-size: 1.2em;
  pointer-events: none;
  z-index: 1000;
  animation: scorePopup 2s ease-out forwards;
}

.score-change.positive {
  color: #00ff00;
}

.score-change.negative {
  color: #ff4444;
}

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

/* Fullscreen Mode Styles */
.fullscreen-mode {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullscreen-mode #gameCanvas {
  border: none;
  border-radius: 0;
}

/* Fullscreen Toggle Button */
#fullscreenButton {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  padding: 10px 15px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 1001;
  min-height: 48px;
  min-width: 48px;
  display: block; /* Now visible on all devices */
}

#fullscreenButton:hover {
  background: rgba(0, 0, 0, 0.9);
  border-color: rgba(255, 255, 255, 0.8);
  transform: scale(1.05);
}

#fullscreenButton:active {
  transform: scale(0.95);
}

/* Exit Fullscreen Button (shown in fullscreen mode) */
#exitFullscreenButton {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 1002;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

#exitFullscreenButton:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.6);
}

/* Compact UI for Fullscreen */
.fullscreen-mode #gameMessages {
  top: 10px;
  right: 80px;
  width: 250px;
}

.fullscreen-mode .message {
  padding: 8px 12px;
  font-size: 14px;
}

/* Fullscreen button visibility for all devices */
.fullscreen-mode #exitFullscreenButton {
  display: flex;
}

/* Mobile-specific fullscreen styles */
@media (max-width: 900px) {
  
  /* Hide debug panel in fullscreen on mobile */
  .fullscreen-mode #debugPanel {
    display: none !important;
  }
  
  /* Optimize message positioning for mobile fullscreen */
  .fullscreen-mode #gameMessages {
    top: 5px;
    right: 5px;
    left: 5px;
    width: auto;
    max-width: calc(100vw - 80px);
  }
}

/* Prevent scrolling and zooming on mobile */
@media (max-width: 900px) {
  body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Prevent pull-to-refresh */
  body {
    overscroll-behavior: none;
  }
}

/* Enhanced touch targets for mobile */
@media (max-width: 900px) {
  /* Ensure all interactive elements meet touch target requirements */
  button, input[type="button"], input[type="submit"] {
    min-height: 48px;
    min-width: 48px;
  }
  
  /* Optimize canvas touch handling */
  #gameCanvas {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}
