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

body {
  background: #0a0a1a;
  color: #e0e0ff;
  font-family: 'Press Start 2P', monospace;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Scanline overlay */
#scanlines {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

/* Screens */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.screen.active {
  display: flex;
}

/* Main menu */
#menuScreen {
  background: transparent;
}

#menuBgCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.btn-wipe {
  position: absolute;
  bottom: 1.2rem;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.4rem, 1.2vw, 0.55rem);
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid #333366;
  color: #555580;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-wipe:hover, .btn-wipe:active {
  border-color: #ff3030;
  color: #ff3030;
}

/* Install app button */
.btn-install {
  position: absolute;
  bottom: 3.5rem;
  right: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  background: rgba(0, 200, 255, 0.08);
  border: 2px solid #00c8ff;
  border-radius: 10px;
  color: #00ffcc;
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.45rem, 1.3vw, 0.6rem);
  animation: installPulse 2.5s ease-in-out infinite;
  transition: background 0.15s;
}
.btn-install:active {
  background: rgba(0, 200, 255, 0.2);
}
.btn-install-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
}
.btn-install-text {
  line-height: 1.4;
}
@keyframes installPulse {
  0%, 100% { border-color: #00c8ff; box-shadow: 0 0 6px rgba(0, 200, 255, 0.3); }
  50% { border-color: #00ffcc; box-shadow: 0 0 14px rgba(0, 255, 200, 0.5); }
}

/* iOS install banner */
.ios-install-banner {
  position: absolute;
  bottom: 3.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: rgba(0, 20, 40, 0.92);
  border: 2px solid #00c8ff;
  border-radius: 10px;
  color: #00ffcc;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.4rem, 1.2vw, 0.55rem);
  line-height: 1.6;
  animation: installPulse 2.5s ease-in-out infinite;
  white-space: nowrap;
  z-index: 10;
}
.ios-install-banner b { color: #fff; }
.ios-install-dismiss {
  position: absolute;
  top: -0.5rem;
  right: -0.5rem;
  width: 1.4rem;
  height: 1.4rem;
  background: #00c8ff;
  color: #000;
  border: none;
  border-radius: 50%;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ios-share-icon { vertical-align: middle; }

.title {
  font-size: clamp(1.8rem, 6vw, 3.5rem);
  letter-spacing: 0.15em;
  margin-bottom: 3rem;
  text-shadow: 0 0 20px rgba(0, 200, 255, 0.6), 0 0 40px rgba(0, 200, 255, 0.3), 0 0 80px rgba(0, 200, 255, 0.15);
  animation: titleSlideIn 0.8s ease-out;
  position: relative;
}

@keyframes titlePulse {
  0%, 100% { text-shadow: 0 0 20px rgba(0, 200, 255, 0.6), 0 0 40px rgba(0, 200, 255, 0.3), 0 0 80px rgba(0, 200, 255, 0.15); }
  50% { text-shadow: 0 0 30px rgba(0, 200, 255, 0.8), 0 0 60px rgba(0, 200, 255, 0.4), 0 0 100px rgba(0, 200, 255, 0.2); }
}

@keyframes titleSlideIn {
  0% { transform: translateY(-20px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.accent {
  color: #ff3077;
  text-shadow: 0 0 20px rgba(255, 48, 119, 0.6), 0 0 40px rgba(255, 48, 119, 0.3), 0 0 80px rgba(255, 48, 119, 0.15);
  animation: titleSlideIn 0.8s ease-out;
}

@keyframes accentPulse {
  0%, 100% { text-shadow: 0 0 20px rgba(255, 48, 119, 0.6), 0 0 40px rgba(255, 48, 119, 0.3); }
  50% { text-shadow: 0 0 30px rgba(255, 48, 119, 0.9), 0 0 60px rgba(255, 48, 119, 0.5), 0 0 100px rgba(255, 48, 119, 0.2); }
}

.instructions {
  margin-bottom: 2.5rem;
  text-align: center;
  opacity: 0.85;
}

.instructions p {
  font-size: clamp(0.55rem, 1.8vw, 0.75rem);
  line-height: 2;
  color: #b0b0d0;
  margin: 0.4rem 0;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.menu-buttons .btn {
  background: rgba(0, 0, 0, 0.50);
}

.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.7rem, 2vw, 1rem);
  padding: 1rem 2rem;
  background: transparent;
  border: 2px solid #00c8ff;
  color: #00c8ff;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 220px;
  text-align: center;
}

.btn:hover, .btn:active {
  background: #00c8ff;
  color: #0a0a1a;
  box-shadow: 0 0 20px rgba(0, 200, 255, 0.4);
}

.btn-small {
  font-size: clamp(0.5rem, 1.5vw, 0.7rem);
  padding: 0.7rem 1.5rem;
  min-width: auto;
  margin-top: 1.5rem;
}

/* Lobby screen */
#lobbyScreen {
  background: radial-gradient(ellipse at center, rgba(26, 26, 58, 0.85) 0%, rgba(10, 10, 26, 0.9) 70%);
  gap: 1rem;
}

#lobbyScreen h2 {
  font-size: clamp(0.7rem, 2.5vw, 1.1rem);
  color: #a0a0d0;
}

.lobby-link {
  background: #12122a;
  border: 1px solid #333366;
  padding: 0.8rem 1.2rem;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lobby-link:hover, .lobby-link:active {
  border-color: #00c8ff;
}

#lobbyUrl {
  font-size: clamp(0.45rem, 1.5vw, 0.7rem);
  color: #00c8ff;
  word-break: break-all;
}

.copied-msg {
  font-size: 0.6rem;
  color: #50ff50;
  opacity: 0;
  transition: opacity 0.3s;
}

.copied-msg.show {
  opacity: 1;
}

.player-list {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.player-entry {
  font-size: clamp(0.5rem, 1.5vw, 0.7rem);
}

.player-entry.you {
  color: #00c8ff;
}

.player-entry.waiting {
  color: #555580;
}

.player-entry.joined {
  color: #ff3077;
}

.player-entry.p0 { color: #00c8ff; }
.player-entry.p1 { color: #ff3077; }
.player-entry.p2 { color: #ffcc00; }
.player-entry.p3 { color: #50ff50; }
.player-entry.p4 { color: #cc66ff; }

.btn-start-game {
  background: rgba(80, 255, 80, 0.08);
  border-color: #50ff50;
  color: #50ff50;
  animation: startPulse 1.5s ease-in-out infinite;
}

.btn-start-game:hover, .btn-start-game:active {
  background: #50ff50;
  color: #0a0a1a;
  box-shadow: 0 0 20px rgba(80, 255, 80, 0.4);
}

@keyframes startPulse {
  0%, 100% { box-shadow: 0 0 5px rgba(80, 255, 80, 0.2); }
  50% { box-shadow: 0 0 15px rgba(80, 255, 80, 0.5); }
}

.countdown {
  font-size: clamp(1rem, 4vw, 2rem);
  color: #ffcc00;
  text-shadow: 0 0 15px rgba(255, 204, 0, 0.5);
  min-height: 2.5rem;
}

/* Options screen */
#optionsScreen {
  background: radial-gradient(ellipse at center, #1a1a3a 0%, #0a0a1a 70%);
  gap: 0;
}

#optionsScreen h2 {
  font-size: clamp(0.8rem, 2.8vw, 1.2rem);
  color: #a0a0d0;
  margin-bottom: 3rem;
}

.options-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  min-width: 260px;
  margin-bottom: 2.5rem;
}

#optionsScreen .btn-small {
  margin-top: 1.5rem;
}

.options-label {
  font-size: clamp(0.5rem, 1.6vw, 0.7rem);
  color: #8080a0;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.options-slider-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.options-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 12px;
  background: #1a1a3a;
  border: 1px solid #333366;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}

.options-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #00c8ff;
  border: 2px solid #0af;
  box-shadow: 0 0 8px rgba(0, 200, 255, 0.4);
  cursor: pointer;
  margin-top: -5px;
}

.options-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #00c8ff;
  border: 2px solid #0af;
  box-shadow: 0 0 8px rgba(0, 200, 255, 0.4);
  cursor: pointer;
}

.options-slider::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 6px;
}

.options-slider::-moz-range-track {
  height: 12px;
  background: #1a1a3a;
  border: 1px solid #333366;
  border-radius: 6px;
}

.options-value {
  font-size: clamp(0.5rem, 1.6vw, 0.7rem);
  color: #00c8ff;
  min-width: 3.5em;
  text-align: right;
}

/* Name input */
.options-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-name-action {
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
}

.name-input-group,
.name-display-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.name-input-group.hidden,
.name-display-group.hidden,
.btn-name-action.hidden {
  display: none;
}

.name-input {
  font-family: inherit;
  font-size: clamp(0.5rem, 1.6vw, 0.7rem);
  background: #0a0a1a;
  border: 1px solid #333366;
  border-radius: 4px;
  color: #e0e0ff;
  padding: 0.3em 0.5em;
  width: 9em;
  outline: none;
}

.name-input:focus {
  border-color: #00c8ff;
  box-shadow: 0 0 6px rgba(0, 200, 255, 0.3);
}

.name-display {
  font-size: clamp(0.5rem, 1.6vw, 0.7rem);
  color: #00c8ff;
  letter-spacing: 0.05em;
}

.btn-icon {
  background: none;
  border: 1px solid #333366;
  border-radius: 4px;
  color: #00c8ff;
  font-size: clamp(0.6rem, 1.8vw, 0.8rem);
  cursor: pointer;
  padding: 0.15em 0.4em;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}

.btn-icon:hover {
  border-color: #00c8ff;
}

.btn-icon-danger {
  color: #ff4466;
}

.btn-icon-danger:hover {
  border-color: #ff4466;
}

/* Join Lobby screen */
#joinScreen {
  background: radial-gradient(ellipse at center, #1a1a3a 0%, #0a0a1a 70%);
  gap: 1rem;
}

#joinScreen h2 {
  font-size: clamp(0.8rem, 2.8vw, 1.2rem);
  color: #a0a0d0;
}

.join-code-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.join-label {
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
  color: #8080a0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.join-code-row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.join-code-input {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.6rem, 1.8vw, 0.8rem);
  padding: 0.7rem 1rem;
  width: 180px;
  text-align: center;
  background: #12122a;
  border: 2px solid #333366;
  color: #00c8ff;
  border-radius: 4px;
  outline: none;
  text-transform: lowercase;
  letter-spacing: 0.15em;
}

.btn-join-code {
  font-size: clamp(0.55rem, 1.6vw, 0.7rem);
  padding: 0.7rem 1.2rem;
  min-width: auto;
}

.join-code-input:focus {
  border-color: #00c8ff;
  box-shadow: 0 0 10px rgba(0, 200, 255, 0.3);
}

.join-code-input::placeholder {
  color: #333366;
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
}

.join-divider {
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
  color: #555580;
  margin: 0.3rem 0;
}

.join-lobby-list-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.join-lobby-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 280px;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.5rem;
  background: #12122a;
  border: 1px solid #333366;
  border-radius: 4px;
}

.join-lobby-empty {
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
  color: #555580;
  text-align: center;
  padding: 0.8rem 0;
}

.join-lobby-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.7rem;
  background: rgba(0, 200, 255, 0.05);
  border: 1px solid #333366;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.join-lobby-item:hover, .join-lobby-item:active {
  border-color: #00c8ff;
  background: rgba(0, 200, 255, 0.1);
}

.join-lobby-code {
  font-size: clamp(0.5rem, 1.6vw, 0.7rem);
  color: #00c8ff;
  letter-spacing: 0.1em;
}

.join-lobby-players {
  font-size: clamp(0.4rem, 1.2vw, 0.55rem);
  color: #8080a0;
}

/* HUD */
#hud {
  pointer-events: none;
  justify-content: space-between;
  padding: 1rem;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  font-size: clamp(0.55rem, 1.8vw, 0.85rem);
}

.hud-top-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  pointer-events: auto;
}

.hud-controls-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
}

.hud-lower-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.8rem;
}

.hud-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.8rem;
}

#sessionTimer {
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4), 0 0 4px #000, 0 1px 3px #000;
}

#speedDisplay {
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4), 0 0 4px #000, 0 1px 3px #000;
}

/* Top-right HUD area */
.hud-top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  padding-top: calc(clamp(36px, 8vw, 48px) + 0.8rem);
}

/* Time list (top-right) */
.time-list {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  font-size: clamp(0.55rem, 1.8vw, 0.85rem);
  max-height: 40vh;
  overflow: hidden;
}

.time-entry {
  opacity: 0.7;
  color: #a0a0d0;
}

.time-entry.pb {
  opacity: 1;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
  font-weight: bold;
}

.time-entry.best {
  color: #50ff50;
  text-shadow: 0 0 8px rgba(80, 255, 80, 0.4);
  opacity: 1;
}

/* Run complete flash overlay */
.run-flash {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(1.2rem, 5vw, 2.5rem);
  color: #50ff50;
  text-shadow: 0 0 30px rgba(80, 255, 80, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
}

.run-flash.visible {
  opacity: 1;
  animation: flashPulse 0.5s ease-out;
}

.run-flash.new-best {
  color: #ffcc00;
  text-shadow: 0 0 30px rgba(255, 204, 0, 0.8);
}

@keyframes flashPulse {
  0% { transform: translate(-50%, -50%) scale(1.4); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Nitro bar is now in hud-top-left, no hud-bottom needed */

.btn-pause {
  font-family: Arial, sans-serif;
  font-size: clamp(1rem, 2.8vw, 1.3rem);
  width: clamp(36px, 8vw, 48px);
  height: clamp(36px, 8vw, 48px);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.7);
  border: 2px solid #555580;
  border-radius: 6px;
  color: #8080a0;
  cursor: pointer;
  transition: all 0.15s;
  pointer-events: auto;
  letter-spacing: 0.1em;
  line-height: 1;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

.btn-pause:hover, .btn-pause:active {
  border-color: #00c8ff;
  color: #00c8ff;
}

/* Fullscreen button */
.btn-fullscreen {
  font-family: Arial, sans-serif;
  font-size: 0;
  width: clamp(36px, 8vw, 48px);
  height: clamp(36px, 8vw, 48px);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.7);
  border: 2px solid #555580;
  border-radius: 6px;
  color: #8080a0;
  cursor: pointer;
  transition: all 0.15s;
  pointer-events: auto;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

.btn-fullscreen::before {
  content: '';
  display: block;
  width: 16px;
  height: 12px;
  border: 2px solid currentColor;
}

.btn-fullscreen:hover, .btn-fullscreen:active {
  border-color: #00c8ff;
  color: #00c8ff;
}

.btn-fullscreen-global {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
}

/* Multiplayer scoreboard */
.mp-scoreboard {
  display: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  font-size: clamp(0.5rem, 1.5vw, 0.7rem);
  margin-top: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: rgba(10, 10, 26, 0.5);
  border: 1px solid #333366;
  border-radius: 4px;
}

.mp-scoreboard.visible {
  display: flex;
}

.mp-score {
  white-space: nowrap;
}

.mp-score.p0 { color: #00c8ff; }
.mp-score.p1 { color: #ff3077; }
.mp-score.p2 { color: #ffcc00; }
.mp-score.p3 { color: #50ff50; }
.mp-score.p4 { color: #cc66ff; }

/* Pause popup overlay */
.pause-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 26, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: auto;
}

.pause-overlay.hidden {
  display: none;
}

.pause-popup {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 2rem;
}

.btn-pause-action {
  min-width: 260px;
  font-size: clamp(0.8rem, 2.5vw, 1.1rem);
  padding: 1.2rem 2.5rem;
}

.nitro-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nitro-label {
  font-size: clamp(0.55rem, 1.6vw, 0.8rem);
  color: #ff3077;
  text-shadow: 0 0 8px rgba(255, 48, 119, 0.4);
}

.nitro-bar-bg {
  position: relative;
  width: 160px;
  height: clamp(28px, 6vw, 42px);
  background: #1a1a3a;
  border: 1px solid #333366;
  border-radius: 2px;
  overflow: hidden;
  transition: border-color 0.1s, box-shadow 0.1s;
}

.nitro-bar-text {
  position: absolute;
  top: 0;
  white-space: nowrap;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.5rem, 2.5vw, 1.1rem);
  color: #fff;
  text-shadow: 0 0 4px rgba(255, 48, 119, 0.6);
  pointer-events: none;
}

.nitro-bar-bg.warn {
  border-color: #ffcc00;
  box-shadow: 0 0 12px rgba(255, 204, 0, 0.6), inset 0 0 8px rgba(255, 204, 0, 0.15);
}

.nitro-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff3077, #ff6b3d);
  transition: width 0.1s linear;
  box-shadow: 0 0 8px rgba(255, 48, 119, 0.4);
}

.nitro-bar-fill.charging {
  background: linear-gradient(90deg, #553040, #554030);
  box-shadow: none;
}

.nitro-bar-fill.ready {
  animation: nitroPulse 0.8s ease-in-out infinite;
}

@keyframes nitroPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(255, 48, 119, 0.4); }
  50% { box-shadow: 0 0 20px rgba(255, 48, 119, 0.8); }
}

.race-countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(2rem, 10vw, 5rem);
  color: #ffcc00;
  text-shadow: 0 0 30px rgba(255, 204, 0, 0.6);
}

/* End screen */
#endScreen {
  background: rgba(10, 10, 26, 0.92);
  gap: 1.5rem;
}

#endTitle {
  font-size: clamp(1rem, 4vw, 2rem);
}

#endTitle.win {
  color: #50ff50;
  text-shadow: 0 0 20px rgba(80, 255, 80, 0.5);
}

#endTitle.lose {
  color: #ff3030;
  text-shadow: 0 0 20px rgba(255, 48, 48, 0.5);
}

#endTime {
  font-size: clamp(0.6rem, 2vw, 0.9rem);
  color: #a0a0d0;
}

.end-rankings {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: clamp(0.55rem, 1.8vw, 0.8rem);
  padding: 0.6rem 1rem;
  background: rgba(10, 10, 40, 0.5);
  border: 1px solid #333366;
  border-radius: 4px;
  min-width: 200px;
}

.end-ranking-row {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  white-space: nowrap;
}

.end-ranking-row.is-me {
  font-weight: bold;
}

.end-ranking-pos {
  opacity: 0.6;
  margin-right: 0.3rem;
}

.end-ranking-row.p0 { color: #00c8ff; }
.end-ranking-row.p1 { color: #ff3077; }
.end-ranking-row.p2 { color: #ffcc00; }
.end-ranking-row.p3 { color: #50ff50; }
.end-ranking-row.p4 { color: #cc66ff; }

/* Touch controls (mobile steer + nitro) */
.touch-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px 16px 16px;
  pointer-events: auto;
  z-index: 50;
}

#hud.active .touch-controls.touch-enabled {
  display: flex;
}

/* Mode visibility: buttons */
.touch-controls.mode-buttons .touch-left-buttons { display: flex; }
.touch-controls.mode-buttons .touch-left-joystick { display: none; }

/* Mode visibility: joystick */
.touch-controls.mode-joystick .touch-left-buttons { display: none; }
.touch-controls.mode-joystick .touch-left-joystick { display: flex; }

.touch-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.touch-steer-row {
  display: flex;
  gap: 12px;
  touch-action: none;
}

.btn-steer {
  width: 100px;
  height: 100px;
  border-radius: 10px;
  background: rgba(0, 200, 255, 0.1);
  border: 3px solid rgba(0, 200, 255, 0.5);
  color: rgba(0, 200, 255, 0.8);
  font-family: 'Press Start 2P', monospace;
  font-size: 1.4rem;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s, border-color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-steer.active {
  background: rgba(0, 200, 255, 0.3);
  border-color: #00c8ff;
  color: #00c8ff;
  box-shadow: 0 0 15px rgba(0, 200, 255, 0.4);
}

.touch-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: auto;
}

.btn-gas-touch {
  width: 100px;
  height: 100px;
  border-radius: 10px;
  background: rgba(80, 255, 80, 0.1);
  border: 3px solid rgba(80, 255, 80, 0.5);
  color: rgba(80, 255, 80, 0.8);
  font-family: 'Press Start 2P', monospace;
  font-size: 0.7rem;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s, border-color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-gas-touch.active {
  background: rgba(80, 255, 80, 0.3);
  border-color: #50ff50;
  color: #50ff50;
  box-shadow: 0 0 15px rgba(80, 255, 80, 0.4);
}

.btn-nitro-touch {
  width: 100px;
  height: 60px;
  border-radius: 10px;
  background: rgba(255, 48, 119, 0.1);
  border: 3px solid rgba(255, 48, 119, 0.5);
  color: rgba(255, 48, 119, 0.8);
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s, border-color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-nitro-touch.active {
  background: rgba(255, 48, 119, 0.3);
  border-color: #ff3077;
  color: #ff3077;
  box-shadow: 0 0 15px rgba(255, 48, 119, 0.4);
}

/* Item touch button */
.btn-item-touch {
  width: 100px;
  height: 60px;
  border-radius: 10px;
  background: rgba(255, 200, 0, 0.1);
  border: 3px solid rgba(255, 200, 0, 0.5);
  color: rgba(255, 200, 0, 0.7);
  font-family: 'Press Start 2P', monospace;
  font-size: 0.55rem;
  pointer-events: auto;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-item-touch.active {
  background: rgba(255, 200, 0, 0.3);
  border-color: #ffc800;
  color: #ffc800;
  box-shadow: 0 0 15px rgba(255, 200, 0, 0.4);
}

/* Item indicator in HUD */
.item-indicator {
  display: none;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  font-size: clamp(0.5rem, 2.5vw, 1.1rem);
  font-family: 'Press Start 2P', monospace;
  text-align: center;
  margin-top: 0.8rem;
}

.item-indicator.visible {
  display: block;
}

.item-indicator.item-emp_mine {
  background: rgba(0, 180, 255, 0.2);
  border: 2px solid #00b4ff;
  color: #00b4ff;
}

.item-indicator.item-homing_rocket {
  background: rgba(255, 50, 50, 0.2);
  border: 2px solid #ff3232;
  color: #ff3232;
}

.item-indicator.item-iron_nails {
  background: rgba(180, 180, 180, 0.2);
  border: 2px solid #b4b4b4;
  color: #b4b4b4;
}

.item-indicator.item-nitro {
  background: rgba(0, 221, 255, 0.2);
  border: 2px solid #00ddff;
  color: #00ddff;
}

/* Stun overlay */
.stun-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 150, 255, 0.15);
  pointer-events: none;
  z-index: 90;
  display: none;
}

.stun-overlay.active {
  display: block;
  animation: stun-flicker 0.15s infinite;
}

@keyframes stun-flicker {
  0%, 100% { opacity: 0.1; }
  50% { opacity: 0.25; }
}

/* Virtual joystick */
.joystick-base {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(0, 200, 255, 0.08);
  border: 3px solid rgba(0, 200, 255, 0.35);
  position: relative;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.joystick-knob {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(0, 200, 255, 0.3);
  border: 2px solid rgba(0, 200, 255, 0.7);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: background 0.1s;
}

.joystick-base.active .joystick-knob {
  background: rgba(0, 200, 255, 0.5);
  border-color: #00c8ff;
  box-shadow: 0 0 10px rgba(0, 200, 255, 0.4);
}

/* Control mode selector (main menu) */
.control-mode-select {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.control-mode-select.visible {
  display: flex;
}

.control-mode-label {
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
  color: #8080a0;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.control-mode-options {
  display: flex;
  gap: 0.5rem;
}

.btn-mode {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
  padding: 0.6rem 1rem;
  background: transparent;
  border: 2px solid #333366;
  color: #555580;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-mode.active {
  border-color: #00c8ff;
  color: #00c8ff;
  box-shadow: 0 0 10px rgba(0, 200, 255, 0.3);
}

.btn-mode:hover {
  border-color: #6060a0;
  color: #8080c0;
}

/* Split time display (checkpoint deltas) */
.split-display {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(1rem, 4vw, 2rem);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease-out;
  z-index: 15;
}

.split-display.visible {
  opacity: 1;
  animation: splitPop 0.3s ease-out;
}

.split-display.ahead {
  color: #50ff50;
  text-shadow: 0 0 20px rgba(80, 255, 80, 0.6);
}

.split-display.behind {
  color: #ff3030;
  text-shadow: 0 0 20px rgba(255, 48, 48, 0.6);
}

@keyframes splitPop {
  0% { transform: translateX(-50%) scale(1.5); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Map selection screen */
#mapSelectScreen {
  background: radial-gradient(ellipse at center, rgba(26, 26, 58, 0.85) 0%, rgba(10, 10, 26, 0.9) 70%);
  gap: 1rem;
  padding: 1rem;
}

#mapSelectScreen h2 {
  font-size: clamp(0.8rem, 2.8vw, 1.2rem);
  color: #a0a0d0;
}

/* Large centered preview canvas */
.map-preview-large {
  width: 340px;
  height: 260px;
  background: #0a0a1a;
  border-radius: 8px;
  border: 2px solid #333366;
}

@media (max-width: 700px) {
  .map-preview-large {
    display: none;
  }
}

.map-preview-info {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.35rem, 1.1vw, 0.5rem);
  color: #8080a0;
  text-align: center;
  line-height: 1.8;
  min-height: 1.5em;
}

.map-preview-info .best-time {
  color: #50ff50;
}

/* Map buttons row */
.map-grid {
  display: flex;
  flex-direction: row;
  gap: 1rem;
}

@media (max-width: 700px) {
  .map-grid {
    flex-direction: column;
    align-items: center;
  }
}

.map-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.8rem 1.5rem;
  background: rgba(18, 18, 42, 0.8);
  border: 2px solid #333366;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 140px;
}

.map-card:hover, .map-card:active, .map-card.selected {
  border-color: #00c8ff;
  box-shadow: 0 0 20px rgba(0, 200, 255, 0.3);
}

.map-name {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.55rem, 1.8vw, 0.75rem);
  color: #00c8ff;
  text-shadow: 0 0 8px rgba(0, 200, 255, 0.4);
}

.map-meta {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.3rem, 0.9vw, 0.4rem);
  color: #8080a0;
  text-align: center;
}

.map-meta .best-time {
  color: #50ff50;
}

/* Lobby track selector (host picks track inline) */
.lobby-track-selector {
  display: flex;
  flex-direction: row;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}

.lobby-track-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.4rem, 1.2vw, 0.55rem);
  padding: 0.5rem 1rem;
  background: rgba(18, 18, 42, 0.8);
  border: 2px solid #333366;
  color: #8080a0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.lobby-track-btn:hover {
  border-color: #6060a0;
  color: #b0b0d0;
}

.lobby-track-btn.active {
  border-color: #00c8ff;
  color: #00c8ff;
  box-shadow: 0 0 12px rgba(0, 200, 255, 0.3);
}

/* Lobby track info (shown for non-host) */
.lobby-track-info {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: clamp(0.5rem, 1.5vw, 0.7rem);
  color: #8080a0;
}

.lobby-track-info #lobbyTrackName {
  color: #00c8ff;
}

/* Current run time display */
.current-run-time {
  font-size: clamp(0.75rem, 2.5vw, 1.1rem);
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4), 0 0 4px #000, 0 1px 3px #000;
  text-align: left;
  min-height: 1.2em;
}

/* Bot count selector (menu screen) */
.bot-count-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 0.4rem;
  margin-bottom: 0.4rem;
}

.bot-count-label {
  font-size: clamp(0.45rem, 1.4vw, 0.6rem);
  color: #8080a0;
  letter-spacing: 0.1em;
}

.bot-count-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.6rem, 1.8vw, 0.8rem);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 2px solid #333366;
  color: #8080a0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
  line-height: 1;
}

.bot-count-btn:hover, .bot-count-btn:active {
  border-color: #00c8ff;
  color: #00c8ff;
}

.bot-count-value {
  font-size: clamp(0.6rem, 1.8vw, 0.8rem);
  color: #00c8ff;
  min-width: 1.5em;
  text-align: center;
}
