#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  z-index: 5;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) 0;
  box-sizing: border-box;
}

.hud-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.stats-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.controls-container {
  display: flex;
  flex-direction: column; /* Stack buttons vertically */
  gap: 8px;
  pointer-events: auto;
}

.score-board,
.lives-board,
.level-board {
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  line-height: 1;
  margin: 0;
  padding: 0;
}

.stats-container .label {
  display: inline-flex;
  justify-content: space-between;
  width: 105px;
  margin-right: 15px;
}

.score-board {
  color: #ffffff;
  text-shadow:
    0 0 10px rgba(255, 255, 255, 0.4),
    0 0 20px rgba(255, 255, 255, 0.2);
}

.lives-board {
  color: var(--danger-color);
  text-shadow:
    0 0 10px var(--danger-color),
    0 0 20px var(--danger-color);
}

.level-board {
  color: var(--primary-color);
  opacity: 1;
  text-shadow:
    0 0 10px var(--primary-color),
    0 0 20px var(--primary-color);
}

/* Compact HUD Buttons */
.pause-btn,
.restart-btn,
.home-btn {
  background: rgba(0, 87, 205, 0.2);
  border: 2px solid var(--primary-color);
  color: #fff;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;

  /* --- HARD RESET: FIXES FIREFOX/MOBILE ALIGNMENT --- */
  padding: 0;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  /* -------------------------------------------------- */

  font-weight: 900;
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.2s;
  font-family: "Orbitron", sans-serif;
  border-radius: 5px;
  text-shadow: 0 0 5px var(--primary-color);
  z-index: 100;
  -webkit-tap-highlight-color: transparent;
}

/* Specific hover logic - Converted to Classes for Mobile Specificity */
.pause-btn:hover,
.restart-btn:hover {
  background: var(--primary-color);
  box-shadow: 0 0 20px var(--primary-color);
  text-shadow: 0 0 10px #fff;
}

.home-btn:hover {
  background: var(--primary-color);
  box-shadow: 0 0 20px var(--primary-color);
  text-shadow:
    0 0 1px #fff,
    0 0 1px #fff,
    0 0 1px #fff,
    0 0 2px #fff,
    0 0 10px #fff;
}

.pause-btn:active,
.restart-btn:active,
.home-btn:active {
  transform: scale(0.95);
}

/* Individual Button Tweaks - Converted to Classes */
.restart-btn {
  font-size: 1.3rem;
  padding-bottom: 1px;
  line-height: 1;
  text-shadow:
    0 0 1px #fff,
    0 0 5px var(--primary-color);
}

.pause-btn {
  font-size: 0.9rem;
  line-height: 1;
  padding-bottom: 2px;
  /* Removed padding-left & letter-spacing to fix centering */
  text-shadow:
    0 0 1px #fff,
    0 0 5px var(--primary-color);
}

.home-btn {
  font-size: 1.4rem;
  line-height: 1;
  padding-bottom: 1px;
  /* Extra heavy layering for boldness */
  text-shadow:
    0 0 0 #fff,
    0 0 1px #fff,
    0 0 1px #fff,
    0 0 1px #fff,
    0 0 5px var(--primary-color);
}

/* SVG Styling within HUD Buttons */
.pause-btn svg,
.restart-btn svg,
.home-btn svg {
  width: 24px; /* INCREASED: Was 20px, now 24px for visibility */
  height: 24px; /* INCREASED: Was 20px, now 24px for visibility */
  stroke-width: 2.8; /* Precise control over boldness */
  filter: drop-shadow(0 0 5px var(--primary-color));
  transition: all 0.2s;
}

/* Specific Nudge for Pause Symbol Only */
.pause-btn svg {
  transform: translate(0px, 1px);
}

/* Shared hover logic for SVGs */
.pause-btn:hover svg,
.restart-btn:hover svg,
.home-btn:hover svg {
  filter: drop-shadow(0 0 8px #fff);
  stroke-width: 3.2; /* Slightly thicker on hover for interaction feedback */
}

#pause-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 5rem;
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 0 20px var(--primary-color),
    0 0 40px var(--primary-color);
  display: none;
  z-index: 20;
  pointer-events: none;
  letter-spacing: 5px;
  text-align: center;
  animation: pulseText 1.5s infinite ease-in-out;
  width: 100%;
}

@keyframes pulseText {
  0%,
  100% {
    opacity: 1;
    text-shadow: 0 0 20px var(--primary-color);
  }
  50% {
    opacity: 0.5;
    text-shadow: 0 0 5px var(--primary-color);
  }
}

#game-footer {
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 15px var(--primary-color);
  font-size: 0.7rem;
  text-align: center;
  opacity: 0.3;
  padding-bottom: 20px;
  width: 100%;
}

#level-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 5rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 50px var(--primary-color);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 8;
  text-transform: uppercase;
  white-space: nowrap;
  text-align: center;
}

#modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(10, 15, 30, 0.9);
  background-image:
    linear-gradient(rgba(0, 87, 205, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 87, 205, 0.1) 1px, transparent 1px);
  background-size: 20px 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 40px;
  border: 2px solid var(--primary-color);
  box-shadow:
    0 0 60px var(--primary-color),
    inset 0 0 30px rgba(0, 87, 205, 0.3);
  border-radius: 15px;
  text-align: center;
  pointer-events: auto;
  z-index: 10;
  width: 85%;
  max-width: 450px;
  transition: all 0.5s ease;
}

#modal.game-over-state {
  border-color: var(--game-over-red);
  box-shadow:
    0 0 60px var(--game-over-red),
    inset 0 0 30px rgba(205, 0, 36, 0.3);
  background-image:
    linear-gradient(rgba(205, 0, 36, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(205, 0, 36, 0.1) 1px, transparent 1px);
}

/* --- Title Logo / Ship Icon --- */
.title-icon {
  width: 120px; /* Increased size (was 80px) */
  height: 120px;
  /* Margin Breakdown:
       Top: -10px (Pulls it slightly up into the 40px modal padding for better vertical balance)
       Bottom: 15px (Adds clear separation from the "SIGNAL LOST" text)
    */
  margin: -20px auto 15px auto;
  display: block;
  position: relative;
  z-index: 2;
}

.title-icon svg {
  width: 100%;
  height: 100%;
  overflow: visible; /* Allows the glow filters to extend beyond the box */
}

h1 {
  margin: 0 0 5px 0;
  font-size: clamp(1.5rem, 11vw, 2.5rem);
  color: #ffffff;
  text-shadow:
    0 0 10px var(--primary-color),
    0 0 20px var(--primary-color),
    0 0 40px var(--primary-color);
  letter-spacing: 2px;
  line-height: 1.2;
  white-space: nowrap;
}

#modalTitle {
  color: #e0f7ff;
  animation: signal-glitch 5s infinite;
}

@keyframes signal-glitch {
  0%,
  92%,
  94%,
  97%,
  100% {
    opacity: 1;
    transform: translate(0);
    text-shadow: 0 0 10px var(--primary-color);
  }
  93% {
    opacity: 0.8;
    transform: translate(-2px, 1px);
    text-shadow:
      2px 0 var(--primary-color),
      -2px 0 var(--danger-color);
  }
  96% {
    opacity: 0.9;
    transform: translate(1px, -1px);
    text-shadow: -1px 0 var(--primary-color);
  }
}

.logo-subtitle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(224, 247, 255, 0.7);
  text-shadow: 0 0 5px rgba(0, 87, 205, 0.5);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 3px;
  margin-bottom: 25px;
  text-transform: uppercase;
  width: 100%;
  animation: light-bulb-flicker 7s infinite linear;
}

@keyframes light-bulb-flicker {
  0%,
  15%,
  17%,
  40%,
  43%,
  70%,
  73%,
  100% {
    opacity: 0.7;
  }
  3%,
  16%,
  42%,
  72% {
    opacity: 0.5;
  }
}

.logo-subtitle::before,
.logo-subtitle::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--primary-color);
  box-shadow: 0 0 10px var(--primary-color);
  opacity: 1;
}

.logo-subtitle::before {
  margin-right: 15px;
}
.logo-subtitle::after {
  margin-left: 15px;
}

/* RED THEME LINES FOR GAME OVER & VICTORY */
#modal.game-over-state .logo-subtitle::before,
#modal.game-over-state .logo-subtitle::after,
#victory-modal .logo-subtitle::before,
#victory-modal .logo-subtitle::after {
  background: var(--game-over-red);
  box-shadow: 0 0 10px var(--game-over-red);
}

/* ORANGE THEME TEXT FOR GAME OVER & VICTORY */
#modal.game-over-state .logo-subtitle,
#victory-modal .logo-subtitle {
  text-shadow: 0 0 5px var(--warning-color);
  color: var(--warning-color);
}

#final-score {
  display: block;
  font-size: 1.5rem;
  color: var(--primary-color);
  text-shadow: 0 0 10px var(--primary-color);
  margin-bottom: 20px;
  font-weight: bold;
}

#modal.game-over-state #final-score {
  color: var(--game-over-red);
  text-shadow: 0 0 10px var(--game-over-red);
}

p {
  color: #ccc;
  margin-bottom: 25px;
  line-height: 1.6;
  font-size: 0.9rem;
  font-family: "Segoe UI", sans-serif;
}

.settings-bar {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 25px;
}

.toggle-btn {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #aaa;
  padding: 8px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  border-radius: 4px;
  font-family: "Orbitron", sans-serif;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Updated active state to include hover for Briefing button */
.toggle-btn.active,
#btnBriefing:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border-color: #fff;
  text-shadow: 0 0 5px #fff;
}

.instructions {
  background: rgba(0, 0, 0, 0.6);
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 25px;
  font-size: 0.85rem;
  color: #aaa;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-family: "Segoe UI", monospace;
}

.instructions strong {
  color: var(--accent-color);
  display: block;
  margin-bottom: 8px;
  font-family: "Orbitron", sans-serif;
  letter-spacing: 1px;
}

.key {
  display: inline-block;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  margin: 0 2px;
}

/* Utility Row Styles */
.utility-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 15px;
}

.util-btn {
  flex: 1;
  aspect-ratio: 1/1; /* Ensure square */
  background: rgba(0, 87, 205, 0.2);
  border: 2px solid var(--primary-color);
  color: #fff;
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
  box-sizing: border-box;
  box-shadow: 0 0 10px rgba(0, 87, 205, 0.3);
}

.util-btn svg {
  width: 55%; /* Scales with the button size */
  height: 55%;
  stroke-width: 2; /* Keeps the lines looking bold when larger */
  filter: drop-shadow(0 0 5px var(--primary-color));
  transition: all 0.2s;
}

.util-btn:hover {
  background: var(--primary-color);
  box-shadow: 0 0 20px var(--primary-color);
}

.util-btn:hover svg {
  stroke-width: 2.8;
  filter: drop-shadow(0 0 8px #fff);
}

.util-btn:active {
  transform: scale(0.95);
}

#modal.game-over-state .util-btn {
  border-color: var(--game-over-red);
  background: rgba(205, 0, 36, 0.2);
  box-shadow: 0 0 10px rgba(205, 0, 36, 0.3);
}

#modal.game-over-state .util-btn svg {
  filter: drop-shadow(0 0 5px var(--game-over-red));
}

#modal.game-over-state .util-btn:hover {
  background: var(--game-over-red);
  box-shadow: 0 0 20px var(--game-over-red);
}

button#startBtn {
  background: rgba(0, 87, 205, 0.3);
  color: #fff;
  border: 2px solid var(--primary-color);
  padding: 15px 10px;
  font-size: 1.2rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 3px;
  transition: all 0.3s ease;
  font-weight: 900;
  width: 100%; /* Full width */
  display: block;
  font-family: "Orbitron", sans-serif;
  text-shadow: 0 0 8px var(--primary-color);
  box-shadow: 0 0 20px var(--primary-color);
  position: relative;
  overflow: hidden;
  text-align: center;
  text-indent: 3px; /* Center alignment fix */
  box-sizing: border-box;
  animation: pulse 1s infinite alternate ease-in-out;
}

button#startBtn:hover {
  background: var(--primary-color);
  text-shadow: 0 0 15px #fff;
  box-shadow: 0 0 40px var(--primary-color);
  animation: none;
}

#modal.game-over-state button#startBtn {
  border-color: var(--game-over-red);
  background: rgba(205, 0, 36, 0.3);
  text-shadow: 0 0 8px var(--game-over-red);
  box-shadow: 0 0 20px var(--game-over-red);
}

#modal.game-over-state button#startBtn:hover {
  background: var(--game-over-red);
  box-shadow: 0 0 40px var(--game-over-red);
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.03);
    opacity: 1;
  }
}
