/*
 * FYRKA shared in-game HUD
 * ------------------------
 * ONE minimal, non-overlapping heads-up display for every FYRKA game.
 *
 * Rules of the house (extracted from game_01, the reference HUD):
 *   - The HUD is a compact translucent rail parked TOP-LEFT.
 *   - The top-right stays clear for the FYRKA badge (shell launcher).
 *   - The bottom stays clear for the touch controls (joystick + buttons).
 *   - Everything is pointer-events:none so it never eats a tap.
 *   - On phones only the CORE live stats survive; anything tagged
 *     [data-hud="secondary"] (level, score, credits, district, upgrades,
 *     objective prose …) is hidden — it lives in the central FYRKA menu.
 *
 * A game reskins the whole HUD by overriding just --fh-accent (and, if it
 * wants, --fh-bg) on the .fyrka-hud root. Everything else derives from tokens.
 *
 * Class contract:
 *   .fyrka-hud                 fixed top-left rail (put it on the HUD root)
 *   .fyrka-hud__stat           one compact cell (label + value and/or bar)
 *     .fyrka-hud__label        small uppercase caption
 *     .fyrka-hud__value        the number/text
 *     .fyrka-hud__bar > i      a fill bar (set inline width on the <i>)
 *   .fyrka-hud__objective      compact one-line mission/objective chip
 *     .fyrka-hud__objective-text   prose (auto-hidden on phones)
 *   [data-hud="secondary"]     drop this element on phones / coarse pointers
 */

.fyrka-hud {
  --fh-bg: rgba(14, 20, 30, 0.56);
  --fh-bg-hi: rgba(255, 255, 255, 0.05);
  --fh-line: rgba(255, 255, 255, 0.14);
  --fh-ink: #f5f8ff;
  --fh-muted: rgba(223, 231, 248, 0.66);
  --fh-accent: #9d8cff;
  --fh-radius: 10px;
  --fh-gap: 8px;
  /* space kept clear top-right for the FYRKA badge */
  --fh-badge-reserve: 120px;
  --fh-z: 30;

  position: fixed;
  top: max(env(safe-area-inset-top, 0px), 0px);
  left: 0;
  right: 0;
  z-index: var(--fh-z);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--fh-gap);
  margin: 0;
  padding: 14px 14px 0;
  padding-right: var(--fh-badge-reserve);
  pointer-events: none;
  color: var(--fh-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

.fyrka-hud[hidden] {
  display: none;
}

/* ---- Stat cell -------------------------------------------------------- */

.fyrka-hud__stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  min-height: 44px;
  padding: 7px 13px;
  border: 1px solid var(--fh-line);
  border-radius: var(--fh-radius);
  background: var(--fh-bg);
  box-shadow: 0 14px 34px rgba(6, 10, 18, 0.28);
  backdrop-filter: blur(11px);
  -webkit-backdrop-filter: blur(11px);
}

.fyrka-hud__stat[hidden] {
  display: none;
}

/* a stat can flag itself full / in-danger to draw the eye */
.fyrka-hud__stat.is-full {
  border-color: color-mix(in srgb, var(--fh-accent) 55%, transparent);
  background: color-mix(in srgb, var(--fh-accent) 16%, var(--fh-bg));
}

.fyrka-hud__stat.is-danger {
  border-color: rgba(255, 137, 112, 0.5);
  background: rgba(228, 71, 54, 0.2);
}

.fyrka-hud__label {
  display: block;
  color: var(--fh-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.fyrka-hud__value {
  display: block;
  color: var(--fh-ink);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.fyrka-hud__value small {
  font-size: 0.62em;
  font-weight: 700;
  color: var(--fh-muted);
}

/* ---- Fill bar (health, energy, load, drift, …) ------------------------ */

.fyrka-hud__bar {
  display: block;
  width: 100%;
  min-width: 60px;
  height: 6px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(6, 10, 18, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.fyrka-hud__bar > i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--fh-accent);
  transition: width 140ms ease;
}

.fyrka-hud__bar.is-danger > i {
  background: linear-gradient(90deg, #ff7a5c, #ffd45c);
}

/* ---- Compact objective / mission chip --------------------------------- */

.fyrka-hud__objective {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(52vw, 360px);
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--fh-line);
  border-radius: var(--fh-radius);
  background: var(--fh-bg);
  box-shadow: 0 14px 34px rgba(6, 10, 18, 0.28);
  backdrop-filter: blur(11px);
  -webkit-backdrop-filter: blur(11px);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.25;
}

.fyrka-hud__objective-label {
  flex: 0 0 auto;
  color: var(--fh-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.fyrka-hud__objective-count {
  flex: 0 0 auto;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.fyrka-hud__objective-text {
  min-width: 0;
  overflow: hidden;
  color: var(--fh-muted);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Phones & touch: strip it down to the essentials ------------------ */

@media (max-width: 760px), (pointer: coarse) {
  .fyrka-hud {
    top: calc(env(safe-area-inset-top, 0px) + 10px);
    left: 10px;
    right: 10px;
    gap: 6px;
    padding: 0;
    /* the launcher shrinks to a 40px icon on phones — keep just enough clear */
    padding-right: 64px;
  }

  /* Non-essential HUD pieces move into the central FYRKA menu. */
  .fyrka-hud [data-hud="secondary"] {
    display: none !important;
  }

  .fyrka-hud__stat {
    min-height: 0;
    padding: 5px 9px 6px;
    border-radius: 8px;
  }

  .fyrka-hud__label {
    font-size: 9px;
  }

  .fyrka-hud__value {
    font-size: 15px;
  }

  .fyrka-hud__bar {
    height: 5px;
    margin-top: 5px;
    min-width: 48px;
  }

  .fyrka-hud__objective {
    max-width: calc(100% - 88px);
    min-height: 0;
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Objective prose is menu-only on phones — keep just the label + count. */
  .fyrka-hud__objective-text {
    display: none;
  }

  /* Keyboard-key hint strips are useless on touch — the joystick is on. */
  .fyrka-hud .fyrka-control-strip,
  .fyrka-hud .control-strip {
    display: none;
  }
}

/* Very small phones: allow the rail to wrap tightly but never sprawl. */
@media (max-width: 380px) {
  .fyrka-hud {
    --fh-gap: 5px;
  }
}

/* ---- Central primitives usable by ANY game, even bespoke HUDs ---------- *
 * A game that can't (yet) adopt the .fyrka-hud__* components still gets the
 * two most important mobile wins by using these on its own markup:
 *   1. tag any non-essential widget  data-hud="secondary"   → gone on phones
 *   2. put .fyrka-hud-safe on the fixed HUD root             → clears the
 *      notch (top) and the FYRKA badge (right) automatically.                */

@media (max-width: 760px), (pointer: coarse) {
  [data-hud="secondary"] {
    display: none !important;
  }
}

/* Clears the notch and reserves the top-right corner for the FYRKA badge.
   Works on any fixed, top-anchored HUD root regardless of its inner layout. */
.fyrka-hud-safe {
  top: max(env(safe-area-inset-top, 0px), 14px) !important;
  padding-right: 120px;
}

@media (max-width: 760px), (pointer: coarse) {
  .fyrka-hud-safe {
    top: calc(env(safe-area-inset-top, 0px) + 10px) !important;
    padding-right: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fyrka-hud__bar > i {
    transition: none;
  }
}
