/* War in the Void — in-match HUD (src/game/hud.js). Overlay on the match canvas:
   top resource bar, selection panel, command card, armed banner, end overlay.
   Layering: HUD chrome 40, armed banner 45, (radial menu 50), end overlay 60.
   Orientation via :root[data-orient="portrait"|"landscape"]; HUD hugs the
   edges — the center of the screen is always clear for the battlefield. */

/* ---- Top resource bar ---- */
.hud-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  padding: calc(var(--safe-top) + 4px) calc(var(--safe-right) + 8px) 4px calc(var(--safe-left) + 8px);
  display: flex; align-items: center; justify-content: flex-start; gap: 6px;
  pointer-events: none; /* readouts only — taps fall through to the map */
}
.hud-res {
  display: flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 3px 10px;
  background: rgba(16, 16, 28, 0.88); /* --bg-elev at HUD opacity */
  /* faction-accented top edge; falls back to the neutral theme line */
  border: var(--border-w) solid var(--line-soft);
  border-top: 2px solid var(--faction, var(--line-soft));
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1);
  font-size: 13px; font-weight: 800; letter-spacing: 0.03em;
}
.hud-res-ico { font-size: 11px; line-height: 1; }
.hud-res-min .hud-res-ico { color: #4dd8e6; }   /* minerals — cyan diamond */
.hud-res-gas .hud-res-ico { color: var(--good); }
.hud-res-sup .hud-res-ico { color: var(--text-mute); }
.hud-res-val { color: var(--text); line-height: 1; }
.hud-res-sup { margin-left: auto; }
.hud-res-sup.is-full { border-color: var(--warn); }
.hud-res-sup.is-full .hud-res-val { color: var(--warn); }

/* ---- Attack-move armed banner ---- */
.hud-armed {
  position: fixed; z-index: 45;
  top: calc(var(--safe-top) + 44px);
  left: 50%; transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 6px 16px;
  background: rgba(255, 77, 94, 0.14);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 11px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
  text-align: center; white-space: nowrap;
  pointer-events: none;
}

/* ---- Selection panel (name + aggregate HP bar) ---- */
.hud-sel {
  position: fixed; z-index: 40;
  left: calc(var(--safe-left) + 10px);
  bottom: calc(var(--safe-bot) + 10px);
  min-width: 140px; max-width: 44vw;
  padding: 8px 10px;
  background: rgba(16, 16, 28, 0.88);
  /* faction-accented border + left edge; falls back to the neutral theme line */
  border: var(--border-w) solid var(--faction, var(--line));
  border-left: 3px solid var(--faction, var(--line));
  border-radius: var(--radius);
  box-shadow: var(--bevel-up), var(--shadow-1);
  pointer-events: none;
}
.hud-sel-name {
  font-size: 12px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--faction, var(--text)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px;
}
.hud-sel-info {
  font-size: 10px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 5px; min-height: 12px;
}
/* animated gif portrait: floats left of the text block when present */
.hud-sel-portrait {
  float: left; width: 52px; height: 52px; margin: 0 8px 2px 0;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  object-fit: cover; background: #10131f;
  image-rendering: pixelated;
}
.hud-sel-portrait.is-hidden { display: none; }
.hud-sel.has-portrait { min-width: 210px; }
.hud-sel-track {
  height: 7px; background: var(--bg); border: 1px solid var(--line-soft);
  border-radius: 2px; overflow: hidden; clear: none;
}
.hud-sel-fill {
  height: 100%; width: 0; background: var(--good);
  transition: width 0.15s ease;
}
.hud-sel-fill.is-mid { background: var(--warn); }
.hud-sel-fill.is-low { background: var(--danger); }

/* ---- Command card (3x2 button grid, bottom-right) ---- */
.hud-card {
  position: fixed; z-index: 40;
  right: calc(var(--safe-right) + 10px);
  bottom: calc(var(--safe-bot) + 10px);
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-auto-rows: minmax(56px, auto);
  gap: 6px;
  justify-items: stretch;
}
.hud-cbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 48px; min-height: 48px; padding: 4px 3px;
  border-radius: var(--radius); border: var(--border-w) solid var(--line);
  background: rgba(24, 24, 41, 0.94); /* --bg-elev-2 at HUD opacity */
  color: var(--text);
  box-shadow: var(--bevel-up);
  cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  transition: box-shadow 0.08s, transform 0.08s, border-color 0.12s;
}
.hud-cbtn:active { box-shadow: var(--bevel-down); transform: translateY(1px); }
.hud-cbtn:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 1px; }
.hud-cbtn-label {
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.03em; text-transform: uppercase;
  line-height: 1.15; text-align: center; overflow: hidden;
}
.hud-cbtn-cost {
  font-size: 9px; font-weight: 700; color: var(--text-mute);
  line-height: 1; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hud-cbtn-danger { border-color: var(--danger); color: var(--danger); }
.hud-cbtn-danger:active { background: rgba(255, 77, 94, 0.14); }
.hud-cbtn-research { border-color: #9d85ff; color: #c9bcff; }
.hud-cbtn-research:active { background: rgba(157, 133, 255, 0.16); }
.hud-cbtn-ability { border-color: #35d0e0; color: #a6f0f6; }
.hud-cbtn-ability:active { background: rgba(53, 208, 224, 0.16); }
.hud-cbtn-addon { border-color: #d0a035; color: #f0d6a0; }
.hud-cbtn-addon:active { background: rgba(208, 160, 53, 0.16); }
.hud-cbtn-morph { border-color: #d24d6e; color: #f2b3c4; }
.hud-cbtn-morph:active { background: rgba(210, 77, 110, 0.16); }
.hud-cbtn-menu { border-color: var(--accent); }
.hud-cbtn-back { border-color: var(--line); color: var(--text-mute); }

/* icon buttons: image fills the button, caption + cost overlay */
.hud-cbtn.has-icon { position: relative; padding: 2px; }
.hud-cbtn-icon {
  width: 100%; height: 100%; object-fit: contain; pointer-events: none;
  image-rendering: pixelated;
}
.hud-cbtn-label.is-iconed {
  position: absolute; left: 2px; right: 2px; bottom: 1px;
  font-size: 8px; line-height: 1.1; text-shadow: 0 1px 2px #000c;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hud-cbtn.has-icon .hud-cbtn-cost {
  position: absolute; top: 1px; right: 3px; text-shadow: 0 1px 2px #000c;
}

/* hold/hover tooltip bubble */
.hud-tip {
  position: absolute; width: 190px; z-index: 40; pointer-events: none;
  background: rgba(10, 12, 22, 0.94); border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm); padding: 7px 9px;
  box-shadow: 0 4px 14px #000a;
}
.hud-tip.is-hidden { display: none; }
.hud-tip-title { font-size: 12px; font-weight: 800; color: var(--text); margin-bottom: 2px; }
.hud-tip-line { font-size: 11px; color: var(--text-dim); padding: 1px 0; }
.hud-cbtn:disabled, .hud-cbtn.is-dim {
  opacity: 0.4; cursor: default;
}
.hud-cbtn:disabled:active { box-shadow: var(--bevel-up); transform: none; }

/* ---- Train queue indicator (lives inside the card grid) ---- */
.hud-queue {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: center;
  min-height: 22px; padding: 3px 8px;
  background: rgba(16, 16, 28, 0.88);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  color: var(--accent-bright);
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* ---- Orientation layout ----
   Portrait: card bottom-right 3x2 above safe-bot; selection bottom-left.
   Landscape: card stays bottom-right corner; selection panel bottom-center. */
:root[data-orient="landscape"] .hud-sel {
  left: 50%; transform: translateX(-50%);
  max-width: 46vw;
}
:root[data-orient="landscape"] .hud-card {
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bot) + 12px);
}
/* very narrow portrait phones: keep the 3x2 grid on screen */
@media (max-width: 380px) {
  :root[data-orient="portrait"] .hud-card { grid-template-columns: repeat(3, 52px); }
  :root[data-orient="portrait"] .hud-sel { max-width: 38vw; }
}

/* ---- End-of-match overlay ---- */
.hud-end {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 8, 15, 0.85);
  display: flex; align-items: center; justify-content: center;
  padding: 24px calc(var(--safe-right) + 24px) calc(var(--safe-bot) + 24px) calc(var(--safe-left) + 24px);
}
.hud-end-card {
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.hud-end-title {
  font-size: 44px; font-weight: 900; line-height: 1;
  letter-spacing: 0.12em; text-transform: uppercase;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.6);
}
.hud-end-title.is-victory { color: var(--good); }
.hud-end-title.is-defeat { color: var(--danger); }
.hud-end-time {
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}
/* results: army-value graph + stat table */
.hud-end-graphwrap {
  width: 100%; padding: 10px;
  background: rgba(16, 16, 28, 0.9);
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
}
.hud-end-graphtitle {
  font-size: 10px; font-weight: 800; letter-spacing: 0.14em;
  color: var(--text-mute); text-align: left; margin-bottom: 6px;
}
.hud-end-graph { width: 100%; height: auto; display: block; }
.hud-end-legend { font-size: 11px; font-weight: 700; margin-top: 6px; text-align: left; }
.hud-end-stats {
  width: 100%;
  background: rgba(16, 16, 28, 0.9);
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  padding: 6px 12px;
}
.hud-end-statrow {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 5px 0; font-size: 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.hud-end-statrow:last-child { border-bottom: none; }
.hud-end-statlabel { color: var(--text-dim); }
.hud-end-statval { font-weight: 800; color: var(--text); }

/* ---- Shared visibility helper (hud.js toggles .is-hidden) ---- */
.hud-top.is-hidden, .hud-armed.is-hidden, .hud-sel.is-hidden,
.hud-card.is-hidden, .hud-queue.is-hidden, .hud-cbtn.is-hidden { display: none; }
