/* MW2 AC130 / Chopper Gunner HUD styles.
 *
 * Owned by public/mw2/hud.js. The original MW2 HUD font is not part of the
 * handoff, so the stack names the closest shipped condensed faces and falls back
 * to the system UI font. Positions and sizes come from the menu files (native
 * 640x480) and are expressed through --mw2hud-u, one native pixel.
 *
 * The ground canvas carries the AC-130 film filter in white-hot and black-hot
 * (vision/ac130.vision, vision/ac130_inverted.vision) and the engine supplies the
 * target highlights. NORMAL is the plain engine view: the canvas filter is the empty
 * string, the fullscreen thermal plates (grain, goggles, the chopper window) are not
 * drawn at all, and only the aiming overlays and readouts remain.
 * This stylesheet only composes the real overlay textures.
 */

.mw2hud {
  --mw2hud-u: 1px;
  --mw2hud-ink: #f2f6f4;
  /* JS-owned readout of the live ground-canvas filter; empty in NORMAL. */
  --mw2hud-thermal-filter: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 30;
  color: var(--mw2hud-ink);
  font-family: "MW2 HUD", "Bahnschrift", "DIN Alternate", "Roboto Condensed",
    "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
  contain: layout style;
  user-select: none;
  -webkit-user-select: none;
}

.mw2hud[hidden] {
  display: none;
}

.mw2hud-fixed {
  position: fixed;
}

/* Real full-resolution overlay textures, stretched exactly as the engine
   stretches the fullscreen itemDefs (object-fit: fill, never letterboxed). */
.mw2hud img {
  position: absolute;
  display: block;
  object-fit: fill;
  pointer-events: none;
  image-rendering: auto;
}

/* `hidden` must win over the img display rule above. Without this an overlay the
   HUD marks hidden (the other aircraft's plates, the AC-130 lock boxes, and every
   thermal plate in NORMAL) still paints, because an author `display: block` beats
   the user agent's `[hidden] { display: none }`. */
.mw2hud img[hidden],
.mw2hud [hidden] {
  display: none;
}

.mw2hud-overlay {
  z-index: 10;
}

.mw2hud-window {
  z-index: 9;
}

.mw2hud-goggles {
  z-index: 12;
}

.mw2hud-grain {
  z-index: 14;
  pointer-events: none;
}

/* NORMAL (the third vision state): no thermal or night-vision plate is drawn,
   so nothing tints, frames or obscures the unfiltered engine view. The aiming
   overlays, heading tape, readouts, reticles, lock boxes and blips stay. */
.mw2hud[data-polarity="normal"] .mw2hud-grain,
.mw2hud[data-polarity="normal"] .mw2hud-goggles,
.mw2hud[data-polarity="normal"] .mw2hud-window {
  display: none;
}

/* Every text readout gets a hard dark edge so it survives a bright ground. */
.mw2hud p,
.mw2hud ol,
.mw2hud dl {
  margin: 0;
  padding: 0;
  text-shadow:
    0 0 calc(var(--mw2hud-u) * 1.5) rgba(0, 0, 0, 0.9),
    0 0 calc(var(--mw2hud-u) * 4) rgba(0, 0, 0, 0.55);
}

.mw2hud-weapons {
  list-style: none;
}

.mw2hud-weapon {
  position: absolute;
  display: flex;
  align-items: center;
  gap: calc(var(--mw2hud-u) * 6);
  font-size: calc(var(--mw2hud-u) * 15);
  opacity: 0.55;
  transition: opacity 120ms linear;
}

.mw2hud-weapon-label {
  white-space: nowrap;
}

.mw2hud-ammo {
  font-size: calc(var(--mw2hud-u) * 13);
  opacity: 0.85;
}

/* The menu blinks the selected gun: exp forecolor a = 1 - selected*(sin(ms/90)*0.65),
   a 565 ms cycle between full and 35% alpha. */
.mw2hud-weapon.is-active {
  opacity: 1;
  animation: mw2hud-blink 0.565s linear infinite;
}

.mw2hud-weapon.is-active .mw2hud-ammo {
  opacity: 1;
}

.mw2hud-weapon-single {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 15);
  opacity: 1;
}

.mw2hud-thermal {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 16);
  letter-spacing: 0.14em;
  opacity: 0.9;
}

.mw2hud-zoom {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 15);
  letter-spacing: 0.16em;
  opacity: 0.85;
}

.mw2hud-timer {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 22);
  opacity: 0.95;
}

.mw2hud-timer.is-low {
  color: #ffb4a2;
  animation: mw2hud-blink 0.565s linear infinite;
}

/* rect 0 130 "@AC130_RELOADING" (2,2) — the label blinks while reloading. */
.mw2hud-reload {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 19);
  letter-spacing: 0.16em;
  animation: mw2hud-blink 0.565s linear infinite;
}

/* The active weapon overlay blinks while its reload runs. */
.mw2hud.is-reloading .mw2hud-overlay {
  animation: mw2hud-blink 0.565s linear infinite;
}

.mw2hud-reloadbar {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--mw2hud-u) * 150);
  transform: translateX(-50%);
  width: calc(var(--mw2hud-u) * 160);
  height: calc(var(--mw2hud-u) * 4);
  background: rgba(0, 0, 0, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.mw2hud-reloadbar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--mw2hud-ink);
  transition: width 80ms linear;
}

/* No controller progress value: run the retail reload time for that gun. */
.mw2hud.is-reloading:not(.is-reload-progress) .mw2hud-reloadbar-fill {
  animation: mw2hud-reload-fill var(--mw2hud-reload-time, 3s) linear forwards;
}

@keyframes mw2hud-reload-fill {
  from { width: 0; }
  to { width: 100%; }
}

.mw2hud-block {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 15);
  opacity: 0.85;
}

.mw2hud-coords {
  position: absolute;
  inset: 0;
}

.mw2hud-coord {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 15);
  opacity: 0.9;
}

.mw2hud-ownerdraw {
  position: absolute;
  font-size: calc(var(--mw2hud-u) * 15);
  opacity: 0.8;
}

.mw2hud-blips {
  position: absolute;
  inset: 0;
}

.mw2hud-blip {
  position: absolute;
  display: block;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 calc(var(--mw2hud-u) * 3) rgba(0, 0, 0, 0.6);
}

.mw2hud-blip.is-hidden {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.4);
}

.mw2hud-blip.is-locking {
  border-color: #ffd28a;
  border-width: 2px;
}

.mw2hud-blip.is-hurt {
  opacity: 0.5;
  border-style: dotted;
}

.mw2hud-blip.is-locked {
  border-color: #ff6f5e;
  border-width: 2px;
}

/* Heading tape: the real 1024 px tape spans 360 degrees inside the menu's
   400x20 window (ownerdraw 145). */
.mw2hud-tape {
  position: absolute;
  overflow: hidden;
  opacity: 0.65;
}

.mw2hud-tape-strip {
  position: absolute;
  top: 0;
  left: 0;
  background-repeat: repeat-x;
  background-size: 100% 100%;
  will-change: transform;
}

.mw2hud-tape-mark {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 calc(var(--mw2hud-u) * 3) rgba(0, 0, 0, 0.8);
}

.mw2hud-reticle {
  z-index: 11;
}

.mw2hud-lock {
  position: absolute;
  z-index: 11;
  transform: translate(-50%, -50%);
}

.mw2hud-locking {
  opacity: 0.65;
}

.mw2hud-badge {
  position: absolute;
  z-index: 16;
  opacity: 0.9;
}

.mw2hud-warning {
  position: absolute;
  left: 50%;
  top: calc(50% - var(--mw2hud-u) * 70);
  transform: translateX(-50%);
  font-size: calc(var(--mw2hud-u) * 16);
  letter-spacing: 0.18em;
  color: #ffb4a2;
  animation: mw2hud-blink 0.8s linear infinite;
}

/* ------------------------------------------------------------------ *
 * Controls strip and expandable help overlay.
 * ------------------------------------------------------------------ */

.mw2hud-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--mw2hud-u) * 10);
  z-index: 18;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--mw2hud-u) * 6);
}

.mw2hud-strip {
  font-size: calc(var(--mw2hud-u) * 12);
  letter-spacing: 0.12em;
  opacity: 0.8;
  text-align: center;
  text-wrap: balance;
  width: max-content;
  max-width: calc(100% - var(--mw2hud-u) * 24);
  padding: calc(var(--mw2hud-u) * 3) calc(var(--mw2hud-u) * 8);
  background: rgba(0, 0, 0, 0.42);
}

.mw2hud-help-toggle {
  pointer-events: auto;
  width: calc(var(--mw2hud-u) * 22);
  height: calc(var(--mw2hud-u) * 22);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(0, 0, 0, 0.5);
  color: inherit;
  font: inherit;
  font-size: calc(var(--mw2hud-u) * 12);
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
}

.mw2hud-help-toggle:hover,
.mw2hud-help-toggle:focus-visible {
  opacity: 1;
  border-color: #fff;
}

.mw2hud-help {
  position: absolute;
  pointer-events: auto;
  text-transform: none;
  z-index: 19;
  display: grid;
  grid-template-columns: max-content max-content;
  gap: calc(var(--mw2hud-u) * 3) calc(var(--mw2hud-u) * 10);
  margin: 0;
  padding: calc(var(--mw2hud-u) * 8) calc(var(--mw2hud-u) * 12);
  background: rgba(0, 0, 0, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: calc(var(--mw2hud-u) * 12);
  max-height: 46vh;
  overflow: auto;
}

.mw2hud-help dt {
  margin: 0;
  color: #fff;
  font-weight: 600;
}

.mw2hud-help dd {
  margin: 0;
  opacity: 0.85;
}

.mw2hud-help[hidden] {
  display: none;
}

@keyframes mw2hud-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* The help panel sits under the killstreak badge, clear of the reticle. */
@media (min-width: 561px) {
  .mw2hud-help {
    left: calc(var(--mw2hud-u) * 12);
    top: calc(var(--mw2hud-u) * 80);
  }
}

/* Narrow viewports: the strip stays, the help becomes a compact sheet. */
@media (max-width: 560px) {
  .mw2hud-controls {
    bottom: calc(var(--mw2hud-u) * 6);
  }

  .mw2hud-strip {
    max-width: calc(100% - var(--mw2hud-u) * 12);
  }

  .mw2hud-strip {
    font-size: calc(var(--mw2hud-u) * 11);
    letter-spacing: 0.06em;
  }

  /* A phone gets a bottom sheet above the strip, not a full-height panel. */
  .mw2hud-help {
    left: calc(var(--mw2hud-u) * 8);
    right: calc(var(--mw2hud-u) * 8);
    top: auto;
    bottom: calc(var(--mw2hud-u) * 40);
    width: auto;
    max-height: 38vh;
    overflow: auto;
    grid-template-columns: max-content 1fr;
    gap: calc(var(--mw2hud-u) * 2) calc(var(--mw2hud-u) * 6);
    font-size: calc(var(--mw2hud-u) * 11);
  }

  .mw2hud-help dd {
    margin-bottom: calc(var(--mw2hud-u) * 4);
  }
}

@media (max-width: 430px) {
  .mw2hud-weapon {
    font-size: calc(var(--mw2hud-u) * 13);
  }

  .mw2hud-strip {
    display: none;
  }

  .mw2hud-help-toggle {
    opacity: 0.9;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mw2hud-weapon.is-active,
  .mw2hud-timer.is-low,
  .mw2hud-reload,
  .mw2hud-warning,
  .mw2hud.is-reloading .mw2hud-overlay {
    animation: none;
  }

  .mw2hud-weapon.is-active {
    opacity: 1;
    text-decoration: underline;
    text-underline-offset: calc(var(--mw2hud-u) * 3);
  }

  .mw2hud-reloadbar-fill {
    transition: none;
  }

  .mw2hud.is-reloading:not(.is-reload-progress) .mw2hud-reloadbar-fill {
    animation: none;
    width: 100%;
  }
}
