/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: 'Rajdhani', sans-serif;
  user-select: none;
  touch-action: none; /* Prevent browser gestures on the game */
  -webkit-touch-callout: none;
}

body.pointer-locked {
  cursor: none;
}

canvas {
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

kbd {
  display: inline-block;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: 'Orbitron', monospace;
  font-size: 0.8em;
  margin-right: 4px;
}

/* ===== DEVICE-SPECIFIC VISIBILITY ===== */
/* By default, show desktop elements, hide touch elements.
   main.js adds .is-touch to body on touch devices. */
.start-controls-touch,
.start-hint-touch,
.death-respawn-touch {
  display: none;
}

.is-touch .start-controls-desktop,
.is-touch .start-hint-desktop,
.is-touch .death-respawn-desktop,
.is-touch #hud-bottom-left,
.is-touch #sidebar {
  display: none !important;
}

.is-touch .start-controls-touch,
.is-touch .start-hint-touch,
.is-touch .death-respawn-touch {
  display: flex;
}

/* Death respawn touch is not flex */
.is-touch .death-respawn-touch {
  display: block;
}

/* ===== START SCREEN ===== */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #0a0a1a 0%, #000 70%);
  animation: starPulse 4s ease-in-out infinite alternate;
}

@keyframes starPulse {
  from { background: radial-gradient(ellipse at center, #0a0a2a 0%, #000 70%); }
  to { background: radial-gradient(ellipse at center, #0f0a1a 0%, #000 70%); }
}

.start-content {
  text-align: center;
  max-width: 500px;
  padding: 0 20px;
}

.start-title {
  font-family: 'Orbitron', monospace;
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: 6px;
  line-height: 1.1;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #fff 0%, #6af 40%, #f6a 70%, #fa6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  from { filter: brightness(1); }
  to { filter: brightness(1.3); }
}

.start-subtitle {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.5);
  margin-bottom: 32px;
  font-weight: 300;
  letter-spacing: 1px;
}

.start-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 32px;
  font-size: 0.95rem;
  color: rgba(255,255,255,0.6);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#start-btn {
  font-family: 'Orbitron', monospace;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 4px;
  padding: 14px 48px;
  border: 2px solid rgba(100,170,255,0.6);
  background: rgba(100,170,255,0.1);
  color: #6af;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
}

#start-btn:hover {
  background: rgba(100,170,255,0.25);
  border-color: #6af;
  box-shadow: 0 0 30px rgba(100,170,255,0.3), inset 0 0 30px rgba(100,170,255,0.1);
}

.start-hint {
  margin-top: 16px;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.3);
}

/* ===== DEATH SCREEN ===== */
#death-screen {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.95);
  animation: deathFadeIn 0.5s ease-out;
}

@keyframes deathFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.death-content {
  text-align: center;
  max-width: 500px;
  padding: 0 20px;
}

.death-title {
  font-family: 'Orbitron', monospace;
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 6px;
  color: #f44;
  margin-bottom: 8px;
  animation: deathPulse 1s ease-in-out infinite alternate;
}

@keyframes deathPulse {
  from { text-shadow: 0 0 20px rgba(255,68,68,0.5); }
  to { text-shadow: 0 0 40px rgba(255,68,68,0.8); }
}

.death-subtitle {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.5);
  margin-bottom: 24px;
}

.death-fact {
  font-size: 1rem;
  color: rgba(255,200,100,0.8);
  margin-bottom: 24px;
  line-height: 1.5;
  padding: 16px;
  border-left: 2px solid rgba(255,200,100,0.4);
  text-align: left;
}

.death-respawn {
  font-family: 'Orbitron', monospace;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.5);
  letter-spacing: 2px;
  animation: gentlePulse 2s ease-in-out infinite;
}

.death-respawn kbd {
  color: rgba(255,255,255,0.7);
}

@keyframes gentlePulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ===== HUD ===== */
#hud {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}

#hud-top-left {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#hud-speed, #hud-proximity {
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(100,170,255,0.2);
  border-radius: 4px;
  padding: 8px 14px;
  min-width: 180px;
}

.hud-label {
  display: block;
  font-family: 'Orbitron', monospace;
  font-size: 0.6rem;
  letter-spacing: 2px;
  color: rgba(100,170,255,0.6);
  margin-bottom: 2px;
}

#speed-value {
  font-family: 'Orbitron', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: #6af;
}

.hud-unit {
  font-size: 0.75rem;
  color: rgba(100,170,255,0.5);
  margin-left: 4px;
}

#proximity-name {
  display: block;
  font-family: 'Orbitron', monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
}

#proximity-distance {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
}

/* Minimap */
#hud-top-right {
  position: absolute;
  top: 20px;
  right: 20px;
}

#minimap {
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(100,170,255,0.2);
  border-radius: 50%;
}

/* Crosshair */
#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  color: rgba(255,255,255,0.3);
  font-family: monospace;
  text-shadow: 0 0 4px rgba(100,170,255,0.3);
}

/* Bottom controls */
#hud-bottom-left {
  position: absolute;
  bottom: 20px;
  left: 20px;
}

#controls-hint {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.25);
  letter-spacing: 0.5px;
}

#controls-hint span {
  font-family: 'Orbitron', monospace;
  color: rgba(100,170,255,0.4);
  font-size: 0.65rem;
}

/* Gravity warning */
#gravity-warning {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Orbitron', monospace;
  font-size: 0.85rem;
  letter-spacing: 2px;
  color: #f80;
  background: rgba(255,136,0,0.1);
  border: 1px solid rgba(255,136,0,0.3);
  padding: 8px 20px;
  border-radius: 4px;
  animation: warningPulse 1s ease-in-out infinite alternate;
}

@keyframes warningPulse {
  from { opacity: 0.7; border-color: rgba(255,136,0,0.2); }
  to { opacity: 1; border-color: rgba(255,136,0,0.6); }
}

.warning-icon {
  margin-right: 8px;
}

/* Frame-dragging warning */
#frame-drag-warning {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Orbitron', monospace;
  font-size: 0.85rem;
  letter-spacing: 2px;
  color: #2da;
  background: rgba(34,221,170,0.1);
  border: 1px solid rgba(34,221,170,0.3);
  padding: 8px 20px;
  border-radius: 4px;
  animation: frameDragPulse 1s ease-in-out infinite alternate;
}

@keyframes frameDragPulse {
  from { opacity: 0.7; border-color: rgba(34,221,170,0.2); }
  to { opacity: 1; border-color: rgba(34,221,170,0.6); }
}

/* Naked singularity message */
#naked-singularity-message {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: nakedFadeIn 1s ease-out;
}

@keyframes nakedFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.naked-msg-content {
  text-align: center;
  max-width: 500px;
  padding: 30px 40px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  animation: nakedGlow 2s ease-in-out infinite alternate;
}

@keyframes nakedGlow {
  from { border-color: rgba(255,255,255,0.2); box-shadow: 0 0 30px rgba(200,200,255,0.1); }
  to { border-color: rgba(255,255,255,0.5); box-shadow: 0 0 60px rgba(200,200,255,0.3); }
}

.naked-msg-content h3 {
  font-family: 'Orbitron', monospace;
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 4px;
  color: #fff;
  margin-bottom: 12px;
  text-shadow: 0 0 20px rgba(255,255,255,0.6);
}

.naked-msg-content p {
  font-size: 1rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.7);
}

/* ===== SIDEBAR ===== */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  z-index: 200;
  background: rgba(5,5,20,0.85);
  backdrop-filter: blur(12px);
  border-left: 1px solid rgba(100,170,255,0.15);
  padding: 24px;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
}

#sidebar.slide-out {
  transform: translateX(100%);
}

#sidebar-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(100,170,255,0.1);
}

#sidebar-type {
  font-family: 'Orbitron', monospace;
  font-size: 0.65rem;
  letter-spacing: 3px;
  color: rgba(100,170,255,0.5);
  margin-bottom: 4px;
  text-transform: uppercase;
}

#sidebar-title {
  font-family: 'Orbitron', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 1px;
}

#sidebar-body {
  font-size: 0.95rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.7);
}

#sidebar-body .fact-section {
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(100,170,255,0.05);
  border-radius: 4px;
  border-left: 2px solid rgba(100,170,255,0.2);
}

#sidebar-body .fact-section h4 {
  font-family: 'Orbitron', monospace;
  font-size: 0.7rem;
  letter-spacing: 1.5px;
  color: rgba(100,170,255,0.6);
  margin-bottom: 4px;
}

#sidebar-body .stat-value {
  font-family: 'Orbitron', monospace;
  font-size: 1.1rem;
  color: #6af;
  font-weight: 700;
}

#sidebar-hint {
  margin-top: 20px;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.2);
  text-align: center;
  font-style: italic;
}

/* ===== SIDEBAR BANNER (touch devices) ===== */
#sidebar-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  pointer-events: auto;
  transition: max-height 0.3s ease;
  max-height: 48px;
  overflow: hidden;
}

#sidebar-banner.expanded {
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#banner-collapsed {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(5,5,20,0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(100,170,255,0.2);
  cursor: pointer;
  min-height: 48px;
}

#banner-type {
  font-family: 'Orbitron', monospace;
  font-size: 0.55rem;
  letter-spacing: 2px;
  color: rgba(100,170,255,0.5);
  text-transform: uppercase;
  flex-shrink: 0;
}

#banner-title {
  font-family: 'Orbitron', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#banner-expand-hint {
  margin-left: auto;
  font-family: 'Orbitron', monospace;
  font-size: 0.5rem;
  letter-spacing: 1px;
  color: rgba(100,170,255,0.4);
  flex-shrink: 0;
  text-transform: uppercase;
}

#sidebar-banner.expanded #banner-expand-hint {
  display: none;
}

#banner-expanded {
  background: rgba(5,5,20,0.9);
  backdrop-filter: blur(12px);
  padding: 16px;
  border-bottom: 1px solid rgba(100,170,255,0.15);
}

#banner-expanded .fact-section {
  margin-bottom: 12px;
  padding: 10px;
  background: rgba(100,170,255,0.05);
  border-radius: 4px;
  border-left: 2px solid rgba(100,170,255,0.2);
}

#banner-expanded .fact-section h4 {
  font-family: 'Orbitron', monospace;
  font-size: 0.6rem;
  letter-spacing: 1.5px;
  color: rgba(100,170,255,0.6);
  margin-bottom: 3px;
}

#banner-expanded .stat-value {
  font-family: 'Orbitron', monospace;
  font-size: 0.9rem;
  color: #6af;
  font-weight: 700;
}

#banner-expanded .banner-description {
  font-size: 0.85rem;
  line-height: 1.5;
  color: rgba(255,255,255,0.6);
  margin-bottom: 12px;
}

/* ===== FACT POPUP ===== */
#fact-popup {
  position: fixed;
  z-index: 300;
  max-width: 300px;
  background: rgba(5,5,30,0.9);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(100,170,255,0.3);
  border-radius: 6px;
  padding: 14px 18px;
  pointer-events: none;
  animation: popIn 0.2s ease-out;
  left: 50%;
  top: 60%;
  transform: translateX(-50%);
}

@keyframes popIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.9); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

#fact-title {
  font-family: 'Orbitron', monospace;
  font-size: 0.75rem;
  letter-spacing: 1.5px;
  color: #6af;
  margin-bottom: 6px;
}

#fact-text {
  font-size: 0.9rem;
  line-height: 1.5;
  color: rgba(255,255,255,0.8);
}

/* ===== VIRTUAL JOYSTICKS & TOUCH CONTROLS ===== */
.joystick-zone {
  position: fixed;
  z-index: 150;
  width: 140px;
  height: 140px;
  bottom: 20px;
  pointer-events: auto;
}

.joystick-left {
  left: 20px;
}

.joystick-right {
  right: 20px;
}

.joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(100,170,255,0.08);
  border: 2px solid rgba(100,170,255,0.2);
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(100,170,255,0.25);
  border: 2px solid rgba(100,170,255,0.5);
  box-shadow: 0 0 10px rgba(100,170,255,0.2);
}

.touch-btn {
  position: fixed;
  z-index: 150;
  pointer-events: auto;
  font-family: 'Orbitron', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 10px 16px;
  border-radius: 6px;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s, border-color 0.15s;
}

.touch-btn-boost {
  right: 30px;
  bottom: 180px;
  color: #4af;
  background: rgba(68,170,255,0.1);
  border: 1px solid rgba(68,170,255,0.3);
}

.touch-btn-boost.active {
  background: rgba(68,170,255,0.3);
  border-color: rgba(68,170,255,0.7);
  box-shadow: 0 0 15px rgba(68,170,255,0.3);
}

.touch-btn-brake {
  left: 30px;
  bottom: 180px;
  color: #f80;
  background: rgba(255,136,0,0.1);
  border: 1px solid rgba(255,136,0,0.3);
}

.touch-btn-brake.active {
  background: rgba(255,136,0,0.3);
  border-color: rgba(255,136,0,0.7);
  box-shadow: 0 0 15px rgba(255,136,0,0.3);
}

/* ===== RESPONSIVE — SMALL SCREENS (PHONES) ===== */
@media (max-width: 600px) {
  .start-title {
    font-size: 2.2rem;
    letter-spacing: 3px;
  }

  .start-subtitle {
    font-size: 0.9rem;
    margin-bottom: 20px;
  }

  .start-controls {
    font-size: 0.85rem;
    margin-bottom: 20px;
  }

  #start-btn {
    font-size: 1rem;
    padding: 12px 36px;
  }

  .death-title {
    font-size: 1.8rem;
    letter-spacing: 3px;
  }

  .death-fact {
    font-size: 0.85rem;
    padding: 12px;
  }

  /* HUD: smaller, tighter */
  #hud-top-left {
    top: 10px;
    left: 10px;
    gap: 6px;
  }

  #hud-speed, #hud-proximity {
    min-width: 130px;
    padding: 5px 10px;
  }

  #speed-value {
    font-size: 1.2rem;
  }

  .hud-label {
    font-size: 0.5rem;
  }

  #proximity-name {
    font-size: 0.75rem;
  }

  /* Minimap: smaller */
  #hud-top-right {
    top: 10px;
    right: 10px;
  }

  #minimap {
    width: 100px;
    height: 100px;
  }

  /* Crosshair: smaller */
  #crosshair {
    font-size: 18px;
  }

  /* Warnings: move up above joysticks */
  #gravity-warning {
    bottom: 220px;
    font-size: 0.7rem;
    padding: 6px 14px;
  }

  #frame-drag-warning {
    bottom: 255px;
    font-size: 0.7rem;
    padding: 6px 14px;
  }

  /* Fact popup: narrower, positioned higher */
  #fact-popup {
    max-width: 250px;
    top: 40%;
    padding: 10px 14px;
  }

  #fact-text {
    font-size: 0.8rem;
  }

  /* Naked singularity message */
  .naked-msg-content {
    max-width: 90vw;
    padding: 20px 24px;
  }

  .naked-msg-content h3 {
    font-size: 1.1rem;
  }

  .naked-msg-content p {
    font-size: 0.85rem;
  }

  /* Banner: smaller on phones */
  #banner-title {
    font-size: 0.7rem;
  }

  #banner-collapsed {
    padding: 8px 12px;
    min-height: 40px;
  }

  #sidebar-banner {
    max-height: 40px;
  }

  #sidebar-banner.expanded {
    max-height: 50vh;
  }

  /* Joysticks: slightly smaller on very small screens */
  .joystick-zone {
    width: 110px;
    height: 110px;
    bottom: 15px;
  }

  .joystick-left {
    left: 15px;
  }

  .joystick-right {
    right: 15px;
  }

  .joystick-knob {
    width: 40px;
    height: 40px;
  }

  .touch-btn {
    font-size: 0.55rem;
    padding: 8px 12px;
  }

  .touch-btn-boost {
    bottom: 145px;
    right: 20px;
  }

  .touch-btn-brake {
    bottom: 145px;
    left: 20px;
  }
}

/* ===== RESPONSIVE — TABLETS (iPads in landscape) ===== */
@media (min-width: 601px) and (max-width: 1024px) {
  .start-title {
    font-size: 2.8rem;
  }

  /* Warnings above joysticks */
  .is-touch #gravity-warning {
    bottom: 200px;
  }

  .is-touch #frame-drag-warning {
    bottom: 240px;
  }


}
