// screens-hud.jsx — Direction 2: TACTICAL HUD
// Geist sans + mono, crosshair corners, stencil headers, mil-spec amber/red

const HUD = {
  bg: '#0B0D11',
  panel: '#10141B',
  panelHi: '#161B24',
  line: '#1E2330',
  line2: '#2B3243',
  text: '#E7ECF2',
  textDim: '#8B94A6',
  textMute: '#4E5564',
  ok: '#46D1A0',
  amber: '#FFB020',
  danger: '#FF3B30',
  hairline: 'rgba(255,255,255,0.08)',
};

// Corner crosshair marks on a panel
function HUDCorners({ color = HUD.line2, size = 8, inset = 4 }) {
  const C = ({ pos }) => (
    <svg width={size + 2} height={size + 2} viewBox={`0 0 ${size + 2} ${size + 2}`}
      style={{ position: 'absolute', ...pos }}>
      <path d={`M0,0 L${size},0 M0,0 L0,${size}`} stroke={color} strokeWidth="1" fill="none"
        transform={pos.transform || ''}/>
    </svg>
  );
  return (
    <>
      <C pos={{ top: inset, left: inset }} />
      <C pos={{ top: inset, right: inset, transform: 'scaleX(-1)' }} />
      <C pos={{ bottom: inset, left: inset, transform: 'scaleY(-1)' }} />
      <C pos={{ bottom: inset, right: inset, transform: 'scale(-1)' }} />
    </>
  );
}

// Panel with corners
function HUDPanel({ children, color, style, padding = 12, corners = true }) {
  return (
    <div style={{
      position: 'relative', background: HUD.panel,
      border: `1px solid ${HUD.line}`,
      boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.03)',
      padding, ...style,
    }}>
      {corners && <HUDCorners color={color || HUD.line2}/>}
      {children}
    </div>
  );
}

// Top sticky grid-coord strip — every screen has it
function HUDInfoStrip({ accent, label, right }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      padding: '4px 16px', background: HUD.panel, borderBottom: `1px solid ${HUD.line}`,
      fontSize: 9, letterSpacing: 2, height: 24,
    }} className="geist-mono">
      <div style={{ display: 'flex', gap: 14, color: HUD.textDim }}>
        <span><span style={{ color: HUD.ok }}>●</span> LINK</span>
        <span>STORM-7</span>
        <span>02:14:08</span>
      </div>
      <div style={{ color: HUD.textDim }}>{right || '187/250'}</div>
    </div>
  );
}

// Stencil header
function HUDHeader({ title, kicker, accent, right }) {
  return (
    <div style={{ padding: '12px 16px 14px', background: HUD.bg, borderBottom: `1px solid ${HUD.hairline}`, position: 'relative' }}>
      <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', gap: 8 }}>
        <div>
          <div className="geist-mono" style={{ color: accent, fontSize: 10, letterSpacing: 4, marginBottom: 4, fontWeight: 500 }}>{kicker}</div>
          <div className="geist" style={{ fontSize: 28, fontWeight: 700, letterSpacing: -0.5, lineHeight: 1, color: HUD.text }}>{title}</div>
        </div>
        {right}
      </div>
    </div>
  );
}

// Sharp-cornered button (clipped diagonal)
function HUDBtn({ children, accent, primary, danger, full, onClick, style }) {
  const col = danger ? HUD.danger : primary ? accent : HUD.text;
  const bg = primary ? accent : 'transparent';
  return (
    <button onClick={onClick} className="geist-mono" style={{
      appearance: 'none', border: `1px solid ${danger ? HUD.danger : primary ? accent : HUD.line2}`,
      background: bg, color: primary ? '#000' : col,
      padding: '10px 14px', fontSize: 11, letterSpacing: 2, textTransform: 'uppercase',
      cursor: 'pointer', fontWeight: 600,
      clipPath: 'polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px))',
      width: full ? '100%' : 'auto', ...style,
    }}>{children}</button>
  );
}

// Tab bar
function HUDTabBar({ screen, onChange, accent }) {
  const tabs = [
    { id: 'home', label: 'OPS', icon: 'hard-drives' },
    { id: 'map', label: 'MAP', icon: 'map-pin' },
    { id: 'freqs', label: 'RF', icon: 'broadcast' },
    { id: 'events', label: 'FEED', icon: 'list-bullets' },
    { id: 'squad', label: 'SQD', icon: 'users-three' },
  ];
  return (
    <div style={{
      position: 'absolute', bottom: 0, left: 0, right: 0,
      background: HUD.panel, borderTop: `1px solid ${HUD.line}`,
      paddingBottom: 28, paddingTop: 8,
      display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', zIndex: 60,
    }}>
      {tabs.map(t => {
        const sel = screen === t.id;
        return (
          <button key={t.id} onClick={() => onChange(t.id)} className="geist-mono"
            style={{ border: 0, background: 'transparent', cursor: 'pointer', padding: '6px 4px',
              display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
              color: sel ? accent : HUD.textDim, position: 'relative',
            }}>
            {sel && <div style={{ position: 'absolute', top: -8, left: '50%', transform: 'translateX(-50%)', width: 14, height: 2, background: accent }}/>}
            <Icon name={t.icon} size={18} weight={sel ? 'fill' : 'regular'} />
            <span style={{ fontSize: 9, letterSpacing: 1.5, fontWeight: 600 }}>{t.label}</span>
          </button>
        );
      })}
    </div>
  );
}

// ───────────────────────────────────────────────
// HOME
// ───────────────────────────────────────────────
function HudHome({ accent, onOpenServer }) {
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative' }}>
      <div style={{ paddingTop: 52 }}><HUDInfoStrip accent={accent}/></div>
      <HUDHeader title="Ops Console" kicker="ADLEY · 04 LINKED" accent={accent} right={
        <HUDBtn accent={accent} primary style={{ padding: '6px 10px', fontSize: 10 }}>+ ADD</HUDBtn>
      } />
      <div style={{ padding: '12px 16px 100px', overflow: 'auto', height: 'calc(100% - 188px)' }}>
        {/* Active server card — bigger */}
        <HUDPanel color={accent} style={{ borderColor: `${accent}55`, marginBottom: 12 }}>
          <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', marginBottom: 10 }}>
            <div>
              <div className="geist-mono" style={{ fontSize: 10, color: accent, letterSpacing: 3, marginBottom: 2 }}>ACTIVE · OWNER</div>
              <div className="geist" style={{ fontSize: 18, fontWeight: 700, letterSpacing: -0.3 }}>EU 3X MAX</div>
              <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, marginTop: 2 }}>185.244.218.42 · WIPE +2D 14H</div>
            </div>
            <div style={{ width: 28, height: 28, border: `1px solid ${HUD.ok}`, display: 'flex', alignItems: 'center', justifyContent: 'center', position: 'relative' }}>
              <div style={{ width: 8, height: 8, background: HUD.ok, animation: 'adley-pulse 2s infinite' }}/>
            </div>
          </div>
          {/* Stat row */}
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 0, borderTop: `1px solid ${HUD.line}`, paddingTop: 10, marginTop: 10 }}>
            {[
              ['POP', '187/250', HUD.text],
              ['FPS', '252', HUD.ok],
              ['UP', '4D02H', HUD.text],
              ['RF', '2', accent],
            ].map(([k, v, c], i) => (
              <div key={k} style={{ borderRight: i < 3 ? `1px solid ${HUD.line}` : 0, paddingLeft: i ? 8 : 0 }}>
                <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 2, marginBottom: 2 }}>{k}</div>
                <div className="geist-mono" style={{ fontSize: 16, fontWeight: 700, color: c, letterSpacing: 0.5, fontVariantNumeric: 'tabular-nums' }}>{v}</div>
              </div>
            ))}
          </div>
          {/* Population bar */}
          <div style={{ display: 'flex', gap: 1, marginTop: 10, height: 3 }}>
            {Array.from({ length: 50 }).map((_, j) => (
              <div key={j} style={{ flex: 1, background: j < 37 ? accent : HUD.line }}/>
            ))}
          </div>
          <div style={{ display: 'flex', gap: 6, marginTop: 12 }}>
            <HUDBtn accent={accent} primary full onClick={onOpenServer}>OPEN SNAPSHOT</HUDBtn>
            <HUDBtn accent={accent} style={{ padding: '10px 12px' }}><Icon name="map-pin" size={12}/></HUDBtn>
          </div>
        </HUDPanel>

        <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 3, padding: '12px 0 6px' }}>
          ◢ OTHER LINKED · 03
        </div>
        {SERVERS.slice(1).map(s => (
          <HUDPanel key={s.id} corners={false} style={{ marginBottom: 8, padding: 12, cursor: 'pointer' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
              <div style={{ width: 6, height: 36, background: s.verified ? HUD.ok : HUD.amber }}/>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
                  <span className="geist" style={{ fontSize: 13, fontWeight: 600 }}>{s.name}</span>
                  {s.verified && <span className="geist-mono" style={{ fontSize: 8, color: HUD.ok, border: `1px solid ${HUD.ok}`, padding: '0 4px' }}>VFY</span>}
                </div>
                <div className="geist-mono" style={{ fontSize: 9, color: HUD.textDim, marginTop: 2, letterSpacing: 1 }}>
                  {s.tag} · WIPE +{s.wipe} · {s.owner ? 'OWNED' : 'JOINED'}
                </div>
              </div>
              <div style={{ textAlign: 'right' }}>
                <div className="geist-mono" style={{ fontSize: 14, fontWeight: 700, fontVariantNumeric: 'tabular-nums', color: HUD.text }}>{s.players}</div>
                <div className="geist-mono" style={{ fontSize: 8, color: HUD.textMute }}>/{s.max}</div>
              </div>
            </div>
          </HUDPanel>
        ))}
        <HUDBtn accent={accent} full style={{ marginTop: 8 }}><Icon name="globe" size={11} style={{ marginRight: 6 }}/> DISCOVER PUBLIC CE</HUDBtn>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// SERVER SNAPSHOT
// ───────────────────────────────────────────────
function HudSnapshot({ accent, onBack, onOpenMap }) {
  const s = SERVERS[0];
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative' }}>
      <div style={{ paddingTop: 52 }}><HUDInfoStrip accent={accent}/></div>
      <div style={{ padding: '8px 16px 4px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <button onClick={onBack} className="geist-mono" style={{ border: 0, background: 'transparent', color: HUD.textDim, fontSize: 11, letterSpacing: 2, cursor: 'pointer' }}>◂ OPS</button>
        <div className="geist-mono" style={{ fontSize: 9, color: HUD.amber, letterSpacing: 2 }}>SNAPSHOT · LIVE</div>
      </div>
      <HUDHeader title={s.name} kicker={`${s.tag} · ${s.host.split(':')[0]}`} accent={accent}/>

      <div style={{ padding: '12px 16px 100px', overflow: 'auto', height: 'calc(100% - 220px)' }}>
        {/* Big stat panels */}
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 }}>
          <HUDPanel color={accent} style={{ padding: 12 }}>
            <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 2, marginBottom: 4 }}>POPULATION</div>
            <div className="geist" style={{ fontSize: 32, fontWeight: 700, color: HUD.text, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>187</div>
            <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, marginTop: 2 }}>/250 · 75%</div>
          </HUDPanel>
          <HUDPanel color={HUD.ok} style={{ padding: 12 }}>
            <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 2, marginBottom: 4 }}>FRAMERATE</div>
            <div className="geist" style={{ fontSize: 32, fontWeight: 700, color: HUD.ok, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>252</div>
            <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, marginTop: 2 }}>FPS · STABLE</div>
          </HUDPanel>
          <HUDPanel corners={false} style={{ padding: 10 }}>
            <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 2, marginBottom: 4 }}>UPTIME</div>
            <div className="geist-mono" style={{ fontSize: 18, fontWeight: 600 }}>4D 02H</div>
          </HUDPanel>
          <HUDPanel corners={false} style={{ padding: 10 }}>
            <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 2, marginBottom: 4 }}>WIPE IN</div>
            <div className="geist-mono" style={{ fontSize: 18, fontWeight: 600 }}>4D 18H</div>
          </HUDPanel>
        </div>

        {/* Armed RF */}
        <div className="geist-mono" style={{ fontSize: 9, color: HUD.amber, letterSpacing: 3, marginTop: 16, marginBottom: 6 }}>
          ◢ ARMED FREQUENCIES · 02
        </div>
        <HUDPanel corners={false} style={{ padding: 0 }}>
          {FREQS.slice(0, 2).map((f, i) => (
            <div key={f.id} style={{ display: 'flex', alignItems: 'center', padding: '10px 12px', borderTop: i ? `1px solid ${HUD.line}` : 0, gap: 10 }}>
              <div style={{ width: 4, height: 28, background: f.triggered.includes('ago') ? HUD.danger : accent }}/>
              <div className="geist-mono" style={{ fontSize: 18, fontWeight: 700, color: accent, fontVariantNumeric: 'tabular-nums', minWidth: 60 }}>{f.freq}</div>
              <div style={{ flex: 1 }}>
                <div className="geist" style={{ fontSize: 12, fontWeight: 600 }}>{f.label}</div>
                <div className="geist-mono" style={{ fontSize: 9, color: HUD.textDim, letterSpacing: 1 }}>{f.grid} · {f.scope}</div>
              </div>
              <div className="geist-mono" style={{ fontSize: 9, color: f.triggered.includes('ago') ? HUD.danger : HUD.textMute, letterSpacing: 1 }}>{f.triggered}</div>
            </div>
          ))}
        </HUDPanel>

        {/* Entities tracking */}
        <div className="geist-mono" style={{ fontSize: 9, color: HUD.amber, letterSpacing: 3, marginTop: 16, marginBottom: 6 }}>
          ◢ TRACKED ENTITIES · 04
        </div>
        <HUDPanel corners={false} style={{ padding: 0 }}>
          {ENTITIES.map((e, i) => (
            <div key={e.id} style={{ display: 'flex', alignItems: 'center', padding: '8px 12px', borderTop: i ? `1px solid ${HUD.line}` : 0, gap: 10 }}>
              <div style={{
                width: 22, height: 22, border: `1px solid ${e.status === 'armed' ? HUD.danger : HUD.line2}`,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>
                <span className="geist-mono" style={{ fontSize: 9, color: e.status === 'armed' ? HUD.danger : HUD.textDim, fontWeight: 700, letterSpacing: 0.5 }}>{e.kind}</span>
              </div>
              <span className="geist" style={{ fontSize: 12, fontWeight: 500, flex: 1 }}>{e.label}</span>
              <span className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, letterSpacing: 1 }}>{e.grid}</span>
            </div>
          ))}
        </HUDPanel>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 6, marginTop: 14 }}>
          <HUDBtn accent={accent} primary full onClick={onOpenMap}>⌖ MAP</HUDBtn>
          <HUDBtn accent={accent} full>SAY · BROADCAST</HUDBtn>
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// WORLD MAP ★ HERO
// ───────────────────────────────────────────────
function HudMap({ accent }) {
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative', overflow: 'hidden' }}>
      <div style={{ paddingTop: 52 }}><HUDInfoStrip accent={accent}/></div>
      <HUDHeader title="World Map" kicker={`EU 3X MAX · 4500 · PROCEDURAL`} accent={accent} right={
        <div className="geist-mono" style={{ fontSize: 9, color: HUD.textDim, letterSpacing: 2, textAlign: 'right' }}>
          <div>SYNC</div><div style={{ color: HUD.ok }}>02:14:08</div>
        </div>
      }/>
      <div style={{ padding: '8px 16px' }}>
        <div style={{ position: 'relative', width: '100%', aspectRatio: '1 / 1', background: '#03060A', border: `1px solid ${HUD.line}`, overflow: 'hidden' }}>
          {/* Crosshair corners on map */}
          <HUDCorners color={accent} size={14}/>
          {/* Subtle grid */}
          <svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0 }}>
            {Array.from({ length: 19 }).map((_, i) => (
              <line key={`v${i}`} x1={(i + 0.5) * (100 / 18)} y1={0} x2={(i + 0.5) * (100 / 18)} y2={100} stroke="#fff" strokeOpacity={0.05} strokeWidth={0.2} />
            ))}
            {Array.from({ length: 19 }).map((_, i) => (
              <line key={`h${i}`} x1={0} y1={(i + 0.5) * (100 / 18)} x2={100} y2={(i + 0.5) * (100 / 18)} stroke="#fff" strokeOpacity={0.05} strokeWidth={0.2} />
            ))}
            {/* Bigger grid every 4 */}
            {[0,4,8,12,16].map(i => (
              <g key={i}>
                <line x1={i * (100/18)} y1={0} x2={i * (100/18)} y2={100} stroke={accent} strokeOpacity={0.18} strokeWidth={0.3} />
                <line x1={0} y1={i * (100/18)} x2={100} y2={i * (100/18)} stroke={accent} strokeOpacity={0.18} strokeWidth={0.3} />
              </g>
            ))}
            {/* Terrain blob (subtle glow) */}
            <defs>
              <radialGradient id="terrainGlow">
                <stop offset="0%" stopColor={accent} stopOpacity="0.1" />
                <stop offset="100%" stopColor={accent} stopOpacity="0" />
              </radialGradient>
            </defs>
            <path d="M8,28 Q20,15 35,22 T62,28 Q78,18 92,32 L92,72 Q82,86 60,82 T28,78 Q8,80 8,72 Z"
              fill="url(#terrainGlow)" stroke={`${accent}33`} strokeWidth={0.25}/>
            <path d="M14,40 Q35,55 50,50 T80,52 Q85,60 75,68" stroke="#fff" strokeOpacity={0.08} strokeWidth={0.4} fill="none"/>
            {/* radar sweep */}
            <circle cx={50} cy={50} r={48} fill="none" stroke={accent} strokeOpacity={0.1} strokeWidth={0.3}/>
            <circle cx={50} cy={50} r={32} fill="none" stroke={accent} strokeOpacity={0.1} strokeWidth={0.3}/>
            <circle cx={50} cy={50} r={16} fill="none" stroke={accent} strokeOpacity={0.1} strokeWidth={0.3}/>
          </svg>
          {/* Grid labels on edges */}
          {'ABCDEFGHIJKLMNOPQR'.split('').map((c, i) => (
            <div key={c} className="geist-mono" style={{ position: 'absolute', top: 16, left: `${(i + 0.5) * (100 / 18)}%`, transform: 'translateX(-50%)', fontSize: 7, color: HUD.textMute, letterSpacing: 0.5 }}>{c}</div>
          ))}
          {/* Monuments */}
          {MONUMENTS.map(m => {
            const col = m.type === 'safe' ? HUD.ok : m.type === 'tier3' ? accent : HUD.textDim;
            return (
              <div key={m.id} style={{
                position: 'absolute', left: `${m.x * 100}%`, top: `${m.y * 100}%`, transform: 'translate(-50%, -50%)',
              }}>
                <div style={{ width: 6, height: 6, background: col, transform: 'rotate(45deg)', boxShadow: `0 0 8px ${col}` }}/>
                <div className="geist-mono" style={{
                  position: 'absolute', top: 8, left: '50%', transform: 'translateX(-50%)',
                  fontSize: 7, color: col, letterSpacing: 1, whiteSpace: 'nowrap',
                  textShadow: '0 0 4px #000', fontWeight: 600,
                }}>{m.name}</div>
              </div>
            );
          })}
          {/* Entities */}
          {ENTITIES.map(e => (
            <div key={e.id} style={{
              position: 'absolute', left: `${e.x * 100}%`, top: `${e.y * 100}%`, transform: 'translate(-50%, -50%)',
            }}>
              {/* Pulse ring for armed */}
              {e.status === 'armed' && (
                <div style={{
                  position: 'absolute', inset: -8, border: `1px solid ${HUD.danger}`,
                  borderRadius: '50%', animation: 'adley-pingdot 1.5s infinite',
                }}/>
              )}
              <div style={{
                width: 14, height: 14, border: `1.5px solid ${e.status === 'armed' ? HUD.danger : accent}`,
                background: e.status === 'armed' ? HUD.danger : 'transparent',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                position: 'relative',
              }}>
                <span className="geist-mono" style={{ fontSize: 6, color: '#fff', fontWeight: 700, letterSpacing: 0.5 }}>{e.kind[0]}</span>
              </div>
              <div className="geist-mono" style={{
                position: 'absolute', top: 16, left: '50%', transform: 'translateX(-50%)',
                fontSize: 7, color: e.status === 'armed' ? HUD.danger : accent, letterSpacing: 1, fontWeight: 600,
                whiteSpace: 'nowrap', textShadow: '0 0 4px #000',
              }}>{e.grid}</div>
            </div>
          ))}
        </div>

        {/* Bottom info strip — selected entity */}
        <HUDPanel color={HUD.danger} style={{ marginTop: 12, padding: 12, borderColor: `${HUD.danger}44` }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <div>
              <div className="geist-mono" style={{ fontSize: 9, color: HUD.danger, letterSpacing: 3, marginBottom: 2 }}>◢ TC · ARMED</div>
              <div className="geist" style={{ fontSize: 16, fontWeight: 700 }}>MAIN TC · G14</div>
              <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, marginTop: 2, letterSpacing: 1 }}>
                FREQ 4763 · LAST TRIP 02:14:00
              </div>
            </div>
            <div className="geist-mono" style={{ fontSize: 36, fontWeight: 700, color: HUD.danger, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>G14</div>
          </div>
        </HUDPanel>

        <div style={{ display: 'flex', gap: 6, marginTop: 8 }}>
          {[
            ['MON', accent, true], ['TC', HUD.danger, true], ['BAGS', accent, true],
            ['PVP', HUD.textDim, false], ['HELI', HUD.textDim, false],
          ].map(([l, c, on]) => (
            <button key={l} className="geist-mono" style={{
              flex: 1, padding: '6px 4px', fontSize: 9, letterSpacing: 1.5, fontWeight: 600,
              border: `1px solid ${on ? c : HUD.line2}`, background: on ? `${c}22` : 'transparent',
              color: on ? c : HUD.textMute, cursor: 'pointer',
            }}>{l}</button>
          ))}
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// RAID ALERT (tactical HUD treatment)
// ───────────────────────────────────────────────
function HudRaidAlert({ accent }) {
  return (
    <div style={{ height: '100%', background: '#0A0204', color: HUD.text, position: 'relative', overflow: 'hidden' }}>
      {/* Strobe */}
      <div style={{ position: 'absolute', inset: 0, background: HUD.danger, opacity: 0.04, animation: 'adley-strobe-soft 0.5s steps(1) infinite' }}/>
      {/* Full-screen crosshair grid */}
      <svg width="100%" height="100%" viewBox="0 0 100 200" preserveAspectRatio="xMidYMid meet" style={{ position: 'absolute', inset: 0, opacity: 0.4 }}>
        <line x1={50} y1={0} x2={50} y2={200} stroke={HUD.danger} strokeWidth="0.15" strokeOpacity={0.5}/>
        <line x1={0} y1={100} x2={100} y2={100} stroke={HUD.danger} strokeWidth="0.15" strokeOpacity={0.5}/>
      </svg>
      {/* Corner ticks */}
      <HUDCorners color={HUD.danger} size={24} inset={16}/>

      <div style={{ padding: '60px 24px 0', position: 'relative', zIndex: 5 }}>
        {/* Top banner */}
        <div style={{ background: HUD.danger, padding: '8px 12px', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
          clipPath: 'polygon(0 0, calc(100% - 10px) 0, 100% 100%, 10px 100%)',
          animation: 'adley-strobe-soft 0.5s steps(1) infinite',
        }}>
          <span className="geist-mono" style={{ fontSize: 11, color: '#fff', letterSpacing: 4, fontWeight: 700 }}>▲ RAID DETECTED</span>
          <span className="geist-mono" style={{ fontSize: 10, color: '#fff', letterSpacing: 2 }}>T+00:08</span>
        </div>

        {/* Big freq + base */}
        <div style={{ marginTop: 28, textAlign: 'center', position: 'relative' }}>
          <div className="geist-mono" style={{ fontSize: 10, color: HUD.danger, letterSpacing: 6, fontWeight: 700, marginBottom: 4 }}>FREQUENCY</div>
          <div className="geist" style={{ fontSize: 88, fontWeight: 800, color: '#fff', letterSpacing: -2, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>4763</div>
          <div className="geist-mono" style={{ fontSize: 11, color: HUD.textDim, marginTop: 6, letterSpacing: 2 }}>MAIN TC · STORM-7</div>
        </div>

        {/* GRID + BASE crosshair display */}
        <div style={{ marginTop: 32, position: 'relative' }}>
          <HUDPanel color={HUD.danger} style={{ background: 'rgba(255,59,48,0.05)', borderColor: HUD.danger, padding: 16 }}>
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1px 1fr', gap: 12, alignItems: 'center' }}>
              <div>
                <div className="geist-mono" style={{ fontSize: 9, color: HUD.danger, letterSpacing: 3, marginBottom: 4 }}>GRID</div>
                <div className="geist" style={{ fontSize: 56, fontWeight: 800, color: '#fff', letterSpacing: -1, lineHeight: 1 }}>G14</div>
                {/* mini-map crosshair */}
                <svg viewBox="0 0 100 100" style={{ width: 80, height: 80, marginTop: 8, opacity: 0.6 }}>
                  <rect x={0} y={0} width={100} height={100} fill="none" stroke={HUD.line2} strokeWidth="1"/>
                  {Array.from({ length: 18 }).map((_, i) => (
                    <line key={i} x1={(i + 1) * (100 / 18)} y1={0} x2={(i + 1) * (100 / 18)} y2={100} stroke={HUD.line2} strokeWidth="0.3"/>
                  ))}
                  {Array.from({ length: 18 }).map((_, i) => (
                    <line key={`h${i}`} x1={0} y1={(i + 1) * (100 / 18)} x2={100} y2={(i + 1) * (100 / 18)} stroke={HUD.line2} strokeWidth="0.3"/>
                  ))}
                  <rect x={(6) * (100 / 18)} y={(13) * (100 / 18)} width={100 / 18} height={100 / 18} fill={HUD.danger} fillOpacity="0.6"/>
                  <line x1={(6.5) * (100 / 18)} y1={0} x2={(6.5) * (100 / 18)} y2={100} stroke={HUD.danger} strokeWidth="0.5"/>
                  <line x1={0} y1={(13.5) * (100 / 18)} x2={100} y2={(13.5) * (100 / 18)} stroke={HUD.danger} strokeWidth="0.5"/>
                </svg>
              </div>
              <div style={{ background: HUD.line2 }}/>
              <div>
                <div className="geist-mono" style={{ fontSize: 9, color: HUD.danger, letterSpacing: 3, marginBottom: 4 }}>BASE</div>
                <div className="geist" style={{ fontSize: 18, fontWeight: 700, color: '#fff', letterSpacing: -0.3, lineHeight: 1.1 }}>BLDG ALPHA</div>
                <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, marginTop: 6, letterSpacing: 1 }}>EU 3X MAX</div>
                <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, letterSpacing: 1 }}>185.244.218.42</div>
                <div style={{ marginTop: 10 }}>
                  <div className="geist-mono" style={{ fontSize: 9, color: HUD.danger, letterSpacing: 2 }}>NOTIFIED</div>
                  <div className="geist" style={{ fontSize: 16, fontWeight: 700, color: '#fff' }}>06 / 06</div>
                </div>
              </div>
            </div>
          </HUDPanel>
        </div>

        <div className="geist-mono" style={{ marginTop: 20, fontSize: 10, color: HUD.danger, textAlign: 'center', letterSpacing: 4, animation: 'adley-blink 0.6s infinite' }}>
          ◢ SIREN ACTIVE · LOOP ◣
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, marginTop: 28 }}>
          <HUDBtn accent={HUD.danger} primary full style={{ background: HUD.danger, color: '#fff', borderColor: HUD.danger, fontWeight: 700 }}>JUMP TO MAP ⌖</HUDBtn>
          <HUDBtn accent={HUD.danger} full>SILENCE 60s</HUDBtn>
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// LOCK SCREEN + LIVE ACTIVITY
// ───────────────────────────────────────────────
function HudLockScreen({ accent }) {
  return (
    <div style={{ height: '100%', background: '#000', color: HUD.text, position: 'relative', overflow: 'hidden' }}>
      {/* Wallpaper: dark satellite */}
      <div style={{ position: 'absolute', inset: 0, background: `
        radial-gradient(circle at 25% 30%, ${accent}10, transparent 40%),
        radial-gradient(circle at 70% 70%, ${HUD.danger}08, transparent 50%),
        #04050A
      `}}>
        <svg width="100%" height="100%" style={{ position: 'absolute', inset: 0, opacity: 0.12 }}>
          <defs>
            <pattern id="hgrid" width="32" height="32" patternUnits="userSpaceOnUse">
              <path d="M0,0 L32,0 M0,0 L0,32" stroke={accent} strokeWidth="0.5"/>
            </pattern>
          </defs>
          <rect width="100%" height="100%" fill="url(#hgrid)"/>
        </svg>
        {/* Dot stars */}
        {[[60,200],[120,400],[300,150],[80,650],[280,720],[200,260],[340,500]].map(([x,y], i) => (
          <div key={i} style={{ position: 'absolute', left: x, top: y, width: 2, height: 2, background: '#fff', opacity: 0.4 }}/>
        ))}
      </div>

      {/* Time */}
      <div style={{ position: 'absolute', top: 80, left: 0, right: 0, textAlign: 'center', zIndex: 10 }}>
        <div className="geist-mono" style={{ fontSize: 13, color: HUD.textDim, letterSpacing: 3, marginBottom: 4 }}>FRI · 22 MAY</div>
        <div className="geist" style={{ fontSize: 84, fontWeight: 300, color: '#fff', letterSpacing: -2, lineHeight: 1 }}>02:14</div>
      </div>

      {/* Live Activity card */}
      <div style={{ position: 'absolute', top: 270, left: 16, right: 16, zIndex: 10 }}>
        <HUDPanel color={accent} style={{ background: 'rgba(15,20,28,0.85)', backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)', padding: 14 }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 12 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <div style={{ width: 22, height: 22, background: accent, display: 'flex', alignItems: 'center', justifyContent: 'center', clipPath: 'polygon(0 0, calc(100% - 4px) 0, 100% 4px, 100% 100%, 4px 100%, 0 calc(100% - 4px))' }}>
                <span className="geist-mono" style={{ color: '#000', fontSize: 11, fontWeight: 800 }}>A</span>
              </div>
              <span className="geist-mono" style={{ fontSize: 10, letterSpacing: 3, fontWeight: 700, color: HUD.text }}>EU 3X MAX</span>
            </div>
            <span className="geist-mono" style={{ fontSize: 9, color: HUD.ok, letterSpacing: 2 }}>● LIVE</span>
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)' }}>
            {[
              ['POP', '187', '/250', HUD.text],
              ['FPS', '252', 'STBL', HUD.ok],
              ['RF', '02', 'SQD', accent],
              ['EVT', '14', '/HR', HUD.textDim],
            ].map(([k, v, sub, c], i) => (
              <div key={k} style={{ borderRight: i < 3 ? `1px solid ${HUD.line}` : 0, paddingLeft: i ? 10 : 0 }}>
                <div className="geist-mono" style={{ fontSize: 8, color: HUD.textMute, letterSpacing: 2 }}>{k}</div>
                <div className="geist" style={{ fontSize: 22, fontWeight: 700, color: c, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>{v}</div>
                <div className="geist-mono" style={{ fontSize: 8, color: HUD.textMute, letterSpacing: 1 }}>{sub}</div>
              </div>
            ))}
          </div>
        </HUDPanel>
        <div className="geist-mono" style={{ fontSize: 8, color: HUD.textMute, letterSpacing: 3, textAlign: 'center', marginTop: 8 }}>
          ◢ LIVE ACTIVITY · ACTIVITYKIT ◣
        </div>
      </div>

      {/* Raid notification card */}
      <div style={{ position: 'absolute', top: 440, left: 16, right: 16, zIndex: 10 }}>
        <div style={{
          background: 'rgba(40,5,10,0.9)', border: `1px solid ${HUD.danger}`,
          padding: 14, backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)',
          position: 'relative',
        }}>
          <HUDCorners color={HUD.danger} size={6} inset={3}/>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
              <span style={{ width: 6, height: 6, background: HUD.danger, animation: 'adley-blink 0.5s infinite', display: 'inline-block' }}/>
              <span className="geist-mono" style={{ fontSize: 10, color: HUD.danger, letterSpacing: 3, fontWeight: 700 }}>▲ RAID · ADLEY</span>
            </div>
            <span className="geist-mono" style={{ fontSize: 9, color: HUD.textDim }}>now</span>
          </div>
          <div className="geist" style={{ fontSize: 14, color: '#fff', fontWeight: 700, marginBottom: 4 }}>TC tripped · 4763</div>
          <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, letterSpacing: 1 }}>G14 · BLDG ALPHA · STORM-7</div>
        </div>
      </div>

      {/* Dynamic island raid */}
      <div style={{
        position: 'absolute', top: 11, left: '50%', transform: 'translateX(-50%)',
        background: '#000', borderRadius: 24, height: 37, padding: '0 14px 0 50px',
        display: 'flex', alignItems: 'center', gap: 8, zIndex: 51,
      }}>
        <div style={{ width: 8, height: 8, background: HUD.danger, animation: 'adley-blink 0.5s infinite' }}/>
        <span className="geist-mono" style={{ fontSize: 10, color: HUD.danger, fontWeight: 700, letterSpacing: 2 }}>RAID G14</span>
      </div>

      {/* Bottom controls */}
      <div style={{ position: 'absolute', bottom: 60, left: 0, right: 0, display: 'flex', justifyContent: 'space-between', padding: '0 32px', zIndex: 10 }}>
        <div style={{ width: 44, height: 44, borderRadius: '50%', background: 'rgba(40,40,50,0.6)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <Icon name="flashlight" size={18} color="#fff"/>
        </div>
        <div style={{ width: 44, height: 44, borderRadius: '50%', background: 'rgba(40,40,50,0.6)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
          <Icon name="camera" size={18} color="#fff"/>
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// ARMED FREQS
// ───────────────────────────────────────────────
function HudFreqs({ accent }) {
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative' }}>
      <div style={{ paddingTop: 52 }}><HUDInfoStrip accent={accent}/></div>
      <HUDHeader title="Armed RF" kicker="TRIP-WIRES · 05 ACTIVE" accent={accent} right={
        <HUDBtn accent={accent} primary style={{ padding: '6px 10px', fontSize: 10 }}>+ ARM</HUDBtn>
      }/>
      <div style={{ padding: '12px 16px 100px', overflow: 'auto', height: 'calc(100% - 188px)' }}>
        {FREQS.map(f => (
          <HUDPanel key={f.id} corners={f.triggered.includes('ago')} color={HUD.danger}
            style={{ marginBottom: 8, padding: 12, borderColor: f.triggered.includes('ago') ? `${HUD.danger}66` : HUD.line }}>
            <div style={{ display: 'flex', alignItems: 'flex-start', gap: 12 }}>
              <div style={{
                width: 76, padding: '8px 6px', border: `1px solid ${f.triggered.includes('ago') ? HUD.danger : accent}55`,
                background: `${f.triggered.includes('ago') ? HUD.danger : accent}11`,
                textAlign: 'center',
              }}>
                <div className="geist-mono" style={{ fontSize: 8, color: f.triggered.includes('ago') ? HUD.danger : accent, letterSpacing: 2 }}>MHz</div>
                <div className="geist" style={{ fontSize: 22, fontWeight: 700, color: f.triggered.includes('ago') ? HUD.danger : accent, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>{f.freq}</div>
              </div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 4 }}>
                  <span className="geist" style={{ fontSize: 13, fontWeight: 600 }}>{f.label}</span>
                  {f.locked && <span className="geist-mono" style={{ fontSize: 8, border: `1px solid ${HUD.amber}`, color: HUD.amber, padding: '0 4px', letterSpacing: 1 }}>LOCK</span>}
                </div>
                <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, letterSpacing: 1, marginBottom: 6 }}>
                  <span style={{ color: accent }}>{f.grid}</span> · {f.scope}{f.squad ? ` · ${f.squad}` : ''}
                </div>
                <div className="geist-mono" style={{ fontSize: 9, color: f.triggered.includes('ago') ? HUD.danger : HUD.textMute, letterSpacing: 2 }}>
                  LAST TRIP: {f.triggered.toUpperCase()}
                </div>
              </div>
            </div>
          </HUDPanel>
        ))}

        <HUDPanel color={accent} style={{ marginTop: 16, padding: 14, borderColor: `${accent}66`, borderStyle: 'dashed' }}>
          <div className="geist-mono" style={{ fontSize: 10, color: accent, letterSpacing: 3, marginBottom: 8 }}>◢ ARM NEW FREQ</div>
          <div style={{ display: 'flex', gap: 6 }}>
            {[4,7,6,3].map((d, i) => (
              <div key={i} className="geist" style={{
                flex: 1, height: 52, border: `1px solid ${accent}66`,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                fontSize: 28, fontWeight: 700, color: accent, fontVariantNumeric: 'tabular-nums',
              }}>{d}</div>
            ))}
          </div>
          <div style={{ display: 'flex', gap: 6, marginTop: 10 }}>
            {['USER', 'SQUAD'].map((s, i) => (
              <button key={s} className="geist-mono" style={{
                flex: 1, padding: '6px', fontSize: 10, letterSpacing: 2, fontWeight: 600,
                border: `1px solid ${i === 1 ? accent : HUD.line2}`, background: i === 1 ? `${accent}22` : 'transparent',
                color: i === 1 ? accent : HUD.textDim, cursor: 'pointer',
              }}>{s}</button>
            ))}
          </div>
        </HUDPanel>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// SQUAD
// ───────────────────────────────────────────────
function HudSquad({ accent }) {
  const sq = SQUAD;
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative' }}>
      <div style={{ paddingTop: 52 }}><HUDInfoStrip accent={accent} right={`${sq.members.filter(m => m.status === 'ONLINE').length}/${sq.members.length} ONLINE`}/></div>
      <HUDHeader title={sq.name} kicker={`SQUAD · ${sq.server}`} accent={accent}/>
      <div style={{ padding: '12px 16px 100px', overflow: 'auto', height: 'calc(100% - 188px)' }}>
        <HUDPanel color={accent} style={{ borderColor: accent, padding: 16, marginBottom: 16 }}>
          <div className="geist-mono" style={{ fontSize: 9, color: accent, letterSpacing: 3, marginBottom: 6 }}>◢ INVITE CODE</div>
          <div className="geist" style={{ fontSize: 32, fontWeight: 700, color: '#fff', letterSpacing: 4, fontVariantNumeric: 'tabular-nums' }}>{sq.code}</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 6, marginTop: 12 }}>
            <HUDBtn accent={accent}><Icon name="copy" size={12}/>&nbsp;COPY</HUDBtn>
            <HUDBtn accent={accent}><Icon name="share-network" size={12}/>&nbsp;SHARE</HUDBtn>
            <HUDBtn accent={accent}><Icon name="arrows-clockwise" size={12}/>&nbsp;REGEN</HUDBtn>
          </div>
        </HUDPanel>

        <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 3, marginBottom: 6 }}>
          ◢ ROSTER · {sq.members.length}
        </div>
        <HUDPanel corners={false} style={{ padding: 0 }}>
          {sq.members.map((m, i) => (
            <div key={m.id} style={{ padding: '12px', borderTop: i ? `1px solid ${HUD.line}` : 0, display: 'flex', alignItems: 'center', gap: 12 }}>
              <div style={{
                width: 36, height: 36, border: `1px solid ${m.status === 'ONLINE' ? HUD.ok : HUD.line2}`,
                background: m.status === 'ONLINE' ? `${HUD.ok}11` : 'transparent',
                color: m.status === 'ONLINE' ? HUD.ok : HUD.textMute,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                fontWeight: 700, fontSize: 12, letterSpacing: 1,
              }} className="geist-mono">{m.name.slice(0, 2)}</div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
                  <span className="geist" style={{ fontSize: 14, fontWeight: 600 }}>{m.name}</span>
                  {m.role === 'LEADER' && <span className="geist-mono" style={{ fontSize: 8, color: accent, border: `1px solid ${accent}`, padding: '0 4px', letterSpacing: 1, fontWeight: 600 }}>LEAD</span>}
                </div>
                <div className="geist-mono" style={{ fontSize: 9, color: HUD.textDim, marginTop: 2, letterSpacing: 1 }}>
                  K/D {m.kdr} · {m.hours}H
                </div>
              </div>
              <div className="geist-mono" style={{ fontSize: 9, color: m.status === 'ONLINE' ? HUD.ok : HUD.textMute, letterSpacing: 2 }}>
                {m.status}
              </div>
            </div>
          ))}
        </HUDPanel>

        <HUDBtn accent={HUD.danger} danger full style={{ marginTop: 16 }}>LEAVE SQUAD</HUDBtn>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// EVENT FEED
// ───────────────────────────────────────────────
function HudEvents({ accent }) {
  const sev = (s) => s === 'crit' ? HUD.danger : s === 'warn' ? HUD.amber : HUD.textDim;
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative' }}>
      <div style={{ paddingTop: 52 }}><HUDInfoStrip accent={accent}/></div>
      <HUDHeader title="Event Feed" kicker="SSE STREAM · LIVE" accent={accent} right={
        <span className="geist-mono" style={{ fontSize: 9, color: HUD.ok, letterSpacing: 2 }}>● STREAM</span>
      }/>
      <div style={{ padding: '12px 16px 100px', overflow: 'auto', height: 'calc(100% - 188px)' }}>
        <div style={{ display: 'flex', gap: 6, marginBottom: 12, flexWrap: 'wrap' }}>
          {['ALL · 14', 'RAID · 1', 'PVP · 4', 'WORLD · 6', 'RF · 3'].map((f, i) => (
            <button key={f} className="geist-mono" style={{
              padding: '4px 8px', fontSize: 9, letterSpacing: 1.5, fontWeight: 600,
              border: `1px solid ${i === 0 ? accent : HUD.line2}`, background: i === 0 ? `${accent}22` : 'transparent',
              color: i === 0 ? accent : HUD.textDim, cursor: 'pointer',
            }}>{f}</button>
          ))}
        </div>

        {EVENTS.map((e, i) => (
          <div key={i} style={{
            display: 'flex', gap: 10, padding: '10px 0', borderBottom: `1px solid ${HUD.line}`,
            alignItems: 'flex-start',
          }}>
            <div style={{ width: 3, alignSelf: 'stretch', background: sev(e.sev), opacity: e.sev === 'info' ? 0.3 : 1, flexShrink: 0 }}/>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 2, gap: 6 }}>
                <span className="geist-mono" style={{ fontSize: 9, color: sev(e.sev), letterSpacing: 2, fontWeight: 700 }}>
                  {e.kind.toUpperCase()}
                </span>
                <span className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, fontVariantNumeric: 'tabular-nums' }}>{e.t}</span>
              </div>
              <div className="geist" style={{ fontSize: 12, color: e.sev === 'crit' ? '#fff' : HUD.text, fontWeight: e.sev === 'crit' ? 600 : 500, letterSpacing: 0.2 }}>
                {e.text}
              </div>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// STATS
// ───────────────────────────────────────────────
function HudStats({ accent }) {
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative' }}>
      <div style={{ paddingTop: 52 }}><HUDInfoStrip accent={accent}/></div>
      <HUDHeader title="Telemetry" kicker="EU 3X MAX · 24H ROLLUP" accent={accent}/>
      <div style={{ padding: '12px 16px 100px', overflow: 'auto', height: 'calc(100% - 188px)' }}>
        {[
          ['Raid events', STATS_24H.raids, HUD.danger, 9],
          ['PvP kills', STATS_24H.pvp, accent, 64],
          ['World events', STATS_24H.world, HUD.amber, 71],
        ].map(([label, data, color, total]) => (
          <HUDPanel key={label} corners={false} style={{ padding: 14, marginBottom: 10 }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', marginBottom: 8 }}>
              <div>
                <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 3, marginBottom: 2 }}>◢ {label.toUpperCase()}</div>
                <div className="geist" style={{ fontSize: 28, fontWeight: 700, color, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>{total}</div>
              </div>
              <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 1, textAlign: 'right' }}>
                <div>PEAK 20:00</div>
                <div>AVG {(total / 24).toFixed(1)}/HR</div>
              </div>
            </div>
            <Bars data={data} color={color} height={56}/>
            <div className="geist-mono" style={{ display: 'flex', justifyContent: 'space-between', fontSize: 8, color: HUD.textMute, marginTop: 4, letterSpacing: 1 }}>
              <span>−24H</span><span>−18</span><span>−12</span><span>−06</span><span>NOW</span>
            </div>
          </HUDPanel>
        ))}
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// RCON ONBOARDING
// ───────────────────────────────────────────────
function HudRcon({ accent }) {
  return (
    <div style={{ height: '100%', background: HUD.bg, color: HUD.text, position: 'relative' }}>
      <div style={{ padding: '52px 16px 0', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <button className="geist-mono" style={{ border: 0, background: 'transparent', color: HUD.textDim, fontSize: 11, letterSpacing: 2, cursor: 'pointer' }}>◂ CANCEL</button>
        <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 3 }}>02 / 03</div>
      </div>
      <HUDHeader title="RCON Creds" kicker="LINK SERVER · STEP 2" accent={accent}/>
      <div style={{ padding: '12px 16px' }}>
        {/* Step indicator */}
        <div style={{ display: 'flex', gap: 4, marginBottom: 16 }}>
          {[1, 2, 3].map(n => (
            <div key={n} style={{ flex: 1, height: 3, background: n <= 2 ? accent : HUD.line }}/>
          ))}
        </div>

        <div className="geist" style={{ fontSize: 12, color: HUD.textDim, lineHeight: 1.5, marginBottom: 16 }}>
          Adley connects via WebRCON. Paste your <span style={{ color: accent }} className="geist-mono">rcon.port</span> and <span style={{ color: accent }} className="geist-mono">rcon.password</span> — read-only is fine.
        </div>

        {[
          { l: 'HOST · IP', v: '185.244.218.42' },
          { l: 'RCON PORT', v: '28016' },
          { l: 'PASSWORD', v: '••••••••••••' },
          { l: 'NICKNAME', v: 'EU 3X MAX' },
        ].map(f => (
          <div key={f.l} style={{ marginBottom: 10 }}>
            <div className="geist-mono" style={{ fontSize: 9, color: HUD.textMute, letterSpacing: 3, marginBottom: 4 }}>◢ {f.l}</div>
            <HUDPanel corners={false} style={{ padding: 10, borderColor: HUD.line2 }}>
              <div className="geist-mono" style={{ fontSize: 14, color: HUD.text, letterSpacing: 0.5 }}>{f.v}</div>
            </HUDPanel>
          </div>
        ))}

        <HUDPanel color={HUD.ok} style={{ borderColor: `${HUD.ok}55`, padding: 12, marginTop: 12 }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 6 }}>
            <div style={{ width: 8, height: 8, background: HUD.ok, animation: 'adley-pulse 1.5s infinite' }}/>
            <span className="geist-mono" style={{ fontSize: 10, color: HUD.ok, letterSpacing: 3, fontWeight: 700 }}>HANDSHAKE OK</span>
          </div>
          <div className="geist-mono" style={{ fontSize: 10, color: HUD.textDim, lineHeight: 1.6 }}>
            <div>&gt; rust 2503 · build 87642</div>
            <div>&gt; sse subscribed</div>
            <div>&gt; entities 4 / monuments 12</div>
          </div>
        </HUDPanel>

        <HUDBtn accent={accent} primary full style={{ marginTop: 20, padding: 14, fontSize: 12 }}>LINK SERVER →</HUDBtn>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// FLOW WRAPPER
// ───────────────────────────────────────────────
function HudFlow({ accent, initial = 'home' }) {
  const [screen, setScreen] = React.useState(initial);
  const [serverOpen, setServerOpen] = React.useState(false);
  const view = serverOpen ? <HudSnapshot accent={accent} onBack={() => setServerOpen(false)} onOpenMap={() => { setServerOpen(false); setScreen('map'); }}/>
    : screen === 'home' ? <HudHome accent={accent} onOpenServer={() => setServerOpen(true)}/>
    : screen === 'map' ? <HudMap accent={accent}/>
    : screen === 'freqs' ? <HudFreqs accent={accent}/>
    : screen === 'events' ? <HudEvents accent={accent}/>
    : screen === 'squad' ? <HudSquad accent={accent}/>
    : <HudHome accent={accent}/>;
  return (
    <div style={{ height: '100%', position: 'relative', background: HUD.bg }}>
      {view}
      <HUDTabBar screen={serverOpen ? '' : screen} onChange={(id) => { setServerOpen(false); setScreen(id); }} accent={accent}/>
    </div>
  );
}

Object.assign(window, {
  HudFlow, HudHome, HudSnapshot, HudMap, HudRaidAlert, HudLockScreen,
  HudFreqs, HudSquad, HudEvents, HudStats, HudRcon,
});
