/* Long Haul – gameplay HUD (js/ui/hud.js). Minimal: no panels or frames, just type and a few thin lines over the
   world, each thing in a fixed place, and most of it only on screen when it matters. Hold Status to see the rest. */
#hud {
  --hud-base: clamp(11px, 0.55vh + 0.32vw + 6px, 19px);
  --hud-scale: 1; --hud-scale-max: 1.5; --hud-opacity: 1; --hud-dim: 1;
  --fg: #fbf8f2; --fg2: rgba(251, 248, 242, 0.86); --fg3: rgba(251, 248, 242, 0.55);
  --accent: #f6b445; --danger: #ff5f45; --warn: #ffc94d; --good: #8fdc9c;
  --line: rgba(251, 248, 242, 0.22);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.7), 0 0 0.25em rgba(0, 0, 0, 0.35), 0 0 1em rgba(0, 0, 0, 0.35);
  --edge-x: 2.6em; --edge-y: 2.1em;
  --radar: 10.5em;
  container-type: size;
  position: fixed; inset: 0; z-index: 20; pointer-events: none; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  font-family: var(--lh-ui); font-size: calc(var(--hud-base) * min(var(--hud-scale), var(--hud-scale-max)));
  line-height: 1.3; color: var(--fg); text-shadow: var(--shadow); font-variant-numeric: tabular-nums;
  opacity: calc(var(--hud-opacity) * var(--hud-dim)); transition: opacity 0.25s ease;
}
@media (max-width: 1000px), (max-height: 760px) { #hud { --hud-scale-max: 1.2; } }
@media (max-width: 720px), (max-height: 460px) { #hud { --hud-scale-max: 1; --edge-x: 1.3em; --edge-y: 1.1em; --radar: 8.5em; } }
#hud.dim { --hud-dim: 0.35; }
#hud[data-mode="drive"] .only-foot, #hud[data-mode="foot"] .only-drive { display: none !important; }
#hud kbd { min-width: 1.55em; height: 1.55em; padding: 0 0.38em; border: 0; border-radius: 0.3em; background: rgba(251, 248, 242, 0.92);
  color: #14110d; font: 700 0.74em/1 var(--lh-ui); text-shadow: none; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }
#hud .ic { width: 1.05em; height: 1.05em; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.55)); }
#hud .bar { position: relative; display: block; height: 0.2em; border-radius: 1em; background: var(--line); overflow: hidden; box-shadow: 0 0 0.4em rgba(0, 0, 0, 0.2); }
#hud .bar i { position: absolute; inset: 0; border-radius: inherit; background: var(--fg); transform-origin: 0 50%; transform: scaleX(var(--v, 0)); transition: transform 0.2s linear; }
#hud .sep { display: inline-block; width: 1px; height: 0.8em; margin: 0 0.6em; background: var(--fg3); vertical-align: -0.05em; box-shadow: none; }

/* ── top left: objective ───────────────────────────────────────────────── */
.h-tl { position: absolute; left: var(--edge-x); top: var(--edge-y); display: grid; gap: 1em; max-width: min(28em, 40cqw); }
.h-obj { display: grid; gap: 0.2em; }
.h-obj.fresh { animation: hud-drop 0.5s ease-out; }
.obj-k { display: flex; align-items: center; gap: 0.5em; font-size: 0.72em; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.obj-k::before { content: ""; width: 1.4em; height: 2px; border-radius: 1px; background: currentColor; box-shadow: var(--shadow); }
.obj-k:has(.ic)::before { display: none; }
.obj-k .ic { width: 1.35em; height: 1.35em; }
.obj-t { font-size: 1.36em; font-weight: 650; line-height: 1.15; letter-spacing: -0.005em; overflow-wrap: anywhere; }
.obj-d { font-size: 0.9em; font-weight: 500; color: var(--fg2); overflow-wrap: anywhere; }
.h-obj[data-level="warn"] .obj-k { color: var(--warn); }
.h-obj[data-level="crit"] .obj-k { color: var(--danger); }
.obj-p { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3em 0.7em; margin-top: 0.25em; font-size: 0.82em; color: var(--fg2); }
.pips { display: flex; gap: 0.3em; }
.pips i { width: 0.55em; height: 0.55em; border-radius: 50%; border: 1.5px solid var(--fg2); box-shadow: var(--shadow); }
.pips i.on { background: var(--danger); border-color: var(--danger); }

/* ── top right: feed ───────────────────────────────────────────────────── */
.h-feed { position: absolute; right: var(--edge-x); top: var(--edge-y); display: grid; justify-items: end; gap: 0.45em; max-width: min(24em, 38cqw); }
.note { display: flex; align-items: center; gap: 0.5em; font-size: 0.86em; font-weight: 550; text-align: right; overflow-wrap: anywhere; animation: hud-slide 0.3s ease-out; }
.note.out { opacity: 0; transform: translateX(0.6em); transition: opacity 0.25s, transform 0.25s; }
.note .ic { width: 1.15em; height: 1.15em; order: -1; }
.note.lv-crit { color: var(--danger); font-weight: 650; }
.note.lv-crit .n-text { color: var(--fg); }
.note.lv-warn .ic { color: var(--warn); }
.note.lv-good .ic { color: var(--good); }
.note.lv-info { color: var(--fg); font-weight: 500; }

/* ── bottom left: radar, rim, needs, status ────────────────────────────── */
.h-radar { position: absolute; left: var(--edge-x); bottom: var(--edge-y); display: grid; grid-template-columns: var(--radar) auto; grid-template-areas: "status status" "radar needs"; align-items: end; column-gap: 0.7em; }
.radar { grid-area: radar; position: relative; width: var(--radar); aspect-ratio: 1; pointer-events: auto; cursor: default; }
.radar .hud-map, .radar .lh-minimap { position: absolute; inset: 0.42em; border-radius: 50%; overflow: hidden; }
.radar .lh-minimap { background: rgba(10, 9, 8, 0.55); box-shadow: 0 0.2em 1.2em rgba(0, 0, 0, 0.3); }
.radar .lh-minimap canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.88; }
#hud.no-map .radar .hud-map { background: rgba(10, 9, 8, 0.35); }
.rim { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.rim circle { fill: none; stroke-width: 2.1; stroke-linecap: round; }
.rim-bg { stroke: rgba(251, 248, 242, 0.16); }
.rim-hp { stroke: var(--fg); transition: stroke-dasharray 0.3s ease; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.5)); }
.rim-st { stroke: #b9d6ea; transition: stroke-dasharray 0.15s linear; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.5)); }
.radar.hp-low .rim-hp { stroke: var(--warn); }
.radar.hp-crit .rim-hp { stroke: var(--danger); animation: hud-pulse 1s ease-in-out infinite; }
.radar.st-low .rim-st { stroke: var(--warn); }
#hud[data-mode="drive"] .rim-st { opacity: 0.35; }
.north { position: absolute; left: 50%; top: 0.6em; transform: translateX(-50%); font-size: 0.62em; font-weight: 800; letter-spacing: 0.04em; color: var(--fg2); }
#hud.no-map .north { display: none; }
.needs { grid-area: needs; display: grid; gap: 0.45em; padding-bottom: 0.4em; }
.need { position: relative; width: 2.2em; height: 2.2em; display: grid; place-items: center; animation: hud-pop 0.3s ease-out; }
.need svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.5)); }
.need circle { fill: rgba(10, 9, 8, 0.45); stroke-width: 2.6; }
.need .n-bg { stroke: rgba(251, 248, 242, 0.18); }
.need .n-v { fill: none; stroke: var(--fg); stroke-linecap: round; transition: stroke-dasharray 0.3s; }
.need .ic { position: relative; width: 1em; height: 1em; }
.need.low .n-v, .need.low .ic { stroke: var(--warn); color: var(--warn); }
.need.crit .n-v, .need.crit .ic { stroke: var(--danger); color: var(--danger); }
.need.crit { animation: hud-pulse 1.2s ease-in-out infinite; }
.status { grid-area: status; display: grid; gap: 0.15em; margin-bottom: 0.7em; opacity: 0; transform: translateY(0.4em); transition: opacity 0.25s ease, transform 0.25s ease; }
.status.on { opacity: 1; transform: none; }
.st-time { display: flex; align-items: baseline; gap: 0.5em; }
.st-time b { font-size: 1.7em; font-weight: 650; letter-spacing: -0.01em; }
.st-time span { font-size: 0.82em; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg2); }
.st-meta, .st-trip { display: flex; align-items: center; gap: 0.35em; font-size: 0.84em; color: var(--fg2); white-space: nowrap; }
.st-meta b { color: var(--fg); font-weight: 650; }
.st-meta .sep, .st-trip .sep { margin: 0 0.3em; }

/* ── bottom right: driving, warnings, hands ────────────────────────────── */
.h-right { position: absolute; right: var(--edge-x); bottom: var(--edge-y); display: grid; justify-items: end; gap: 0.6em; max-width: min(24em, 40cqw); text-align: right; }
.warns { display: grid; justify-items: end; gap: 0.3em; }
.warn { display: flex; align-items: center; gap: 0.45em; font-size: 0.84em; font-weight: 600; animation: hud-slide 0.3s ease-out; }
.warn .ic { color: var(--warn); }
.warn.crit .ic { color: var(--danger); animation: hud-pulse 1s ease-in-out infinite; }
.drive { display: grid; justify-items: end; gap: 0.25em; }
.ign { font-size: 0.78em; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--warn); }
.spd { display: flex; align-items: baseline; gap: 0.3em; line-height: 0.9; }
.spd b { font-size: 3.2em; font-weight: 700; letter-spacing: -0.03em; }
.spd span { font-size: 0.85em; font-weight: 600; color: var(--fg2); }
.drv { display: flex; align-items: center; gap: 0.9em; font-size: 0.84em; color: var(--fg2); }
.gear { display: inline-flex; align-items: baseline; gap: 0.1em; }
.gear b { color: var(--fg); font-size: 1.15em; font-weight: 700; }
.gear i { font-style: normal; font-size: 0.75em; font-weight: 700; color: var(--accent); }
.gauge { display: inline-flex; align-items: center; gap: 0.45em; }
.gauge .bar { width: 4.5em; }
.gauge.low .ic, .gauge.low > span:last-child { color: var(--warn); }
.gauge.low .bar i { background: var(--warn); }
.gauge.crit .ic, .gauge.crit > span:last-child { color: var(--danger); }
.gauge.crit .bar i { background: var(--danger); }
.gauge.hot { color: var(--warn); }
.gauge.hot.crit { color: var(--danger); animation: hud-pulse 1s ease-in-out infinite; }
.lamp { display: inline-flex; color: #9fd6ff; }
.rpm { width: 9em; height: 2px; border-radius: 1px; background: rgba(251, 248, 242, 0.14); overflow: hidden; margin-top: 0.2em; }
.rpm i { display: block; height: 100%; background: var(--fg2); transform-origin: 100% 50%; transform: scaleX(var(--v, 0)); }
.drive.redline .rpm i { background: var(--danger); }
.held { display: grid; justify-items: end; gap: 0.35em; }
.held-n { display: flex; align-items: baseline; gap: 0.55em; }
.held-n b { font-size: 0.98em; font-weight: 650; overflow-wrap: anywhere; }
.held-n span { font-size: 0.84em; color: var(--fg2); white-space: nowrap; }
.keys { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35em 0.9em; font-size: 0.78em; color: var(--fg2); }
.keys > span { display: inline-flex; align-items: center; gap: 0.4em; white-space: nowrap; }
.cargo { display: flex; align-items: center; gap: 0.45em; font-size: 0.84em; font-weight: 550; }
.cargo .ic { color: var(--accent); }

/* ── centre: dot, target, actions ──────────────────────────────────────── */
.h-centre { position: absolute; inset: 0; }
.dot { position: absolute; left: 50%; top: 50%; width: 0.3em; height: 0.3em; margin: -0.15em 0 0 -0.15em; border-radius: 50%; background: var(--fg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 0 4px rgba(0, 0, 0, 0.4); transition: transform 0.15s ease, background 0.15s; }
.dot.aim { transform: scale(1.5); background: var(--accent); }
.target { position: absolute; left: calc(50% + 1.5em); top: 50%; transform: translateY(-0.75em); display: grid; gap: 0.5em; max-width: min(22em, 40cqw); }
.t-card { display: grid; gap: 0.12em; }
.t-name { font-size: 0.95em; font-weight: 650; overflow-wrap: anywhere; }
.t-info { display: flex; flex-wrap: wrap; align-items: center; font-size: 0.8em; color: var(--fg2); }
.t-info .sep { margin: 0 0.5em; }
.t-cond { display: inline-flex; align-items: center; gap: 0.4em; }
.t-cond .bar { width: 3.5em; }
.t-cond.bad { color: var(--danger); }
.t-cond.bad .bar i { background: var(--danger); }
.t-note { color: var(--warn); }
.acts { display: grid; gap: 0.32em; }
.act { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 0.55em; font-size: 0.92em; font-weight: 600; }
.act .a-b { grid-column: 2; font-size: 0.82em; font-weight: 500; color: var(--warn); }
.act.blocked kbd { opacity: 0.45; }
.act.blocked .a-l { color: var(--fg3); }
.act .a-p { grid-column: 2; width: 8em; height: 2px; margin-top: 0.15em; border-radius: 1px; background: var(--line); overflow: hidden; }
.act .a-p i { display: block; height: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(var(--v, 0)); }

/* ── bottom centre: prompt, progress, subtitles, key hints ─────────────── */
.h-bottom { position: absolute; left: 50%; bottom: var(--edge-y); transform: translateX(-50%); width: min(44em, 100cqw - 2 * var(--radar) - 6em);
  display: flex; flex-direction: column; align-items: center; gap: 0.65em; text-align: center; }
.prompt { display: inline-flex; align-items: center; gap: 0.55em; font-size: 0.95em; font-weight: 600; animation: hud-rise 0.25s ease-out; }
.prog { display: grid; justify-items: center; gap: 0.35em; font-size: 0.8em; font-weight: 600; color: var(--fg2); }
.prog .bar { width: 12em; height: 0.18em; }
.prog .bar i { background: var(--accent); }
.stam { width: 7em; height: 2px; border-radius: 1px; background: var(--line); overflow: hidden; }
.stam i { display: block; height: 100%; background: #b9d6ea; transform-origin: 50% 50%; transform: scaleX(var(--v, 0)); }
.stam.low i { background: var(--warn); }
.sub { max-width: 100%; font-size: 1.1em; font-weight: 550; line-height: 1.4; overflow-wrap: anywhere; pointer-events: auto;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85), 0 0 0.6em rgba(0, 0, 0, 0.6), 0 0 1.6em rgba(0, 0, 0, 0.35); }
.sub b { color: var(--accent); font-weight: 700; margin-right: 0.45em; }
.sub b::after { content: ":"; }
.hint-row { display: none; justify-content: center; }
#hud.reveal .hint-row { display: flex; animation: hud-rise 0.2s ease-out; }
#hud.no-help .hint-row { display: none !important; }

.lockhint { position: absolute; left: 50%; top: calc(50% + 2.2em); transform: translateX(-50%); display: flex; align-items: center; gap: 0.5em; font-size: 0.82em; color: var(--fg2); }

/* ── settings: minimal, off, high contrast ─────────────────────────────── */
#hud.show-minimal :is(.radar .hud-map, .north, .status, .hint-row, .rpm) { display: none !important; }
#hud.show-minimal .need:not(.crit) { display: none !important; }
#hud.show-off > * { display: none !important; }
#hud.show-off.keep-crit > .h-radar { display: grid !important; }
#hud.show-off.keep-crit .h-radar > :not(.needs) { display: none !important; }
#hud.show-off.keep-crit .need:not(.crit) { display: none !important; }
#hud.show-off.keep-crit:has(.h-obj[data-level="crit"]:not([hidden])) > .h-tl { display: grid !important; }
#hud.show-off .lh-convoy { display: none !important; }
#hud.hc { --fg2: #fff; --fg3: #ddd; --line: rgba(255, 255, 255, 0.45); --shadow: 0 0 2px #000, 0 0 4px #000, 0 0 8px #000; }
#hud.hc :is(.obj-t, .obj-d, .note, .sub, .t-card, .act, .prompt, .held-n, .warn, .status) { background: rgba(0, 0, 0, 0.78); padding: 0.1em 0.4em; border-radius: 0.25em; }

/* ── screen effects ─────────────────────────────────────────────────────── */
#hud-vignette { position: fixed; inset: 0; z-index: 10; pointer-events: none; --hurt: 0; --tired: 0; }
#hud-vignette i { position: absolute; inset: 0; }
#hud-vignette .v-hurt { background: radial-gradient(ellipse at center, transparent 45%, rgba(140, 22, 8, 0.75) 100%); opacity: var(--hurt); }
#hud-vignette .v-hit { background: radial-gradient(ellipse at center, transparent 48%, rgba(200, 16, 8, 0.5) 78%, rgba(220, 20, 10, 0.9) 100%); opacity: 0; }
#hud-vignette .v-tired { background: radial-gradient(ellipse at center, transparent 30%, rgba(0, 0, 0, 0.94) 100%); opacity: var(--tired); }
#hud-fade { position: fixed; inset: 0; z-index: 30; pointer-events: none; display: grid; place-items: center; background: rgba(5, 4, 3, var(--o, 0)); }
#hud-fade span { opacity: var(--o, 0); color: var(--lh-bone); font: 600 clamp(14px, 1.6vh + 8px, 26px)/1.4 var(--lh-ui); letter-spacing: 0.04em; text-align: center; padding: 0 1em; white-space: pre-line; }

@keyframes hud-drop { from { opacity: 0; transform: translateY(-0.4em); } }
@keyframes hud-slide { from { opacity: 0; transform: translateX(0.6em); } }
@keyframes hud-rise { from { opacity: 0; transform: translateY(0.35em); } }
@keyframes hud-pop { from { opacity: 0; transform: scale(0.7); } }
@keyframes hud-pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { #hud *, #hud-fade * { animation: none !important; transition: none !important; } }
.lh-reduce-motion #hud *, .lh-reduce-motion #hud-fade * { animation: none !important; transition: none !important; }

/* ── convoy (js/convoy.js): who else is on the road, under the objective ── */
.lh-convoy { position: fixed; left: 14px; top: 34%; z-index: 21; pointer-events: none; display: grid; gap: 0.2em;
  font-size: clamp(10px, 0.55vh + 0.3vw + 5px, 17px); line-height: 1.35; color: var(--lh-bone); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7), 0 0 0.8em rgba(0, 0, 0, 0.3); max-width: 19em; }
.lh-convoy[hidden] { display: none; }
#hud .lh-convoy { position: static; font-size: 0.86em; }
.lh-convoy-head { font-size: 0.8em; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg2); }
.lh-convoy-head b { color: var(--accent); }
.lh-convoy div:not(.lh-convoy-head) { display: flex; justify-content: space-between; gap: 1em; }
.lh-convoy em { font-style: normal; color: var(--fg2); font-size: 0.92em; }
.lh-paused { display: inline-block; width: 0.62em; height: 0.72em; margin-left: 0.35em; vertical-align: -0.05em;
  background: linear-gradient(90deg, currentColor 0 35%, transparent 35% 65%, currentColor 65%); color: var(--lh-bone); opacity: 0.9; }
.lh-vc { display: inline-block; width: 0.75em; height: 0.75em; margin-left: 0.3em; vertical-align: -0.05em; border-radius: 50%;
  background: radial-gradient(circle, var(--lh-sand) 0 30%, transparent 32% 52%, rgba(201, 191, 174, 0.55) 54% 66%, transparent 68%); }
.lh-vc-talk { background: radial-gradient(circle, #7fdc8f 0 30%, transparent 32% 52%, #7fdc8f 54% 66%, transparent 68%); filter: drop-shadow(0 0 3px #7fdc8f); }
.lh-vc-wait { opacity: 0.4; }
.lh-vc-off { background: radial-gradient(circle, #b85a4a 0 34%, transparent 36%); }
.lh-vc-ptt { opacity: 0.55; }
.lh-convoy .lh-talking span { color: #b9f5c3; }
.lh-convoy-me { display: flex !important; align-items: center; gap: 0.35em; font-size: 0.85em; color: var(--fg2); justify-content: flex-start !important; }
.lh-convoy-me .lh-vc { margin-left: 0; }

/* ── small windows ──────────────────────────────────────────────────────── */
@container (max-width: 60em) or (max-height: 38em) {
  #hud { --radar: 8em; --edge-x: 1.4em; --edge-y: 1.2em; }
  .obj-t { font-size: 1.18em; }
  .spd b { font-size: 2.6em; }
  .h-bottom { width: min(36em, 100cqw - 2 * var(--radar) - 4em); }
}
@container (max-width: 38em) {
  .h-tl { max-width: 52cqw; }
  .h-feed { max-width: 44cqw; }
  .target { left: 50%; top: calc(50% + 1.4em); transform: translateX(-50%); justify-items: center; text-align: center; }
  .act { grid-template-columns: auto auto; }
}
html[data-lh-menu="inventory"] #hud :is(.h-centre, .lockhint, .h-bottom) { visibility: hidden; }
