:root {
  --bg-deep: #070b12;
  --panel-bg: rgba(10, 14, 22, 0.88);
  --panel-border: rgba(148, 163, 184, 0.22);
  --text-main: #f1f5f9;
  --text-dim: #94a3b8;
  --amber: #f59e0b;
  --amber-hot: #fbbf24;
  --danger: #ef4444;
  --emerald: #10b981;
  --hud-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono-font: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] {
  display: none !important;
}

[data-xgh-host] .masthead-left {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--hud-font);
  touch-action: none;
}

.masthead {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  min-height: 48px;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 40;
  background: linear-gradient(180deg, rgba(6, 9, 15, 0.84), rgba(6, 9, 15, 0));
  pointer-events: none;
}

.masthead > * {
  pointer-events: auto;
}

.masthead h1 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.16em;
  font-weight: 800;
  text-transform: uppercase;
}

.masthead nav {
  display: flex;
  gap: 8px;
}

.masthead nav button {
  background: rgba(15, 23, 42, 0.72);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.game-stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #05080f;
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.webgl-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #080c14;
  color: var(--text-dim);
  padding: 24px;
  text-align: center;
  z-index: 25;
}

/* Cinematic 2.35:1 Film Letterbox Bars */
.letterbox {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  background: #020306;
  z-index: 16;
  pointer-events: none;
  transition: height 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}
.letterbox-top { top: 0; }
.letterbox-bottom { bottom: 0; }
.game-stage.is-cinematic .letterbox {
  height: clamp(34px, 8.5vh, 72px);
}

.film-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 56%, rgba(0, 0, 0, 0.58) 100%);
}

.damage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 9;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(185, 28, 28, 0) 44%, rgba(185, 28, 28, 0.72) 100%);
  transition: opacity 0.1s linear;
}

.scope-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  background: radial-gradient(circle at center, transparent 27%, rgba(3, 6, 12, 0.88) 44%, rgba(2, 4, 8, 0.96) 100%);
  transition: opacity 0.14s ease;
}
.scope-overlay.is-active {
  opacity: 1;
}

/* Minimal Military Telemetry HUD */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 14;
}

.hud-top {
  position: absolute;
  top: max(54px, env(safe-area-inset-top) + 50px);
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100% - 28px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-progress-box {
  background: rgba(8, 12, 20, 0.74);
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 6px 12px;
}

.hud-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono-font);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.hud-sector { color: #e2e8f0; font-weight: 700; }
.hud-distance { color: var(--amber-hot); font-weight: 700; }

.hud-progress-track {
  height: 3px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
}

.hud-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--amber), #fde047);
  transition: width 0.15s linear;
}

.hud-boss {
  background: rgba(24, 10, 12, 0.72);
  border: 1px solid rgba(239, 68, 68, 0.45);
  padding: 6px 12px;
}

.hud-boss-head {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono-font);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: #fecaca;
  margin-bottom: 4px;
}

.hud-boss-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hud-boss-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
}

.hud-boss-armor {
  height: 100%;
  background: #38bdf8;
  width: 100%;
  transition: width 0.12s linear;
}

.hud-boss-hp {
  height: 100%;
  background: linear-gradient(90deg, #dc2626, #f59e0b);
  width: 100%;
  transition: width 0.12s linear;
}

.hud-alerts {
  position: absolute;
  top: 23%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.hud-alert-banner {
  background: rgba(12, 16, 26, 0.82);
  border-left: 3px solid var(--amber);
  border-right: 3px solid var(--amber);
  padding: 7px 18px;
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #fef3c7;
  text-transform: uppercase;
  white-space: nowrap;
}

.hud-alert-banner.is-danger {
  border-color: var(--danger);
  color: #fecaca;
  background: rgba(45, 10, 14, 0.86);
}

.hud-breach-btn {
  pointer-events: auto;
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fff;
  border: 1px solid #fde68a;
  padding: 10px 22px;
  font-family: var(--mono-font);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  cursor: pointer;
  box-shadow: 0 0 24px rgba(245, 158, 11, 0.45);
  animation: breachPulse 1.1s infinite ease-in-out;
}

@keyframes breachPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* Hairline Dynamic Crosshair & Hitmarkers */
.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  margin-left: -18px;
  margin-top: -18px;
  transition: opacity 0.1s ease;
}

.crosshair.is-ads {
  opacity: 0;
}

.ch-tick {
  position: absolute;
  background: rgba(248, 250, 252, 0.88);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.85);
}

.ch-t, .ch-b { width: 1.5px; height: 9px; left: 17.25px; }
.ch-t { top: calc(4px - var(--ch-gap, 0px)); }
.ch-b { top: calc(23px + var(--ch-gap, 0px)); }
.ch-l, .ch-r { height: 1.5px; width: 9px; top: 17.25px; }
.ch-l { left: calc(4px - var(--ch-gap, 0px)); }
.ch-r { left: calc(23px + var(--ch-gap, 0px)); }

.ch-dot {
  position: absolute;
  width: 2px;
  height: 2px;
  left: 17px;
  top: 17px;
  background: rgba(254, 240, 138, 0.9);
}

.hitmarker {
  position: absolute;
  left: 6px;
  top: 6px;
  width: 24px;
  height: 24px;
  opacity: 0;
  transition: opacity 0.08s ease;
}
.hitmarker::before, .hitmarker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 2px;
  background: #ffffff;
  transform: translate(-50%, -50%) rotate(45deg);
}
.hitmarker::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}
.hitmarker.is-hit { opacity: 1; }
.hitmarker.is-head::before, .hitmarker.is-head::after {
  background: #ff2a2a;
  width: 24px;
  height: 2.5px;
  box-shadow: 0 0 8px rgba(255, 42, 42, 0.9);
}
.hitmarker.is-shield::before, .hitmarker.is-shield::after {
  background: #38bdf8;
}

.hud-subprompt {
  position: absolute;
  bottom: max(84px, env(safe-area-inset-bottom) + 74px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono-font);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(241, 245, 249, 0.85);
  background: rgba(8, 12, 20, 0.72);
  padding: 5px 12px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  white-space: nowrap;
}

/* Bottom Corners Telemetry */
.hud-bottom-left {
  position: absolute;
  left: max(18px, env(safe-area-inset-left) + 14px);
  bottom: max(18px, env(safe-area-inset-bottom) + 14px);
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: rgba(8, 12, 20, 0.74);
  border-left: 2px solid var(--emerald);
  padding: 8px 12px;
  min-width: 175px;
}

.vital-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono-font);
  font-size: 11px;
}

.vital-label { color: var(--text-dim); letter-spacing: 0.1em; }
.vital-track { flex: 1; height: 5px; background: rgba(255, 255, 255, 0.14); }
.vital-fill { height: 100%; width: 100%; background: var(--emerald); transition: width 0.12s linear, background 0.2s; }
.vital-num { font-weight: 800; min-width: 28px; text-align: right; }

.hud-stance {
  font-family: var(--mono-font);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: #cbd5e1;
  text-transform: uppercase;
}

.hud-bottom-right {
  position: absolute;
  right: max(18px, env(safe-area-inset-right) + 14px);
  bottom: max(18px, env(safe-area-inset-bottom) + 14px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.weapon-slots {
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

.wslot-btn {
  background: rgba(8, 12, 20, 0.68);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: var(--text-dim);
  font-family: var(--mono-font);
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  cursor: pointer;
}

.wslot-btn.is-active {
  border-color: var(--amber);
  color: #fef3c7;
  background: rgba(245, 158, 11, 0.22);
}

.ammo-panel {
  background: rgba(8, 12, 20, 0.76);
  border-right: 2px solid var(--amber);
  padding: 8px 14px;
  min-width: 196px;
  text-align: right;
}

.ammo-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--mono-font);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.ammo-frag { color: #fde68a; font-weight: 700; }

.ammo-count-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
  font-family: var(--mono-font);
  margin-top: 2px;
}

.ammo-mag { font-size: 30px; line-height: 1; font-weight: 800; color: #ffffff; }
.ammo-mag.is-low { color: var(--danger); }
.ammo-sep { color: var(--text-dim); font-size: 16px; }
.ammo-reserve { font-size: 16px; color: var(--text-dim); font-weight: 600; }

/* Touch Dual-Thumb Controls */
.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}

.touch-stick-zone {
  position: absolute;
  left: max(18px, env(safe-area-inset-left) + 12px);
  bottom: max(84px, env(safe-area-inset-bottom) + 74px);
  width: 132px;
  height: 132px;
  pointer-events: auto;
  touch-action: none;
}

.touch-stick-base {
  width: 112px;
  height: 112px;
  margin: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(241, 245, 249, 0.28);
  background: rgba(8, 12, 20, 0.35);
  position: relative;
}

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.72);
  border: 2px solid rgba(254, 243, 199, 0.85);
}

.touch-action-cluster {
  position: absolute;
  right: max(14px, env(safe-area-inset-right) + 10px);
  bottom: max(116px, env(safe-area-inset-bottom) + 108px);
  display: grid;
  grid-template-columns: repeat(2, 54px);
  gap: 8px;
  pointer-events: auto;
  touch-action: none;
}

.tbtn {
  border-radius: 50%;
  border: 1.5px solid rgba(241, 245, 249, 0.34);
  background: rgba(10, 15, 24, 0.56);
  color: #f8fafc;
  font-family: var(--mono-font);
  font-weight: 800;
  letter-spacing: 0.05em;
  display: grid;
  place-items: center;
  touch-action: none;
}

.tbtn-sm { width: 54px; height: 54px; font-size: 11px; }
.tbtn-sm.is-active { border-color: var(--amber); background: rgba(245, 158, 11, 0.35); color: #fef3c7; }

.tbtn-fire {
  grid-column: span 2;
  justify-self: end;
  width: 78px;
  height: 78px;
  font-size: 13px;
  border-color: rgba(245, 158, 11, 0.85);
  background: rgba(217, 119, 6, 0.45);
}
.tbtn-fire.is-active {
  background: rgba(245, 158, 11, 0.82);
}

/* Cinematic Command Overlays */
.overlay-root {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 58px 16px 20px;
  background: linear-gradient(135deg, rgba(5, 8, 14, 0.78), rgba(7, 11, 18, 0.54));
}

.overlay-root[hidden] {
  display: none;
}

.overlay-card {
  width: min(860px, 100%);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-top: 2px solid var(--amber);
  padding: 22px 24px;
  box-shadow: 0 28px 64px rgba(0, 0, 0, 0.65);
}

.ov-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.ov-kicker {
  font-family: var(--mono-font);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--amber-hot);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.ov-title {
  margin: 0;
  font-size: clamp(22px, 3.6vw, 32px);
  letter-spacing: 0.08em;
  font-weight: 800;
  text-transform: uppercase;
}

.ov-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.ov-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ov-tab {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  padding: 7px 14px;
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.ov-tab.is-active {
  border-color: var(--amber);
  color: #fef3c7;
  background: rgba(245, 158, 11, 0.18);
}

.credits-badge {
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  color: #fde68a;
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 6px 12px;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stage-card {
  text-align: left;
  background: rgba(15, 23, 42, 0.66);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 12px 14px;
  color: var(--text-main);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.stage-card:hover:not(:disabled) {
  border-color: rgba(245, 158, 11, 0.65);
  background: rgba(30, 41, 59, 0.72);
}

.stage-card.is-selected {
  border-color: var(--amber);
  background: rgba(245, 158, 11, 0.14);
}

.stage-card:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.stage-card-top {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono-font);
  font-size: 11px;
  color: var(--amber-hot);
  margin-bottom: 4px;
}

.stage-card-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}

.stage-card-loc {
  font-size: 11px;
  color: var(--text-dim);
}

.briefing-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
}

.briefing-copy {
  flex: 1;
  min-width: 240px;
  font-size: 13px;
  line-height: 1.55;
  color: #cbd5e1;
}

.btn-primary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0b0f17;
  border: none;
  padding: 12px 24px;
  font-family: var(--mono-font);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.btn-secondary {
  background: rgba(15, 23, 42, 0.85);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  padding: 11px 18px;
  font-family: var(--mono-font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.upgrade-card {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--panel-border);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upgrade-pips {
  display: flex;
  gap: 4px;
}

.upgrade-pip {
  height: 4px;
  flex: 1;
  background: rgba(148, 163, 184, 0.22);
}

.upgrade-pip.is-on {
  background: var(--amber);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.stat-box {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--panel-border);
  padding: 10px 12px;
}

.stat-lbl {
  font-family: var(--mono-font);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.stat-val {
  font-family: var(--mono-font);
  font-size: 20px;
  font-weight: 800;
  margin-top: 4px;
}

.guide-block {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}
.guide-block h3 {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--amber-hot);
}
.guide-block p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: #cbd5e1;
}

@media (max-width: 720px) {
  .hud-bottom-left { min-width: 136px; padding: 6px 8px; }
  .ammo-panel { min-width: 148px; padding: 6px 10px; }
  .ammo-mag { font-size: 24px; }
  .overlay-card { padding: 16px; }
}
