* { box-sizing: border-box; touch-action: none; user-select: none; -webkit-user-select: none; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: #05080f; color: #d7e6ff;
  font-family: "Segoe UI", system-ui, sans-serif;
}
#game { position: fixed; inset: 0; z-index: 0; }
#game canvas { display: block; width: 100%; height: 100%; }

#join {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: radial-gradient(ellipse at center, #12203a 0%, #05080f 70%);
  padding: 24px;
}
#join h1 {
  margin: 0; letter-spacing: 0.35em; font-weight: 700; font-size: 2rem; color: #7ec8ff;
}
#join .sub { margin: 0 0 12px; opacity: 0.7; letter-spacing: 0.2em; text-transform: uppercase; font-size: 0.75rem; }
#join label { display: flex; flex-direction: column; gap: 4px; width: min(320px, 90vw); font-size: 0.8rem; opacity: 0.9; }
#join input, #join select {
  background: #0b1424; border: 1px solid #2a4a72; color: #e8f1ff;
  padding: 10px 12px; border-radius: 6px; font-size: 1rem;
}
#shipPreview {
  display: flex; gap: 16px; margin: 4px 0 8px; align-items: flex-end;
}
#shipPreview img {
  width: 56px; height: 56px; object-fit: contain; opacity: 0.35;
  filter: drop-shadow(0 0 6px rgba(100,160,255,0.35));
  transition: opacity 0.15s, transform 0.15s;
}
#shipPreview img.active { opacity: 1; transform: scale(1.15); }

#joinBtn {
  margin-top: 8px; width: min(320px, 90vw); padding: 14px;
  background: #1c6dd0; border: none; color: white; font-weight: 700;
  letter-spacing: 0.15em; border-radius: 6px; font-size: 1rem; cursor: pointer;
}
#joinBtn:active { background: #1557a8; }
.error { color: #ff7b7b; min-height: 1.2em; }

.hidden { display: none !important; }

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#matchHud {
  position: absolute; top: 48px; left: 12px;
  font-size: 0.8rem; letter-spacing: 0.08em; font-weight: 700;
  opacity: 0.85; background: rgba(8,14,28,0.55); padding: 4px 8px; border-radius: 4px;
}
#matchHud.urgent { color: #ffb060; }
#countdownOverlay {
  position: absolute; inset: 0; z-index: 12;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(5, 6, 14, 0.62);
}
#countdownOverlay .cdNumber {
  font-size: min(28vw, 160px); font-weight: 900; line-height: 1;
  color: #fff; text-shadow: 0 0 28px rgba(255,80,80,0.55);
  animation: pilotCdBoom 0.5s cubic-bezier(0.2, 1.4, 0.3, 1);
}
#countdownOverlay .cdNumber.final { color: #ff6a4a; }
#countdownOverlay .cdSub {
  margin-top: 6px; letter-spacing: 0.2em; font-weight: 700; font-size: 0.85rem; color: #9ec8ff;
}
@keyframes pilotCdBoom {
  from { transform: scale(1.35); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}
#topLeft { position: absolute; top: 10px; left: 12px; }
#callsignHud { font-weight: 700; letter-spacing: 0.08em; font-size: 1.1rem; }
#stats { font-size: 0.85rem; opacity: 0.85; }
#bars { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: min(280px, 50vw); }
.bar { height: 10px; background: #1a2436; border: 1px solid #345; border-radius: 3px; margin-bottom: 4px; overflow: hidden; }
.bar.energy { height: 8px; }
#healthFill { height: 100%; width: 100%; background: #3dce6e; transition: width 0.08s linear; }
#healthFill.flash { background: #ff6666; }
#energyFill { height: 100%; width: 100%; background: #4aa3ff; transition: width 0.08s linear; }
#onCamera {
  position: absolute; top: 48px; left: 50%; transform: translateX(-50%);
  background: #c0392b; color: white; font-weight: 800; letter-spacing: 0.12em;
  padding: 4px 12px; border-radius: 4px; font-size: 0.75rem; animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: 0.65; } }
#radar {
  position: absolute; top: 10px; right: 12px;
  width: 120px; height: 120px; border-radius: 50%;
  border: 1px solid #2a4a72; background: rgba(5, 12, 24, 0.75);
}
#diedBanner {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(20, 8, 8, 0.9); border: 1px solid #a33;
  padding: 16px 24px; border-radius: 8px; text-align: center; font-size: 1.05rem;
  white-space: pre-line; line-height: 1.45; max-width: 90vw;
}
#streamAlert {
  position: absolute; top: 86px; left: 50%; transform: translateX(-50%);
  z-index: 7; max-width: 90vw; text-align: center;
  background: rgba(40, 20, 0, 0.88); border: 1px solid #e0a030;
  color: #ffe6a8; padding: 8px 16px; border-radius: 6px;
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.04em;
  animation: slideAlert 0.3s ease;
}
@keyframes slideAlert {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

#join .backHub {
  position: absolute; left: 14px; top: 12px;
  color: #8ab; text-decoration: none; font-size: 0.9rem;
}
#controls {
  position: fixed; inset: 0; z-index: 6; pointer-events: none;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 24px 28px;
}
#emoteBar {
  position: absolute; left: 50%; bottom: 118px; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  max-width: min(520px, 92vw); pointer-events: auto;
}
#emoteBar button {
  border: 1px solid rgba(140, 180, 230, 0.35);
  background: rgba(12, 20, 40, 0.75);
  color: #d7e6ff; font-size: 0.7rem; font-weight: 700;
  padding: 6px 8px; letter-spacing: 0.02em;
}
#emoteBar button:disabled { opacity: 0.35; }
#stickZone {
  pointer-events: auto; width: 160px; height: 160px;
  border-radius: 50%; background: rgba(80, 120, 180, 0.12);
  border: 1px solid rgba(120, 170, 230, 0.25); position: relative;
}
#stickZone::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 56px; height: 56px;
  margin: -28px 0 0 -28px; border-radius: 50%;
  background: rgba(140, 190, 255, 0.35); border: 1px solid rgba(180, 220, 255, 0.5);
  transform: translate(var(--sx, 0px), var(--sy, 0px));
}
#btnZone { pointer-events: auto; display: flex; gap: 16px; align-items: flex-end; }
#btnZone button {
  position: relative; width: 88px; height: 88px; border-radius: 50%;
  border: 2px solid #4a7ab0; background: rgba(20, 40, 70, 0.7);
  color: #d7e6ff; font-weight: 800; letter-spacing: 0.05em; font-size: 0.85rem;
}
#btnZone button span { position: relative; z-index: 1; }
#btnZone button canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#fireBtn { border-color: #c45; background: rgba(80, 20, 20, 0.65); }
#fireBtn:active, #fireBtn.held { background: rgba(160, 40, 40, 0.85); }
#abilityBtn:active, #abilityBtn.held { background: rgba(40, 80, 140, 0.9); }

@media (orientation: portrait) {
  #join .sub::after { content: " — rotate to landscape"; }
}
