:root {
  --bg-dark: #07090e;
  --bg-panel: rgba(13, 17, 27, 0.88);
  --bg-card: rgba(20, 27, 43, 0.75);
  --border-cyan: rgba(0, 242, 254, 0.35);
  --border-glow: #00f2fe;
  --accent-cyan: #00f2fe;
  --accent-magenta: #ff007f;
  --accent-gold: #ffd700;
  --accent-green: #39ff14;
  --accent-purple: #9d4edd;
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --danger: #ff3366;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font-main: 'Segoe UI Variable Display', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Consolas', 'Cascadia Code', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-main);
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

canvas#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #0c1220 0%, #05070c 100%);
  cursor: crosshair;
}

/* CRT Scanline & Grain Overlay */
.crt-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
              linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
  background-size: 100% 3px, 6px 100%;
  z-index: 10;
  opacity: 0.85;
}

/* UI Layers */
.ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.interactive {
  pointer-events: auto;
}

/* HUD Header (XP Bar, Stats, Music Player) */
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.xp-container {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.level-badge {
  background: linear-gradient(135deg, #00f2fe, #4facfe);
  color: #030a16;
  font-weight: 900;
  font-size: 0.95rem;
  padding: 6px 14px;
  border-radius: 8px;
  letter-spacing: 0.05em;
  box-shadow: 0 0 16px rgba(0, 242, 254, 0.6);
  white-space: nowrap;
}

.xp-bar-bg {
  flex: 1;
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  border: 1px solid rgba(0, 242, 254, 0.3);
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
}

.xp-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00f2fe, #39ff14);
  border-radius: 6px;
  transition: width 150ms var(--ease-out);
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.8);
}

.hud-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: #c9d1d9;
}

.hud-stats-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hud-stats-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(13, 17, 27, 0.7);
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
}

.stat-item i {
  font-style: normal;
  color: var(--accent-cyan);
}

.stat-item.timer {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  border-color: rgba(0, 242, 254, 0.4);
}

.stat-item.credits i {
  color: var(--accent-gold);
}

/* Auto-Fire Toggle Button */
.btn-toggle-autofire {
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid var(--border-cyan);
  color: #fff;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  font-weight: 700;
  cursor: pointer;
  transition: all 140ms ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-toggle-autofire.active {
  background: rgba(57, 255, 20, 0.15);
  border-color: #39ff14;
  color: #39ff14;
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.3);
}

.btn-toggle-autofire.inactive {
  background: rgba(255, 51, 102, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}

/* IVOXYGEN Music Player Widget */
.music-player-widget {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(13, 17, 27, 0.85);
  border: 1px solid rgba(255, 0, 127, 0.4);
  padding: 5px 14px;
  border-radius: 8px;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 16px rgba(255, 0, 127, 0.2);
}

.music-eq {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.music-eq-bar {
  width: 3px;
  background: #ff007f;
  border-radius: 1px;
  animation: eqBounce 0.8s ease-in-out infinite alternate;
}
.music-eq-bar:nth-child(1) { height: 40%; animation-delay: 0.1s; }
.music-eq-bar:nth-child(2) { height: 90%; animation-delay: 0.3s; }
.music-eq-bar:nth-child(3) { height: 60%; animation-delay: 0.2s; }
.music-eq-bar:nth-child(4) { height: 100%; animation-delay: 0.4s; }

@keyframes eqBounce {
  0% { transform: scaleY(0.3); }
  100% { transform: scaleY(1); }
}

.music-track-info {
  display: flex;
  flex-direction: column;
  text-align: left;
  line-height: 1.15;
}

.music-track-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-track-artist {
  font-size: 0.65rem;
  color: #ff007f;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.music-btn {
  background: transparent;
  border: 0;
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
  border-radius: 4px;
  transition: transform 120ms ease, color 120ms ease;
}

.music-btn:hover {
  color: #ff007f;
  transform: scale(1.15);
}

/* Player Health, Dash & Boost Gauge (Bottom Center) */
.hud-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 380px;
}

.hp-bar-bg {
  width: 100%;
  height: 18px;
  background: rgba(15, 20, 30, 0.8);
  border-radius: 10px;
  border: 1px solid rgba(255, 51, 102, 0.5);
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 14px rgba(255, 51, 102, 0.3);
}

.hp-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff3366, #ff758c);
  transition: width 120ms ease-out;
}

.hp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: bold;
  text-shadow: 0 1px 2px #000;
}

.gauges-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 16px;
}

.gauge-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.gauge-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.gauge-bar-dash {
  height: 100%;
  width: 100%;
  background: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan);
}

.gauge-bar-boost {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff007f, #ffd700);
  box-shadow: 0 0 8px rgba(255, 0, 127, 0.8);
}

/* Interactive Numbered Skill Bar (Bottom Left) */
.hud-skills-bar {
  position: absolute;
  bottom: 20px;
  left: 24px;
  display: flex;
  gap: 10px;
}

.skill-slot {
  width: 54px;
  height: 54px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  transition: transform 140ms var(--ease-out), border-color 140ms ease, box-shadow 140ms ease;
  overflow: hidden;
}

.skill-slot:hover {
  transform: translateY(-4px) scale(1.05);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 16px rgba(0, 242, 254, 0.5);
}

.skill-slot:active {
  transform: scale(0.95);
}

.skill-slot.ready {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.35);
}

.skill-slot.is-disabled {
  opacity: 0.42;
  filter: grayscale(0.4);
  cursor: not-allowed;
}

.skill-slot.is-disabled:hover {
  transform: none;
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
}

.skill-hotkey-badge {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  font-weight: 900;
  color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.6);
  padding: 1px 4px;
  border-radius: 4px;
}

.skill-icon {
  font-size: 1.35rem;
}

.skill-level-badge {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  font-weight: bold;
  color: var(--accent-cyan);
}

.skill-cooldown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-weight: bold;
  color: #fff;
  transition: height 80ms linear;
  pointer-events: none;
}

/* Floating Notification / Boss Warnings */
.boss-banner {
  position: absolute;
  top: 15%;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: linear-gradient(90deg, rgba(255, 0, 60, 0.85), rgba(120, 0, 30, 0.95), rgba(255, 0, 60, 0.85));
  padding: 14px 40px;
  border-radius: 8px;
  border: 1px solid #ff3366;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: transform 300ms var(--ease-out), opacity 300ms ease;
  box-shadow: 0 0 30px rgba(255, 0, 60, 0.7);
  z-index: 50;
}

.boss-banner.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.boss-banner h2 {
  font-size: 1.6rem;
  color: #fff;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.boss-banner p {
  font-size: 0.9rem;
  color: #ffd2dc;
  margin-top: 4px;
}

/* Modal Overlay Screens (Start, Level Up, Hangar, Game Over, Pause) */
.modal-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 15, 0.82);
  backdrop-filter: blur(16px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 250ms ease, visibility 250ms ease;
  z-index: 60;
  padding: 20px;
}

.modal-screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-cyan);
  border-radius: 16px;
  padding: 36px 42px;
  max-width: 720px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 40px rgba(0, 242, 254, 0.15), 0 20px 40px rgba(0, 0, 0, 0.8);
  position: relative;
  transform: translateY(16px) scale(0.97);
  transition: transform 250ms var(--ease-out);
}

.modal-screen.active .modal-box {
  transform: translateY(0) scale(1);
}

/* Main Menu Styles */
.game-title {
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1.1;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #ffffff 30%, #00f2fe 80%, #ff007f 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 20px rgba(0, 242, 254, 0.4));
}

.game-subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 32px;
}

.ship-selection {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.ship-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 18px 14px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
  text-align: left;
}

.ship-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-cyan);
  background: rgba(0, 242, 254, 0.08);
}

.ship-card.selected {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 16px rgba(0, 242, 254, 0.4);
  background: rgba(0, 242, 254, 0.12);
}

.ship-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.ship-name {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 1.05rem;
  color: #fff;
  margin-bottom: 4px;
}

.btn-ship-hangar {
  margin-top: 10px;
  width: 100%;
  border: 1px solid rgba(217, 194, 143, 0.55);
  background: rgba(217, 194, 143, 0.08);
  color: var(--accent-gold);
  font: 700 0.72rem var(--font-main);
  letter-spacing: 0.08em;
  padding: 7px 10px;
  cursor: pointer;
}

.btn-ship-hangar:hover {
  background: rgba(217, 194, 143, 0.18);
}

.ship-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 380px;
  margin: 0 auto;
}

/* Generic Cyber Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), filter 140ms ease, box-shadow 140ms ease;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, #00f2fe, #4facfe);
  color: #04101e;
  box-shadow: 0 0 20px rgba(0, 242, 254, 0.4);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 28px rgba(0, 242, 254, 0.6);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent-cyan);
}

.btn-reward {
  background: linear-gradient(135deg, #ffd700, #ff007f);
  color: #ffffff;
  box-shadow: 0 0 22px rgba(255, 0, 127, 0.5), 0 0 10px rgba(255, 215, 0, 0.4);
  font-weight: 800;
  border: 1px solid rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.03em;
}

.btn-reward:hover {
  filter: brightness(1.18);
  box-shadow: 0 0 32px rgba(255, 0, 127, 0.75), 0 0 16px rgba(255, 215, 0, 0.6);
  transform: translateY(-2px) scale(1.02);
}

.btn-reward:disabled {
  opacity: 0.5;
  filter: grayscale(0.8);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.controls-hint {
  margin-top: 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
}

/* Level Up Card Selection */
.modal-box.level-up-box {
  max-width: 900px;
}

.cards-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin: 28px 0 20px;
}

.upgrade-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: transform 180ms var(--ease-out), border-color 180ms ease, box-shadow 180ms ease;
  position: relative;
  overflow: hidden;
}

.upgrade-card:hover {
  transform: translateY(-6px) scale(1.02);
}

.upgrade-card.rarity-common {
  border-color: rgba(255, 255, 255, 0.2);
}
.upgrade-card.rarity-common:hover {
  border-color: #a8dadc;
  box-shadow: 0 0 20px rgba(168, 218, 220, 0.3);
}

.upgrade-card.rarity-rare {
  border-color: var(--accent-cyan);
}
.upgrade-card.rarity-rare:hover {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 24px rgba(0, 242, 254, 0.5);
}

.upgrade-card.rarity-epic {
  border-color: var(--accent-purple);
}
.upgrade-card.rarity-epic:hover {
  border-color: var(--accent-purple);
  box-shadow: 0 0 28px rgba(157, 78, 221, 0.6);
}

.upgrade-card.rarity-legendary {
  border-color: var(--accent-gold);
  background: linear-gradient(160deg, rgba(255, 215, 0, 0.1), rgba(20, 27, 43, 0.9));
}
.upgrade-card.rarity-legendary:hover {
  border-color: var(--accent-gold);
  box-shadow: 0 0 32px rgba(255, 215, 0, 0.7);
}

.card-icon {
  font-size: 2.4rem;
  margin-bottom: 12px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: #fff;
}

.card-rarity {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  font-weight: bold;
}

.rarity-common .card-rarity { color: #a8dadc; }
.rarity-rare .card-rarity { color: var(--accent-cyan); }
.rarity-epic .card-rarity { color: var(--accent-purple); }
.rarity-legendary .card-rarity { color: var(--accent-gold); }

.card-desc {
  font-size: 0.82rem;
  color: #c9d1d9;
  line-height: 1.45;
  flex: 1;
}

/* Hangar / Meta Upgrades Shop */
.hangar-nav-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 8px 0 16px;
}

.hangar-tab-btn {
  padding: 10px 14px;
  border: 1px solid #3e4c4d;
  background: #15191a;
  color: var(--text-muted);
  font: 800 0.72rem var(--font-mono);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 140ms ease;
  border-radius: 0;
}

.hangar-tab-btn:hover {
  border-color: #6a7d80;
  background: #1d2425;
  color: var(--text-main);
}

.hangar-tab-btn.active {
  border-color: var(--accent-gold);
  background: #242c26;
  color: var(--accent-gold);
  box-shadow: inset 0 -2px 0 var(--accent-gold);
}

.stat-item.perf {
  gap: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.stat-item.perf span {
  color: var(--accent-cyan);
}

.settings-stack {
  display: grid;
  gap: 10px;
  margin: 16px 0 20px;
  text-align: left;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
}

.settings-row input[type="range"] {
  width: 140px;
  accent-color: var(--accent-cyan);
}

.settings-row:has(input[type="checkbox"]) {
  grid-template-columns: 1fr auto;
}

.settings-row input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  transform: scale(1.25);
  justify-self: end;
}

.settings-row b {
  min-width: 40px;
  text-align: right;
  font: 700 0.78rem var(--font-mono);
  color: var(--accent-cyan);
}

.hangar-section {
  grid-column: 1 / -1;
  margin-top: 14px;
}

.hangar-section:first-child {
  margin-top: 0;
}

.hangar-section-title {
  color: var(--accent-cyan);
  font: 700 0.7rem var(--font-mono);
  letter-spacing: 0.14em;
  border-bottom: 1px solid #354040;
  padding: 0 0 6px;
}

.hangar-tag {
  margin-left: 6px;
  color: var(--accent-gold);
  font: 700 0.62rem var(--font-mono);
  letter-spacing: 0.08em;
}

.hangar-max {
  color: var(--accent-cyan);
  font: 700 0.75rem var(--font-mono);
}

.hangar-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 12px 0 20px;
  text-align: left;
}

.hangar-item {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hangar-item-info h4 {
  font-size: 0.95rem;
  color: #fff;
  margin-bottom: 3px;
}

.hangar-item-info p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hangar-item-level {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.level-pip {
  width: 14px;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.level-pip.filled {
  background: var(--accent-gold);
  box-shadow: 0 0 6px var(--accent-gold);
}

.btn-buy {
  padding: 8px 14px;
  font-size: 0.8rem;
}

/* Game Over Screen Stats */
.gameover-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 24px 0;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 14px;
}

.stat-box .val {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

.stat-box .lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 4px;
}

/* Touch Controls for Mobile / Tablets */
.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 25;
}

.touch-stick {
  position: absolute;
  bottom: 40px;
  left: 40px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(0, 242, 254, 0.4);
  background: rgba(0, 242, 254, 0.06);
  pointer-events: auto;
}

.touch-stick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 16px var(--accent-cyan);
}

.touch-dash-btn {
  position: absolute;
  bottom: 40px;
  right: 40px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff007f, #ff3366);
  color: #fff;
  font-weight: 900;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  box-shadow: 0 0 20px rgba(255, 0, 127, 0.6);
}

/* Pulse Dot for Online Indicators */
.pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00ff88;
  box-shadow: 0 0 8px #00ff88;
  animation: pulseDot 1.4s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 14px #00ff88; }
}

.stat-item.online {
  color: #00ff88;
  border-color: rgba(0, 255, 136, 0.35);
  background: rgba(0, 255, 136, 0.08);
}

/* Pilot Identity Input (Main Menu) */
.pilot-identity-box {
  background: rgba(0, 242, 254, 0.04);
  border: 1px solid rgba(0, 242, 254, 0.2);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 22px;
  text-align: left;
}

.pilot-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  letter-spacing: 0.08em;
  font-weight: bold;
}

.online-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #00ff88;
  background: rgba(0, 255, 136, 0.1);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(0, 255, 136, 0.25);
}

.nickname-input-group {
  display: flex;
  align-items: center;
  background: rgba(10, 15, 26, 0.85);
  border: 1px solid rgba(0, 242, 254, 0.3);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.nickname-input-group:focus-within {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.4), inset 0 2px 6px rgba(0,0,0,0.5);
}

.nick-prefix {
  padding: 0 10px 0 14px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: bold;
  user-select: none;
}

.nickname-input-group input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  padding: 10px 8px;
  color: #ffffff;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.nickname-input-group input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.btn-random-nick {
  padding: 8px 14px !important;
  font-size: 0.75rem !important;
  border: 0 !important;
  border-left: 1px solid rgba(255, 255, 255, 0.12) !important;
  border-radius: 0 !important;
  background: rgba(255, 255, 255, 0.05) !important;
  white-space: nowrap;
}

.btn-random-nick:hover {
  background: rgba(0, 242, 254, 0.15) !important;
  color: var(--accent-cyan) !important;
}

/* Tactical Minimap / Radar HUD */
.minimap-wrapper {
  position: absolute;
  top: 90px;
  right: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(10, 15, 26, 0.82);
  border: 1px solid rgba(0, 242, 254, 0.35);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 0 20px rgba(0, 242, 254, 0.2), inset 0 0 15px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  pointer-events: none;
  z-index: 10;
}

.minimap-header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0 4px 6px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: 0.08em;
}

.radar-live-badge {
  color: #00ff88;
  font-size: 0.62rem;
}

.minimap-frame {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid rgba(0, 242, 254, 0.45);
  background: radial-gradient(circle, rgba(0, 40, 60, 0.6) 0%, rgba(5, 10, 20, 0.95) 100%);
  box-shadow: inset 0 0 16px rgba(0, 242, 254, 0.35);
}

#minimapCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.radar-scan-line {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg, transparent 270deg, rgba(0, 242, 254, 0.25) 360deg);
  animation: radarRotate 3.5s linear infinite;
  pointer-events: none;
}

@keyframes radarRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.minimap-legend {
  display: flex;
  justify-content: space-around;
  width: 100%;
  margin-top: 6px;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Multiplayer Feed / Killfeed Alerts */
.mp-feed-container {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 12;
}

.mp-feed-item {
  background: rgba(10, 15, 26, 0.88);
  border: 1px solid rgba(0, 242, 254, 0.4);
  color: #ffffff;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  box-shadow: 0 4px 14px rgba(0,0,0,0.6), 0 0 10px rgba(0, 242, 254, 0.2);
  animation: feedSlideIn 250ms ease-out, feedFadeOut 400ms ease-in 3.6s forwards;
  backdrop-filter: blur(4px);
}

@keyframes feedSlideIn {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes feedFadeOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.92); }
}

@media (max-width: 900px) {
  .minimap-wrapper {
    top: auto;
    bottom: 90px;
    right: 12px;
    transform: scale(0.85);
    transform-origin: bottom right;
  }
}

@media (max-width: 768px) {
  .ship-selection {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cards-container,
  .hangar-grid,
  .gameover-stats {
    grid-template-columns: 1fr;
  }

  .modal-box {
    padding: 24px 18px;
  }

  .hud-bottom {
    min-width: 280px;
  }

  .touch-controls {
    display: block;
  }
}

/* 2026 cockpit redesign: restrained CRT, shared geometry, one steel accent */
:root {
  --bg-dark: #090b0c;
  --bg-panel: rgba(17, 20, 20, 0.96);
  --bg-card: #151919;
  --border-cyan: rgba(143, 177, 183, 0.42);
  --border-glow: #8faeb3;
  --accent-cyan: #9fbfc7;
  --accent-magenta: #b66b71;
  --accent-gold: #d9c28f;
  --accent-green: #91aa91;
  --accent-purple: #aaa0b8;
  --text-main: #e5e8e5;
  --text-muted: #8d9693;
  --danger: #c96d73;
  --font-main: 'Bahnschrift', 'Arial Narrow', 'Segoe UI', sans-serif;
  --font-mono: 'Cascadia Mono', 'Consolas', monospace;
}

canvas#gameCanvas {
  background: radial-gradient(circle at center, #171c1d 0%, #080a0b 70%);
}

.crt-overlay {
  opacity: 0.36;
  background:
    linear-gradient(rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.2) 50%),
    linear-gradient(90deg, rgba(155, 190, 195, 0.015), rgba(0, 0, 0, 0), rgba(190, 135, 135, 0.012));
  background-size: 100% 4px, 5px 100%;
}

.modal-screen {
  background:
    linear-gradient(rgba(7, 9, 9, 0.88), rgba(7, 9, 9, 0.94)),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(159, 191, 199, 0.035) 80px);
  padding: 18px;
}

.modal-box {
  width: min(760px, 96vw);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  padding: 26px 30px;
  border: 1px solid #4a5555;
  border-radius: 0;
  background: #111414;
  box-shadow: 14px 14px 0 rgba(0, 0, 0, 0.28);
  scrollbar-width: thin;
  scrollbar-color: #5d7073 #111414;
}

.game-title {
  margin: 0;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: clamp(2.2rem, 6vw, 4.8rem);
  font-weight: 800;
  font-stretch: condensed;
  letter-spacing: -0.045em;
  line-height: 0.86;
  text-shadow: none;
  background: none;
  -webkit-text-fill-color: currentColor;
}

.game-subtitle {
  margin: 10px 0 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid #354040;
  color: var(--accent-cyan);
  font: 600 0.72rem/1.4 var(--font-mono);
  letter-spacing: 0.14em;
}

.pilot-identity-box,
.ship-card,
.upgrade-card,
.hangar-item,
.stat-box {
  border-radius: 0;
  border-color: #394343;
  background: #151919;
  box-shadow: none;
}

.pilot-identity-box {
  padding: 12px;
  margin-bottom: 10px;
}

.pilot-label-row label,
.online-status-badge,
.nick-prefix {
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
}

.nickname-input-group {
  border-radius: 0;
  border-color: #414c4c;
  background: #0d1010;
}

.nickname-input-group input {
  color: var(--text-main);
  font-family: var(--font-mono);
}

.mode-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0 16px;
}

.mode-card {
  min-height: 64px;
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid #394343;
  border-radius: 0;
  color: var(--text-main);
  background: #111414;
  font-family: var(--font-main);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.mode-card:hover {
  border-color: #71888c;
  background: #181d1d;
}

.mode-card:active {
  transform: translateY(1px);
}

.mode-card.active {
  border-color: var(--accent-cyan);
  background: #1b2324;
  box-shadow: inset 3px 0 0 var(--accent-cyan);
}

.mode-code {
  color: var(--accent-cyan);
  font: 800 0.85rem var(--font-mono);
  letter-spacing: 0.04em;
}

.mode-copy {
  display: grid;
  gap: 2px;
}

.mode-copy b {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.mode-copy small {
  color: var(--text-muted);
  font-size: 0.65rem;
  line-height: 1.2;
}

.lobby-box h2 {
  margin: 0 0 6px;
  color: var(--text-main);
  font-size: 1.55rem;
  letter-spacing: 0.04em;
}

.lobby-kicker {
  margin: 0 0 8px;
  color: var(--accent-magenta);
  font: 700 0.68rem var(--font-mono);
  letter-spacing: 0.16em;
}

.lobby-lead {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 16px;
}

.lobby-create,
.lobby-browser {
  border: 1px solid #394343;
  background: #0d1010;
  padding: 14px;
}

.lobby-create h3,
.lobby-browser h3 {
  margin: 0 0 12px;
  color: var(--accent-cyan);
  font: 700 0.72rem var(--font-mono);
  letter-spacing: 0.12em;
}

.lobby-create label,
.lobby-browser label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--text-muted);
  font: 600 0.68rem var(--font-mono);
  letter-spacing: 0.08em;
}

.lobby-create label span,
.lobby-browser label span {
  color: #6d7c7c;
  font-weight: 500;
  letter-spacing: 0;
}

.lobby-create input,
.lobby-browser input {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #414c4c;
  background: #111414;
  color: var(--text-main);
  font: 600 0.85rem var(--font-mono);
}

.lobby-create input:focus,
.lobby-browser input:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

.lobby-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}

.lobby-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  padding: 8px 10px;
  border: 1px solid #394343;
  background: #111414;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
}

.lobby-row:hover {
  border-color: var(--accent-cyan);
  background: #181d1d;
}

.lobby-row-name {
  font: 700 0.82rem var(--font-main);
}

.lobby-row-meta {
  font: 700 0.72rem var(--font-mono);
  color: var(--accent-cyan);
}

.lobby-row-lock {
  font: 700 0.62rem var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.lobby-row-host {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 0.68rem;
}

.lobby-empty {
  padding: 18px 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.lobby-error {
  margin: 12px 0 0;
  color: var(--danger);
  font: 600 0.78rem var(--font-mono);
}

@media (max-width: 768px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.ship-selection {
  gap: 8px;
}

.ship-card {
  min-height: 140px;
  padding: 12px 10px;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.ship-card:hover,
.ship-card.selected {
  transform: none;
  border-color: var(--accent-cyan);
  background: #1a2020;
  box-shadow: inset 0 -3px 0 var(--accent-cyan);
}

.ship-svg-container {
  width: 100%;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
  transition: border-color 160ms ease, background 160ms ease;
}

.ship-svg {
  width: 72px;
  height: 52px;
  transition: transform 200ms var(--ease-out), filter 200ms ease;
  filter: drop-shadow(0 0 6px rgba(0, 242, 254, 0.25));
}

.ship-card:hover .ship-svg {
  transform: scale(1.08) translateY(-2px);
  filter: drop-shadow(0 0 12px rgba(0, 242, 254, 0.6));
}

.ship-card[data-ship="phantom"]:hover .ship-svg {
  filter: drop-shadow(0 0 12px rgba(217, 70, 239, 0.6));
}

.ship-card[data-ship="colossus"]:hover .ship-svg {
  filter: drop-shadow(0 0 12px rgba(245, 158, 11, 0.6));
}

.ship-card[data-ship="necron"] .ship-svg {
  filter: drop-shadow(0 0 6px rgba(184, 245, 60, 0.28));
}

.ship-card[data-ship="necron"]:hover .ship-svg {
  filter: drop-shadow(0 0 10px rgba(184, 245, 60, 0.45));
}

.ship-card.selected .ship-svg-container {
  border-color: var(--accent-cyan);
  background: rgba(0, 242, 254, 0.08);
}

.ship-card.selected[data-ship="phantom"] .ship-svg-container {
  border-color: #d946ef;
}

.ship-card.selected[data-ship="colossus"] .ship-svg-container {
  border-color: #f59e0b;
}

.ship-card[data-ship="necron"]:hover,
.ship-card.selected[data-ship="necron"] {
  border-color: #b8f53c;
  box-shadow: inset 0 -3px 0 #b8f53c;
  background: rgba(184, 245, 60, 0.06);
}

.ship-card.selected[data-ship="necron"] .ship-svg-container {
  border-color: #b8f53c;
  background: rgba(184, 245, 60, 0.08);
}

.ship-mark {
  position: relative;
  width: 44px;
  height: 34px;
  margin: 2px auto 8px;
  filter: none;
}

.ship-mark::before,
.ship-mark::after {
  content: '';
  position: absolute;
  display: block;
}

.ship-mark-apex::before {
  left: 7px;
  top: 3px;
  width: 30px;
  height: 28px;
  background: var(--accent-cyan);
  clip-path: polygon(100% 50%, 0 0, 23% 50%, 0 100%);
}

.ship-mark-phantom::before {
  left: 4px;
  top: 6px;
  width: 36px;
  height: 22px;
  border: 2px solid var(--accent-cyan);
  clip-path: polygon(100% 50%, 0 0, 22% 50%, 0 100%);
}

.ship-mark-colossus::before {
  left: 6px;
  top: 3px;
  width: 32px;
  height: 28px;
  border: 3px solid var(--accent-gold);
  clip-path: polygon(72% 0, 100% 30%, 100% 70%, 72% 100%, 0 82%, 0 18%);
}

.btn {
  min-height: 38px;
  border-radius: 0;
  box-shadow: none;
  font-family: var(--font-main);
  letter-spacing: 0.055em;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  color: #0c1010;
  border-color: var(--accent-cyan);
  background: var(--accent-cyan);
}

.btn-primary:hover {
  background: #bed1d4;
}

.btn-secondary {
  color: var(--text-main);
  border-color: #4c5a5a;
  background: #171b1b;
}

.btn-reward {
  color: #15120b;
  border-color: var(--accent-gold);
  background: var(--accent-gold);
}

.controls-hint {
  color: #7f8986;
  border-color: #333d3d;
  font-family: var(--font-mono);
}

.hud-top {
  padding: 12px 16px;
  gap: 6px;
}

.level-badge,
.stat-item,
.btn-toggle-autofire,
.music-player-widget,
.skill-slot,
.hp-bar-bg,
.gauge-bar-bg {
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.level-badge {
  padding: 5px 10px;
  background: var(--accent-cyan);
  color: #0b0e0e;
}

.xp-bar-bg {
  height: 7px;
  border-radius: 0;
  background: #202626;
  border-color: #4f5f60;
  box-shadow: none;
}

.xp-bar-fill,
.gauge-bar-dash,
.gauge-bar-boost {
  border-radius: 0;
  background: var(--accent-cyan);
  box-shadow: none;
}

.stat-item,
.btn-toggle-autofire,
.music-player-widget {
  border-color: #3e4949;
  background: rgba(15, 18, 18, 0.92);
}

.stat-item.mode {
  color: var(--accent-gold);
  border-color: rgba(217, 194, 143, 0.5);
  font-weight: 800;
}

.hud-key {
  color: var(--accent-cyan);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
}

.btn-toggle-autofire.active {
  color: var(--accent-green);
  border-color: #526852;
  background: #151d17;
  box-shadow: none;
}

.music-player-widget {
  gap: 7px;
  padding: 4px 8px;
}

.music-eq-bar {
  width: 2px;
  background: var(--accent-cyan);
}

.music-track-artist {
  color: var(--accent-cyan);
}

.music-btn {
  min-width: 32px;
  color: var(--text-muted);
  font: 700 0.56rem var(--font-mono);
}

.music-btn:hover {
  color: var(--text-main);
  transform: none;
}

.hud-bottom {
  bottom: 14px;
  min-width: 360px;
  gap: 7px;
}

.hp-bar-bg {
  height: 14px;
  border-color: #634248;
  background: #211719;
}

.hp-bar-fill {
  background: var(--danger);
}

.gauge-bar-bg {
  height: 5px;
  border-color: #414a49;
  background: #202525;
}

.hud-skills-bar {
  bottom: 14px;
  left: 16px;
  gap: 5px;
}

.skill-slot {
  width: 50px;
  height: 50px;
  border-color: #465252;
  background: #151919;
}

.skill-slot.ready {
  border-color: var(--accent-cyan);
  box-shadow: inset 0 -2px 0 var(--accent-cyan);
}

.skill-slot:hover {
  transform: translateY(-2px);
  border-color: var(--accent-cyan);
  box-shadow: none;
}

.skill-slot.is-disabled {
  opacity: 0.42;
  filter: grayscale(0.35);
  cursor: not-allowed;
}

.skill-slot.is-disabled:hover {
  transform: none;
  border-color: #465252;
}

.skill-icon {
  color: var(--text-main);
  font: 700 0.68rem var(--font-mono);
  letter-spacing: 0.04em;
}

.skill-hotkey-badge,
.skill-level-badge {
  color: var(--accent-cyan);
  background: transparent;
}

.minimap-wrapper {
  top: 76px;
  right: 16px;
  border-radius: 0;
  border-color: #4d5b5b;
  background: rgba(13, 16, 16, 0.94);
  box-shadow: none;
}

.minimap-frame {
  border-radius: 0;
  border-color: #394444;
}

.radar-live-badge {
  color: var(--accent-green);
}

.radar-scan-line {
  opacity: 0.22;
}

.mp-feed-item {
  border-radius: 0;
  border-color: #414b4b;
  background: rgba(14, 17, 17, 0.92);
  box-shadow: none;
}

.system-mark {
  margin-bottom: 8px;
  color: var(--accent-magenta);
  font: 700 0.7rem var(--font-mono);
  letter-spacing: 0.14em;
}

@media (max-width: 768px) {
  .modal-box {
    width: 100%;
    padding: 20px 16px;
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.28);
  }

  .mode-selector {
    grid-template-columns: 1fr;
  }

  .ship-selection {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-card {
    min-height: 56px;
  }

  .hud-info-row {
    align-items: flex-start;
  }

  .hud-stats-left {
    max-width: calc(100vw - 32px);
    flex-wrap: wrap;
    gap: 4px;
  }

  .music-player-widget {
    display: none;
  }

  .hud-bottom {
    min-width: min(330px, calc(100vw - 24px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Touch-first layout and fullscreen safe areas */
html,
body,
#game-container {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  -webkit-touch-callout: none;
}

canvas#gameCanvas {
  touch-action: none;
}

@media (pointer: coarse) {
  .touch-controls {
    display: none;
  }

  body.mobile-playing .touch-controls {
    display: block;
  }

  .touch-stick {
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 124px;
    height: 124px;
    border: 1px solid rgba(159, 191, 199, 0.62);
    border-radius: 50%;
    background: rgba(13, 18, 18, 0.46);
    box-shadow: inset 0 0 0 10px rgba(159, 191, 199, 0.035);
    touch-action: none;
  }

  .touch-stick::before,
  .touch-stick::after {
    content: '';
    position: absolute;
    pointer-events: none;
    background: rgba(159, 191, 199, 0.22);
  }

  .touch-stick::before {
    width: 1px;
    height: 74%;
    left: 50%;
    top: 13%;
  }

  .touch-stick::after {
    width: 74%;
    height: 1px;
    left: 13%;
    top: 50%;
  }

  .touch-stick-knob {
    width: 48px;
    height: 48px;
    border: 2px solid #c4d3d5;
    border-radius: 50%;
    background: #71898d;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    will-change: transform;
  }

  .touch-actions {
    position: absolute;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: 58px 78px;
    grid-template-rows: 58px 58px;
    gap: 8px;
    pointer-events: auto;
  }

  .touch-action {
    position: relative;
    inset: auto;
    width: auto;
    height: auto;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 1px solid #617173;
    border-radius: 0;
    color: var(--text-main);
    background: rgba(19, 23, 23, 0.88);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.3);
    font: 800 0.64rem/1 var(--font-mono);
    letter-spacing: 0.04em;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 100ms var(--ease-out), background-color 100ms ease, border-color 100ms ease;
  }

  .touch-action:active,
  .touch-action.pressed {
    transform: translateY(2px) scale(0.97);
    border-color: var(--accent-cyan);
    background: #263133;
    box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
  }

  .touch-dash-btn {
    grid-column: 2;
    grid-row: 1 / span 2;
    color: #15110b;
    border-color: var(--accent-gold);
    background: var(--accent-gold);
    font-size: 0.72rem;
  }

  .touch-boost-btn {
    grid-column: 1;
    grid-row: 2;
  }

  .touch-fire-btn {
    grid-column: 1;
    grid-row: 1;
    border-color: #8b5157;
    color: #e8c8ca;
  }

  .hud-top {
    top: env(safe-area-inset-top);
    padding: 6px max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  }

  .xp-container {
    gap: 6px;
  }

  .level-badge {
    padding: 4px 7px;
    font-size: 0.68rem;
  }

  .hud-info-row {
    align-items: flex-start;
  }

  .hud-stats-left {
    max-width: calc(100vw - 130px);
    flex-wrap: wrap;
    gap: 3px;
  }

  .stat-item,
  .btn-toggle-autofire {
    min-height: 27px;
    padding: 3px 7px;
    font-size: 0.63rem;
  }

  .stat-item.timer {
    font-size: 0.72rem;
  }

  .hud-stats-right {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
  }

  .hud-stats-right .music-player-widget {
    display: none;
  }

  #btnPause {
    min-width: 72px;
    min-height: 34px;
    padding: 4px 7px !important;
    font-size: 0.61rem !important;
  }

  .minimap-wrapper {
    top: calc(max(8px, env(safe-area-inset-top)) + 40px);
    right: max(8px, env(safe-area-inset-right));
    bottom: auto;
    width: 112px;
    transform: none;
  }

  .minimap-header {
    padding: 4px 5px;
    font-size: 0.52rem;
  }

  .minimap-frame canvas {
    display: block;
    width: 104px;
    height: 104px;
  }

  .minimap-legend {
    display: none;
  }

  .mp-feed-container {
    top: 74px;
    right: 128px;
    max-width: min(220px, 34vw);
  }

  .mp-feed-item {
    padding: 5px 7px;
    font-size: 0.58rem;
  }

  .hud-skills-bar {
    left: 50%;
    bottom: max(8px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    gap: 4px;
  }

  .skill-slot {
    width: 44px;
    height: 44px;
  }

  .skill-slot:hover {
    transform: none;
  }

  .hud-bottom {
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 51px);
    width: min(330px, 44vw);
    min-width: 220px;
    gap: 4px;
  }

  .hp-bar-bg {
    height: 12px;
  }

  .hp-text {
    font-size: 0.58rem;
  }

  .gauges-row {
    gap: 7px;
  }

  .gauge-item {
    font-size: 0.5rem;
  }

  .modal-screen {
    align-items: flex-start;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .modal-box {
    width: min(760px, 100%);
    max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
    margin: auto;
    padding: 18px;
  }

  .nickname-input-group input,
  .btn,
  .mode-card {
    min-height: 44px;
  }

  .mode-selector {
    grid-template-columns: 1fr 1fr;
  }

  .ship-selection {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ship-card {
    min-height: 118px;
  }

  .controls-hint {
    display: none;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  .touch-stick {
    width: 116px;
    height: 116px;
  }

  .touch-actions {
    grid-template-columns: 54px 72px;
    grid-template-rows: 54px 54px;
  }

  .hud-skills-bar {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 126px);
  }

  .hud-bottom {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 176px);
    width: calc(100vw - 32px);
  }

  .stat-item.credits,
  .stat-item.online {
    display: none;
  }

  .minimap-wrapper {
    width: 96px;
  }

  .minimap-frame canvas {
    width: 88px;
    height: 88px;
  }

  .mode-selector {
    grid-template-columns: 1fr;
  }

  .ship-selection {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
  }

  .ship-card {
    flex: 0 0 78%;
    scroll-snap-align: center;
  }
}

@media (hover: hover) and (pointer: fine) {
  .touch-action:hover {
    border-color: var(--accent-cyan);
  }
}

/* On-the-fly DM Tactical Attachment Quick-Loot Drawer */
.dm-attachment-drawer {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  background: rgba(14, 18, 19, 0.96);
  border: 1px solid var(--accent-gold);
  border-radius: 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.75), 0 0 16px rgba(217, 194, 143, 0.25);
  animation: dmDrawerPop 180ms var(--ease-out);
  pointer-events: auto;
  max-width: min(640px, 94vw);
}

@keyframes dmDrawerPop {
  from { opacity: 0; transform: translate(-50%, -12px) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.dm-attachment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(217, 194, 143, 0.12);
  border-bottom: 1px solid rgba(217, 194, 143, 0.3);
}

.dm-attachment-title {
  color: var(--accent-gold);
  font: 800 0.72rem var(--font-mono);
  letter-spacing: 0.08em;
}

.dm-attachment-timer {
  color: #fff;
  font: 700 0.7rem var(--font-mono);
  background: rgba(0, 0, 0, 0.6);
  padding: 1px 6px;
  border-radius: 2px;
}

.dm-attachment-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px 10px 10px;
}

.dm-attachment-card {
  background: #15191a;
  border: 1px solid #3d4a4c;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  transition: transform 120ms var(--ease-out), border-color 120ms ease, background 120ms ease;
  position: relative;
  overflow: hidden;
}

.dm-attachment-card:hover {
  border-color: var(--accent-gold);
  background: #1c2324;
  transform: translateY(-2px);
}

.dm-attachment-card:active {
  transform: scale(0.97);
}

.dm-attachment-hotkey {
  position: absolute;
  top: 4px;
  right: 5px;
  font: 800 0.64rem var(--font-mono);
  color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.5);
  padding: 1px 4px;
}

.dm-attachment-tag {
  font: 800 0.58rem var(--font-mono);
  letter-spacing: 0.08em;
  color: var(--accent-cyan);
  margin-bottom: 2px;
}

.dm-attachment-card.is-skill {
  border-color: rgba(0, 242, 254, 0.45);
}

.dm-attachment-card.is-buff {
  border-color: rgba(217, 194, 143, 0.45);
}

.dm-attachment-name {
  font: 700 0.78rem var(--font-main);
  color: #ffffff;
  margin-bottom: 3px;
  padding-right: 20px;
}

.dm-attachment-desc {
  font: 0.66rem/1.2 var(--font-main);
  color: var(--text-muted);
}

.hangar-item-dimmed {
  opacity: 0.55;
  filter: grayscale(0.25);
}

.hangar-item-owned {
  border-color: rgba(217, 194, 143, 0.45);
  box-shadow: inset 0 0 0 1px rgba(217, 194, 143, 0.12);
}

.skill-slot.ship-ability-slot {
  width: 76px;
  height: 76px;
  border-width: 2px;
  border-color: var(--accent-gold);
  background: linear-gradient(145deg, #25221b, #15191a);
}

.skill-slot.ship-ability-slot .skill-icon svg {
  width: 38px;
  height: 38px;
}

.skill-slot.ship-ability-slot .skill-level-badge {
  font-size: 0.55rem;
  color: var(--accent-gold);
}

.skill-slot.flare-slot {
  border-color: #ffb703;
}

@media (max-width: 640px) {
  .dm-attachment-drawer {
    top: 68px;
    max-width: 96vw;
  }
  .dm-attachment-cards {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 6px;
  }
  .dm-attachment-card {
    padding: 6px 8px;
  }
  .dm-attachment-name {
    font-size: 0.72rem;
  }
  .dm-attachment-desc {
    font-size: 0.6rem;
  }
}

/* Tactical Galaxy Map & Sector Warp Styles */
.tactical-map-box {
  width: min(840px, 96vw);
  max-width: 840px;
  padding: 20px 24px;
}

.tactical-map-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid #3d4a4c;
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.tactical-map-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
}

.tactical-map-canvas-wrap {
  position: relative;
  background: #080b0c;
  border: 1px solid #3c494b;
  overflow: hidden;
  height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#galaxyMapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.galaxy-scan-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 40%, rgba(0, 242, 254, 0.04) 95%),
    repeating-linear-gradient(0deg, transparent 0 29px, rgba(0, 242, 254, 0.04) 30px);
}

.tactical-sectors-sidebar {
  display: flex;
  flex-direction: column;
  background: #111516;
  border: 1px solid #354143;
  padding: 10px;
  height: 380px;
  overflow-y: auto;
}

.sectors-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.sector-card-item {
  background: #171c1d;
  border: 1px solid #3a4749;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  transition: all 120ms ease;
  border-radius: 0;
}

.sector-card-item:hover {
  border-color: var(--accent-cyan);
  background: #1e2526;
}

.sector-card-item.active {
  border-color: var(--accent-cyan);
  background: #1e282a;
  box-shadow: inset 3px 0 0 var(--accent-cyan);
}

.sector-card-item.current {
  border-color: var(--accent-gold);
  box-shadow: inset 3px 0 0 var(--accent-gold);
}

.sector-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.sector-card-name {
  font: 800 0.78rem var(--font-mono);
  color: #fff;
}

.sector-card-badge {
  font: 700 0.6rem var(--font-mono);
  padding: 1px 4px;
  background: rgba(0, 242, 254, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 242, 254, 0.3);
}

.sector-card-desc {
  font: 0.64rem/1.2 var(--font-main);
  color: var(--text-muted);
}

.sector-card-pilots {
  font: 600 0.62rem var(--font-mono);
  color: var(--accent-gold);
  margin-top: 3px;
}

.tactical-map-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #3d4a4c;
  padding-top: 12px;
  margin-top: 12px;
  gap: 12px;
}

.warp-target-info {
  font: 0.82rem var(--font-mono);
  color: var(--text-muted);
}

.btn-warp-action {
  font-size: 0.85rem;
  padding: 10px 22px;
}

/* Scoreboard Table */
.scoreboard-table-wrap {
  overflow-x: auto;
  max-height: 380px;
}

.scoreboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font: 0.78rem var(--font-mono);
}

.scoreboard-table th {
  background: #1b2122;
  color: var(--accent-cyan);
  padding: 8px 10px;
  border-bottom: 1px solid #4a5a5c;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.scoreboard-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #283335;
  color: var(--text-main);
}

.scoreboard-table tr:hover td {
  background: rgba(0, 242, 254, 0.06);
}

.scoreboard-table tr.is-me td {
  background: rgba(217, 194, 143, 0.08);
  font-weight: bold;
}

/* Hyperjump Cinematic Warp Overlay */
.warp-cinematic-overlay {
  position: absolute;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  display: none;
  background: rgba(0, 0, 0, 0.88);
}

#warpCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.warp-hud-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.warp-status-text {
  font: 800 1.2rem var(--font-mono);
  color: #00f2fe;
  letter-spacing: 0.25em;
  text-shadow: 0 0 18px #00f2fe;
  margin-bottom: 6px;
  animation: warpPulse 0.4s infinite alternate;
}

.warp-destination-text {
  font: 900 2.2rem var(--font-main);
  color: #ffffff;
  letter-spacing: 0.15em;
  text-shadow: 0 0 24px #fff;
}

@keyframes warpPulse {
  from { opacity: 0.6; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1.02); }
}

@media (max-width: 768px) {
  .tactical-map-layout {
    grid-template-columns: 1fr;
  }
  .tactical-map-canvas-wrap {
    height: 240px;
  }
  .tactical-sectors-sidebar {
    height: 180px;
  }
  .tactical-map-footer {
    flex-direction: column;
    align-items: stretch;
  }
}
