body { 
  margin: 0; 
  overflow: hidden; 
  background: #000; 
}

canvas { 
  display: block; 
}

/* Settings screen overlay */
#settingsScreen {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(78, 5, 131, 0.85);
  padding: 25px;
  border-radius: 10px;
  border: 2px solid #ff77ff;
  box-shadow: 0 0 30px rgba(255, 119, 255, 0.6);
  z-index: 200;
  display: none;
  font-family: sans-serif;
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  width: 320px;
  box-sizing: border-box;
}

#settingsScreen h2 { 
  margin-top: 0;
  font-size: 24px;
  text-align: center;
  margin-bottom: 20px;
  color: #ff77ff;
}

#settingsScreen label { 
  display: block; 
  margin: 10px 0 5px; 
  font-size: 16px;
}

.hidden-file-input {
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  z-index: -1;
}

.neon-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 15px 0;
  padding: 12px;
  background: rgba(255, 119, 255, 0.2);
  border: 2px solid #ff77ff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  transition: all 0.3s ease;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
}

.neon-upload-btn:hover {
  background: rgba(255, 119, 255, 0.4);
  box-shadow: 0 0 20px rgba(255, 119, 255, 0.6);
  text-shadow: 0 0 8px #ff77ff;
}

.upload-icon {
  font-size: 24px;
  margin-right: 10px;
}

.upload-text {
  font-weight: bold;
  letter-spacing: 1px;
}

.song-name {
  text-align: center;
  margin: 10px 0;
  padding: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  border: 1px solid rgba(255, 119, 255, 0.3);
  font-style: italic;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
}

.music-upload {
  margin-bottom: 20px;
}

.settings-option {
  margin: 15px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-option--column {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.settings-select {
  width: 100%;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid rgba(255, 119, 255, 0.4);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 0 10px rgba(255, 119, 255, 0.2) inset;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.settings-select:focus {
  outline: none;
  border-color: #ff77ff;
  box-shadow: 0 0 12px rgba(255, 119, 255, 0.6);
}

.settings-hint {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: none;
}

#closeSettingsButton {
  display: block;
  margin: 20px auto 0;
  padding: 8px 20px;
  background: rgba(255, 119, 255, 0.2);
  border: 2px solid #ff77ff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  transition: all 0.3s ease;
}

#closeSettingsButton:hover {
  background: rgba(255, 119, 255, 0.4);
  box-shadow: 0 0 15px #ff77ff;
}

#settingsScreen input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #ff77ff;
}

#fpsCounter {
  position: fixed;
  top: 10px;
  right: 10px;
  background: rgba(78, 5, 131, 0.7);
  color: #ff77ff;
  font-family: monospace;
  padding: 5px 10px;
  border-radius: 5px;
  border: 1px solid #ff77ff;
  box-shadow: 0 0 10px rgba(255, 119, 255, 0.5);
  font-size: 14px;
  z-index: 100;
  display: none;
  text-shadow: 0 0 3px #ff77ff;
}

#settingsButton, #startButton {
  position: absolute;
  z-index: 100;
  padding: 10px 20px;
  background: rgba(255,119,255,0.2);
  border: 2px solid #ff77ff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  transition: all 0.3s ease;
  font-family: sans-serif;
}

#settingsButton:hover, #startButton:hover {
  background: rgba(255,119,255,0.4);
  box-shadow: 0 0 15px #ff77ff;
}

#settingsButton {
  top: 10px;
  right: 10px;
}

#startButton {
  bottom: 20px;
  right: 20px;
  font-weight: bold;
}

/* Race UI */
#raceUI {
  position: fixed;
  top: 20px; 
  left: 20px; 
  background: rgba(255,119,255,0.2); 
  padding: 15px; 
  border-radius: 10px; 
  font-family: sans-serif; 
  color: #fff; 
  text-shadow: 0 0 5px #ff77ff;
  width: 220px;
  z-index: 101;
}

#gameOverScreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  z-index: 1000;
  font-family: sans-serif;
  color: #fff;
  text-shadow: 0 0 12px #ff77ff;
  pointer-events: none;
}

.game-over-content {
  background: rgba(78, 5, 131, 0.9);
  border: 2px solid #ff77ff;
  border-radius: 12px;
  padding: 30px 40px;
  box-shadow: 0 0 30px rgba(255, 119, 255, 0.6);
  text-align: center;
  max-width: 420px;
  width: 90%;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-over-content h2 {
  margin: 0 0 20px;
  font-size: 32px;
}

#backToMenuButton,
#playAgainButton,
#characterSelectButton,
#exitMatchButton {
  padding: 12px 24px;
  background: rgba(255,119,255,0.25);
  border: 2px solid #ff77ff;
  border-radius: 6px;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  text-shadow: 0 0 5px #ff77ff;
  transition: all 0.3s ease;
  font-family: sans-serif;
  width: 100%;
  box-sizing: border-box;
}

#backToMenuButton:hover,
#playAgainButton:hover,
#characterSelectButton:hover,
#exitMatchButton:hover {
  background: rgba(255,119,255,0.45);
  box-shadow: 0 0 20px #ff77ff;
}

#countdown {
  font-size: 72px; 
  text-align: center; 
  display: none; 
}

#status {
  font-size: 24px; 
  margin-bottom: 10px; 
}

.victory-text {
  color: gold;
  text-shadow: 0 0 10px #ffff00;
  font-weight: bold;
}

.victory-animation {
  animation: victory-pulse 0.6s infinite alternate;
}

@keyframes victory-pulse {
  0% {
    transform: scale(1);
    text-shadow: 0 0 10px #ffff00;
  }
  100% {
    transform: scale(1.1);
    text-shadow: 0 0 20px #ffff00, 0 0 30px #ff00ff;
  }
}

#lapTime {
  font-size: 36px; 
  font-family: monospace; 
}

#lapCounter {
  margin-top: 10px;
  font-size: 18px;
}

#positionInfo {
  margin-top: 10px;
  font-size: 18px;
}

#leaderboard {
  margin-top: 10px;
  font-size: 16px;
  line-height: 1.4;
}

#powerUpStatus {
  margin-top: 10px;
  font-size: 18px;
  color: #ff77ff;
  text-shadow: 0 0 5px #ff77ff;
}

#controls-info {
  margin-top: 20px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  border-top: 1px solid rgba(255, 119, 255, 0.3);
  padding-top: 10px;
}

/* Stage Select Screen */
#stageSelectScreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('../assets/images/char_select_bg.png') no-repeat center center/cover;
  display: none;
  z-index: 999;
  text-align: center;
  font-family: sans-serif;
  color: #fff;
  overflow-y: auto;
  overflow-x: hidden;
}

#stageSelectScreen h2 {
  margin: 20px;
  font-size: 32px;
  text-shadow: 0 0 5px #ff77ff;
}

.stage-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 800px;
  margin: 40px auto;
  gap: 30px;
  padding: 0 20px;
}

.stage-option {
  width: 300px;
  height: 180px;
  background: rgba(255, 119, 255, 0.2);
  border: 3px solid #ff77ff;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.3s;
  box-shadow: 0 0 15px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
}

.stage-option:hover {
  background: rgba(255,119,255,0.4);
  box-shadow: 0 0 25px #ff77ff;
  transform: translateY(-5px);
}

.stage-option.selected {
  box-shadow: 0 0 30px #00ff00, 0 0 15px #ff77ff inset;
  border-color: #00ff00;
  background: rgba(0, 255, 0, 0.15);
}

.stage-option.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.stage-option.disabled:hover {
  transform: none;
  box-shadow: 0 0 15px rgba(0,0,0,0.3);
}

.stage-name {
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 15px;
  text-shadow: 0 0 8px #ff77ff;
}

.stage-description {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 0 3px #ff77ff;
}

#confirmStageButton {
  margin-top: 40px;
  margin-bottom: 20px;
  padding: 12px 24px;
  font-size: 20px;
  background: rgba(255,119,255,0.2);
  border: 2px solid #ff77ff;
  border-radius: 4px;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  transition: 0.3s;
}

#confirmStageButton:hover {
  background: rgba(255,119,255,0.4);
  box-shadow: 0 0 15px #ff77ff;
}

#confirmStageButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(128, 128, 128, 0.2);
  border-color: #aaa;
}

#stageSelectStatus {
  margin-top: 20px;
  font-style: italic;
  color: #eee;
  text-shadow: 0 0 3px #ff77ff;
}

/* Character Select Screen */
#characterSelectScreen {
  position: fixed;
  top: 0; 
  left: 0;
  width: 100%; 
  height: 100%;
  background: url('../assets/images/char_select_bg.png') no-repeat center center/cover;
  display: none;
  z-index: 999;
  text-align: center;
  font-family: sans-serif;
  color: #fff;
  overflow-y: auto;
  overflow-x: hidden;
}

#characterSelectScreen h2 {
  margin: 20px;
  font-size: 32px;
  text-shadow: 0 0 5px #ff77ff;
}

.character-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 1000px;
  margin: 20px auto;
  gap: 20px;
  padding: 0 20px;
}

.character-option {
  width: 150px;
  height: 220px;
  background: rgba(255, 119, 255, 0.2);
  border: 2px solid #ff77ff;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.3s;
  box-shadow: 0 0 10px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.character-option img {
  width: 100%;
  height: 180px;
  object-fit: contain;
  object-position: center;
  border-bottom: 2px solid #ff77ff;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  padding: 10px;
  box-sizing: border-box;
}

.character-option span {
  display: block;
  padding: 10px 0;
  font-size: 18px;
  text-shadow: 0 0 2px #ff77ff;
}

.character-option:hover {
  background: rgba(255,119,255,0.4);
  box-shadow: 0 0 20px #ff77ff;
}

.character-option.selected {
  box-shadow: 0 0 20px #00ff00, 0 0 10px #ff77ff inset;
  border-color: #00ff00; 
}

#confirmCharacterButton {
  margin-top: 40px;
  margin-bottom: 20px;
  padding: 12px 24px;
  font-size: 20px;
  background: rgba(255,119,255,0.2);
  border: 2px solid #ff77ff;
  border-radius: 4px;
  cursor: pointer;
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  transition: 0.3s;
}

#confirmCharacterButton:hover {
  background: rgba(255,119,255,0.4);
  box-shadow: 0 0 15px #ff77ff;
}

/* Custom Character Upload */
.custom-upload-option {
  position: relative;
  cursor: pointer;
}

.custom-upload-option .question-mark {
  width: 100%;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 72px;
  font-weight: bold;
  color: #ff77ff;
  text-shadow: 0 0 10px #ff77ff;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 2px solid #ff77ff;
  box-sizing: border-box;
}

.custom-upload-option img {
  object-fit: cover; 
  height: 180px;
}

.custom-upload-option:hover .question-mark {
  background: rgba(255, 119, 255, 0.15);
}

/* --- Multiplayer UI Styles --- */
#modeSelection {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 150; /* Above game, below settings/char select */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  background: rgba(78, 5, 131, 0.8);
  padding: 30px;
  border-radius: 10px;
  border: 2px solid #ff77ff;
  box-shadow: 0 0 20px rgba(255, 119, 255, 0.5);
}

#modeSelection button,
#multiplayerLobby button {
  padding: 10px 20px;
  background: rgba(255,119,255,0.2);
  border: 2px solid #ff77ff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  transition: all 0.3s ease;
  font-family: sans-serif;
  min-width: 150px; /* Ensure buttons have some width */
}

#modeSelection button:hover,
#multiplayerLobby button:hover:not(:disabled) {
  background: rgba(255,119,255,0.4);
  box-shadow: 0 0 15px #ff77ff;
}

#multiplayerLobby button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(128, 128, 128, 0.2);
  border-color: #aaa;
  text-shadow: none;
}


#joinGameSection {
  display: flex;
  gap: 10px;
  align-items: center;
}

.host-share-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-size: 14px;
  text-align: left;
}

.host-share-row:first-of-type {
  margin-top: 0;
}

.host-share-label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  flex-wrap: wrap;
}

.host-share-value {
  flex: 1;
  overflow-wrap: anywhere;
}

#hostIdInput {
  padding: 8px 12px;
  border: 2px solid #ff77ff;
  background: rgba(0,0,0,0.3);
  color: #fff;
  border-radius: 4px;
  font-size: 14px;
  text-shadow: 0 0 3px #ff77ff;
}

#hostIdInput::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

#multiplayerLobby {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 150;
  background: rgba(78, 5, 131, 0.9);
  padding: 25px;
  border-radius: 10px;
  border: 2px solid #ff77ff;
  box-shadow: 0 0 30px rgba(255, 119, 255, 0.6);
  color: #fff;
  text-shadow: 0 0 5px #ff77ff;
  font-family: sans-serif;
  width: 400px;
  max-width: 90%;
  box-sizing: border-box;
  text-align: center;
}

#multiplayerLobby h2 {
  margin-top: 0;
  color: #ff77ff;
}

#multiplayerLobby h3 {
  margin-top: 20px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255, 119, 255, 0.4);
  padding-bottom: 5px;
}

#lobbyStatus {
  margin-bottom: 15px;
  font-style: italic;
  color: #eee;
}

#hostIdDisplay {
  margin-bottom: 15px;
  background: rgba(0,0,0,0.2);
  padding: 8px;
  border-radius: 4px;
}

#hostIdDisplay span {
  font-weight: bold;
  color: #00ffff; /* Cyan for ID */
  margin-right: 10px;
  word-break: break-all; /* Prevent long IDs from overflowing */
}

#copyHostIdButton {
  padding: 3px 8px;
  font-size: 12px;
  min-width: auto;
}

#playerList {
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
  max-height: 150px;
  overflow-y: auto;
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
  border: 1px solid rgba(255, 119, 255, 0.2);
}

#playerList li {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 119, 255, 0.1);
  font-size: 14px;
  color: #eee;
  word-break: break-all;
}

#playerList li:last-child {
  border-bottom: none;
}

#startMultiplayerRaceButton {
  margin-top: 15px;
}

/* Mobile Touch Controls */
#mobileControls {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 40%;
  pointer-events: none;
  z-index: 500;
}

#leftControls {
  position: absolute;
  bottom: 30px;
  left: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  pointer-events: auto;
}

#steeringButtons {
  display: flex;
  gap: 15px;
}

.steering-btn {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  background: rgba(255, 119, 255, 0.3);
  border: 3px solid #ff77ff;
  color: #fff;
  font-size: 36px;
  font-weight: bold;
  text-shadow: 0 0 5px #ff77ff;
  box-shadow: 0 0 15px rgba(255, 119, 255, 0.4);
  cursor: pointer;
  transition: all 0.1s ease;
  font-family: sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.steering-btn:active {
  background: rgba(255, 119, 255, 0.7);
  box-shadow: 0 0 25px #ff77ff;
  transform: scale(0.95);
}

#rightControls {
  position: absolute;
  bottom: 30px;
  right: 30px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  pointer-events: auto;
}

.action-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(255, 119, 255, 0.3);
  border: 3px solid #ff77ff;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  text-shadow: 0 0 5px #ff77ff;
  box-shadow: 0 0 15px rgba(255, 119, 255, 0.4);
  cursor: pointer;
  transition: all 0.1s ease;
  font-family: sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
  background: rgba(255, 119, 255, 0.7);
  box-shadow: 0 0 25px #ff77ff;
  transform: scale(0.95);
}

#accelerateButton {
  width: 100px;
  height: 100px;
  font-size: 16px;
}

#powerUpButton {
  width: 70px;
  height: 70px;
  font-size: 12px;
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
  #raceUI {
    top: 5px;
    left: 5px;
    transform: none;
    width: auto;
    max-width: 180px;
    padding: 6px 8px;
    font-size: 12px;
  }

  #lapTime {
    font-size: 20px !important;
  }

  #status {
    font-size: 14px !important;
    margin-bottom: 4px !important;
  }

  #lapCounter,
  #positionInfo {
    font-size: 12px !important;
    margin-top: 4px !important;
  }

  #powerUpStatus {
    font-size: 12px !important;
    margin-top: 4px !important;
  }

  #leaderboard {
    font-size: 11px !important;
    margin-top: 4px !important;
    line-height: 1.2 !important;
  }

  #countdown {
    font-size: 48px !important;
  }

  #settingsButton {
    top: 10px;
    right: 10px;
    padding: 8px 16px;
    font-size: 14px;
  }

  #fpsCounter {
    top: 10px;
    left: 10px;
    right: auto;
    font-size: 12px;
  }

  #characterSelectScreen h2 {
    margin: 10px 10px 8px;
    font-size: 22px;
  }

  .character-grid {
    gap: 12px;
    padding: 0 10px 15px;
    margin: 8px auto 8px;
  }

  .character-option {
    width: 105px;
    height: 155px;
  }

  .character-option img {
    height: 120px;
    padding: 5px;
  }

  .character-option span {
    font-size: 15px;
    padding: 6px 0;
  }

  #confirmCharacterButton {
    margin-top: 15px;
    margin-bottom: 80px;
    padding: 10px 20px;
    font-size: 17px;
  }

  #modeSelection {
    width: 90%;
    max-width: 350px;
    padding: 20px;
  }

  #multiplayerLobby {
    width: 90%;
    max-width: 350px;
    padding: 20px;
  }

  #controls-info {
    display: none;
  }
}

@media (max-width: 480px) {
  #raceUI {
    top: 3px;
    left: 3px;
    max-width: 160px;
    padding: 5px 6px;
    font-size: 11px;
  }

  #lapTime {
    font-size: 18px !important;
  }

  #status {
    font-size: 12px !important;
    margin-bottom: 3px !important;
  }

  #lapCounter,
  #positionInfo {
    font-size: 11px !important;
    margin-top: 3px !important;
  }

  #powerUpStatus {
    font-size: 11px !important;
    margin-top: 3px !important;
  }

  #leaderboard {
    font-size: 10px !important;
    margin-top: 3px !important;
    line-height: 1.15 !important;
  }

  #countdown {
    font-size: 40px !important;
  }

  #leftControls {
    bottom: 20px;
    left: 20px;
    gap: 10px;
  }

  #steeringButtons {
    gap: 10px;
  }

  .steering-btn {
    width: 70px;
    height: 70px;
    font-size: 30px;
  }

  #rightControls {
    bottom: 20px;
    right: 20px;
    gap: 10px;
  }

  .action-btn {
    width: 70px;
    height: 70px;
    font-size: 12px;
  }

  #accelerateButton {
    width: 85px;
    height: 85px;
    font-size: 14px;
  }

  #powerUpButton {
    width: 60px;
    height: 60px;
    font-size: 11px;
  }

  #characterSelectScreen h2 {
    margin: 8px 5px 5px;
    font-size: 20px;
  }

  .character-grid {
    gap: 8px;
    padding: 0 5px 10px;
    margin: 5px auto 5px;
  }

  .character-option {
    width: 90px;
    height: 140px;
  }

  .character-option img {
    height: 105px;
    padding: 3px;
  }

  .character-option span {
    font-size: 13px;
    padding: 5px 0;
  }

  #confirmCharacterButton {
    margin-top: 10px;
    margin-bottom: 100px;
    padding: 9px 16px;
    font-size: 15px;
  }
}
