/* File: src/styles/hud.css */
/* ─────────────────────────────────────────────────────────────────────────────
   hud.css
   In-game HUD — MINIMALIST FLOATING style.

   No panel, no backing box. The vitals/level cluster floats directly on the
   world. Legibility comes from a tight blurred dark halo bound to each text
   run + thin dark inset bar tracks (the minimum structure a coloured bar needs
   to read on any biome). Effect/ailment badges keep a faint frame only.

   All element IDs + state classes written by HudOverlay.js are preserved
   (#vital-hp-fill, .vital-value--critical, .vital-blink-*, #hud-levels,
   .level-bar-fill--max, #hud-mode-icons, #hud-trait-icons, …), so this is a
   drop-in CSS swap — no JS change.
───────────────────────────────────────────────────────────────────────────── */

/* ── Shared text-halo: tight blurred dark shadow so floating text reads on
      any background with no hard box edge. Applied to every HUD text run. ── */
.ui-hud,
.hud-title,
.vital-label,
.vital-value,
.level-label,
.level-value {
  text-shadow:
    0 0 3px rgba(0, 0, 0, 0.95),
    0 0 6px rgba(0, 0, 0, 0.9),
    0 1px 2px rgba(0, 0, 0, 1),
    0 0 10px rgba(0, 0, 0, 0.6);
}

/* ── HUD root — floating, no panel ──────────────────────────────────────── */
.ui-hud {
  position: absolute;
  width: 232px;
  padding: 0;
  pointer-events: none;
  background: none;
  border: none;
  box-shadow: none;
  /* Smoothly ease the whole HUD's brightness as day/night transitions. The
     value is animated via the .ui-hud--night class (toggled by HudOverlay
     .setNightMode). Long duration so dusk/dawn fades rather than snapping. */
  filter: brightness(1);
  transition: filter 1.2s ease;
}
/* Night: knock the entire HUD back a touch. brightness() on the root cascades
   to every child — bars, text, icons, badges — in one place, so nothing needs
   per-element rules. Kept subtle (0.82) so it reads as "dimmer at night", not
   "broken". */
.ui-hud--night {
  filter: brightness(0.82);
}

/* ── Header — title only, floating ──────────────────────────────────────── */
.hud-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 6px;
}

.hud-title {
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.06em;
  line-height: 1;
  color: #bdf06a;
  text-shadow:
    0 0 4px rgba(0, 0, 0, 1),
    0 0 10px rgba(143, 206, 80, 0.5),
    0 1px 2px rgba(0, 0, 0, 1);
}

.hud-trait-icons {
  display: flex;
  align-items: center;
  gap: 3px;
}
.hud-trait-icons:empty { display: none; }

.hud-mode-icons {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.9));
}
.hud-mode-icon {
  width: 18px;
  height: 18px;
  opacity: 0.9;
  border-radius: 2px;
  transition: opacity 0.15s;
}
.hud-mode-icon:hover { opacity: 1; }
.hud-mode-custom {
  font-size: 8px;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: #d8a850;
  margin-left: auto;
  text-shadow: 0 0 3px rgba(0, 0, 0, 1), 0 1px 1px rgba(0, 0, 0, 1);
}

#hud-senses-value { font-weight: bold; }

/* ── Vitals — floating rows ─────────────────────────────────────────────── */
.hud-vitals {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.vital-row {
  display: grid;
  grid-template-columns: 14px 26px 1fr auto;
  align-items: center;
  gap: 8px;
}

.vital-icon {
  font-size: 12px;
  text-align: center;
  line-height: 1;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.95)) drop-shadow(0 1px 1px rgba(0, 0, 0, 1));
}
.vital-icon--health    { color: var(--color-vitals-health); }
.vital-icon--nutrition { color: var(--color-vitals-nutrition); }
.vital-icon--energy    { color: var(--color-vitals-energy); }

.vital-label {
  font-size: 8px;
  font-weight: bold;
  letter-spacing: 0.08em;
  color: #cfe6a8;
}

/* ── Vital bars ─────────────────────────────────────────────────────────────
   The track is a thin dark inset channel; the fill is a shaded gradient keyed
   off --fill-col (set by HudOverlay so the threshold colour still drives it),
   with a top highlight rim, an inner shadow for depth, a moving leading edge,
   segmented tick marks, and a "ghost" trail that lags behind on damage.
   Caps are consistently rounded on both track and fill.
─────────────────────────────────────────────────────────────────────────── */
.vital-bar-track {
  position: relative;
  height: 9px;
  overflow: hidden;
  border-radius: 4px;              /* fully rounded caps, consistent w/ fill */
  border: 1px solid rgba(255, 255, 255, 0.10);
  background:
    linear-gradient(180deg, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0.55) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.6),
    inset 0 2px 3px rgba(0, 0, 0, 0.75),   /* deeper inner shadow */
    inset 0 -1px 0 rgba(255, 255, 255, 0.05),
    0 0 4px rgba(0, 0, 0, 0.5);
}

/* Segmented ticks: faint dark dividers laid over the whole track so both the
   filled and empty portions read as segments. Sits above fill via z-index. */
.vital-bar-track::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  background-image: repeating-linear-gradient(
    90deg,
    rgba(0, 0, 0, 0)        0px,
    rgba(0, 0, 0, 0)        13px,
    rgba(0, 0, 0, 0.45)     13px,
    rgba(0, 0, 0, 0.45)     15px
  );
  mix-blend-mode: multiply;
}

/* Ghost trail — a desaturated bar BEHIND the fill. On damage the fill snaps
   to the new (lower) width instantly-ish while the ghost eases down slowly,
   briefly exposing a pale band that marks how much was just lost. On heal the
   ghost tracks up quickly so it never shows ahead of the fill. */
.vital-bar-ghost {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  z-index: 1;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(180deg,
    rgba(255, 255, 255, 0.55) 0%,
    rgba(255, 220, 210, 0.30) 100%);
  transition: width 0.55s cubic-bezier(0.4, 0.0, 0.2, 1) 0.12s;
  pointer-events: none;
}

.vital-bar-fill {
  position: relative;
  z-index: 2;
  height: 100%;
  width: 100%;
  border-radius: inherit;          /* consistent rounded caps with the track */
  /* Solid fallback first (older engines), then the shaded gradient. */
  background: var(--fill-col, #50c030);
  /* Gradient keyed off the JS-set colour: lighter at top, the base colour in
     the middle, a touch darker at the bottom — gives the bar volume. */
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--fill-col, #50c030) 55%, #ffffff) 0%,
    var(--fill-col, #50c030) 48%,
    color-mix(in srgb, var(--fill-col, #50c030) 78%, #000000) 100%
  );
  transition: width 0.22s cubic-bezier(0.4, 0.0, 0.2, 1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),   /* thin highlight rim, top */
    inset 0 -1px 1px rgba(0, 0, 0, 0.25);
}
/* Moving leading edge — brighter the moment the bar changes width */
.vital-bar-fill::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 7px 1px rgba(255, 255, 255, 0.55);
}

.vital-value {
  font-size: 9px;
  text-align: right;
  white-space: nowrap;
  min-width: 52px;
  letter-spacing: 0.02em;
  color: var(--color-green-700);
}
.vital-value--critical           { color: #e88068; }
.vital-value--hurt               { color: #e8c050; }
.vital-value--healthy            { color: #a8e878; }
.vital-value--nutrition-ok       { color: #bff080; }
.vital-value--nutrition-low      { color: #e8c050; }
.vital-value--nutrition-starving { color: #e89850; }
.vital-value--energy-ok          { color: #f0dc60; }
.vital-value--energy-low         { color: #c8a838; }
.vital-value--energy-exhausted   { color: #a0a0a0; }

/* Blink states (JS toggles on the fill). Keep the highlight rim + add the
   coloured danger glow. */
.vital-blink-health {
  animation: vital-blink-health 0.65s ease-in-out infinite;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), inset 0 -1px 1px rgba(0,0,0,0.25), 0 0 8px 2px rgba(200, 48, 32, 0.75);
}
.vital-blink-nutrition {
  animation: vital-blink-nutrition 0.90s ease-in-out infinite;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), inset 0 -1px 1px rgba(0,0,0,0.25), 0 0 8px 2px rgba(192, 96, 32, 0.7);
}
.vital-blink-energy {
  animation: vital-blink-energy 1.20s ease-in-out infinite;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45), inset 0 -1px 1px rgba(0,0,0,0.25), 0 0 7px 2px rgba(96, 96, 96, 0.65);
}
@keyframes vital-blink-health    { 0%,100% { opacity: 1; } 50% { opacity: 0.22; } }
@keyframes vital-blink-nutrition { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
@keyframes vital-blink-energy    { 0%,100% { opacity: 1; } 50% { opacity: 0.28; } }

/* ── Levels — floating "PROGRESSION" sub-group, no panel ─────────────────── */
.hud-levels {
  position: relative;
  margin: 2px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hud-levels::before {
  content: 'PROGRESSION';
  display: block;
  margin-bottom: 1px;
  font-size: 7px;
  letter-spacing: 0.2em;
  color: #c9a8e8;
  text-shadow: 0 0 3px rgba(0, 0, 0, 1), 0 1px 1px rgba(0, 0, 0, 1);
}

.level-icon--combat  { color: var(--color-red-500);   filter: drop-shadow(0 0 3px rgba(0,0,0,0.95)) drop-shadow(0 1px 1px rgba(0,0,0,1)); }
.level-icon--fitness { color: var(--color-amber-500); filter: drop-shadow(0 0 3px rgba(0,0,0,0.95)) drop-shadow(0 1px 1px rgba(0,0,0,1)); }
.level-icon--energy  { color: var(--color-amber-300); filter: drop-shadow(0 0 3px rgba(0,0,0,0.95)) drop-shadow(0 1px 1px rgba(0,0,0,1)); }

.level-label {
  font-size: 8px;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: #d8b8f0;
}

/* Thinner purple-keyed track — same treatment, scaled down (no ticks: too
   short to read them, and no ghost: XP only ever goes up). */
.level-bar-track {
  position: relative;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  border: 1px solid rgba(208, 112, 255, 0.25);
  background: linear-gradient(180deg, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0.55) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.5),
    inset 0 1px 2px rgba(0, 0, 0, 0.7),
    0 0 4px rgba(0, 0, 0, 0.5);
}
.level-bar-fill {
  position: relative;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--color-purple-500);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--color-purple-500) 55%, #ffffff) 0%,
    var(--color-purple-500) 50%,
    color-mix(in srgb, var(--color-purple-500) 80%, #000000) 100%
  );
  transition: width 0.30s cubic-bezier(0.4, 0.0, 0.2, 1), background-color 0.25s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.level-bar-fill::after { display: none; }

.level-value {
  font-size: 8px;
  text-align: right;
  white-space: nowrap;
  min-width: 52px;
  color: #d8a0ff;
}

.level-bar-fill--max {
  background: var(--color-purple-300) !important;
  box-shadow: 0 0 6px 1px rgba(var(--rgb-purple-500), 0.60);
  animation: level-max-pulse 2.0s ease-in-out infinite;
}
@keyframes level-max-pulse { 0%,100% { opacity: 1.0; } 50% { opacity: 0.70; } }

/* ── Status Effect Badges — faint frame only, transparent interior ──────── */
.hud-effects {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 0;
}
.hud-effects:not(:empty) { margin-top: 8px; }
.effect-badge {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 3px 6px 4px;
  border: 1px solid;
  border-radius: 2px;
  min-width: 52px;
  max-width: 90px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}
.effect-badge-header { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.effect-name {
  font-size: 7px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 3px rgba(0, 0, 0, 1), 0 1px 1px rgba(0, 0, 0, 1);
}
.effect-timer-label { font-size: 7px; flex-shrink: 0; text-shadow: 0 0 3px rgba(0, 0, 0, 1); }
.effect-timer-track { height: 2px; background: rgba(0, 0, 0, 0.55); overflow: hidden; }
.effect-timer-fill  { height: 100%; }

/* ── Ailment Badges — faint frame only ──────────────────────────────────── */
.hud-ailments {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 0;
}
.hud-ailments:not(:empty) { margin-top: 6px; }
.ailment-badge {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 3px 6px 4px;
  border: 1px solid;
  border-radius: 2px;
  min-width: 52px;
  max-width: 100px;
  background: rgba(0, 0, 0, 0.40);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.55);
}
.ailment-badge--pulse { animation: ailment-pulse 0.9s ease-in-out infinite; }
@keyframes ailment-pulse { 0% { opacity: 1.0; } 50% { opacity: 0.55; } 100% { opacity: 1.0; } }
.ailment-badge-header { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.ailment-name {
  font-size: 7px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 3px rgba(0, 0, 0, 1), 0 1px 1px rgba(0, 0, 0, 1);
}
.ailment-timer-label { font-size: 7px; flex-shrink: 0; text-shadow: 0 0 3px rgba(0, 0, 0, 1); }
.ailment-timer-track { height: 3px; background: rgba(0, 0, 0, 0.55); overflow: hidden; }
.ailment-timer-fill  { height: 100%; }

/* ── Toast stack ────────────────────────────────────────────────────────── */
.ui-toasts {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: radial-gradient(50% 50% at 50% 50%, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.4) 50%, rgba(0, 0, 0, 0) 100%);
  border: none;
  color: #c0ee80;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.05em;
  padding: 8px 32px;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  text-shadow:
    0 0 3px rgba(0, 0, 0, 0.95),
    0 0 6px rgba(0, 0, 0, 0.9),
    0 1px 2px rgba(0, 0, 0, 1),
    0 0 10px rgba(0, 0, 0, 0.8);
}
.toast--visible { opacity: 1; transform: translateY(0); }

/* ── Tutorial HUD Highlight ─────────────────────────────────────────────── */
@keyframes hud-highlight-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(var(--rgb-amber-500), 0.4), 0 0 8px rgba(var(--rgb-amber-500), 0.2); background-color: rgba(var(--rgb-amber-500), 0.15); }
  50%      { box-shadow: 0 0 0 1.5px rgba(var(--rgb-amber-300), 0.9), 0 0 16px rgba(var(--rgb-amber-300), 0.6); background-color: rgba(var(--rgb-amber-300), 0.35); }
}
.hud-highlight {
  animation: hud-highlight-pulse 1.2s ease-in-out infinite !important;
  z-index: 10;
}

/* ════════════════════════════════════════════════════════════
   HANDHELD / SMALL SCREEN OPTIMIZATIONS
════════════════════════════════════════════════════════════ */
.is-handheld .ui-hud {
  width: max-content !important;
  min-width: 150px !important;
  max-width: 190px !important;
}

/* Hide the x / y numbers for vitals to save horizontal space */
.is-handheld #vital-hp-value,
.is-handheld #vital-nut-value,
.is-handheld #vital-en-value { display: none !important; }

.is-handheld .vital-value,
.is-handheld .level-value { min-width: 28px !important; }

.is-handheld .vital-bar-track,
.is-handheld .level-bar-track { min-width: 22px !important; }

.is-handheld .ui-toasts { bottom: 65px; }