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

body {
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff;
  cursor: crosshair;
}

#gameCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
}

.hidden { display: none !important; }

/* ── Loading Screen ──────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0a1628 0%, #1a2a4a 50%, #0d2137 100%);
}

.loading-content {
  text-align: center;
}

.loading-content h1 {
  font-size: 3rem;
  font-weight: 300;
  letter-spacing: 0.5em;
  margin-bottom: 0.5rem;
  text-shadow: 0 0 40px rgba(100, 180, 255, 0.4);
}

.loading-sub {
  font-size: 1rem;
  letter-spacing: 0.3em;
  opacity: 0.6;
  margin-bottom: 2rem;
}

.loading-bar {
  width: 300px;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin: 0 auto 1rem;
  overflow: hidden;
}

.loading-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #4a9eff, #00d4ff);
  transition: width 0.3s ease;
}

#loadingText {
  font-size: 0.85rem;
  opacity: 0.5;
  letter-spacing: 0.1em;
}

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

#hud * {
  pointer-events: none;
}

#topBar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2rem;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  opacity: 0.7;
}

#callsign {
  font-weight: 600;
  color: #4a9eff;
}

/* ── Instruments Panel ────────────────────────────────── */
#instruments {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 15px 20px;
  backdrop-filter: blur(10px);
}

.instr-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.instr-col.left, .instr-col.right {
  min-width: 100px;
}

.instr-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.instr-label {
  font-size: 0.65rem;
  opacity: 0.5;
  letter-spacing: 0.1em;
  min-width: 40px;
}

.instr-value {
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: #00ff88;
  min-width: 55px;
  text-align: right;
}

.instr-unit {
  font-size: 0.65rem;
  opacity: 0.4;
}

/* Throttle gauge */
.gauge-bar {
  width: 60px;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00ff88, #ffaa00, #ff4444);
  border-radius: 5px;
  transition: width 0.1s;
}

/* Gear indicator */
#gearInd .instr-value.gear-down { color: #00ff88; }
#gearInd .instr-value.gear-up { color: #ffaa00; }

/* Attitude Indicator */
#attitudeCanvas {
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  background: #111;
}

/* Stall Warning */
#stallWarning {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  font-weight: 900;
  color: #ff2222;
  text-shadow: 0 0 30px rgba(255, 0, 0, 0.8);
  animation: stallBlink 0.3s infinite;
  letter-spacing: 0.2em;
}

@keyframes stallBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* Brake */
#brakeInd {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 60px));
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffaa00;
  letter-spacing: 0.2em;
}

/* Camera Mode */
#cameraMode {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  opacity: 0.4;
}

/* ── Minimap ──────────────────────────────────────────── */
#minimap {
  position: absolute;
  bottom: 20px;
  right: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  background: rgba(0, 20, 40, 0.6);
  backdrop-filter: blur(5px);
}

/* ── Chat ─────────────────────────────────────────────── */
#chatBox {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 300px;
}

#chatMessages {
  max-height: 150px;
  overflow-y: auto;
  padding: 5px;
  margin-bottom: 5px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

#chatMessages::-webkit-scrollbar { width: 4px; }
#chatMessages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.chat-msg {
  font-size: 0.8rem;
  margin-bottom: 3px;
  opacity: 0.8;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  word-break: break-word;
}

.chat-msg .chat-name {
  font-weight: 700;
}

.chat-msg.system {
  color: #888;
  font-style: italic;
}

#chatInput {
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 6px 10px;
  color: #fff;
  font-size: 0.8rem;
  outline: none;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.2s;
}

#chatInput.active {
  opacity: 1;
}

#chatInput:focus {
  border-color: rgba(74, 158, 255, 0.5);
}

/* ── Controls Help ────────────────────────────────────── */
#controlsHelp {
  position: absolute;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  font-size: 0.7rem;
  opacity: 0.35;
}

#controlsHelp table {
  border-collapse: collapse;
}

#controlsHelp td {
  padding: 2px 8px;
}

#controlsHelp td:first-child {
  font-weight: 700;
  color: #4a9eff;
  text-align: right;
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  #instruments {
    padding: 10px 12px;
    gap: 10px;
  }
  .instr-value { font-size: 0.9rem; }
  #controlsHelp { display: none; }
  #chatBox { width: 220px; }
  #minimap { width: 120px; height: 120px; }
  .loading-content h1 { font-size: 1.8rem; letter-spacing: 0.3em; }
  #attitudeCanvas { width: 120px; height: 120px; }
}
