:root {
  --hud-bg: rgba(13, 17, 23, 0.78);
  --hud-border: rgba(48, 54, 61, 0.9);
  --hud-text: #e6edf3;
  --hud-muted: #8b949e;
  --hud-accent: #58a6ff;
  --crosshair: rgba(210, 218, 205, 0.48);
  --crosshair-ring: rgba(210, 218, 205, 0.32);
  --crosshair-dot: rgba(210, 218, 205, 0.55);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0e14;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--hud-text);
  user-select: none;
  cursor: crosshair;
}

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

.crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 20;
  color: var(--crosshair);
  opacity: 0.92;
}

.crosshair svg {
  display: block;
}

.crosshair__hair,
.crosshair__tick {
  stroke: currentColor;
  opacity: 0.55;
}

.crosshair__ring {
  stroke: var(--crosshair-ring);
}

.crosshair__dot {
  fill: var(--crosshair-dot);
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}

.hud__panel {
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  min-width: 9.5rem;
  font-size: 0.72rem;
  line-height: 1.35;
  backdrop-filter: blur(4px);
}

.hud__title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hud-muted);
  margin-bottom: 0.25rem;
}

.hud__row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.hud__label {
  color: var(--hud-muted);
}

.hud__value {
  font-variant-numeric: tabular-nums;
  color: var(--hud-text);
  text-align: right;
}

.hud__value--on {
  color: #3fb950;
}

.hud__value--off {
  color: #f85149;
}

.hud__panel kbd {
  font: inherit;
  font-size: 0.65rem;
  background: rgba(48, 54, 61, 0.65);
  border: 1px solid rgba(48, 54, 61, 0.9);
  border-radius: 3px;
  padding: 0 0.2rem;
  color: var(--hud-muted);
}

.hud__panel--controls {
  min-width: 10.5rem;
}

.hud__panel--target {
  margin-top: auto;
  align-self: flex-start;
}

.hud__panel--env {
  align-self: flex-end;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}

.radar-wrap {
  position: fixed;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 12;
  pointer-events: none;
  border: 1px solid rgba(48, 100, 68, 0.75);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(4, 14, 8, 0.94);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35), 0 0 12px rgba(40, 120, 60, 0.12);
}

.radar-wrap canvas {
  display: block;
  width: 300px;
  height: 300px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 14, 0.82);
  backdrop-filter: blur(6px);
}

.overlay[hidden] {
  display: none !important;
}

.overlay__card {
  max-width: min(28rem, calc(100vw - 2rem));
  background: rgba(22, 27, 34, 0.96);
  border: 1px solid var(--hud-border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.overlay__title {
  margin: 0 0 0.65rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.overlay__text {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--hud-muted);
}

.overlay__list {
  margin: 0 0 1rem;
  padding-left: 1.1rem;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--hud-muted);
}

.overlay__list kbd {
  font: inherit;
  background: rgba(48, 54, 61, 0.8);
  border: 1px solid var(--hud-border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  color: var(--hud-text);
}

.overlay__btn {
  appearance: none;
  border: 1px solid rgba(88, 166, 255, 0.55);
  background: rgba(88, 166, 255, 0.18);
  color: var(--hud-accent);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.overlay__btn:hover {
  background: rgba(88, 166, 255, 0.28);
  transform: scale(1.02);
}

.overlay__back {
  display: inline-block;
  margin-top: 0.85rem;
  font-size: 0.78rem;
  color: var(--hud-muted);
  text-decoration: none;
}

.overlay__back:hover {
  color: var(--hud-accent);
  text-decoration: underline;
}

.overlay__card--menu {
  max-width: min(36rem, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.overlay__btn--ghost {
  border-color: var(--hud-border);
  background: transparent;
  color: var(--hud-muted);
}

.overlay__btn--ghost:hover {
  background: rgba(48, 54, 61, 0.5);
  color: var(--hud-text);
}

.leaderboard {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--hud-border);
}

.leaderboard__title {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.leaderboard__hint {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  color: var(--hud-muted);
}

.leaderboard__scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.leaderboard__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.leaderboard__table th {
  text-align: right;
  font-weight: 500;
  color: var(--hud-muted);
  border-bottom: 1px solid var(--hud-border);
  padding: 0;
  white-space: nowrap;
}

.leaderboard__table td {
  padding: 0.4rem 0.5rem 0.4rem 0;
  border-bottom: 1px solid rgba(48, 54, 61, 0.45);
  vertical-align: middle;
}

.leaderboard__table tbody tr:last-child td {
  border-bottom: none;
}

.leaderboard__sort {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 0.35rem 0.25rem 0.35rem 0;
  text-align: right;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.leaderboard__sort:hover {
  color: var(--hud-text);
}

.leaderboard__sort.is-active {
  color: var(--hud-accent);
}

.leaderboard__sort.is-active::after {
  content: "▲";
  font-size: 0.55rem;
  opacity: 0.85;
}

.leaderboard__sort.is-active[data-order="desc"]::after {
  content: "▼";
}

.leaderboard__name {
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding-right: 0.25rem !important;
}

.leaderboard__empty {
  text-align: center;
  color: var(--hud-muted);
  padding: 0.75rem 0 !important;
}

.score-summary {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.score-summary li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--hud-muted);
}

.score-summary strong {
  color: var(--hud-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-name {
  display: block;
  margin-bottom: 1rem;
}

.score-name__label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
  color: var(--hud-muted);
}

.score-name__input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--hud-border);
  background: rgba(13, 17, 23, 0.85);
  color: var(--hud-text);
  font: inherit;
  font-size: 0.88rem;
}

.score-name__input:focus {
  outline: none;
  border-color: rgba(88, 166, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.score-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

#scoreOverlay {
  z-index: 110;
}

.muzzle-flash {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 120%;
  height: 35vh;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 15;
  background: radial-gradient(ellipse at center bottom, rgba(255, 200, 80, 0.35) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.03s;
}

.muzzle-flash.is-on {
  opacity: 1;
}

.overlay__text--mobile {
  display: none;
}

.mobile-controls {
  display: none;
}

.mobile-pause,
.mobile-fire,
.joystick {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 900px), (pointer: coarse) {
  html,
  body {
    cursor: default;
  }

  .overlay__text--desktop {
    display: none;
  }

  .overlay__text--mobile {
    display: block;
  }

  .overlay__list {
    font-size: 0.72rem;
    margin-bottom: 0.75rem;
  }

  .overlay__card {
    padding: 1rem 1.05rem;
  }

  .overlay__title {
    font-size: 1rem;
  }

  .overlay__card--menu {
    max-width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
  }

  .leaderboard__table {
    font-size: 0.72rem;
  }

  .leaderboard__name {
    max-width: 6.5rem;
  }

  body.is-mobile .mobile-controls:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    pointer-events: none;
  }

  .joystick {
    position: fixed;
    left: max(1.15rem, calc(0.65rem + env(safe-area-inset-left)));
    bottom: max(1.15rem, calc(0.65rem + env(safe-area-inset-bottom)));
    width: 146px;
    height: 146px;
    pointer-events: auto;
    opacity: 0.62;
  }

  .joystick__base {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(14, 20, 28, 0.38);
    border: 2px solid rgba(88, 166, 255, 0.32);
    backdrop-filter: blur(3px);
  }

  .joystick__stick {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 57px;
    height: 57px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(88, 166, 255, 0.38);
    border: 2px solid rgba(160, 200, 255, 0.48);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    pointer-events: none;
  }

  .mobile-fire {
    position: fixed;
    right: max(1.15rem, calc(0.65rem + env(safe-area-inset-right)));
    bottom: max(1.15rem, calc(0.65rem + env(safe-area-inset-bottom)));
    width: 99px;
    height: 99px;
    border-radius: 50%;
    border: 2px solid rgba(255, 120, 80, 0.45);
    background: rgba(180, 50, 40, 0.38);
    color: rgba(255, 230, 220, 0.88);
    font: 600 0.62rem/1 system-ui, sans-serif;
    letter-spacing: 0.04em;
    pointer-events: auto;
    backdrop-filter: blur(3px);
    opacity: 0.62;
  }

  .mobile-fire:active {
    background: rgba(220, 70, 50, 0.52);
    opacity: 0.78;
    transform: scale(0.96);
  }

  .mobile-pause {
    position: fixed;
    top: max(0.45rem, env(safe-area-inset-top));
    left: max(0.45rem, env(safe-area-inset-left));
    z-index: 26;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--hud-border);
    background: var(--hud-bg);
    color: var(--hud-text);
    font-size: 0.85rem;
    pointer-events: auto;
    backdrop-filter: blur(4px);
  }

  body.is-mobile .hud {
    padding: 0.3rem;
    gap: 0.22rem;
  }

  body.is-mobile .hud__panel {
    font-size: 0.56rem;
    line-height: 1.25;
    padding: 0.22rem 0.38rem;
    min-width: 0;
    border-radius: 6px;
    backdrop-filter: blur(3px);
  }

  body.is-mobile .hud__title {
    font-size: 0.52rem;
    margin-bottom: 0.12rem;
  }

  body.is-mobile .hud__row {
    gap: 0.45rem;
  }

  body.is-mobile .hud__panel--controls {
    display: none;
  }

  body.is-mobile .hud__panel--env .hud__row:nth-child(n + 4) {
    display: none;
  }

  body.is-mobile .hud__panel--target .hud__row:nth-child(n + 4) {
    display: none;
  }

  body.is-mobile .hud__panel--env {
    position: static;
    max-width: none;
  }

  body.is-mobile .hud__panel--target {
    margin-top: 0;
    position: static;
    max-width: none;
  }

  body.is-mobile .radar-wrap {
    position: fixed;
    right: 0.35rem;
    top: auto;
    bottom: auto;
    transform: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  }

  body.is-mobile .radar-wrap canvas {
    width: 104px;
    height: 104px;
  }

  body.is-mobile .crosshair svg {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 900px) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  body.is-mobile .hud {
    flex-direction: column;
    align-items: flex-start;
    padding-top: calc(0.35rem + env(safe-area-inset-top));
    padding-left: max(2.55rem, calc(0.35rem + env(safe-area-inset-left)));
    padding-right: 0.35rem;
    max-width: 52vw;
  }

  body.is-mobile .hud__panel:first-child,
  body.is-mobile .hud__panel--env,
  body.is-mobile .hud__panel--target {
    position: static;
    width: 100%;
    max-width: none;
  }

  body.is-mobile .radar-wrap {
    top: calc(0.35rem + env(safe-area-inset-top));
    right: max(0.65rem, calc(0.35rem + env(safe-area-inset-right)));
  }

  body.is-mobile .joystick {
    width: 153px;
    height: 153px;
    left: max(1.15rem, calc(0.65rem + env(safe-area-inset-left)));
    bottom: max(1.15rem, calc(0.65rem + env(safe-area-inset-bottom)));
  }

  body.is-mobile .joystick__stick {
    width: 60px;
    height: 60px;
  }

  body.is-mobile .mobile-fire {
    width: 104px;
    height: 104px;
    right: max(1.15rem, calc(0.65rem + env(safe-area-inset-right)));
    bottom: max(1.15rem, calc(0.65rem + env(safe-area-inset-bottom)));
  }
}

@media (max-width: 900px) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
  body.is-mobile .hud {
    flex-direction: row;
    flex-wrap: wrap;
    align-content: flex-start;
    padding-top: max(0.25rem, env(safe-area-inset-top));
    padding-left: max(2.5rem, calc(0.3rem + env(safe-area-inset-left)));
    padding-right: max(0.25rem, env(safe-area-inset-right));
  }

  body.is-mobile .hud__panel:first-child,
  body.is-mobile .hud__panel--env,
  body.is-mobile .hud__panel--target {
    position: static;
    max-width: none;
  }

  body.is-mobile .hud__panel {
    font-size: 0.52rem;
    padding: 0.18rem 0.32rem;
  }

  body.is-mobile .hud__panel--env .hud__row:nth-child(4) {
    display: none;
  }

  body.is-mobile .hud__panel--target {
    margin-left: 0;
  }

  body.is-mobile .radar-wrap {
    right: max(0.65rem, calc(0.35rem + env(safe-area-inset-right)));
    bottom: max(0.65rem, calc(0.35rem + env(safe-area-inset-bottom)));
    top: auto;
  }

  body.is-mobile .radar-wrap canvas {
    width: 128px;
    height: 128px;
  }

  body.is-mobile .joystick {
    width: 125px;
    height: 125px;
    left: max(1.1rem, calc(0.6rem + env(safe-area-inset-left)));
    bottom: max(1.1rem, calc(0.6rem + env(safe-area-inset-bottom)));
  }

  body.is-mobile .joystick__stick {
    width: 49px;
    height: 49px;
  }

  body.is-mobile .mobile-fire {
    width: 88px;
    height: 88px;
    font-size: 0.55rem;
    right: max(1.1rem, calc(0.6rem + env(safe-area-inset-right)));
    bottom: max(1.1rem, calc(0.6rem + env(safe-area-inset-bottom)));
  }

  body.is-mobile .mobile-pause {
    top: max(0.35rem, env(safe-area-inset-top));
  }
}
