/* Enemy chopper HUD panel styles. Enemy AC-130 creates no HUD nodes.
 *
 * Owned by public/mw2/enemy-support.js. The panel is presentation only: it is
 * pointer-events:none so it can never eat a shot or a drag, and it is anchored
 * top-right in the band the shipped CS HUD leaves free. The radar and the health
 * readouts live bottom-left and top-left, so nothing here covers the radar, the
 * crosshair or the scoreboard.
 *
 * The panel is compact on purpose: it is a status strip, not an overlay. It never
 * exceeds a third of the viewport width on desktop, and on a narrow window it
 * becomes a single centred line under the top edge. The integrity row is part of the
 * same strip: a meter, its label and its percentage on one line, hidden whenever
 * the native snapshot carries no integrity numbers.
 *
 * Only a phase change is announced (the live region in enemy-support.js); the
 * countdown is not a live region, so a per-tick update cannot flood a screen
 * reader.
 */

.mw2enemy {
  /* Red enemy identity, on a dark plate that stays readable over any map. */
  --mw2enemy-accent: #ff6a5a;
  --mw2enemy-ink: #ffeceb;
  --mw2enemy-dim: #ffb9b1;
  --mw2enemy-plate: rgba(24, 10, 10, 0.86);
  --mw2enemy-track: rgba(255, 185, 177, 0.55);
  position: fixed;
  z-index: 26;
  top: max(10px, env(safe-area-inset-top, 0px));
  right: max(10px, env(safe-area-inset-right, 0px));
  width: min(310px, 34vw);
  box-sizing: border-box;
  padding: 6px 12px 6px;
  display: grid;
  /* minmax(0, ...) lets the phase column shrink below its content width, so a
     narrow panel wraps its text instead of overflowing it. */
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "head head"
    "phase time"
    "integrity integrity"
    "cover cover"
    "hint hint";
  gap: 2px 10px;
  align-items: baseline;
  background: var(--mw2enemy-plate);
  border: 1px solid var(--mw2enemy-accent);
  border-left-width: 4px;
  color: var(--mw2enemy-ink);
  font-family: "Bahnschrift", "DIN Alternate", "Roboto Condensed", "Arial Narrow",
    "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  line-height: 1.15;
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  contain: layout style;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

/* The module hides the panel whenever the sortie is inactive; an author
   `display: grid` above must not beat the user agent's [hidden] rule. */
.mw2enemy[hidden] {
  display: none;
}

.mw2enemy-head {
  grid-area: head;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.mw2enemy-badge {
  flex: none;
  padding: 2px 6px;
  background: var(--mw2enemy-accent);
  color: #2a0806;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.mw2enemy-kind {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--mw2enemy-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mw2enemy-phase {
  grid-area: phase;
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--mw2enemy-dim);
  overflow-wrap: anywhere;
}

.mw2enemy-time {
  grid-area: time;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--mw2enemy-ink);
  justify-self: end;
}

.mw2enemy-time[hidden] {
  display: none;
}

/* Aircraft integrity. A real meter with its label and its percentage as real text:
   the bar is a visual duplicate, never the only signal, and it is hidden whenever
   the native snapshot carries no integrity numbers, so no stale bar survives an
   aircraft. */
.mw2enemy-integrity {
  grid-area: integrity;
  margin: 1px 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.12em;
  color: var(--mw2enemy-dim);
}

.mw2enemy-integrity[hidden] {
  display: none;
}

.mw2enemy-integrity-label {
  flex: none;
}

/* The bar takes the slack between the label, the percentage and the hit mark, and
   wraps under them if the panel is ever narrower than the row. */
.mw2enemy-meter {
  flex: 1 1 40px;
  min-width: 24px;
  height: 4px;
  box-sizing: border-box;
  border: 1px solid var(--mw2enemy-track);
  background: rgba(0, 0, 0, 0.4);
}

.mw2enemy-meter-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--mw2enemy-accent);
}

.mw2enemy-integrity-value {
  flex: none;
  font-weight: 700;
  color: var(--mw2enemy-ink);
}

.mw2enemy-hitmark {
  flex: none;
  font-weight: 700;
  color: var(--mw2enemy-ink);
}

.mw2enemy-hitmark[hidden] {
  display: none;
}

/* Hit feedback is a steady outline and a brighter bar for a moment: no animation,
   no movement and no resize under the player's aim. */
.mw2enemy-hit {
  outline: 2px solid rgba(255, 255, 255, 0.75);
  outline-offset: -2px;
}

.mw2enemy-hit .mw2enemy-meter-fill {
  background: var(--mw2enemy-ink);
}

/* Shot down: the threat is over, so the plate leaves the enemy red for a calm,
   resolved identity and keeps a readable contrast on its badge. */
.mw2enemy-down {
  --mw2enemy-accent: #a9c08f;
  --mw2enemy-dim: #d6e3c4;
  --mw2enemy-ink: #f2f8e8;
  --mw2enemy-track: rgba(214, 227, 196, 0.55);
}

.mw2enemy-down .mw2enemy-badge {
  color: #1b2415;
}

.mw2enemy-down .mw2enemy-phase {
  color: var(--mw2enemy-ink);
  font-weight: 700;
}

/* "Take cover" is the attack-phase instruction; it is absent in the warning and
   the two pre-attack phases, where the aircraft is not yet shooting at the player. */
.mw2enemy-cover {
  grid-area: cover;
  margin: 1px 0 0;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 106, 90, 0.45);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--mw2enemy-accent);
}

.mw2enemy-cover[hidden] {
  display: none;
}

/* The dismiss key the controller owns, named as a hint rather than a control:
   the panel never handles the key itself. */
.mw2enemy-hint {
  grid-area: hint;
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--mw2enemy-dim);
  opacity: 0.85;
}

.mw2enemy-key {
  padding: 1px 5px;
  border: 1px solid rgba(255, 185, 177, 0.55);
  border-radius: 2px;
  font: inherit;
  font-weight: 700;
  color: var(--mw2enemy-ink);
}

/* The hint is an author `display: flex` row, so the user agent's [hidden] rule
   needs the same help the panel itself gets: a resolved aircraft has no dismiss
   control to offer and the row must really leave the layout. */
.mw2enemy-hint[hidden] {
  display: none;
}

.mw2enemy-phase-warning {
  border-color: var(--mw2enemy-accent);
}

.mw2enemy-phase-opening-105,
.mw2enemy-phase-opening-40 {
  --mw2enemy-accent: #ff8f4d;
}

.mw2enemy-phase-attack {
  --mw2enemy-accent: #ff3b2f;
  animation: mw2enemy-pulse 1.1s ease-in-out infinite;
}

/* Phase changes only: the pulse marks a live attack run without moving or
   resizing anything under the player's aim. */
@keyframes mw2enemy-pulse {
  0%, 100% { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), 0 0 0 0 rgba(255, 59, 47, 0.55); }
  50% { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), 0 0 0 6px rgba(255, 59, 47, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .mw2enemy-phase-attack {
    animation: none;
  }
}

/* Narrow windows: the panel stays anchored to the top-right and keeps a ~120px
   gutter for the native upper-left radar. It is never a full-width strip: the
   width is capped at min(310px, 100% - 126px), so at 320px it is ~194px wide and
   starts at ~120px. Text wraps inside the panel instead of overflowing, and the
   height stays a compact strip. */
@media (max-width: 640px) {
  .mw2enemy {
    top: max(6px, env(safe-area-inset-top, 0px));
    left: auto;
    right: max(6px, env(safe-area-inset-right, 0px));
    width: min(310px, calc(100% - 126px));
    padding: 5px 10px 5px;
    grid-template-areas:
      "head head"
      "phase time"
      "integrity integrity"
      "cover cover"
      "hint hint";
  }

  /* The identity and the phase may wrap at these widths: readable beats
     truncated. */
  .mw2enemy-kind {
    font-size: 13px;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .mw2enemy-phase {
    font-size: 12px;
  }

  .mw2enemy-time {
    font-size: 16px;
  }

  .mw2enemy-cover {
    font-size: 13px;
  }

  /* Tighter tracking at these widths buys slack for a wider fallback face, so
     the dismiss hint cannot clip in a 320px strip. */
  .mw2enemy-hint {
    letter-spacing: 0.1em;
  }
}

/* Very short viewports keep the strip out of the way of the view model and the
   scoreboard: the panel only shrinks, it never grows into the centre. */
@media (max-height: 420px) {
  .mw2enemy {
    padding: 5px 9px 5px;
  }

  .mw2enemy-cover {
    padding-top: 4px;
  }
}

/* The phase-change announcement for assistive technology. It stays in the DOM and
   in the accessibility tree (never display:none, never aria-hidden), and it is
   visually hidden with the clip technique so it cannot cover the game view. */
.mw2enemy-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
