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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: crosshair;
  touch-action: none;
}

.hidden { display: none !important; }

#map-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0, 5, 9, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: zoom-out;
  pointer-events: auto;
  touch-action: none;
}

#expanded-map {
  width: 100vw;
  height: 100vh;
  display: block;
  pointer-events: none;
}

/* ---- HUD ---- */
#hud {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

#level,
#mode {
  color: #5a7184;
  font-size: 13px;
  letter-spacing: 4px;
}

#level {
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#mode {
  color: #8ac6d8;
  font-size: 11px;
  letter-spacing: 2px;
}

#battery {
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid #2a3a48;
  border-radius: 3px;
  min-width: 120px;
  min-height: 24px;
}

#battery .seg {
  width: 9px;
  height: 14px;
  border-radius: 1px;
  background: linear-gradient(180deg, #38e8c8, #1899a8);
  box-shadow: 0 0 6px rgba(56, 232, 200, 0.45);
}

#battery.low .seg {
  background: linear-gradient(180deg, #ff5a4a, #b02818);
  box-shadow: 0 0 6px rgba(255, 90, 74, 0.5);
}

#battery .seg.empty {
  background: #16202a;
  box-shadow: none;
}

#battery.compact {
  position: relative;
  width: 210px;
  height: 24px;
  display: block;
  overflow: hidden;
}

#battery.compact .fill {
  height: 100%;
  width: var(--charge, 0%);
  background: linear-gradient(90deg, #38e8c8, #50b4ff);
  box-shadow: 0 0 10px rgba(56, 232, 200, 0.4);
}

#battery.compact.low .fill {
  background: linear-gradient(90deg, #ff5a4a, #ffd24a);
  box-shadow: 0 0 10px rgba(255, 90, 74, 0.45);
}

#battery.compact .readout {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #c8d6e0;
  font-size: 12px;
  letter-spacing: 2px;
  text-shadow: 0 0 6px #000;
}

@media (orientation: portrait) and (max-width: 700px) {
  body.touch-device #battery.compact {
    transform: translateX(-56px);
  }
}

#warning {
  margin-top: 6px;
  color: #ff5a4a;
  font-size: 13px;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255, 90, 74, 0.6);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---- Overlays (title / level clear) ---- */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(0, 0, 0, 0.82);
  color: #c8d6e0;
  text-align: center;
  transition: opacity 0.4s;
}

#overlay.fading { opacity: 0; pointer-events: none; }

#overlay h1 {
  font-size: 54px;
  font-weight: 300;
  letter-spacing: 18px;
  color: #e8f4ff;
  text-shadow: 0 0 24px rgba(80, 180, 255, 0.55);
}

#overlay .info {
  font-size: 14px;
  color: #7e93a5;
  max-width: 420px;
  line-height: 1.6;
}

#overlay .keys {
  font-size: 14px;
  letter-spacing: 1px;
  color: #b8c8d4;
}

#overlay .mobile-keys {
  display: none;
}

#overlay .exit-word {
  color: #39ff88;
  text-shadow: 0 0 8px rgba(57, 255, 136, 0.6);
}

#overlay .prompt {
  margin-top: 16px;
  font-size: 13px;
  letter-spacing: 3px;
  color: #50b4ff;
  animation: pulse 2s ease-in-out infinite;
}

#pass-form {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 360px;
}

#passphrase-input {
  width: 178px;
  height: 32px;
  border: 1px solid rgba(80, 180, 255, 0.35);
  border-radius: 4px;
  background: rgba(4, 12, 18, 0.82);
  color: #d8edf8;
  font: inherit;
  font-size: 13px;
  letter-spacing: 1px;
  padding: 0 10px;
  outline: none;
}

#passphrase-input:focus {
  border-color: rgba(80, 220, 255, 0.8);
  box-shadow: 0 0 14px rgba(80, 180, 255, 0.26);
}

#pass-form button,
#fire-button {
  border: 1px solid rgba(80, 180, 255, 0.42);
  border-radius: 4px;
  background: rgba(8, 25, 35, 0.9);
  color: #bfeeff;
  font: inherit;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#pass-form button {
  height: 32px;
  padding: 0 12px;
}

#pass-message {
  width: 100%;
  min-height: 15px;
  color: #ffd24a;
  font-size: 11px;
  letter-spacing: 1px;
}

/* ---- Mobile joystick ---- */
#touch-controls {
  position: fixed;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 148px;
  height: 148px;
  pointer-events: auto;
  touch-action: none;
  z-index: 5;
  display: none;
}

#fire-button {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(46px, env(safe-area-inset-bottom));
  width: 96px;
  height: 96px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  z-index: 5;
  display: none;
  background:
    radial-gradient(circle at 42% 34%, rgba(255, 255, 255, 0.9), rgba(255, 210, 74, 0.84) 34%, rgba(200, 70, 38, 0.78) 68%, rgba(55, 10, 12, 0.84));
  color: #fff7d4;
  box-shadow:
    0 0 24px rgba(255, 130, 60, 0.32),
    inset 0 0 24px rgba(255, 255, 255, 0.18);
}

#fire-button:active,
#fire-button.firing {
  transform: scale(0.94);
  box-shadow:
    0 0 36px rgba(255, 160, 68, 0.55),
    inset 0 0 28px rgba(255, 255, 255, 0.26);
}

#joystick {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(114, 198, 223, 0.35);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(99, 209, 255, 0.1), rgba(16, 36, 48, 0.18) 42%, rgba(0, 0, 0, 0.05) 70%),
    radial-gradient(circle at 50% 50%, transparent 57%, rgba(80, 180, 255, 0.2) 58%, transparent 60%);
  box-shadow:
    0 0 22px rgba(80, 180, 255, 0.2),
    inset 0 0 28px rgba(80, 180, 255, 0.12);
  opacity: 0.72;
}

#touch-controls.active #joystick {
  opacity: 1;
  border-color: rgba(142, 232, 255, 0.58);
  box-shadow:
    0 0 30px rgba(80, 180, 255, 0.34),
    inset 0 0 32px rgba(80, 180, 255, 0.2);
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  transform: translate(calc(-50% + var(--jx, 0px)), calc(-50% + var(--jy, 0px)));
  background:
    radial-gradient(circle at 38% 32%, #e8f4ff, #83d9f0 38%, #1f8ea8 72%, #0b3a4a);
  box-shadow:
    0 0 18px rgba(121, 220, 245, 0.55),
    0 0 42px rgba(64, 170, 210, 0.24);
}

@media (pointer: coarse), (max-width: 760px) {
  #hud {
    top: max(12px, env(safe-area-inset-top));
    gap: 5px;
  }

  #overlay {
    padding: 22px;
    gap: 14px;
  }

  #overlay h1 {
    font-size: clamp(34px, 12vw, 52px);
    letter-spacing: 10px;
  }

  #overlay .info {
    font-size: 13px;
  }

  #overlay .keys {
    display: none;
  }

  #overlay .mobile-keys {
    display: block;
    max-width: 300px;
    line-height: 1.45;
  }

  body.touch-device #touch-controls:not(.hidden),
  #touch-controls:not(.hidden) {
    display: block;
  }

  body.touch-device #fire-button:not(.hidden),
  #fire-button:not(.hidden) {
    display: block;
  }
}
