/* Modern Sci-Fi Futuristic Theme & Game HUD Styling */
@font-face { font-family: Orbitron; font-style: normal; font-weight: 400 900; font-display: swap; src: url(../fonts/orbitron.woff2) format("woff2"); }
@font-face { font-family: Rajdhani; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/rajdhani-500.woff2) format("woff2"); }
@font-face { font-family: Rajdhani; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/rajdhani-600.woff2) format("woff2"); }
@font-face { font-family: Rajdhani; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/rajdhani-700.woff2) format("woff2"); }


:root {
  --viewport-height: 100vh;
  --safe-top: max(8px, env(safe-area-inset-top));
  --safe-right: max(8px, env(safe-area-inset-right));
  --safe-bottom: max(8px, env(safe-area-inset-bottom));
  --safe-left: max(8px, env(safe-area-inset-left));
  --bg-dark: #060711;
  --panel-bg: rgba(13, 19, 33, 0.78);
  --panel-border: rgba(0, 210, 255, 0.35);
  --neon-cyan: #00d2ff;
  --neon-red: #ff3b5c;
  --neon-green: #00ff88;
  --neon-gold: #ffd000;
  --neon-purple: #9d4edd;
  --text-primary: #e6f1ff;
  --text-dim: #8b9bb4;
  --font-title: 'Orbitron', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Rajdhani', -apple-system, BlinkMacSystemFont, sans-serif;
}

@supports (height: 100dvh) {
  :root { --viewport-height: 100dvh; }
}

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

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-body);
  color: var(--text-primary);
}

/* Background Canvas */
#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* App Containers */
.screen-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--viewport-height);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-layer:not([style*="display: none"]) {
  display: flex !important;
}

.screen-layer[style*="display: none"] {
  display: none !important;
}

/* Glassmorphic Sci-Fi Panels */
.sci-fi-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 0 35px rgba(0, 210, 255, 0.15), inset 0 0 20px rgba(0, 210, 255, 0.05);
  position: relative;
}

.sci-fi-panel::before, .sci-fi-panel::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: var(--neon-cyan);
  pointer-events: none;
}
.sci-fi-panel::before {
  top: -1px; left: -1px;
  border-top: 2px solid var(--neon-cyan);
  border-left: 2px solid var(--neon-cyan);
}
.sci-fi-panel::after {
  bottom: -1px; right: -1px;
  border-bottom: 2px solid var(--neon-cyan);
  border-right: 2px solid var(--neon-cyan);
}

/* Sci-Fi Buttons */
.btn-cyber {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 1.5px;
  padding: 12px 26px;
  border-radius: 4px;
  background: rgba(0, 210, 255, 0.12);
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-shadow: 0 0 8px rgba(0, 210, 255, 0.6);
}

.btn-cyber:hover {
  background: var(--neon-cyan);
  color: #060a14;
  box-shadow: 0 0 25px rgba(0, 210, 255, 0.65);
  transform: translateY(-1px);
}

.btn-cyber.btn-accent, .btn-cyber.btn-red {
  border-color: var(--neon-red);
  color: var(--neon-red);
  background: rgba(255, 59, 92, 0.15);
  text-shadow: 0 0 8px rgba(255, 59, 92, 0.6);
}
.btn-cyber.btn-accent:hover, .btn-cyber.btn-red:hover {
  background: var(--neon-red);
  color: #ffffff;
  box-shadow: 0 0 25px rgba(255, 59, 92, 0.65);
}

.btn-cyber.btn-green {
  border-color: var(--neon-green);
  color: var(--neon-green);
  background: rgba(0, 255, 136, 0.15);
}
.btn-cyber.btn-green:hover {
  background: var(--neon-green);
  color: #060a14;
  box-shadow: 0 0 25px rgba(0, 255, 136, 0.65);
}

/* Cyber Inputs */
.cyber-input {
  font-family: var(--font-title);
  background: rgba(8, 14, 28, 0.85);
  border: 1px solid rgba(0, 210, 255, 0.4);
  padding: 12px 18px;
  color: #ffffff;
  border-radius: 4px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.cyber-input:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 16px rgba(0, 210, 255, 0.35);
}

/* =========================================================
   1. MAIN MENU SCREEN
   ========================================================= */
.menu-container {
  margin: auto;
  width: 90%;
  max-width: 520px;
  padding: 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.game-title-group h1 {
  font-family: var(--font-title);
  font-size: 2.3rem;
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffffff;
  text-shadow: 0 0 20px var(--neon-cyan);
  margin-bottom: 6px;
}

.game-subtitle {
  font-size: 1.15rem;
  letter-spacing: 2.5px;
  color: var(--neon-cyan);
  text-transform: uppercase;
}

.menu-profile-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.menu-profile-box label {
  font-size: 0.85rem;
  letter-spacing: 1.5px;
  color: var(--text-dim);
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.join-room-row {
  display: flex;
  gap: 10px;
  width: 100%;
  min-width: 0;
}
.join-room-row input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  text-transform: uppercase;
}
.join-room-row #btn-join-room {
  flex: 0 0 auto;
}

.menu-divider {
  display: flex;
  align-items: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 2px;
}
.menu-divider::before, .menu-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(0, 210, 255, 0.2);
  margin: 0 10px;
}

/* =========================================================
   2. ROOM LOBBY SCREEN
   ========================================================= */
.lobby-layout {
  margin: auto;
  width: 95%;
  max-width: 1400px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 24px 30px;
  gap: 18px;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(0, 210, 255, 0.25);
}

.room-code-tag {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-title);
}
.room-code-val {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--neon-gold);
  letter-spacing: 3px;
  text-shadow: 0 0 12px rgba(255, 208, 0, 0.5);
}

.lobby-main-grid {
  display: grid;
  grid-template-columns: 340px 1fr 340px;
  gap: 20px;
  flex: 1;
  min-height: 0;
}

/* Left: Team Rosters */
.lobby-teams-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.team-card-section {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.team-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 700;
}

.player-roster-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  border-left: 3px solid #666;
}
.player-roster-item.ready {
  border-left-color: var(--neon-green);
}
.player-roster-item.bot {
  font-style: italic;
}
.roster-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.roster-name {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.roster-ship {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.roster-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 3px;
}
.roster-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.roster-remove-bot {
  min-height: 32px;
  padding: 4px 7px;
  border: 1px solid var(--neon-red);
  border-radius: 3px;
  background: rgba(255, 59, 92, 0.15);
  color: var(--neon-red);
  font-family: var(--font-title);
  font-size: 0.58rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.roster-remove-bot:hover,
.roster-remove-bot:focus-visible {
  background: var(--neon-red);
  color: #fff;
}

@media (pointer: coarse) {
  .roster-remove-bot { min-height: 44px; }
}
.badge-ready {
  background: rgba(0, 255, 136, 0.2);
  color: var(--neon-green);
  border: 1px solid var(--neon-green);
}
.badge-wait {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
}

/* Center: Ship Customization & Preview */
.lobby-center-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ship-preview-box {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px;
}
#ship-preview-canvas {
  width: 140px;
  height: 140px;
  flex-shrink: 0;
}
.ship-preview-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.preview-role {
  font-family: var(--font-title);
  font-size: 1.25rem;
  color: var(--neon-cyan);
  font-weight: 700;
}
.preview-desc {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.3;
}
.preview-meta {
  font-size: 0.85rem;
  color: var(--text-primary);
}

/* Ship Selection Grid */
.ship-cards-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  flex: 1;
  overflow-y: auto;
}

.ship-card {
  padding: 12px;
  background: rgba(16, 24, 40, 0.6);
  border: 1px solid rgba(0, 210, 255, 0.25);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.2s;
}
.ship-card:hover {
  border-color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.08);
}
.ship-card.selected {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 16px rgba(0, 210, 255, 0.4), inset 0 0 10px rgba(0, 210, 255, 0.15);
  background: rgba(0, 210, 255, 0.12);
}
.ship-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.ship-card-name {
  font-family: var(--font-title);
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
}
.ship-card-role {
  font-size: 0.75rem;
  color: var(--neon-cyan);
}
.ship-card-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.25;
}

.ship-stats-meters {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-family: var(--font-title);
}
.stat-row span {
  width: 28px;
  color: var(--text-dim);
}
.stat-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}
.stat-fill {
  height: 100%;
}
.ship-ability-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--neon-gold);
}

/* Right: Team Select & Controls */
.lobby-controls-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.team-select-box {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.team-select-box h3 {
  font-family: var(--font-title);
  font-size: 0.95rem;
  letter-spacing: 1px;
}
.team-btns-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.team-btn {
  padding: 12px 10px;
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 4px;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid #444;
  color: #fff;
  transition: all 0.2s;
}
.team-btn[data-team="red"].active, .team-btn[data-team="red"]:hover {
  border-color: var(--neon-red);
  background: rgba(255, 59, 92, 0.25);
  box-shadow: 0 0 12px rgba(255, 59, 92, 0.5);
}
.team-btn[data-team="blue"].active, .team-btn[data-team="blue"]:hover {
  border-color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.25);
  box-shadow: 0 0 12px rgba(0, 210, 255, 0.5);
}
.team-btn[data-team="green"].active, .team-btn[data-team="green"]:hover {
  border-color: var(--neon-green);
  background: rgba(0, 255, 136, 0.25);
  box-shadow: 0 0 12px rgba(0, 255, 136, 0.5);
}
.team-btn[data-team="gold"].active, .team-btn[data-team="gold"]:hover {
  border-color: var(--neon-gold);
  background: rgba(255, 208, 0, 0.25);
  box-shadow: 0 0 12px rgba(255, 208, 0, 0.5);
}

.lobby-actions-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#btn-ready.ready-active {
  background: var(--neon-green);
  color: #060a14;
  box-shadow: 0 0 25px rgba(0, 255, 136, 0.8);
}

/* Countdown Overlay Banner */
.countdown-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(6, 10, 20, 0.92);
  border: 2px solid var(--neon-gold);
  box-shadow: 0 0 45px rgba(255, 208, 0, 0.6);
  padding: 30px 60px;
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--neon-gold);
  letter-spacing: 3px;
  text-align: center;
  z-index: 100;
  border-radius: 8px;
}

/* =========================================================
   3. IN-GAME HUD
   ========================================================= */
.hud-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

/* Custom Aim Crosshair */
#custom-crosshair {
  position: absolute;
  width: 32px;
  height: 32px;
  pointer-events: none;
  margin-left: -16px;
  margin-top: -16px;
  z-index: 25;
}
#custom-crosshair::before, #custom-crosshair::after {
  content: '';
  position: absolute;
  background: rgba(0, 210, 255, 0.8);
  box-shadow: 0 0 8px var(--neon-cyan);
}
#custom-crosshair::before {
  top: 15px; left: 0; width: 32px; height: 2px;
}
#custom-crosshair::after {
  top: 0; left: 15px; width: 2px; height: 32px;
}

/* Top Team Status Bar */
.hud-top-teams {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
}
.hud-team-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(6, 12, 24, 0.85);
  border: 1px solid;
  border-radius: 20px;
  padding: 6px 14px;
  font-family: var(--font-title);
  font-size: 0.85rem;
}
.hud-team-badge.eliminated {
  opacity: 0.35;
  filter: grayscale(1);
  text-decoration: line-through;
}
.team-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.team-lbl {
  color: var(--text-dim);
}
.team-val {
  font-weight: 700;
  color: #fff;
}

/* Top-Right: Tactical Radar */
.hud-radar-box {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 170px;
  height: 170px;
  background: rgba(6, 12, 24, 0.85);
  border: 1.5px solid var(--neon-cyan);
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(0, 210, 255, 0.25);
}
#radar-canvas {
  width: 100%;
  height: 100%;
}
.radar-sweep-line {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(0, 210, 255, 0.35) 0deg, transparent 60deg);
  animation: radar-spin 3s linear infinite;
  pointer-events: none;
}
@keyframes radar-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Bottom-Left: Holographic Ship Status */
.hud-ship-status {
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 320px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud-vital-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.vital-header {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-title);
  font-size: 0.8rem;
  letter-spacing: 1px;
}
.vital-bar-container {
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.vital-bar-fill {
  height: 100%;
  transition: width 0.1s linear;
}
.vital-fill-hull {
  background: linear-gradient(90deg, #ff3b5c, #ff708d);
  box-shadow: 0 0 10px #ff3b5c;
}
.vital-fill-shield {
  background: linear-gradient(90deg, #00d2ff, #78e5ff);
  box-shadow: 0 0 10px #00d2ff;
}
.vital-fill-energy {
  background: linear-gradient(90deg, #ffd000, #ffe678);
  box-shadow: 0 0 10px #ffd000;
}

.hud-armour-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-family: var(--font-title);
  font-size: 0.8rem;
}
#hud-armour-badge {
  color: var(--neon-gold);
  font-weight: 700;
}

/* Bottom-Right: Weapons Dock */
.hud-weapons-dock {
  position: absolute;
  bottom: 24px;
  right: 24px;
  display: flex;
  gap: 14px;
}
.weapon-card {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 100px;
  position: relative;
}
.weapon-key-badge {
  font-family: var(--font-title);
  font-size: 0.7rem;
  color: var(--text-dim);
}
.weapon-name {
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 700;
}
.weapon-ammo {
  font-family: var(--font-title);
  font-size: 1.3rem;
  color: var(--neon-cyan);
  font-weight: 800;
}
.special-ability-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--neon-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  position: relative;
  background: rgba(255, 208, 0, 0.1);
}
.ability-cooldown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  font-weight: 900;
  font-size: 1.1rem;
  color: #fff;
}

/* Center: Target Lock Display */
.hud-target-lock-card {
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, 0);
  background: rgba(10, 16, 28, 0.85);
  border: 1px solid var(--neon-red);
  padding: 8px 16px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 220px;
  font-family: var(--font-title);
}
.target-lock-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
}
.target-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.target-bar-bg {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
}

/* Killfeed */
.killfeed-dock {
  position: absolute;
  top: 75px;
  left: 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.killfeed-row {
  background: rgba(6, 12, 24, 0.8);
  border-left: 3px solid var(--neon-cyan);
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.3s;
}
.killfeed-elimination {
  border-left-color: var(--neon-red);
  background: rgba(50, 10, 20, 0.85);
}

/* Spectator Overlay */
.spectator-banner {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 20px;
  font-family: var(--font-title);
  pointer-events: auto;
}
.spectator-text {
  font-size: 1.1rem;
  color: var(--neon-gold);
}

/* Tactical Quick Comm Radial */
.quick-comm-modal {
  position: absolute;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}
.quick-comm-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.quick-comm-btn {
  padding: 10px 14px;
  background: rgba(0, 210, 255, 0.15);
  border: 1px solid var(--neon-cyan);
  color: #fff;
  border-radius: 4px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.quick-comm-btn:hover {
  background: var(--neon-cyan);
  color: #060a14;
}
.comm-key {
  color: var(--neon-gold);
  font-family: var(--font-title);
}

/* Scoreboard Overlay */
.scoreboard-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: var(--viewport-height);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(4, 8, 16, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  pointer-events: auto;
}
.scoreboard-box {
  width: 92%;
  max-width: 980px;
  max-height: min(88vh, calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom)));
  padding: 24px 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  box-shadow: 0 0 45px rgba(0, 210, 255, 0.2);
}

.scoreboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.scoreboard-header h2 {
  font-family: var(--font-title);
  font-size: clamp(1rem, 3vw, 1.5rem);
  letter-spacing: 1px;
}
#btn-close-scoreboard {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 0.75rem;
}
.scoreboard-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.scoreboard-table-container {
  flex: 1 1 auto;
  min-height: 0;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid rgba(0, 210, 255, 0.22);
  border-radius: 6px;
  background: rgba(6, 11, 20, 0.7);
}

/* Custom Cyber Scrollbar for Scoreboard */
.scoreboard-table-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.scoreboard-table-container::-webkit-scrollbar-track {
  background: rgba(4, 7, 15, 0.85);
  border-radius: 4px;
}

.scoreboard-table-container::-webkit-scrollbar-thumb {
  background: rgba(0, 210, 255, 0.45);
  border-radius: 4px;
  border: 1px solid rgba(0, 210, 255, 0.25);
}

.scoreboard-table-container::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 210, 255, 0.75);
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.6);
}

.scoreboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.92rem;
}
.scoreboard-table thead th {
  position: sticky;
  top: 0;
  background: #090e1a;
  font-family: var(--font-title);
  color: var(--neon-cyan);
  font-size: 0.82rem;
  letter-spacing: 1.5px;
  padding: 12px 14px;
  border-bottom: 2px solid rgba(0, 210, 255, 0.35);
  z-index: 3;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.scoreboard-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.scoreboard-table tbody tr:hover {
  background: rgba(0, 210, 255, 0.07);
}
.badge-team {
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Victory / Defeat Modal */
.victory-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: var(--viewport-height);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(4, 7, 15, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: auto;
}
.victory-box {
  width: 92%;
  max-width: 1020px;
  max-height: 90vh;
  max-height: min(90vh, calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom)));
  padding: 26px 36px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  box-shadow: 0 0 50px rgba(0, 210, 255, 0.25);
}
.victory-header-block {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.victory-text {
  font-family: var(--font-title);
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 5px;
  line-height: 1.1;
  margin: 0;
}
.victory-win {
  color: var(--neon-gold);
  text-shadow: 0 0 35px rgba(255, 208, 0, 0.8);
}
.victory-lose {
  color: var(--neon-red);
  text-shadow: 0 0 35px rgba(255, 59, 92, 0.8);
}
.victory-sub {
  font-family: var(--font-title);
  font-size: 1.05rem;
  color: var(--text-primary);
  letter-spacing: 1.5px;
  margin: 0;
}
.victory-buttons {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  gap: 20px;
  padding-top: 14px;
  border-top: 1px solid rgba(0, 210, 255, 0.2);
  margin-top: auto;
}

/* Settings Modal & Overlays */
.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--viewport-height);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(4, 8, 16, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: auto;
}
.settings-box {
  width: 90%;
  max-width: 520px;
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.settings-box > * { flex-shrink: 0; }
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.slider-group label {
  font-family: var(--font-title);
  font-size: 0.85rem;
  color: var(--text-dim);
}
.cyber-slider {
  accent-color: var(--neon-cyan);
  cursor: pointer;
}
.controls-guide-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.85rem;
  text-align: left;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 4px;
}
.controls-guide-list strong {
  color: var(--neon-cyan);
  font-family: var(--font-title);
}

/* Top-Right HUD Settings Button */
.hud-btn-settings {
  position: absolute;
  top: 20px;
  left: 20px;
  padding: 8px 14px;
  font-size: 0.8rem;
  pointer-events: auto;
}

/* =========================================================
   SINGLE PLAYER SETUP MODAL
   ========================================================= */
.sp-setup-box {
  width: 92%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  text-align: left;
}

.sp-header h2 {
  font-family: var(--font-title);
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
}
.sp-sub {
  font-size: 0.85rem;
  letter-spacing: 2px;
  color: var(--neon-green);
  text-transform: uppercase;
}

.sp-field-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sp-field-group label {
  font-family: var(--font-title);
  font-size: 0.8rem;
  letter-spacing: 1.5px;
  color: var(--text-dim);
}

.sp-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.sp-mode-btn, .sp-diff-btn {
  background: rgba(14, 22, 38, 0.7);
  border: 1px solid rgba(0, 210, 255, 0.25);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  transition: all 0.2s;
  color: #fff;
}
.sp-mode-btn:hover, .sp-diff-btn:hover {
  border-color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.1);
}
.sp-mode-btn.active {
  border-color: var(--neon-green);
  background: rgba(0, 255, 136, 0.15);
  box-shadow: 0 0 16px rgba(0, 255, 136, 0.35);
}
.sp-diff-btn.active {
  border-color: var(--neon-gold);
  background: rgba(255, 208, 0, 0.15);
  box-shadow: 0 0 16px rgba(255, 208, 0, 0.35);
}
.sp-btn-title {
  font-family: var(--font-title);
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
}
.sp-btn-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.25;
}

.sp-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.sp-count-selector {
  display: flex;
  align-items: center;
  gap: 14px;
}
.sp-count-badge {
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--neon-gold);
  background: rgba(255, 208, 0, 0.12);
  border: 1px solid var(--neon-gold);
  padding: 6px 14px;
  border-radius: 4px;
  white-space: nowrap;
}

.sp-ship-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.sp-ship-btn {
  background: rgba(14, 22, 38, 0.7);
  border: 1px solid rgba(0, 210, 255, 0.25);
  border-radius: 6px;
  padding: 10px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #fff;
  transition: all 0.2s;
}
.sp-ship-btn:hover {
  border-color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.1);
}
.sp-ship-btn.active {
  border-color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.2);
  box-shadow: 0 0 16px rgba(0, 210, 255, 0.4);
}
.sp-ship-btn strong {
  font-family: var(--font-title);
  font-size: 0.8rem;
}
.sp-ship-btn small {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.sp-actions {
  display: flex;
  gap: 16px;
  margin-top: 10px;
}

/* Single Player Arena Grid */
.sp-map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.sp-map-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-primary);
  text-align: left;
  transition: all 0.2s ease;
}
.sp-map-btn:hover {
  border-color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.08);
}
.sp-map-btn.active {
  border-color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.18);
  box-shadow: 0 0 16px rgba(0, 210, 255, 0.35);
}
.sp-map-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sp-map-info strong {
  display: block;
  font-family: var(--font-title);
  font-size: 0.78rem;
  letter-spacing: 0.5px;
}
.sp-map-info small {
  display: block;
  font-size: 0.68rem;
  color: var(--text-dim);
}

/* In-Game Sector Announcement Banner */
.hud-sector-banner {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 32px;
  background: rgba(6, 10, 20, 0.88);
  border: 1.5px solid var(--neon-cyan);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  pointer-events: none;
  z-index: 25;
  box-shadow: 0 0 24px rgba(0, 210, 255, 0.4);
}
.sector-badge {
  font-family: var(--font-title);
  font-size: 0.65rem;
  letter-spacing: 3px;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.sector-code {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
.sector-sub {
  font-family: var(--font-body);
  font-size: 0.85rem;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Animations */
.slide-in {
  animation: sectorSlideDown 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.fade-out {
  animation: sectorFadeOut 0.8s ease forwards;
}

@keyframes sectorSlideDown {
  from {
    opacity: 0;
    transform: translate(-50%, -25px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes sectorFadeOut {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -15px);
  }
}

/* Responsiveness */
@media (max-width: 1100px) {
  .lobby-main-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .sp-two-col {
    grid-template-columns: 1fr;
  }
  .sp-ship-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Team Voice Channel Comms Dock */
.team-comms-dock {
  position: absolute;
  top: 124px;
  left: 22px;
  width: 290px;
  display: flex;
  flex-direction: column;
  background: rgba(10, 16, 30, 0.92);
  border: 1.5px solid rgba(0, 210, 255, 0.4);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 16px rgba(0, 210, 255, 0.2);
  backdrop-filter: blur(12px);
  z-index: 50;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  overflow: hidden;
}

.comms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  cursor: grab;
  touch-action: none;
}
.comms-header:active { cursor: grabbing; }
.comms-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.comms-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--neon-cyan);
  box-shadow: 0 0 8px var(--neon-cyan);
  animation: commsPulse 2s infinite ease-in-out;
}
@keyframes commsPulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.3); opacity: 1; }
}
.comms-channel-title {
  font-family: var(--font-title);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comms-collapsed .comms-members-box,
.comms-collapsed .comms-control-bar { display: none; }
.comms-connection-row { padding: 4px 8px; display: flex; align-items: center; gap: 6px; font-size: 0.8rem; }
#comms-connection-status { flex: 1; }
#btn-comms-retry { min-height: 44px; flex: 0 0 auto; padding: 4px 6px; }
#btn-comms-talk { min-height: 44px; touch-action: none; }
#btn-comms-retry[hidden], #btn-comms-talk[hidden] { display: none; }
.comms-btn-icon {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 4px;
  transition: color 0.15s;
}
.comms-btn-icon:hover {
  color: #ffffff;
}
.comms-header-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.comms-drag-handle {
  color: var(--text-dim);
  font-family: var(--font-title);
  font-size: 0.55rem;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.comms-position-reset { display: none; }
.team-comms-dock.comms-custom-position .comms-position-reset { display: block; }

.comms-members-box {
  padding: 8px 12px;
  max-height: 160px;
  overflow-y: auto;
}
.comms-members-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.comms-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.comms-member-row.self {
  background: rgba(0, 210, 255, 0.06);
}
.comms-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--neon-cyan);
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.comms-avatar.speaking {
  border-color: #00ff88 !important;
  box-shadow: 0 0 12px #00ff88;
  animation: speakingGlow 0.8s infinite alternate;
}
@keyframes speakingGlow {
  from { box-shadow: 0 0 4px #00ff88; }
  to { box-shadow: 0 0 16px #00ff88, inset 0 0 8px #00ff88; }
}
.comms-name {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.comms-status-tag {
  font-family: var(--font-title);
  font-size: 0.62rem;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.comms-status-tag.muted {
  color: #ff3b5c;
}
.comms-status-tag.active {
  color: #00ff88;
  font-weight: 700;
}

.comms-control-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px 10px 12px;
  background: rgba(15, 23, 42, 0.7);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.comms-btn-group {
  display: flex;
  gap: 6px;
}
.btn-comms-ctrl {
  flex: 1;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 6px 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-comms-ctrl:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: var(--neon-cyan);
}
.btn-comms-ctrl.active-mute,
.btn-comms-ctrl.active-deafen {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
  color: #fca5a5;
}
.btn-comms-mode {
  flex: 1.2;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: var(--font-title);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 6px 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.btn-comms-mode:hover {
  color: #ffffff;
  border-color: var(--neon-cyan);
}

.comms-meter-container {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}
.comms-meter-fill {
  height: 100%;
  width: 0%;
  background: var(--neon-cyan);
  transition: width 0.06s ease;
}

/* ========================================================
   PILOT STATUS BAR & AUTHENTICATION BADGE
   ======================================================== */
.pilot-status-bar {
  width: 100%;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), inset 0 0 10px rgba(0, 240, 255, 0.04);
}

.pilot-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.pilot-badge-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pilot-avatar-icon {
  font-size: 1.8rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 240, 255, 0.1);
  border: 1.5px solid var(--neon-cyan);
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

.pilot-text-block {
  text-align: left;
}

.pilot-name-title {
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffffff;
}

.pilot-auth-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pilot-rank-tag {
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--neon-gold);
  background: rgba(255, 170, 0, 0.15);
  border: 1px solid rgba(255, 170, 0, 0.4);
  border-radius: 3px;
  padding: 2px 6px;
}

.pilot-level-tag {
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--neon-cyan);
  background: rgba(0, 240, 255, 0.15);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 3px;
  padding: 2px 6px;
}

.pilot-status-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.pilot-badge-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========================================================
   AUTH & REGISTRATION MODAL
   ======================================================== */
.auth-panel-box {
  width: 90%;
  max-width: 520px;
  background: rgba(10, 15, 29, 0.96);
  border: 1px solid var(--neon-cyan);
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.2), inset 0 0 20px rgba(0, 240, 255, 0.05);
  border-radius: 8px;
  padding: 24px;
}

.auth-header {
  text-align: center;
  margin-bottom: 18px;
}
.auth-header h2 {
  font-family: var(--font-title);
  font-size: 1.3rem;
  letter-spacing: 2px;
  color: #ffffff;
  margin: 0;
  text-shadow: 0 0 12px var(--neon-cyan);
}
.auth-sub {
  font-size: 0.72rem;
  color: var(--neon-cyan);
  letter-spacing: 1.5px;
}

.auth-tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 10px;
}

.auth-tab-btn {
  flex: 1;
  padding: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: var(--font-title);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s;
}
.auth-tab-btn:hover {
  color: #ffffff;
  border-color: rgba(0, 240, 255, 0.5);
}
.auth-tab-btn.active {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.25);
}

.auth-form-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.auth-field-group label {
  font-family: var(--font-title);
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.avatar-select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.avatar-card-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.avatar-card-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(0, 240, 255, 0.4);
}
.avatar-card-btn.active {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}
.avatar-symbol {
  font-size: 1.3rem;
}
.avatar-name {
  font-family: var(--font-title);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
}

.auth-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.cyber-select {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(0, 240, 255, 0.3);
  color: #ffffff;
  padding: 10px 12px;
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.cyber-select:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.auth-status-msg {
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  text-align: center;
}
.auth-status-msg.error {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #fca5a5;
}
.auth-status-msg.success {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid #10b981;
  color: #6ee7b7;
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* ========================================================
   PILOT CAREER DOSSIER MODAL
   ======================================================== */
.profile-dossier-box {
  width: 90%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  background: rgba(10, 15, 29, 0.96);
  border: 1px solid var(--neon-gold);
  box-shadow: 0 0 35px rgba(255, 170, 0, 0.2), inset 0 0 20px rgba(255, 170, 0, 0.05);
  border-radius: 8px;
  padding: 24px;
}

.dossier-header-card {
  display: flex;
  align-items: center;
  gap: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 170, 0, 0.3);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.dossier-avatar-badge {
  font-size: 2.8rem;
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 170, 0, 0.1);
  border: 2px solid var(--neon-gold);
  border-radius: 10px;
  box-shadow: 0 0 16px rgba(255, 170, 0, 0.3);
  flex-shrink: 0;
}

.dossier-identity {
  text-align: left;
  flex: 1;
}

.dossier-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.dossier-name-row h2 {
  font-family: var(--font-title);
  font-size: 1.35rem;
  letter-spacing: 1.5px;
  color: #ffffff;
  margin: 0;
}

.dossier-sub-title {
  font-family: var(--font-title);
  font-size: 0.82rem;
  color: var(--neon-gold);
  letter-spacing: 1px;
  margin-top: 4px;
}

.dossier-enlist-date {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.dossier-progression-box {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.dossier-xp-label {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-title);
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.dossier-bar-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.dossier-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-gold));
  border-radius: 4px;
  transition: width 0.4s ease;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.dossier-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.dossier-stat-card {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 12px 8px;
  text-align: center;
}

.dossier-stat-num {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
}

.dossier-stat-lbl {
  font-size: 0.65rem;
  font-family: var(--font-title);
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-top: 4px;
}

.dossier-editor-section {
  text-align: left;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dossier-editor-section h3 {
  font-family: var(--font-title);
  font-size: 0.85rem;
  letter-spacing: 1.5px;
  color: var(--neon-cyan);
  margin: 0;
}

/* ========================================================
   CYBER TOAST NOTIFICATIONS
   ======================================================== */
.cyber-toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.cyber-toast {
  background: rgba(12, 17, 29, 0.95);
  border: 1px solid var(--neon-cyan);
  box-shadow: 0 4px 20px rgba(0, 210, 255, 0.28);
  color: #ffffff;
  font-family: var(--font-title);
  font-size: 0.95rem;
  letter-spacing: 1px;
  padding: 12px 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(-15px);
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.cyber-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.cyber-toast-success {
  border-color: var(--neon-green);
  box-shadow: 0 4px 20px rgba(0, 255, 136, 0.3);
}

.cyber-toast-error {
  border-color: var(--neon-red);
  box-shadow: 0 4px 20px rgba(255, 59, 92, 0.3);
}

.toast-icon {
  font-size: 1.15rem;
}

.toast-text {
  font-weight: 600;
}


/* ========================================================
   HUD TOP ACTIONS TOOLBAR (Settings, Scoreboard, Comm, Mic)
   ======================================================== */
.hud-top-actions {
  position: absolute;
  top: 16px;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  left: max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 50;
  pointer-events: auto;
}

.hud-action-icon-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-family: var(--font-title);
  font-size: 0.75rem;
  letter-spacing: 1px;
  background: rgba(10, 16, 30, 0.88);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.hud-action-icon-btn:hover {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.4);
  transform: translateY(-1px);
}

.hud-action-icon-btn:active {
  transform: scale(0.94);
}

.hud-action-icon-btn.active-mute {
  border-color: var(--neon-red);
  color: var(--neon-red);
  box-shadow: 0 0 14px rgba(255, 59, 92, 0.4);
}

.hud-btn-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.hud-btn-lbl {
  font-weight: 700;
}

.hud-zoom-controls {
  position: absolute;
  top: calc(var(--safe-top) + 56px);
  left: max(16px, env(safe-area-inset-left));
  display: flex;
  gap: 4px;
  z-index: 50;
  pointer-events: auto;
}
.hud-zoom-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid rgba(0, 210, 255, 0.4);
  border-radius: 6px;
  background: rgba(10, 16, 30, 0.8);
  color: var(--neon-cyan);
  font-size: 1.4rem;
  cursor: pointer;
  touch-action: manipulation;
}
.hud-zoom-reset {
  min-width: 60px;
  font-family: var(--font-title);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}
.hud-zoom-btn:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}
.hud-zoom-btn:active { background: rgba(0, 210, 255, 0.25); }
.hud-zoom-btn:disabled { opacity: 0.4; cursor: default; }

/* ========================================================
   MOBILE & TABLET VIRTUAL TOUCH CONTROLS
   ======================================================== */
.mobile-controls-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 45;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Left Joystick Zone */
.touch-joystick-zone {
  position: absolute;
  bottom: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 20px;
  left: max(20px, env(safe-area-inset-left));
  width: 200px;
  height: 200px;
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-base {
  position: absolute;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 240, 255, 0.08) 0%, rgba(5, 12, 28, 0.8) 75%);
  border: 2px solid rgba(0, 240, 255, 0.45);
  box-shadow: 0 0 25px rgba(0, 240, 255, 0.25), inset 0 0 15px rgba(0, 240, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.joystick-knob {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #00f0ff 45%, #0077aa 100%);
  border: 2px solid #ffffff;
  box-shadow: 0 0 16px #00f0ff, inset 0 0 8px rgba(255, 255, 255, 0.8);
  pointer-events: none;
  will-change: transform;
}

.joystick-guide-label {
  font-family: var(--font-title);
  font-size: 0.68rem;
  letter-spacing: 2px;
  color: rgba(0, 240, 255, 0.6);
  pointer-events: none;
}

/* Right Touch Action Cluster */
.touch-actions-zone {
  position: absolute;
  bottom: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: 20px;
  right: max(20px, env(safe-area-inset-right));
  width: 220px;
  height: 220px;
  pointer-events: none;
  touch-action: none;
}

.touch-btn {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.08s ease, filter 0.08s ease, box-shadow 0.08s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  outline: none;
  padding: 0;
}

.touch-btn:active, .touch-btn.active {
  transform: scale(0.92);
  filter: brightness(1.4);
}

.touch-btn-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.touch-btn-sub {
  font-family: var(--font-title);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* Primary Fire (Largest button, bottom-right) */
.touch-btn-primary {
  bottom: 8px;
  right: 8px;
  width: 76px;
  height: 76px;
  background: radial-gradient(circle, rgba(255, 75, 43, 0.4) 0%, rgba(18, 5, 8, 0.9) 85%);
  border-color: #ff4b2b;
  box-shadow: 0 0 20px rgba(255, 75, 43, 0.5), inset 0 0 10px rgba(255, 75, 43, 0.25);
  color: #ffffff;
}

.touch-btn-primary .touch-btn-icon {
  font-size: 1.45rem;
}

/* Secondary Missiles (Above primary) */
.touch-btn-secondary {
  bottom: 96px;
  right: 10px;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle, rgba(0, 240, 255, 0.35) 0%, rgba(5, 15, 28, 0.9) 85%);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.4), inset 0 0 8px rgba(0, 240, 255, 0.2);
  color: #ffffff;
}

.touch-ammo-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff0055;
  color: #fff;
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid #ffffff;
  box-shadow: 0 0 6px #ff0055;
}

/* Special Ability (Top-left of cluster) */
.touch-btn-special {
  bottom: 96px;
  right: 86px;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle, rgba(255, 190, 11, 0.35) 0%, rgba(25, 18, 5, 0.9) 85%);
  border-color: var(--neon-gold);
  box-shadow: 0 0 18px rgba(255, 190, 11, 0.45), inset 0 0 8px rgba(255, 190, 11, 0.2);
  color: #ffffff;
}

.touch-cooldown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 800;
  color: #ff3b5c;
  text-shadow: 0 0 10px #ff3b5c;
}

/* Afterburner Boost (Bottom-left of cluster) */
.touch-btn-boost {
  bottom: 10px;
  right: 98px;
  width: 56px;
  height: 56px;
  background: radial-gradient(circle, rgba(0, 255, 136, 0.35) 0%, rgba(4, 24, 14, 0.9) 85%);
  border-color: var(--neon-green);
  box-shadow: 0 0 18px rgba(0, 255, 136, 0.45), inset 0 0 8px rgba(0, 255, 136, 0.2);
  color: #ffffff;
}

/* ========================================================
   RESPONSIVE LAYOUT FOR TABLETS & MOBILES
   ======================================================== */
@media (max-width: 900px) {
  /* Screens and Menu Layout */
  .menu-container {
    width: 92%;
    max-width: 520px;
    padding: 28px 18px;
    margin: 16px auto;
  }
  .game-title {
    font-size: 2.1rem;
    letter-spacing: 3px;
  }
  .game-subtitle {
    font-size: 0.82rem;
    letter-spacing: 1.5px;
  }
  .menu-actions {
    gap: 12px;
  }

  /* Lobby Layout */
  .lobby-layout {
    width: 96%;
    height: 94vh;
    padding: 16px;
  }
  .lobby-header {
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
  }
  .room-code-tag {
    flex-wrap: wrap;
    justify-content: center;
  }
  .lobby-main-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
  }
  .lobby-center-col {
    order: -1; /* Ship preview on top */
    flex: 0 0 auto;
  }
  .lobby-teams-col,
  .lobby-controls-col {
    flex: 0 0 auto;
  }
  .lobby-teams-col,
  .ship-cards-container {
    overflow: visible;
  }
  .ship-cards-container {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    flex: 0 0 auto;
  }

  /* HUD Status Adjustments */
  .hud-top-teams {
    top: 12px;
    top: max(12px, env(safe-area-inset-top));
    gap: 6px;
  }
  .hud-team-badge {
    padding: 4px 8px;
    font-size: 0.72rem;
  }
  .team-lbl {
    display: none; /* Hide label text to prevent crowding */
  }

  .hud-radar-box {
    top: 12px;
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    right: max(12px, env(safe-area-inset-right));
    width: 120px;
    height: 120px;
  }

  /* Hide desktop weapons dock on touch-enabled screens */
  .has-touch .hud-weapons-dock {
    display: none !important;
  }

  /* Voice Comms Dock */
  .team-comms-dock {
    width: min(90%, 280px);
    right: 12px;
    bottom: 84px;
  }

  /* Modals */
  .sp-setup-box, .settings-box, .auth-panel-box {
    width: 95%;
    max-height: calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom));
    overflow-y: auto;
    padding: 20px 16px;
  }
  .sp-two-col {
    grid-template-columns: 1fr;
  }
  .sp-ship-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .modal-actions {
    flex-direction: column;
    gap: 10px;
  }
}

@media (max-width: 600px) {
  .game-title {
    font-size: 1.6rem;
    letter-spacing: 2px;
  }
  .menu-actions {
    flex-direction: column;
    gap: 10px;
  }
  .join-room-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .join-room-row .cyber-input {
    padding-right: 10px;
    padding-left: 10px;
    font-size: 0.85rem;
  }
  .join-room-row #btn-join-room {
    min-width: 76px;
    padding-right: 12px;
    padding-left: 12px;
  }
  .pilot-status-row {
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }
  .pilot-badge-info,
  .pilot-text-block {
    min-width: 0;
  }
  .pilot-badge-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .pilot-badge-actions .btn-cyber {
    width: 100%;
    min-width: 0;
    padding-right: 8px !important;
    padding-left: 8px !important;
  }
  .menu-btn {
    width: 100%;
    padding: 12px;
  }

  /* Top Action Toolbar */
  .hud-top-actions {
    top: 8px;
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    left: max(8px, env(safe-area-inset-left));
    gap: 4px;
  }
  .hud-action-icon-btn {
    padding: 5px 8px;
  }
  .hud-btn-lbl {
    display: none; /* Icon-only button on phone displays */
  }

  /* Radar */
  .hud-radar-box {
    width: 90px;
    height: 90px;
    top: 8px;
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    right: max(8px, env(safe-area-inset-right));
  }

  /* Sector Banner */
  .hud-sector-banner {
    top: 55px;
    transform: translateX(-50%) scale(0.85);
  }

  /* Killfeed */
  .killfeed-dock {
    top: 105px;
    right: 8px;
    max-width: 180px;
    font-size: 0.7rem;
  }

  /* Touch Controls scaling for small phones */
  .touch-joystick-zone {
    bottom: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    left: max(8px, env(safe-area-inset-left));
    width: 160px;
    height: 160px;
  }
  .joystick-base {
    width: 116px;
    height: 116px;
  }
  .joystick-knob {
    width: 42px;
    height: 42px;
  }

  .touch-actions-zone {
    bottom: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    right: 8px;
    right: max(8px, env(safe-area-inset-right));
    width: 180px;
    height: 180px;
  }
  .touch-btn-primary {
    width: 62px;
    height: 62px;
    bottom: 4px;
    right: 4px;
  }
  .touch-btn-secondary {
    width: 48px;
    height: 48px;
    bottom: 74px;
    right: 4px;
  }
  .touch-btn-special {
    width: 48px;
    height: 48px;
    bottom: 74px;
    right: 62px;
  }
  .touch-btn-boost {
    width: 44px;
    height: 44px;
    bottom: 4px;
    right: 74px;
  }

  /* Ship Selection Cards Grid */
  .ship-cards-container {
    grid-template-columns: 1fr;
  }

  /* Auth avatar grid */
  .avatar-select-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Keep mobile vitals beside the battlefield and clear of the thumb controls. */
@media (max-width: 1100px) {
  .hud-radar-box {
    top: var(--safe-top);
    right: var(--safe-right);
    width: 90px;
    height: 90px;
  }
  .hud-ship-status {
    top: calc(var(--safe-top) + 98px);
    right: var(--safe-right);
    bottom: auto;
    left: auto;
    width: 148px;
    padding: 4px 7px;
    gap: 2px;
    background: rgba(6, 12, 24, 0.72);
    box-shadow: none;
  }
  .hud-vital-row { gap: 2px; }
  .vital-header { font-size: 0.625rem; line-height: 1.2; letter-spacing: 0; }
  .vital-label-detail { display: none; }
  .vital-bar-container { height: 4px; }
  .hud-armour-row { padding-top: 2px; font-size: 0.6rem; line-height: 1.2; }
  .hud-armour-row > span:first-child { display: none; }
  #hud-armour-badge { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hud-zoom-controls { top: calc(var(--safe-top) + 52px); left: var(--safe-left); }
  .killfeed-dock { top: calc(var(--safe-top) + 204px); right: var(--safe-right); }
  .has-touch .hud-weapons-dock { display: none !important; }
}

/* Keep voice above the thumb controls in both phone and tablet layouts. */
@media (max-width: 1100px), (pointer: coarse) {
  .team-comms-dock {
    top: auto;
    left: var(--safe-left);
    right: auto;
    bottom: calc(var(--safe-bottom) + 224px);
    width: min(260px, calc(100% - var(--safe-left) - var(--safe-right)));
    max-height: min(280px, calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom) - 336px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .team-comms-dock > * { flex-shrink: 0; }
  .comms-header { padding: 0 8px; }
  .comms-header { cursor: default; touch-action: auto; }
  .comms-drag-handle, .comms-position-reset { display: none !important; }
  .comms-btn-icon { min-width: 44px; min-height: 44px; flex-shrink: 0; }
  .btn-comms-ctrl, .btn-comms-mode { min-height: 44px; }
  .comms-channel-title { font-size: 0.65rem; letter-spacing: 0; }
}

@media (max-width: 600px) and (orientation: portrait) {
  .team-comms-dock {
    bottom: calc(var(--safe-bottom) + 184px);
    max-height: min(280px, calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom) - 372px));
  }
  .hud-top-teams {
    top: calc(var(--safe-top) + 104px);
    left: var(--safe-left);
    transform: none;
    gap: 4px;
  }
  .hud-team-badge { padding: 4px 7px; gap: 4px; font-size: 0.65rem; }
  .team-lbl, .team-state { display: none; }
  .hud-sector-banner {
    top: calc(var(--safe-top) + 148px);
    left: var(--safe-left);
    width: calc(100% - 176px - var(--safe-left) - var(--safe-right));
    transform: none;
    padding: 6px;
  }
  .sector-badge { font-size: 0.45rem; letter-spacing: 0; }
  .sector-code { font-size: 0.6rem; letter-spacing: 0; }
  .sector-sub { display: none; }
}

/* Short, wide phone screens need a layout based on height as well as width. */
@media (max-width: 1100px) and (max-height: 550px) and (orientation: landscape) {
  .menu-container {
    max-height: calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom));
    overflow-y: auto;
    margin: 0;
    padding: 16px;
  }

  .hud-top-actions {
    top: var(--safe-top);
    left: var(--safe-left);
    gap: 4px;
  }
  .hud-action-icon-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 6px 8px;
    justify-content: center;
  }
  .hud-btn-lbl { display: none; }
  #btn-hud-scoreboard .hud-btn-lbl { display: inline; }

  .hud-top-teams {
    top: var(--safe-top);
    left: auto;
    right: calc(var(--safe-right) + 96px);
    transform: none;
    gap: 4px;
  }
  .hud-team-badge {
    min-height: 32px;
    padding: 4px 7px;
    gap: 5px;
    font-size: 0.7rem;
  }
  .team-lbl, .team-state { display: none; }
  .hud-radar-box {
    top: var(--safe-top);
    right: var(--safe-right);
    width: 80px;
    height: 80px;
  }

  .hud-ship-status {
    top: calc(var(--safe-top) + 88px);
    width: 144px;
  }

  .touch-joystick-zone {
    left: var(--safe-left);
    bottom: var(--safe-bottom);
    width: 136px;
    height: 136px;
  }
  .joystick-base { width: 100px; height: 100px; }
  .joystick-knob { width: 40px; height: 40px; }
  .joystick-guide-label { font-size: 0.6rem; }
  .touch-actions-zone {
    right: var(--safe-right);
    bottom: var(--safe-bottom);
    width: 144px;
    height: 136px;
  }
  .touch-btn-primary { width: 60px; height: 60px; bottom: 0; right: 0; }
  .touch-btn-secondary { width: 52px; height: 52px; bottom: 76px; right: 4px; }
  .touch-btn-special { width: 52px; height: 52px; bottom: 76px; right: 76px; }
  .touch-btn-boost { width: 48px; height: 48px; bottom: 4px; right: 76px; }
  .touch-btn-sub { font-size: 0.5rem; }

  .hud-sector-banner {
    top: calc(var(--safe-top) + 48px);
    max-width: calc(100% - 300px - var(--safe-left) - var(--safe-right));
    padding: 5px 10px;
    text-align: center;
  }
  .sector-badge { font-size: 0.5rem; letter-spacing: 1px; }
  .sector-code { font-size: 0.7rem; letter-spacing: 0.5px; }
  .sector-sub { font-size: 0.6rem; letter-spacing: 0; }
  .killfeed-dock {
    top: calc(var(--safe-top) + 104px);
    left: var(--safe-left);
    right: auto;
    max-width: 200px;
  }
  .killfeed-row { padding: 3px 6px; font-size: 0.7rem; }
  .killfeed-row:nth-child(n + 3) { display: none; }
  .hud-target-lock-card {
    top: auto;
    bottom: calc(var(--safe-bottom) + 104px);
    width: 180px;
    padding: 4px 8px;
  }
  .target-lock-header { font-size: 0.6rem; gap: 6px; }
  #target-lock-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #target-lock-dist { flex-shrink: 0; }

  .team-comms-dock {
    left: var(--safe-left);
    right: auto;
    bottom: calc(var(--safe-bottom) + 144px);
    width: 220px;
    max-height: max(64px, calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom) - 248px));
    overflow-y: auto;
  }
  .team-comms-dock > * { flex-shrink: 0; }
  .comms-header { padding: 0 8px; }
  .comms-btn-icon { min-width: 44px; min-height: 44px; }

  .quick-comm-modal {
    top: calc(var(--safe-top) + 52px);
    bottom: auto;
    max-height: calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom) - 60px);
    width: min(480px, calc(100% - var(--safe-left) - var(--safe-right)));
    overflow-y: auto;
    padding: 10px;
    z-index: 60;
  }
  .quick-comm-btn { min-height: 44px; padding: 6px; }
  .spectator-banner {
    bottom: calc(var(--safe-bottom) + 8px);
    width: min(480px, calc(100% - 32px));
    padding: 8px;
    gap: 8px;
    justify-content: space-between;
    z-index: 60;
  }
  .spectator-text { font-size: 0.75rem; }
  .spectator-banner .btn-cyber { min-height: 44px; padding: 8px; font-size: 0.65rem; }
}

/* Keep modal headers/actions visible while the score table scrolls in either direction. */
@media (max-width: 900px), (max-height: 550px) {
  .scoreboard-box, .victory-box {
    width: 100%;
    max-height: calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom));
    padding: 10px 12px;
    gap: 8px;
  }
  .scoreboard-table { font-size: 0.8rem; }
  .scoreboard-table th, .scoreboard-table td { padding: 7px 8px; white-space: nowrap; }
  .scoreboard-table thead th { font-size: 0.65rem; letter-spacing: 0.5px; }
  .victory-text { font-size: 1.6rem; letter-spacing: 2px; }
  .victory-sub { font-size: 0.75rem; letter-spacing: 0.5px; }
  .victory-buttons { gap: 8px; padding-top: 8px; flex-wrap: wrap; }
  .victory-buttons .btn-cyber {
    min-height: 44px;
    padding: 8px 12px !important;
    font-size: 0.7rem !important;
  }
}
