/* ==================================================================================================================
   In-run HUD layout: where every panel sits, per input and screen size. Loaded after style.css and hud-theme.css,
   whose older position rules this overrides; they still own each panel's look (glass, type, bars).

   Keyboard / mouse / gamepad (landscape windows, laptop to 4K), the usual action-game corners:
     top left      objective (story), co-op zone hold above it     top centre   wave / target, kaiju health
     top right     element stats (compact)                         left middle  co-op squad
     bottom left   hull & cells (one slim bar each), the minimap   bottom right abilities over weapons: one compact
                   right above them (+/- keys resize it)                        panel ("arms", js/hud-stack.js)
     bottom centre radio comms, tips above them
   You (health, map) on the left, your gear on the right; the centre of the screen (reticle, the kaiju) stays clear.

   Touch (phones and tablets, always landscape: js/orientation-lock.js covers portrait). The same panels as keyboard
   layouts, compacted:
     top left      wave / target, vitals, minimap                  top centre   kaiju health, co-op squad under it
     top right     pause / more, objective, ability rack            bottom       stick left, action pad right; between
                                                                                them element stats, radio comms above
   ================================================================================================================== */

/* ---------- Keyboard layouts ---------- */
/* The arms panel (weapons + abilities) only exists on keyboard landscape layouts: js/hud-stack.js moves the weapon
   rack and the ability rack into it there, and back out everywhere else */
.kaiju-arms { display: none; }
@media (min-width: 641px) and (orientation: landscape) {
  body.kaiju-active:not(.touch-enabled) {
    --hl-edge: max(var(--edge, 12px), env(safe-area-inset-left), env(safe-area-inset-right));
    --hl-top: max(var(--edge, 12px), env(safe-area-inset-top));
    --hl-bottom: max(var(--edge, 12px), env(safe-area-inset-bottom));
    --hl-side: 380px; /* the wider bottom corner (the arms panel) */
  }

  /* Bottom left: hull and cells, label · bar · value on one line each */
  html body.kaiju-active:not(.touch-enabled) #kaiju-vitals {
    top: auto; right: auto;
    left: var(--hl-edge);
    bottom: var(--hl-bottom);
    width: 228px;
    flex-direction: column; align-items: stretch;
    gap: 5px;
    padding: 7px 10px 8px;
    transform: none;
  }
  html body.kaiju-active:not(.touch-enabled) #kaiju-vitals .vital { display: grid; grid-template-columns: 38px 1fr 30px; align-items: center; gap: 8px; width: auto; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-vitals .vital-head { display: contents; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-vitals .vital-head span:last-child { order: 2; font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-vitals .vital-track { order: 1; height: 6px; }
  /* (the arms panel lists the abilities; this one-line readout is for portrait windows) */
  html body.kaiju-active:not(.touch-enabled) #kaiju-vitals .kaiju-ability { display: none; }
  /* ... and the minimap right above them; its size only changes with the +/- keys (js/nyc-map.js). --vitals-top
     from js/hud-stack.js */
  html body.kaiju-active:not(.touch-enabled) .hud-bottom-left {
    top: auto; right: auto;
    left: var(--hl-edge);
    bottom: calc(100dvh - var(--vitals-top, 100dvh) + 6px);
    align-items: flex-start;
  }

  /* Bottom right: the arms panel, abilities (one row of slots) over the weapons (one row of four) */
  html body.kaiju-active:not(.touch-enabled):not(.kaiju-over) #kaiju-arms {
    position: fixed; z-index: 8;
    right: var(--hl-edge);
    bottom: var(--hl-bottom);
    display: flex; flex-direction: column; gap: 6px;
    width: max-content; min-width: 240px; max-width: var(--hl-side);
    padding: 7px 8px 8px;
    border: 1px solid var(--ew-line);
    background: var(--ew-brackets), var(--ew-plate);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    box-shadow: 0 14px 34px -14px rgba(0, 0, 0, 0.7);
    color: var(--text);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  }
  body.hud-minimized #kaiju-arms { visibility: hidden; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms #kaiju-abilities {
    position: static;
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px;
    width: auto; max-height: none;
    padding: 0; overflow: visible;
    border: 0 !important;
    background: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
    zoom: 1;
  }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-head { grid-column: 1; justify-content: flex-start; gap: 8px; padding: 0; border: 0; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-head h2 { font-size: 9px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-meta { font-size: 10px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-hint { grid-column: 2; grid-row: 1; font-size: 9px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-effect { grid-column: 1 / -1; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-slots { grid-column: 1 / -1; flex-direction: row; gap: 3px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-slot { flex: 1 1 0; min-width: 0; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-slot button { flex-wrap: nowrap; gap: 6px; min-height: 26px; padding: 3px 7px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-slot.is-empty { display: flex; align-items: center; min-height: 26px; padding: 3px 7px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-slot-name { min-width: 0; overflow: hidden; font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-slot.is-empty .loadout-slot-name { font-size: 9px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .loadout-desc { display: none; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .weapon-rack { display: flex; gap: 3px; padding-top: 6px; border-top: 1px solid var(--ew-line); }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .weapon-btn { flex: 1 1 auto; min-width: max-content; flex-direction: row; align-items: center; gap: 5px; padding: 5px 6px 7px; font-size: 10px; white-space: nowrap; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .weapon-btn kbd { font-size: 9px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .weapon-ammo { position: static; margin-left: 1px; font-size: 10px; font-variant-numeric: tabular-nums; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms .weapon-heat { left: 6px; right: 6px; bottom: 2px; }

  /* Top left: what to do next */
  html body.kaiju-active:not(.touch-enabled) #kaiju-zone-hold {
    top: var(--hl-top); right: auto;
    left: var(--hl-edge);
    width: fit-content;
    max-width: min(340px, calc(50vw - 200px));
    margin: 0;
  }
  html body.kaiju-active:not(.touch-enabled) #kaiju-objective {
    top: var(--hl-top); right: auto; bottom: auto;
    left: var(--hl-edge);
    width: min(320px, calc(50vw - 200px));
    max-width: none;
    transform: none;
  }
  html body.kaiju-active:not(.touch-enabled):has(#kaiju-zone-hold:not([hidden])) #kaiju-objective {
    top: calc(var(--hl-top) + 52px);
  }

  /* Top centre: wave / target strip, kaiju health under it. Never narrower than 232px (so it sits still for short
     names) and as wide as the target's name, ward and range need, up to the objective card in the top-left corner
     (the strip is centred, so the same room on both sides); past that the name is clipped (.target-row below). */
  html body.kaiju-active:not(.touch-enabled) .kaiju-combat-telemetry {
    width: max-content; min-width: 232px;
    max-width: max(232px, calc(100vw - 2 * (var(--hl-edge) + min(340px, 50vw - 200px) + 14px)));
  }
  html body.kaiju-active:not(.touch-enabled) .kaiju-combat-telemetry > .combat-readout:nth-child(3) { flex: 1 1 auto; }

  /* Top right: element stats (resist / attack), compact rows */
  html body.kaiju-active:not(.touch-enabled):not(.kaiju-over) #kaiju-loadout {
    top: var(--hl-top); bottom: auto; left: auto;
    right: var(--hl-edge);
    display: flex;
    width: 196px;
    gap: 6px;
    padding: 8px 10px;
    max-height: calc(100dvh - 260px);
  }
  html body.kaiju-active:not(.touch-enabled) #kaiju-loadout .loadout-head { padding-bottom: 4px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-loadout .loadout-elements { gap: 1px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-loadout .loadout-element { grid-template-columns: 1fr 38px 38px; font-size: 10px; }
  html body.kaiju-active:not(.touch-enabled) #kaiju-loadout .loadout-element-name { font-size: 9px; }

  /* Left middle: the co-op squad (your own hull is in the vitals) */
  html body.kaiju-active:not(.touch-enabled) #kaiju-team {
    top: 50%; right: auto; bottom: auto;
    left: var(--hl-edge);
    width: 190px;
    transform: translateY(-50%);
  }

  /* Bottom centre: radio comms between the two bottom corners; tips above them */
  html body.kaiju-active:not(.touch-enabled) #kaiju-comms {
    top: auto; right: auto;
    left: 50%;
    bottom: var(--hl-bottom);
    width: min(520px, calc(100vw - 2 * (var(--hl-side) + var(--hl-edge) + 16px)));
    transform: translateX(-50%);
  }
  html body.kaiju-active:not(.touch-enabled) .kaiju-tip { bottom: calc(var(--edge, 12px) + 96px); }
}
/* 1440p / 4K: style.css zooms the panels by --hud-k; the arms panel too (its ability rack inside it is zoomed once) */
@media (min-width: 2200px) and (min-height: 1200px) {
  html body.kaiju-active:not(.touch-enabled) #kaiju-arms { zoom: var(--hud-k, 1); }
  /* (the minimap is sized, not zoomed: its edge offset scaled like the zoomed vitals' under it) */
  html body.kaiju-active:not(.touch-enabled) .hud-bottom-left { left: calc(var(--hl-edge) * var(--hud-k, 1)); }
}

/* ---------- Touch layouts (landscape only) ---------- */
/* Minimap under the vitals at a fixed size per screen class: it used to take whatever height was left between the
   vitals and the stick, so it grew and shrank as the weapon rack and objective changed during play. */
html body.touch-enabled.kaiju-active .radar {
  width: var(--col);
  height: calc(var(--col) * 0.62);
}
@media (orientation: landscape) and (max-height: 400px) {
  html body.touch-enabled.kaiju-active .radar { height: calc(var(--col) * 0.5); }
}
@media (orientation: landscape) and (max-height: 340px) {
  html body.touch-enabled.kaiju-active .radar { height: calc(var(--col) * 0.4); }
}

/* Wave / target strip: the target readout too (style.css hid it on touch), the strip as wide as the column under it */
html body.touch-enabled.kaiju-active .kaiju-combat-telemetry { width: var(--col); }
html body.touch-enabled.kaiju-active .kaiju-combat-telemetry > :nth-child(3) { display: flex; }

/* Ability rack: right column under the objective (or the toolbar), stopping above the action pad; tap a slot to pick it,
   ABIL on the pad uses it */
html body.touch-enabled.kaiju-active:not(.kaiju-over) #kaiju-abilities {
  position: fixed; z-index: 8;
  display: flex; flex-direction: column; gap: 3px;
  top: calc(var(--t-top) + var(--bar) + 8px); right: var(--t-right); bottom: auto; left: auto;
  width: var(--side);
  max-height: calc(100dvh - var(--t-top) - var(--bar) - 8px - var(--c-bottom) - var(--pad-h) - 12px);
  padding: calc(5px * var(--k)) calc(7px * var(--k));
  overflow-y: auto;
  border: 1px solid var(--glass-border); color: var(--text); background: rgba(14, 14, 17, 0.6);
  scrollbar-width: none;
}
html body.touch-enabled.kaiju-active:has(#kaiju-objective:not([hidden])) #kaiju-abilities {
  top: calc(var(--t-top) + var(--bar) + 8px + var(--objective-h, 60px) + 6px);
  max-height: calc(100dvh - var(--t-top) - var(--bar) - 20px - var(--objective-h, 60px) - var(--c-bottom) - var(--pad-h));
}
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-head { padding-bottom: 3px; }
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-head h2 { font-size: calc(9px * var(--k)); }
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-slot-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-slot button,
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-slot.is-empty { padding: calc(4px * var(--k)) calc(6px * var(--k)); }
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-slot-name { font-size: calc(10px * var(--k)); }
html body.touch-enabled.kaiju-active #kaiju-abilities :is(.loadout-desc, .loadout-hint, kbd) { display: none; }
html body.touch-enabled.kaiju-active #kaiju-abilities .loadout-effect { font-size: calc(8px * var(--k)); }

/* Element stats: one strip of chips along the bottom between the stick and the pad (name, resist, attack) */
html body.touch-enabled.kaiju-active:not(.kaiju-over) #kaiju-loadout {
  position: fixed; z-index: 8;
  display: flex;
  top: auto; right: auto; left: 50%;
  bottom: var(--c-bottom);
  width: auto;
  max-width: calc(100vw - 2 * (var(--c-side) + var(--pad-w) + 10px));
  max-height: none;
  padding: 3px 4px;
  overflow: hidden;
  transform: translateX(-50%);
  border: 1px solid var(--glass-border); color: var(--text); background: rgba(14, 14, 17, 0.6);
  pointer-events: none;
}
html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-head { display: none; }
html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-group { gap: 0; }
html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-elements { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 2px 3px; }
html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-element {
  grid-template-columns: auto auto auto; gap: 4px; padding: 1px 6px 1px 5px;
  font-size: calc(9px * var(--k)); white-space: nowrap;
}
html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-element-name { font-size: calc(8px * var(--k)); letter-spacing: 0.06em; }
html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-element-val { text-align: left; }
/* Phones (up to the largest iPhone, 932 px wide): the chips wrapped to two or three rows. One row of five columns
   instead, each the element's name over its resist and attack values; tablets keep the chips */
@media (max-width: 932px) {
  html body.touch-enabled.kaiju-active #kaiju-loadout { padding: 3px 3px 2px; }
  html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-elements { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); flex-wrap: nowrap; gap: 3px; }
  html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-element {
    grid-template-columns: auto auto; justify-content: center; column-gap: 4px; row-gap: 0;
    padding: 1px 3px 2px 4px; font-size: 8.5px; line-height: 1.25;
  }
  html body.touch-enabled.kaiju-active #kaiju-loadout .loadout-element-name { grid-column: 1 / -1; font-size: 7.5px; letter-spacing: 0.04em; text-align: center; overflow: hidden; text-overflow: clip; }
}
/* ... with the radio comms and the look hint sitting just above it */
@media (orientation: landscape) {
  html body.touch-enabled.kaiju-active .kaiju-comms { bottom: calc(var(--c-bottom) + var(--elements-h, 24px) + 6px); }
  html body.touch-enabled .touch-look-hint { bottom: calc(var(--c-bottom) + var(--elements-h, 24px) + 8px); }
  /* the look hint (first seconds of a run) shares that spot: it steps aside while a radio message is up */
  html body.touch-enabled:has(#kaiju-comms:not([hidden])) .touch-look-hint { visibility: hidden; }
}

/* Kaiju health (or the co-op zone hold in its slot) top centre, between the score/vitals column and the toolbar */
@media (orientation: landscape) {
  html body.touch-enabled.kaiju-active :is(.kaiju-threat, .kaiju-threat.is-visible, .kaiju-zone-hold) {
    top: var(--t-top);
    right: auto;
    left: 50%;
    width: min(calc(320px * var(--k)), calc(100vw - 2 * (var(--t-left) + var(--side) + 12px)));
    transform: translateX(-50%);
  }
  html body.touch-enabled.kaiju-active .threat-head,
  html body.touch-enabled.kaiju-active .threat-chips { justify-content: center; }
  /* Squad chips under the kaiju bar */
  html body.touch-enabled.kaiju-active .kaiju-team {
    top: calc(var(--t-top) + var(--bar) + 4px);
    left: calc(var(--t-left) + var(--col) + 12px);
    right: calc(var(--t-right) + var(--side) + 12px);
  }
}

/* ---------- Portrait on phones & tablets: covered until rotated (js/orientation-lock.js) ---------- */
.orientation-guard { display: none; }
html.is-portrait-blocked .orientation-guard {
  position: fixed; inset: 0; z-index: 2147483000;
  display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background: radial-gradient(120% 80% at 50% 40%, #16161a 0%, #070708 70%);
  color: var(--text, #ece6d6);
  touch-action: none;
}
html.is-portrait-blocked body { overflow: hidden; }
.orientation-guard-card { display: flex; max-width: 300px; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.orientation-guard-icon { width: 88px; height: 88px; fill: none; stroke: var(--warn, #d9ad55); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.orientation-guard-icon rect:first-child { opacity: 0.35; }
.orientation-guard-icon .is-landscape { animation: orientation-turn 2.4s ease-in-out infinite; transform-origin: 33px 46px; }
@keyframes orientation-turn { 0%, 20% { transform: rotate(-90deg); opacity: 0.4; } 55%, 100% { transform: rotate(0); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .orientation-guard-icon .is-landscape { animation: none; } }
.orientation-guard-title { margin: 6px 0 0; font-family: var(--font-sign, inherit); font-size: 18px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.orientation-guard-text { margin: 0; color: var(--text-2, #b9b3a5); font-size: 14px; line-height: 1.5; }

/* ---------- Minimap hide / show (js/nyc-map.js) ---------- */
/* Shown: a small dash button on the radar's top-left corner. Hidden: the radar goes and the button becomes a "Map" tab
   where the radar's corner was. */
.radar-toggle { display: none; }
body.kaiju-active .hud-bottom-left .radar-toggle {
  position: absolute; z-index: 2; top: 6px; left: 6px;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-width: 22px; height: 22px; padding: 0 5px;
  border: 0; border-radius: 0;
  color: rgba(255, 255, 255, 0.9); background: rgba(10, 12, 15, 0.72);
  box-shadow: inset 0 0 0 1px var(--ew-line, rgba(255, 255, 255, 0.14));
  font: 700 10px/1 var(--font-sign, inherit); letter-spacing: 0.14em; text-transform: uppercase;
  cursor: pointer; pointer-events: auto;
}
body.kaiju-active .hud-bottom-left .radar-toggle svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
body.kaiju-active .hud-bottom-left .radar-toggle:hover,
body.kaiju-active .hud-bottom-left .radar-toggle:focus-visible { color: var(--taxi-ink, #111); background: var(--warn, #d9ad55); }
.radar-toggle-label { display: none; }
body.radar-hidden .hud-bottom-left #minimap-card { display: none !important; }
body.kaiju-active.radar-hidden .hud-bottom-left .radar-toggle { position: static; height: 26px; padding: 0 10px 0 8px; }
body.radar-hidden .radar-toggle svg path { d: path("M3 8h10M8 3v10"); }
body.radar-hidden .radar-toggle-label { display: inline; }
/* touch: a bigger target */
body.touch-enabled.kaiju-active .hud-bottom-left .radar-toggle { top: 4px; left: 4px; min-width: 26px; height: 26px; }
body.touch-enabled.kaiju-active.radar-hidden .hud-bottom-left .radar-toggle { height: calc(28px * var(--k)); }

/* ---------- Wave / target strip ---------- */
/* Wave: a fixed column (tabular digits); target: the rest. */
html body.kaiju-active .kaiju-combat-telemetry { justify-content: stretch; }
html body.kaiju-active .kaiju-combat-telemetry > .combat-readout:first-child { flex: none; width: calc(58px * var(--k, 1)); min-width: 0; }
html body.kaiju-active .kaiju-combat-telemetry > .combat-readout:nth-child(3) { flex: 1 1 0; min-width: 0; }
html body.kaiju-active .kaiju-combat-telemetry .combat-readout :is(strong, .combat-sub) { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
/* Target lines: name (or element label) then numbers (ward %, range). Short of room, the name takes the ellipsis and
   the numbers stay whole. */
.target-row { display: flex; min-width: 0; gap: 0.4em; }
.target-row > :is(.target-name, .target-elem) { flex: 0 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.target-row > .target-num { display: inline-flex; flex: none; flex-direction: column; align-items: flex-start; white-space: nowrap; }
/* The numbers keep the room of their widest reading (an unseen copy under them, of no height), so the strip is sized by
   the target's name and stands still while the ward drains or the range changes: it resized with every digit otherwise.
   (The copy was a grid item pinned to cell 1/1: the text beside it is auto-placed and may not share an occupied cell,
   so it dropped to a second row: the ward on a line of its own, the range pushed out of sight.) */
.target-num::after { height: 0; overflow: hidden; visibility: hidden; content: ''; }
.target-num.target-ward::after { content: '· WARD 100%'; }
.target-num.target-dist::after { content: '0000M'; }
.target-row > :empty { display: none; }

/* Pause menu: the run's score, wave and kills under the title */
.kaiju-pause-stats { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 0; color: var(--text-2, #b9b3a5); font-family: var(--font-sign, inherit); font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.kaiju-pause-stats strong { margin-left: 4px; color: var(--warn, #d9ad55); font-variant-numeric: tabular-nums; letter-spacing: 0.06em; }
.kaiju-pause-stats:empty { display: none; }
