/* Global Styles */
body {
  margin: 0;
  padding: 0;
  background: #000;
  font-family: 'Zilla Slab', serif;
  overflow: hidden;
}

/* Game Container */
#gameContainer {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* UI Overlay */
#ui {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

/* Login Container - Centers both join form and help box */
#loginContainer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  pointer-events: all;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}

/* Join Form */
#joinForm {
  position: relative;
  background: rgba(0, 0, 0, 0.8);
  padding: 20px;
  border-radius: 10px;
  color: white;
  text-align: center;
  min-width: 300px;
  max-width: 400px;
  box-sizing: border-box;
  width: 100%;
}

#joinForm input {
  padding: 10px;
  margin: 10px;
  border: 2px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
  transition: border-color 0.3s ease;
}

#joinForm input:focus {
  outline: none;
  border-color: #007bff;
}

#joinForm select {
  padding: 8px;
  margin: 5px;
  border: 2px solid #ddd;
  border-radius: 5px;
  background: white;
  font-size: 14px;
}

#joinForm button {
  padding: 10px 20px;
  margin: 10px auto; /* Centers button horizontally with auto left/right margins */
  border: none;
  border-radius: 5px;
  background: #007bff;
  color: white;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s ease;
  min-width: 120px; /* Consistent width to prevent horizontal shifts */
  box-sizing: border-box;
  display: block; /* Required for margin auto centering to work */
}

#joinForm button:hover:not(:disabled) {
  background: #0056b3;
}

#joinForm button:disabled {
  background: #666;
  cursor: not-allowed;
}

#status {
  margin-top: 10px;
  font-size: 12px;
  height: 40px; /* Fixed height to prevent layout shifts */
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.3;
}

/* Help Box */
#helpBox {
  position: relative;
  background: rgba(0, 0, 0, 0.85);
  padding: 15px 20px;
  border-radius: 10px;
  color: white;
  text-align: left;
  min-width: 500px;
  max-width: 90vw;
  width: 100%;
  box-sizing: border-box;
  display: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  
  /* Responsive sizing */
  max-height: 40vh;
  overflow-y: auto;
}

#helpBox h3 {
  margin: 0 0 15px 0;
  color: #44aaff;
  font-size: 18px;
  font-weight: bold;
}

#helpBox .help-toggle-text {
  color: #888;
  font-size: 15px;
  font-weight: normal;
}

#helpBox .controls-section {
  margin-bottom: 15px;
  text-align: left;
}

/* Landscape layout for controls */
#helpBox .controls-section:first-child {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: space-between;
  margin-bottom: 20px;
}

#helpBox .control-item {
  display: flex;
  align-items: center;
  font-size: 13px;
  flex: 1;
  min-width: 140px;
}

#helpBox .control-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  margin-right: 8px;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
}

#helpBox .control-desc {
  flex: 1;
  color: #cccccc;
  font-size: 12px;
}

/* HUD */
#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(21, 21, 21, 0.6);
  padding: 10px;
  border-radius: 5px;
  color: white;
  pointer-events: none;
  font-size: 14px;
  min-width: 200px;
}

#playerStats {
  line-height: 1.4;
}

#playerStats > div {
  margin-bottom: 4px;
  display: flex;
  align-items: center;
}

#playerStats > div::before {
  margin-right: 8px;
  width: 16px;
  text-align: center;
  font-size: 14px;
}

/* Stat Icons */
#experience::before {
  content: "🏆";
}

#strength::before {
  content: "💪";
}

#constitution::before {
  content: "🛡️";
}

#dexterity::before {
  content: "⚡";
}

/* Dexterity bonus line (mobile only) */
#dexterityBonus {
  display: none; /* Hidden by default on desktop */
  font-size: 11px;
  color: #aaa;
  padding-left: 24px; /* Indent to align with text after icon */
  margin-top: -2px;
  margin-bottom: 4px;
}

#dexterityBonus::before {
  content: none; /* No icon for the bonus line */
}

/* Show dexterity bonus on mobile/small screens */
@media (max-width: 768px) {
  #dexterityBonus:not(:empty) {
    display: block;
  }
}

#damage::before {
  content: "⚔️";
}

#health::before {
  content: "❤️";
}

#statUpgrade::before {
  content: "⬆️";
}

/* Leaderboard */
#leaderboard {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(21, 21, 21, 0.6);
  padding: 10px;
  border-radius: 5px;
  color: white;
  min-width: 200px;
}

#leaderboard h3 {
  margin: 0 0 8px 0;
  padding: 0;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  padding-bottom: 5px;
}

.leaderboard-entry {
  padding: 3px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.leaderboard-entry .rank {
  font-weight: bold;
  margin-right: 8px;
}

.leaderboard-entry .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-entry .level {
  font-size: 0.9em;
  color: #ccc;
}

.leaderboard-entry.rank-1 {
  color: #ffd700;
  font-weight: bold;
}

.leaderboard-entry.rank-2 {
  color: #c0c0c0;
  font-weight: bold;
}

.leaderboard-entry.rank-3 {
  color: #cd7f32;
  font-weight: bold;
}

/* Killfeed */
#killfeed {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  text-align: center;
  min-width: 300px;
}

.killfeed-entry {
  background: rgba(0, 0, 0, 0.6);
  padding: 5px 10px;
  margin: 2px 0;
  border-radius: 3px;
  animation: fadeIn 0.3s ease-in;
}

/* Spectator Controls */
#spectatorControls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  padding: 10px;
  border-radius: 5px;
  color: white;
  text-align: center;
  pointer-events: all;
}

#spectatorControls button {
  padding: 8px 16px;
  margin: 0 5px;
  border: none;
  border-radius: 3px;
  background: #007bff;
  color: white;
  cursor: pointer;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* Responsive Design */
@media (max-height: 600px) {
  #loginContainer {
    top: 20px;
    transform: translateX(-50%);
    max-height: calc(100vh - 40px);
    gap: 15px;
  }
}

@media (max-width: 600px) {
  #loginContainer {
    max-width: 95vw;
    gap: 15px;
  }
  
  #helpBox {
    min-width: 280px;
    max-width: 90vw;
    padding: 12px 15px;
  }
  
  #helpBox .controls-section:first-child {
    flex-direction: column;
    gap: 8px;
  }
  
  #helpBox .control-item {
    min-width: auto;
    margin: 4px 0;
  }
  
  #joinForm {
    min-width: 280px;
  }
}

@media (max-height: 500px) {
  #loginContainer {
    top: 10px;
    max-height: calc(100vh - 20px);
    gap: 10px;
  }
  
  #helpBox {
    max-height: 25vh;
  }
}

/* Status Alert System */
.status-alert-container {
  position: fixed;
  left: 20px;
  top: 200px; /* Below HUD when present - extra spacing from HUD content */
  z-index: 1000;
  pointer-events: none;
}

.status-alert {
  background: rgba(0, 0, 0, 0.85);
  color: #44aaff;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  border: 1px solid rgba(68, 170, 255, 0.3);
  margin-bottom: 8px;
  transform: translateX(-100%);
  opacity: 0;
  transition: all 0.3s ease-in-out;
}

.status-alert.show {
  transform: translateX(0);
  opacity: 1;
}

.status-alert.hide {
  transform: translateX(-100%);
  opacity: 0;
}

/* Adjust position when no HUD is present */
#ui:not(:has(#hud[style*="display: block"])) .status-alert-container,
#ui:not(:has(#hud:not([style*="display: none"]))) .status-alert-container {
  top: 10px; /* 10px margin from top when HUD is hidden */
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .status-alert-container {
    left: 10px;
    top: 220px; /* Well below HUD on mobile - HUD takes more space on mobile */
  }
  
  .status-alert {
    font-size: 12px;
    padding: 6px 12px;
  }
  
  #ui:not(:has(#hud[style*="display: block"])) .status-alert-container,
  #ui:not(:has(#hud:not([style*="display: none"]))) .status-alert-container {
    top: 10px; /* 10px margin from top on mobile when HUD hidden */
  }
}

/* Countdown Overlay */
#countdownOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  pointer-events: none;
}

.countdown-content {
  text-align: center;
  color: white;
}

.countdown-time {
  font-size: 120px;
  font-weight: bold;
  color: #ff4444;
  text-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
  margin-bottom: 20px;
  font-family: 'Arial Black', Arial, sans-serif;
}

.countdown-message {
  font-size: 28px;
  font-weight: bold;
  color: #ffaa44;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.countdown-subtitle {
  font-size: 20px;
  color: #cccccc;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* Countdown active animation */
.countdown-active .countdown-time {
  animation: countdownPulse 1s infinite ease-in-out;
}

.countdown-active .countdown-content {
  animation: countdownGlow 2s infinite ease-in-out;
}

@keyframes countdownPulse {
  0% { 
    transform: scale(1);
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
  }
  50% { 
    transform: scale(1.1);
    text-shadow: 0 0 40px rgba(255, 68, 68, 1);
  }
  100% { 
    transform: scale(1);
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
  }
}

@keyframes countdownGlow {
  0% { 
    filter: brightness(1);
  }
  50% { 
    filter: brightness(1.3);
  }
  100% { 
    filter: brightness(1);
  }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .countdown-time {
    font-size: 80px;
  }
  
  .countdown-message {
    font-size: 20px;
  }
  
  .countdown-subtitle {
    font-size: 16px;
  }
}

/* Victory Mode Styling */
.victory-mode .countdown-time {
  color: #ffd700 !important; /* Golden color for victory */
  font-size: 150px !important; /* Larger emoji */
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.8) !important;
}

.victory-mode .countdown-message {
  color: #ffd700 !important; /* Golden color for winner text */
  font-size: 32px !important; /* Larger victory message */
  font-weight: bold;
}

.victory-mode .countdown-subtitle {
  color: #ffeb3b !important; /* Bright yellow for "Victory!" */
  font-size: 24px !important;
  font-weight: bold;
}

.victory-mode .countdown-content {
  animation: victoryGlow 2s infinite ease-in-out !important;
}

@keyframes victoryGlow {
  0% { 
    filter: brightness(1) drop-shadow(0 0 20px rgba(255, 215, 0, 0.5));
  }
  50% { 
    filter: brightness(1.4) drop-shadow(0 0 40px rgba(255, 215, 0, 0.8));
  }
  100% { 
    filter: brightness(1) drop-shadow(0 0 20px rgba(255, 215, 0, 0.5));
  }
}

/* Mobile victory styling */
@media (max-width: 768px) {
  .victory-mode .countdown-time {
    font-size: 100px !important;
  }
  
  .victory-mode .countdown-message {
    font-size: 24px !important;
  }
  
  .victory-mode .countdown-subtitle {
    font-size: 18px !important;
  }

  /* Google Sign In button - smaller on mobile */
  #googleSignInBtn {
    padding: 8px 12px !important;
    font-size: 13px !important;
    gap: 8px !important;
  }

  #googleSignInBtn svg {
    width: 16px !important;
    height: 16px !important;
  }

  /* HUD - smaller font and width on mobile */
  #hud {
    font-size: 11px !important;
    min-width: 150px !important;
    padding: 8px !important;
  }

  #playerStats > div {
    margin-bottom: 3px !important;
  }

  #playerStats > div::before {
    margin-right: 6px !important;
    width: 14px !important;
    font-size: 12px !important;
  }

  /* Leaderboard - smaller text and width on mobile */
  #leaderboard {
    min-width: 150px !important;
    padding: 8px !important;
    font-size: 11px !important;
  }

  #leaderboard h3 {
    font-size: 13px !important;
    margin-bottom: 6px !important;
  }

  .leaderboard-entry {
    padding: 2px 0 !important;
  }

  .leaderboard-entry .rank {
    margin-right: 6px !important;
    font-size: 11px !important;
  }

  .leaderboard-entry .name {
    font-size: 11px !important;
  }

  .leaderboard-entry .level {
    font-size: 10px !important;
  }
}
