// screens-control.jsx — Direction 3: MISSION CONTROL
// Inter + JetBrains Mono, rounded cards, glowy markers, polished glass

const MC = {
  bg: '#08090D',
  bg2: '#0D0F15',
  card: '#13151D',
  cardHi: '#191C26',
  line: '#252834',
  line2: '#363A48',
  text: '#ECEDF1',
  textDim: '#8B8F9E',
  textMute: '#54586A',
  ok: '#3DDC97',
  amber: '#FFB020',
  danger: '#FF3B30',
};

const radius = 14;

function MCCard({ children, glow, accent, style, padding = 14 }) {
  return (
    <div style={{
      background: MC.card, borderRadius: radius,
      border: `1px solid ${glow ? `${accent}55` : MC.line}`,
      boxShadow: glow ? `0 0 0 1px ${accent}22, 0 4px 24px ${accent}15` : '0 1px 2px rgba(0,0,0,0.3)',
      padding, ...style,
    }}>{children}</div>
  );
}

function MCBtn({ children, primary, danger, accent, full, size = 'md', onClick, style }) {
  const sizes = { sm: { p: '6px 10px', f: 11 }, md: { p: '10px 14px', f: 12 }, lg: { p: '13px 16px', f: 13 } };
  const s = sizes[size];
  const bg = primary ? accent : danger ? `${MC.danger}22` : 'transparent';
  const col = primary ? '#000' : danger ? MC.danger : MC.text;
  const bor = primary ? accent : danger ? MC.danger : MC.line2;
  return (
    <button onClick={onClick} className="sans" style={{
      appearance: 'none', border: `1px solid ${bor}`, background: bg, color: col,
      padding: s.p, fontSize: s.f, fontWeight: primary ? 600 : 500, letterSpacing: 0.2,
      borderRadius: 10, cursor: 'pointer', display: 'inline-flex', alignItems: 'center', gap: 6, justifyContent: 'center',
      width: full ? '100%' : 'auto', ...style,
    }}>{children}</button>
  );
}

function MCStatusPill({ color, label, mono = true }) {
  return (
    <div style={{
      display: 'inline-flex', alignItems: 'center', gap: 6, padding: '3px 9px',
      borderRadius: 999, background: `${color}15`, border: `1px solid ${color}33`,
    }}>
      <span style={{ width: 6, height: 6, borderRadius: 3, background: color, boxShadow: `0 0 6px ${color}` }}/>
      <span className={mono ? 'mono' : 'sans'} style={{ fontSize: 9, color, letterSpacing: 1, fontWeight: 600 }}>{label}</span>
    </div>
  );
}

function MCHeader({ title, sub, accent, right }) {
  return (
    <div style={{ padding: '64px 18px 12px', background: MC.bg }}>
      <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', gap: 8 }}>
        <div style={{ flex: 1, minWidth: 0 }}>
          {sub && <div className="mono" style={{ color: MC.textDim, fontSize: 10, letterSpacing: 2, marginBottom: 4 }}>{sub}</div>}
          <div className="sans" style={{ fontSize: 28, fontWeight: 700, letterSpacing: -0.5, color: MC.text }}>{title}</div>
        </div>
        {right}
      </div>
    </div>
  );
}

const MC_TABS = [
  { id: 'home', label: 'Servers', 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: 'Squad', icon: 'users-three' },
];

function MCTabBar({ screen, onChange, accent }) {
  return (
    <div style={{
      position: 'absolute', bottom: 0, left: 0, right: 0,
      background: `linear-gradient(180deg, ${MC.bg}cc, ${MC.bg})`,
      borderTop: `1px solid ${MC.line}`,
      paddingBottom: 28, paddingTop: 10,
      display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', zIndex: 60,
      backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)',
    }}>
      {MC_TABS.map(t => {
        const sel = screen === t.id;
        return (
          <button key={t.id} onClick={() => onChange(t.id)} className="sans"
            style={{ border: 0, background: 'transparent', cursor: 'pointer', padding: '6px 4px',
              display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
              color: sel ? accent : MC.textDim, position: 'relative',
            }}>
            <div style={{
              padding: '4px 10px', borderRadius: 8,
              background: sel ? `${accent}1A` : 'transparent',
            }}>
              <Icon name={t.icon} size={20} weight={sel ? 'fill' : 'regular'} />
            </div>
            <span style={{ fontSize: 10, fontWeight: sel ? 600 : 500, letterSpacing: 0.2 }}>{t.label}</span>
          </button>
        );
      })}
    </div>
  );
}

// ───────────────────────────────────────────────
// HOME
// ───────────────────────────────────────────────
function MCHome({ accent, onOpenServer }) {
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <MCHeader title="Servers" sub="ADLEY · 04 LINKED" accent={accent} right={
        <MCBtn primary accent={accent} size="sm"><Icon name="plus" size={12}/>&nbsp;Add</MCBtn>
      }/>
      <div style={{ padding: '4px 18px 100px', overflow: 'auto', height: 'calc(100% - 140px)' }}>
        {/* Featured / Active server */}
        <MCCard glow accent={accent} style={{ marginBottom: 12 }}>
          <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 8, marginBottom: 12 }}>
            <div style={{ flex: 1 }}>
              <div style={{ display: 'flex', gap: 6, alignItems: 'center', marginBottom: 6 }}>
                <MCStatusPill color={MC.ok} label="LIVE"/>
                <MCStatusPill color={accent} label="OWNER"/>
                <MCStatusPill color={MC.ok} label="VERIFIED"/>
              </div>
              <div className="sans" style={{ fontSize: 18, fontWeight: 700, letterSpacing: -0.3 }}>EU 3X MAX</div>
              <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 4 }}>
                185.244.218.42 · Wipe +2d 14h
              </div>
            </div>
            <div style={{
              width: 44, height: 44, borderRadius: 12,
              background: `linear-gradient(135deg, ${accent}33, ${accent}08)`,
              border: `1px solid ${accent}55`,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              boxShadow: `0 0 16px ${accent}33`,
            }}>
              <span className="mono" style={{ color: accent, fontSize: 14, fontWeight: 700, letterSpacing: 0.5 }}>3X</span>
            </div>
          </div>
          {/* Pop bar with handle */}
          <div style={{ marginBottom: 12 }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 6 }}>
              <span className="sans" style={{ fontSize: 11, color: MC.textDim }}>Population</span>
              <span className="mono" style={{ fontSize: 11, color: MC.text, fontVariantNumeric: 'tabular-nums', fontWeight: 600 }}>
                187 <span style={{ color: MC.textMute }}>/ 250</span>
              </span>
            </div>
            <div style={{ height: 6, background: MC.line, borderRadius: 3, overflow: 'hidden', position: 'relative' }}>
              <div style={{ width: '75%', height: '100%', background: `linear-gradient(90deg, ${accent}, ${accent}88)`, boxShadow: `0 0 8px ${accent}55` }}/>
            </div>
          </div>
          {/* Stat row */}
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 8 }}>
            {[
              ['FPS', '252', MC.ok],
              ['Uptime', '4d', MC.text],
              ['RF', '2', accent],
              ['Squad', '5', MC.text],
            ].map(([k, v, c]) => (
              <div key={k} style={{ padding: '8px 10px', background: MC.cardHi, borderRadius: 8 }}>
                <div className="mono" style={{ fontSize: 9, color: MC.textMute, letterSpacing: 1 }}>{k.toUpperCase()}</div>
                <div className="sans" style={{ fontSize: 16, fontWeight: 700, color: c, fontVariantNumeric: 'tabular-nums', lineHeight: 1.2 }}>{v}</div>
              </div>
            ))}
          </div>
          <MCBtn primary accent={accent} full size="md" style={{ marginTop: 12 }} onClick={onOpenServer}>
            Open snapshot →
          </MCBtn>
        </MCCard>

        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '8px 4px 6px' }}>
          <div className="sans" style={{ fontSize: 12, color: MC.textDim, fontWeight: 600 }}>Other servers · 3</div>
          <div className="mono" style={{ fontSize: 10, color: MC.textMute }}>1 owned · 2 joined</div>
        </div>

        {SERVERS.slice(1).map(s => (
          <MCCard key={s.id} style={{ marginBottom: 8, padding: 12 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
              <div style={{
                width: 40, height: 40, borderRadius: 10,
                background: MC.cardHi, border: `1px solid ${MC.line2}`,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>
                <span className="mono" style={{ fontSize: 11, color: s.verified ? accent : MC.textDim, fontWeight: 700, letterSpacing: 0.5 }}>{s.region.slice(0, 2)}</span>
              </div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div className="sans" style={{ fontSize: 14, fontWeight: 600, color: MC.text }}>{s.name}</div>
                <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 2 }}>
                  {s.tag} · Wipe +{s.wipe} · {s.owner ? 'Owner' : 'Member'}
                </div>
              </div>
              <div style={{ textAlign: 'right' }}>
                <div className="sans" style={{ fontSize: 15, fontWeight: 700, color: MC.text, fontVariantNumeric: 'tabular-nums', lineHeight: 1 }}>{s.players}</div>
                <div className="mono" style={{ fontSize: 9, color: MC.textMute }}>/{s.max}</div>
              </div>
              <div style={{ width: 6, height: 6, borderRadius: 3, background: MC.ok, boxShadow: `0 0 4px ${MC.ok}` }}/>
            </div>
          </MCCard>
        ))}

        <MCCard style={{ padding: 14, marginTop: 12, borderStyle: 'dashed', background: 'transparent' }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
            <div style={{ width: 32, height: 32, borderRadius: 8, background: `${accent}15`, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
              <Icon name="globe" size={16} color={accent}/>
            </div>
            <div style={{ flex: 1 }}>
              <div className="sans" style={{ fontSize: 13, fontWeight: 600 }}>Discover public CE servers</div>
              <div className="mono" style={{ fontSize: 9, color: MC.textDim, marginTop: 2 }}>342 servers in directory</div>
            </div>
            <Icon name="caret-right" size={14} color={MC.textDim}/>
          </div>
        </MCCard>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// SERVER SNAPSHOT
// ───────────────────────────────────────────────
function MCSnapshot({ accent, onBack, onOpenMap }) {
  const s = SERVERS[0];
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <div style={{ padding: '54px 18px 0', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <button onClick={onBack} className="sans" style={{ border: 0, background: 'transparent', color: MC.textDim, fontSize: 14, cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 4 }}>
          <Icon name="caret-left" size={14}/> Servers
        </button>
        <MCStatusPill color={MC.ok} label="LIVE · SYNC 02:14:08"/>
      </div>
      <MCHeader title={s.name} sub={`${s.tag} · ${s.host}`} accent={accent}/>
      <div style={{ padding: '0 18px 100px', overflow: 'auto', height: 'calc(100% - 200px)' }}>
        {/* Big stat tiles */}
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 }}>
          <MCCard glow accent={accent} style={{ padding: 14 }}>
            <div className="mono" style={{ fontSize: 9, color: MC.textMute, letterSpacing: 1.5, marginBottom: 4 }}>POPULATION</div>
            <div className="sans" style={{ fontSize: 32, fontWeight: 700, color: MC.text, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>187</div>
            <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 4 }}>of 250 · 75%</div>
            <div style={{ height: 4, background: MC.line, borderRadius: 2, marginTop: 8, overflow: 'hidden' }}>
              <div style={{ width: '75%', height: '100%', background: accent }}/>
            </div>
          </MCCard>
          <MCCard style={{ padding: 14 }}>
            <div className="mono" style={{ fontSize: 9, color: MC.textMute, letterSpacing: 1.5, marginBottom: 4 }}>FRAMERATE</div>
            <div className="sans" style={{ fontSize: 32, fontWeight: 700, color: MC.ok, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>252</div>
            <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 4 }}>fps · stable</div>
            {/* spark */}
            <svg viewBox="0 0 100 16" style={{ width: '100%', height: 16, marginTop: 8 }}>
              <path d="M0,10 L12,9 L24,11 L36,8 L48,9 L60,7 L72,8 L84,6 L96,7 L100,7"
                fill="none" stroke={MC.ok} strokeWidth="1.5"/>
            </svg>
          </MCCard>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 8, marginTop: 8 }}>
          {[
            ['Uptime', '4d 02h', 'started Mon'],
            ['Wipe in', '4d 18h', 'Thu 19:00'],
            ['Region', 'EU', 'Frankfurt'],
          ].map(([k, v, sub]) => (
            <MCCard key={k} style={{ padding: 10 }}>
              <div className="mono" style={{ fontSize: 9, color: MC.textMute, letterSpacing: 1 }}>{k.toUpperCase()}</div>
              <div className="sans" style={{ fontSize: 14, fontWeight: 700, marginTop: 2 }}>{v}</div>
              <div className="mono" style={{ fontSize: 9, color: MC.textMute, marginTop: 2 }}>{sub}</div>
            </MCCard>
          ))}
        </div>

        {/* Armed RF section */}
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '16px 4px 6px' }}>
          <div className="sans" style={{ fontSize: 12, color: MC.textDim, fontWeight: 600 }}>Armed RF · 2</div>
          <button className="mono" style={{ border: 0, background: 'transparent', color: accent, fontSize: 10, letterSpacing: 1, cursor: 'pointer' }}>VIEW ALL →</button>
        </div>
        {FREQS.slice(0, 2).map(f => (
          <MCCard key={f.id} style={{ marginBottom: 6, padding: 12 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
              <div style={{
                padding: '8px 12px', borderRadius: 10,
                background: `${accent}15`, border: `1px solid ${accent}33`,
                minWidth: 64, textAlign: 'center',
              }}>
                <div className="mono" style={{ fontSize: 16, fontWeight: 700, color: accent, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>{f.freq}</div>
              </div>
              <div style={{ flex: 1 }}>
                <div className="sans" style={{ fontSize: 13, fontWeight: 600 }}>{f.label}</div>
                <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 2 }}>{f.grid} · {f.scope}</div>
              </div>
              <Icon name={f.locked ? 'lock-simple' : 'lock-simple-open'} size={14} color={f.locked ? MC.amber : MC.textMute}/>
            </div>
          </MCCard>
        ))}

        {/* Entities */}
        <div style={{ padding: '12px 4px 6px' }}>
          <div className="sans" style={{ fontSize: 12, color: MC.textDim, fontWeight: 600 }}>Tracked entities · 4</div>
        </div>
        <MCCard style={{ padding: 0 }}>
          {ENTITIES.map((e, i) => (
            <div key={e.id} style={{ display: 'flex', alignItems: 'center', padding: '10px 12px', borderTop: i ? `1px solid ${MC.line}` : 0, gap: 12 }}>
              <div style={{
                width: 28, height: 28, borderRadius: 8,
                background: e.status === 'armed' ? `${MC.danger}22` : MC.cardHi,
                border: `1px solid ${e.status === 'armed' ? MC.danger : MC.line2}`,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
              }}>
                <span className="mono" style={{ fontSize: 9, color: e.status === 'armed' ? MC.danger : MC.textDim, fontWeight: 700 }}>{e.kind}</span>
              </div>
              <span className="sans" style={{ flex: 1, fontSize: 13, fontWeight: 500 }}>{e.label}</span>
              <span className="mono" style={{ fontSize: 10, color: MC.textDim, letterSpacing: 1 }}>{e.grid}</span>
            </div>
          ))}
        </MCCard>

        <div style={{ display: 'flex', gap: 8, marginTop: 12 }}>
          <MCBtn primary accent={accent} full size="md" onClick={onOpenMap}>
            <Icon name="map-pin" size={14}/>&nbsp;Open Map
          </MCBtn>
          <MCBtn accent={accent} size="md"><Icon name="megaphone" size={14}/></MCBtn>
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// WORLD MAP ★ HERO
// ───────────────────────────────────────────────
function MCMap({ accent }) {
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative', overflow: 'hidden' }}>
      <MCHeader title="World Map" sub="EU 3X MAX · PROCEDURAL 4500" accent={accent} right={
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 4 }}>
          <MCStatusPill color={MC.ok} label="SYNC 02:14:08"/>
        </div>
      }/>
      <div style={{ padding: '0 18px' }}>
        <MCCard glow accent={accent} style={{ padding: 0, overflow: 'hidden' }}>
          <div style={{ position: 'relative', width: '100%', aspectRatio: '1 / 1', background: '#04060B' }}>
            {/* Glow vignette */}
            <div style={{ position: 'absolute', inset: 0, background: `radial-gradient(ellipse at 60% 45%, ${accent}1A 0%, transparent 60%)`}}/>
            {/* Subtle grid */}
            <svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0 }}>
              <defs>
                <pattern id="mcgrid" width={100/18} height={100/18} patternUnits="userSpaceOnUse">
                  <path d={`M0,0 L${100/18},0 M0,0 L0,${100/18}`} stroke={accent} strokeOpacity={0.06} strokeWidth="0.15"/>
                </pattern>
                <radialGradient id="mcland">
                  <stop offset="0%" stopColor={accent} stopOpacity="0.08"/>
                  <stop offset="100%" stopColor={accent} stopOpacity="0"/>
                </radialGradient>
              </defs>
              <rect width="100" height="100" fill="url(#mcgrid)"/>
              {/* terrain */}
              <path d="M8,28 Q22,16 38,22 T62,26 Q78,16 92,30 L92,72 Q82,86 60,82 T28,78 Q8,80 8,72 Z"
                fill="url(#mcland)" stroke={`${accent}44`} strokeWidth="0.4"/>
              {/* contour lines */}
              <path d="M20,40 Q40,52 60,46 T85,52" stroke={`${accent}33`} strokeWidth="0.25" fill="none"/>
              <path d="M25,55 Q42,62 60,58 T82,62" stroke={`${accent}22`} strokeWidth="0.2" fill="none"/>
              {/* roads */}
              <path d="M15,50 Q35,50 50,55 T88,52" stroke={MC.textMute} strokeOpacity={0.4} strokeDasharray="1.5,1.5" strokeWidth="0.3" fill="none"/>
            </svg>
            {/* Grid coords */}
            {'ABCDEFGHIJKLMNOPQR'.split('').map((c, i) => (
              <div key={c} className="mono" style={{ position: 'absolute', top: 6, left: `${(i + 0.5) * (100 / 18)}%`, transform: 'translateX(-50%)', fontSize: 7, color: MC.textMute, fontWeight: 600 }}>{c}</div>
            ))}
            {/* Monuments */}
            {MONUMENTS.map(m => {
              const col = m.type === 'safe' ? MC.ok : m.type === 'tier3' ? accent : MC.textDim;
              return (
                <div key={m.id} style={{
                  position: 'absolute', left: `${m.x * 100}%`, top: `${m.y * 100}%`, transform: 'translate(-50%, -50%)',
                }}>
                  <div style={{
                    width: 8, height: 8, borderRadius: '50%', background: col,
                    boxShadow: `0 0 10px ${col}, 0 0 20px ${col}66`,
                  }}/>
                  <div className="sans" style={{
                    position: 'absolute', top: 11, left: '50%', transform: 'translateX(-50%)',
                    fontSize: 8, color: col, fontWeight: 600, whiteSpace: 'nowrap', letterSpacing: 0.5,
                    textShadow: '0 0 4px #000, 0 1px 2px #000',
                  }}>{m.name}</div>
                </div>
              );
            })}
            {/* Entities — glowy */}
            {ENTITIES.map(e => (
              <div key={e.id} style={{
                position: 'absolute', left: `${e.x * 100}%`, top: `${e.y * 100}%`, transform: 'translate(-50%, -50%)',
              }}>
                {e.status === 'armed' && (
                  <>
                    <div style={{ position: 'absolute', inset: -10, borderRadius: '50%', background: `${MC.danger}33`, animation: 'adley-pingdot 1.6s infinite' }}/>
                    <div style={{ position: 'absolute', inset: -5, borderRadius: '50%', background: `${MC.danger}55`, animation: 'adley-pulse 1.2s infinite' }}/>
                  </>
                )}
                <div style={{
                  width: 18, height: 18, borderRadius: 6,
                  background: e.status === 'armed' ? MC.danger : `${accent}22`,
                  border: `1.5px solid ${e.status === 'armed' ? MC.danger : accent}`,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  boxShadow: e.status === 'armed' ? `0 0 12px ${MC.danger}` : `0 0 8px ${accent}55`,
                  position: 'relative',
                }}>
                  <span className="mono" style={{ fontSize: 7, color: '#fff', fontWeight: 700, letterSpacing: 0.5 }}>{e.kind}</span>
                </div>
              </div>
            ))}
          </div>
        </MCCard>

        {/* Selected entity callout */}
        <MCCard glow accent={MC.danger} style={{ marginTop: 12, padding: 14 }}>
          <div style={{ display: 'flex', gap: 12, alignItems: 'center' }}>
            <div style={{
              width: 48, height: 48, borderRadius: 12,
              background: `linear-gradient(135deg, ${MC.danger}66, ${MC.danger}22)`,
              border: `1px solid ${MC.danger}`,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              boxShadow: `0 0 20px ${MC.danger}55`, position: 'relative',
              animation: 'adley-pulse 2s infinite',
            }}>
              <span className="mono" style={{ fontSize: 11, color: '#fff', fontWeight: 700 }}>TC</span>
            </div>
            <div style={{ flex: 1 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 2 }}>
                <MCStatusPill color={MC.danger} label="ARMED"/>
              </div>
              <div className="sans" style={{ fontSize: 15, fontWeight: 700 }}>Main TC · Bldg Alpha</div>
              <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 2 }}>Freq 4763 · last trip 02:14:00</div>
            </div>
            <div style={{ textAlign: 'right' }}>
              <div className="sans" style={{ fontSize: 28, fontWeight: 700, color: MC.danger, lineHeight: 1, fontVariantNumeric: 'tabular-nums' }}>G14</div>
            </div>
          </div>
        </MCCard>

        {/* Filter chips */}
        <div style={{ display: 'flex', gap: 6, marginTop: 12, flexWrap: 'wrap' }}>
          {[
            ['Monuments', true], ['TC', true], ['Bags', true], ['Cargo', false], ['Heli', false],
          ].map(([l, on]) => (
            <button key={l} className="sans" style={{
              padding: '6px 10px', borderRadius: 999, fontSize: 11, fontWeight: 600,
              border: `1px solid ${on ? `${accent}55` : MC.line}`,
              background: on ? `${accent}22` : 'transparent',
              color: on ? accent : MC.textDim, cursor: 'pointer',
            }}>{l}</button>
          ))}
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// RAID ALERT
// ───────────────────────────────────────────────
function MCRaidAlert({ accent }) {
  return (
    <div style={{ height: '100%', background: '#0A0204', color: MC.text, position: 'relative', overflow: 'hidden' }}>
      <div style={{ position: 'absolute', inset: 0, background: `radial-gradient(ellipse at 50% 30%, ${MC.danger}33, transparent 60%)`, animation: 'adley-strobe-soft 0.7s steps(1) infinite' }}/>
      <div style={{ position: 'absolute', inset: 0, background: MC.danger, opacity: 0.03, animation: 'adley-strobe-soft 0.5s steps(1) infinite' }}/>

      <div style={{ padding: '60px 24px 0', position: 'relative', zIndex: 5 }}>
        {/* Top */}
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, marginBottom: 8 }}>
          <div style={{ width: 8, height: 8, borderRadius: 4, background: MC.danger, boxShadow: `0 0 10px ${MC.danger}`, animation: 'adley-blink 0.5s infinite' }}/>
          <span className="mono" style={{ fontSize: 11, color: MC.danger, letterSpacing: 6, fontWeight: 700 }}>RAID DETECTED</span>
        </div>

        {/* Big freq with glow */}
        <div style={{ textAlign: 'center', marginTop: 30, position: 'relative' }}>
          <div style={{ position: 'absolute', inset: '20px 30%', background: `radial-gradient(${MC.danger}66, transparent 70%)`, filter: 'blur(20px)' }}/>
          <div className="mono" style={{ fontSize: 10, color: MC.danger, letterSpacing: 4, marginBottom: 6, position: 'relative' }}>FREQUENCY</div>
          <div className="sans" style={{
            fontSize: 88, fontWeight: 800, color: '#fff', letterSpacing: -3, lineHeight: 1,
            fontVariantNumeric: 'tabular-nums',
            textShadow: `0 0 32px ${MC.danger}, 0 0 64px ${MC.danger}88`,
            position: 'relative',
          }}>4763</div>
          <div className="sans" style={{ fontSize: 12, color: MC.textDim, marginTop: 8, fontWeight: 500 }}>Main TC · STORM-7</div>
        </div>

        {/* Grid + base card */}
        <MCCard glow accent={MC.danger} style={{ marginTop: 36, padding: 18, background: 'rgba(20,3,5,0.8)', borderColor: MC.danger, backdropFilter: 'blur(20px)' }}>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 18 }}>
            <div>
              <div className="mono" style={{ fontSize: 9, color: MC.danger, letterSpacing: 3, marginBottom: 4 }}>GRID</div>
              <div className="sans" style={{ fontSize: 48, fontWeight: 800, color: '#fff', lineHeight: 1, letterSpacing: -1 }}>G14</div>
              <div className="mono" style={{ fontSize: 9, color: MC.textDim, marginTop: 6, letterSpacing: 1 }}>NORTH-WEST QUAD</div>
            </div>
            <div>
              <div className="mono" style={{ fontSize: 9, color: MC.danger, letterSpacing: 3, marginBottom: 4 }}>BASE</div>
              <div className="sans" style={{ fontSize: 16, fontWeight: 700, color: '#fff', lineHeight: 1.2, letterSpacing: -0.2 }}>Bldg Alpha</div>
              <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 4 }}>EU 3X MAX</div>
              <div className="mono" style={{ fontSize: 10, color: MC.textDim }}>T+00:08 · 6/6 notified</div>
            </div>
          </div>
        </MCCard>

        <div className="mono" style={{ marginTop: 22, fontSize: 10, color: MC.danger, textAlign: 'center', letterSpacing: 4, animation: 'adley-blink 0.6s infinite' }}>
          ◉ SIREN LOOP ACTIVE ◉
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, marginTop: 32 }}>
          <MCBtn size="lg" style={{ background: MC.danger, color: '#fff', borderColor: MC.danger, fontWeight: 700, boxShadow: `0 0 24px ${MC.danger}88` }}>
            <Icon name="crosshair" size={14}/> Jump to Map
          </MCBtn>
          <MCBtn size="lg" danger>Silence 60s</MCBtn>
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// LOCK SCREEN
// ───────────────────────────────────────────────
function MCLockScreen({ accent }) {
  return (
    <div style={{ height: '100%', background: '#000', color: MC.text, position: 'relative', overflow: 'hidden' }}>
      {/* Wallpaper */}
      <div style={{ position: 'absolute', inset: 0, background: `
        radial-gradient(ellipse at 20% 25%, ${accent}1A, transparent 50%),
        radial-gradient(ellipse at 75% 75%, ${MC.danger}10, transparent 55%),
        linear-gradient(180deg, #05060B 0%, #0A0C12 100%)
      `}}>
        <svg width="100%" height="100%" style={{ position: 'absolute', inset: 0, opacity: 0.18 }}>
          <defs>
            <pattern id="mclpat" width="40" height="40" patternUnits="userSpaceOnUse">
              <circle cx="0" cy="0" r="1" fill={accent}/>
              <circle cx="40" cy="40" r="1" fill={accent}/>
            </pattern>
          </defs>
          <rect width="100%" height="100%" fill="url(#mclpat)"/>
        </svg>
        {/* Map silhouette in bg */}
        <svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid slice" style={{ position: 'absolute', inset: 0, opacity: 0.18 }}>
          <path d="M8,28 Q22,16 38,22 T62,26 Q78,16 92,30 L92,72 Q82,86 60,82 T28,78 Q8,80 8,72 Z" fill={`${accent}55`} stroke={accent} strokeWidth="0.3"/>
        </svg>
      </div>

      {/* Time */}
      <div style={{ position: 'absolute', top: 80, left: 0, right: 0, textAlign: 'center', zIndex: 10 }}>
        <div className="sans" style={{ fontSize: 14, color: MC.textDim, letterSpacing: 2, marginBottom: 4, fontWeight: 500 }}>Friday, 22 May</div>
        <div className="sans" style={{ fontSize: 88, fontWeight: 200, color: '#fff', letterSpacing: -3, lineHeight: 1 }}>02:14</div>
      </div>

      {/* Live Activity */}
      <div style={{ position: 'absolute', top: 270, left: 16, right: 16, zIndex: 10 }}>
        <div style={{
          background: 'rgba(15,17,24,0.7)', borderRadius: 22, padding: 16,
          border: `1px solid ${accent}33`, boxShadow: `0 0 0 1px ${accent}11, 0 8px 32px rgba(0,0,0,0.4)`,
          backdropFilter: 'blur(24px)', WebkitBackdropFilter: 'blur(24px)',
        }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 14 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
              <div style={{ width: 26, height: 26, borderRadius: 7, background: `linear-gradient(135deg, ${accent}, ${accent}88)`, display: 'flex', alignItems: 'center', justifyContent: 'center', boxShadow: `0 0 8px ${accent}55` }}>
                <span className="sans" style={{ color: '#000', fontSize: 13, fontWeight: 800 }}>A</span>
              </div>
              <div>
                <div className="sans" style={{ fontSize: 13, fontWeight: 700 }}>EU 3X MAX</div>
                <div className="mono" style={{ fontSize: 9, color: MC.textDim, letterSpacing: 1 }}>STORM-7 · LIVE</div>
              </div>
            </div>
            <div style={{ width: 8, height: 8, borderRadius: 4, background: MC.ok, boxShadow: `0 0 6px ${MC.ok}`, animation: 'adley-pulse 2s infinite' }}/>
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
            {[
              ['Pop', '187', MC.text, '/250'],
              ['FPS', '252', MC.ok, 'stbl'],
              ['RF', '02', accent, 'arm'],
              ['Evt', '14', MC.textDim, '/hr'],
            ].map(([k, v, c, sub]) => (
              <div key={k} style={{ background: 'rgba(255,255,255,0.04)', borderRadius: 10, padding: '8px 6px', textAlign: 'center' }}>
                <div className="mono" style={{ fontSize: 8, color: MC.textMute, letterSpacing: 1 }}>{k.toUpperCase()}</div>
                <div className="sans" style={{ fontSize: 18, fontWeight: 700, color: c, lineHeight: 1.2, fontVariantNumeric: 'tabular-nums' }}>{v}</div>
                <div className="mono" style={{ fontSize: 8, color: MC.textMute }}>{sub}</div>
              </div>
            ))}
          </div>
        </div>
        <div className="mono" style={{ fontSize: 9, color: MC.textMute, letterSpacing: 2, textAlign: 'center', marginTop: 8 }}>
          Live Activity
        </div>
      </div>

      {/* Raid notif (incoming) */}
      <div style={{ position: 'absolute', top: 470, left: 16, right: 16, zIndex: 10 }}>
        <div style={{
          background: 'rgba(30,4,8,0.85)', borderRadius: 18, padding: 14,
          border: `1px solid ${MC.danger}`, boxShadow: `0 0 0 2px ${MC.danger}33, 0 8px 32px ${MC.danger}55`,
          backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)',
          animation: 'adley-strobe-soft 0.7s steps(1) infinite',
        }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
              <div style={{ width: 8, height: 8, borderRadius: 4, background: MC.danger, boxShadow: `0 0 8px ${MC.danger}`, animation: 'adley-blink 0.5s infinite' }}/>
              <span className="sans" style={{ fontSize: 11, color: MC.danger, letterSpacing: 2, fontWeight: 700 }}>RAID · ADLEY</span>
            </div>
            <span className="mono" style={{ fontSize: 9, color: MC.textDim }}>now</span>
          </div>
          <div className="sans" style={{ fontSize: 14, color: '#fff', fontWeight: 700, marginBottom: 4 }}>TC tripped · 4763</div>
          <div className="mono" style={{ fontSize: 10, color: MC.textDim, letterSpacing: 0.5 }}>G14 · Bldg Alpha · STORM-7</div>
        </div>
      </div>

      {/* Dynamic island */}
      <div style={{
        position: 'absolute', top: 11, left: '50%', transform: 'translateX(-50%)',
        background: '#000', borderRadius: 24, height: 37, padding: '0 16px 0 50px',
        display: 'flex', alignItems: 'center', gap: 8, zIndex: 51,
        boxShadow: `0 0 16px ${MC.danger}88`,
      }}>
        <div style={{ width: 8, height: 8, borderRadius: 4, background: MC.danger, animation: 'adley-blink 0.5s infinite' }}/>
        <span className="sans" style={{ fontSize: 11, color: MC.danger, fontWeight: 700 }}>RAID · G14</span>
      </div>

      <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: 22, background: 'rgba(40,40,50,0.6)', display: 'flex', alignItems: 'center', justifyContent: 'center', backdropFilter: 'blur(20px)' }}>
          <Icon name="flashlight" size={18} color="#fff"/>
        </div>
        <div style={{ width: 44, height: 44, borderRadius: 22, background: 'rgba(40,40,50,0.6)', display: 'flex', alignItems: 'center', justifyContent: 'center', backdropFilter: 'blur(20px)' }}>
          <Icon name="camera" size={18} color="#fff"/>
        </div>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// ARMED FREQS
// ───────────────────────────────────────────────
function MCFreqs({ accent }) {
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <MCHeader title="Armed RF" sub="TRIP-WIRES · 5 ACTIVE" accent={accent} right={
        <MCBtn primary accent={accent} size="sm"><Icon name="plus" size={12}/>&nbsp;Arm</MCBtn>
      }/>
      <div style={{ padding: '0 18px 100px', overflow: 'auto', height: 'calc(100% - 140px)' }}>
        {/* Scope toggle */}
        <div style={{ display: 'flex', gap: 4, background: MC.card, padding: 3, borderRadius: 10, marginBottom: 12 }}>
          {['All · 5', 'Squad · 3', 'Mine · 2'].map((t, i) => (
            <button key={t} className="sans" style={{
              flex: 1, padding: '6px 8px', borderRadius: 8, fontSize: 11, fontWeight: 600,
              border: 0, background: i === 0 ? MC.cardHi : 'transparent',
              color: i === 0 ? MC.text : MC.textDim, cursor: 'pointer',
            }}>{t}</button>
          ))}
        </div>

        {FREQS.map(f => {
          const recent = f.triggered.includes('ago');
          return (
            <MCCard key={f.id} glow={recent} accent={MC.danger} style={{ marginBottom: 8, padding: 14 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
                <div style={{
                  padding: '10px 8px', borderRadius: 12,
                  background: `linear-gradient(135deg, ${recent ? MC.danger : accent}22, ${recent ? MC.danger : accent}05)`,
                  border: `1px solid ${recent ? MC.danger : accent}55`,
                  minWidth: 78, textAlign: 'center', boxShadow: `0 0 12px ${recent ? MC.danger : accent}22`,
                }}>
                  <div className="mono" style={{ fontSize: 7, color: recent ? MC.danger : accent, letterSpacing: 2, marginBottom: 2 }}>MHz</div>
                  <div className="mono" style={{ fontSize: 20, fontWeight: 700, color: recent ? MC.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="sans" style={{ fontSize: 14, fontWeight: 600 }}>{f.label}</span>
                    {f.locked && <Icon name="lock-simple" size={11} color={MC.amber}/>}
                  </div>
                  <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginBottom: 4 }}>
                    <span style={{ color: accent }}>{f.grid}</span> · {f.scope.toLowerCase()}{f.squad ? ` · ${f.squad}` : ''}
                  </div>
                  <div className="mono" style={{ fontSize: 9, color: recent ? MC.danger : MC.textMute, letterSpacing: 0.5 }}>
                    last trip · {f.triggered}
                  </div>
                </div>
              </div>
            </MCCard>
          );
        })}

        {/* Arm new */}
        <MCCard style={{ marginTop: 16, padding: 14, borderStyle: 'dashed', borderColor: `${accent}55` }}>
          <div className="sans" style={{ fontSize: 12, color: accent, fontWeight: 600, marginBottom: 8 }}>Arm new frequency</div>
          <div style={{ display: 'flex', gap: 6 }}>
            {[4,7,6,3].map((d, i) => (
              <div key={i} className="sans" style={{
                flex: 1, height: 56, borderRadius: 10, border: `1px solid ${accent}66`,
                background: MC.cardHi,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                fontSize: 28, fontWeight: 700, color: accent, fontVariantNumeric: 'tabular-nums',
              }}>{d}</div>
            ))}
          </div>
          <div style={{ display: 'flex', gap: 4, marginTop: 10, background: MC.cardHi, padding: 3, borderRadius: 8 }}>
            {['User', 'Squad'].map((s, i) => (
              <button key={s} className="sans" style={{
                flex: 1, padding: '5px', borderRadius: 6, fontSize: 11, fontWeight: 600,
                border: 0, background: i === 1 ? accent : 'transparent',
                color: i === 1 ? '#000' : MC.textDim, cursor: 'pointer',
              }}>{s}</button>
            ))}
          </div>
        </MCCard>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// SQUAD
// ───────────────────────────────────────────────
function MCSquad({ accent }) {
  const sq = SQUAD;
  const online = sq.members.filter(m => m.status === 'ONLINE').length;
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <MCHeader title={sq.name} sub={`SQUAD · ${sq.server}`} accent={accent} right={
        <MCStatusPill color={MC.ok} label={`${online}/${sq.members.length} ONLINE`}/>
      }/>
      <div style={{ padding: '0 18px 100px', overflow: 'auto', height: 'calc(100% - 140px)' }}>
        <MCCard glow accent={accent} style={{ padding: 18 }}>
          <div className="mono" style={{ fontSize: 9, color: accent, letterSpacing: 2, marginBottom: 8 }}>INVITE CODE</div>
          <div className="sans" style={{ fontSize: 30, fontWeight: 700, color: '#fff', letterSpacing: 4, fontVariantNumeric: 'tabular-nums', textShadow: `0 0 16px ${accent}55` }}>{sq.code}</div>
          <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 6 }}>Expires in 23h 14m</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 6, marginTop: 14 }}>
            <MCBtn accent={accent} size="sm"><Icon name="copy" size={12}/> Copy</MCBtn>
            <MCBtn accent={accent} size="sm"><Icon name="share-network" size={12}/> Share</MCBtn>
            <MCBtn accent={accent} size="sm"><Icon name="arrows-clockwise" size={12}/> Regen</MCBtn>
          </div>
        </MCCard>

        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '16px 4px 6px' }}>
          <div className="sans" style={{ fontSize: 12, color: MC.textDim, fontWeight: 600 }}>Roster · {sq.members.length}</div>
          <button className="mono" style={{ border: 0, background: 'transparent', color: accent, fontSize: 10, letterSpacing: 1, cursor: 'pointer' }}>SORT ↓</button>
        </div>
        <MCCard style={{ padding: 0 }}>
          {sq.members.map((m, i) => (
            <div key={m.id} style={{ padding: '12px 14px', borderTop: i ? `1px solid ${MC.line}` : 0, display: 'flex', alignItems: 'center', gap: 12 }}>
              <div style={{
                width: 40, height: 40, borderRadius: 10,
                background: m.status === 'ONLINE' ? `linear-gradient(135deg, ${accent}33, ${accent}11)` : MC.cardHi,
                border: `1px solid ${m.status === 'ONLINE' ? `${accent}55` : MC.line2}`,
                color: m.status === 'ONLINE' ? accent : MC.textMute,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                fontSize: 13, fontWeight: 700, letterSpacing: 0.5, position: 'relative',
              }} className="sans">
                {m.name.slice(0, 2)}
                {m.status === 'ONLINE' && (
                  <div style={{
                    position: 'absolute', bottom: -2, right: -2, width: 12, height: 12, borderRadius: 6,
                    background: MC.ok, border: `2px solid ${MC.card}`, boxShadow: `0 0 4px ${MC.ok}`,
                  }}/>
                )}
              </div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
                  <span className="sans" style={{ fontSize: 14, fontWeight: 600 }}>{m.name}</span>
                  {m.role === 'LEADER' && <MCStatusPill color={accent} label="LEAD"/>}
                </div>
                <div className="mono" style={{ fontSize: 10, color: MC.textDim, marginTop: 2 }}>
                  K/D {m.kdr} · {m.hours}h
                </div>
              </div>
              <Icon name="dots-three" size={16} color={MC.textMute}/>
            </div>
          ))}
        </MCCard>

        <MCBtn danger full size="md" style={{ marginTop: 16 }}>
          <Icon name="sign-out" size={14}/> Leave Squad
        </MCBtn>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// EVENT FEED
// ───────────────────────────────────────────────
function MCEvents({ accent }) {
  const sev = (s) => s === 'crit' ? MC.danger : s === 'warn' ? MC.amber : MC.textDim;
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <MCHeader title="Event Feed" sub="SSE STREAM · LIVE" accent={accent} right={
        <MCStatusPill color={MC.ok} label="STREAM"/>
      }/>
      <div style={{ padding: '0 18px 100px', overflow: 'auto', height: 'calc(100% - 140px)' }}>
        <div style={{ display: 'flex', gap: 6, marginBottom: 12, overflowX: 'auto' }}>
          {['All · 14', 'Raid', 'PvP', 'World', 'RF'].map((f, i) => (
            <button key={f} className="sans" style={{
              padding: '6px 12px', borderRadius: 999, fontSize: 11, fontWeight: 600, whiteSpace: 'nowrap',
              border: `1px solid ${i === 0 ? `${accent}55` : MC.line}`,
              background: i === 0 ? `${accent}22` : MC.card,
              color: i === 0 ? accent : MC.textDim, cursor: 'pointer',
            }}>{f}</button>
          ))}
        </div>

        {EVENTS.map((e, i) => (
          <div key={i} style={{
            display: 'flex', gap: 10, padding: '10px 4px', borderBottom: `1px solid ${MC.line}`,
            alignItems: 'flex-start',
          }}>
            <div style={{
              width: 32, height: 32, borderRadius: 8, flexShrink: 0,
              background: `${sev(e.sev)}15`, border: `1px solid ${sev(e.sev)}33`,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
            }}>
              <Icon name={e.glyph} size={14} color={sev(e.sev)}/>
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div className="sans" style={{ fontSize: 13, fontWeight: e.sev === 'crit' ? 600 : 500, color: e.sev === 'crit' ? '#fff' : MC.text, letterSpacing: 0.1 }}>
                {e.text}
              </div>
              <div style={{ display: 'flex', gap: 8, marginTop: 3 }}>
                <span className="mono" style={{ fontSize: 9, color: sev(e.sev), letterSpacing: 1.5, fontWeight: 600 }}>{e.kind.toUpperCase()}</span>
                <span className="mono" style={{ fontSize: 9, color: MC.textMute, fontVariantNumeric: 'tabular-nums' }}>{e.t}</span>
              </div>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// STATS
// ───────────────────────────────────────────────
function MCStats({ accent }) {
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <MCHeader title="Telemetry" sub="EU 3X MAX · 24H" accent={accent}/>
      <div style={{ padding: '0 18px 100px', overflow: 'auto', height: 'calc(100% - 140px)' }}>
        {[
          ['Raid events', STATS_24H.raids, MC.danger, 9, 'TC trips & explosions'],
          ['PvP kills', STATS_24H.pvp, accent, 64, 'Player & sleeper deaths'],
          ['World events', STATS_24H.world, MC.amber, 71, 'Cargo, heli, supply, ship'],
        ].map(([label, data, color, total, sub]) => (
          <MCCard key={label} style={{ padding: 14, marginBottom: 10 }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 12 }}>
              <div>
                <div className="sans" style={{ fontSize: 12, color: MC.textDim, fontWeight: 600 }}>{label}</div>
                <div className="sans" style={{ fontSize: 28, fontWeight: 700, color, lineHeight: 1.2, marginTop: 2, fontVariantNumeric: 'tabular-nums' }}>{total}</div>
                <div className="mono" style={{ fontSize: 9, color: MC.textMute, marginTop: 2 }}>{sub}</div>
              </div>
              <div style={{ textAlign: 'right' }}>
                <div className="mono" style={{ fontSize: 9, color: MC.textMute, letterSpacing: 1 }}>PEAK</div>
                <div className="sans" style={{ fontSize: 13, fontWeight: 700, color: MC.text }}>20:00</div>
              </div>
            </div>
            <Bars data={data} color={color} height={56}/>
            <div className="mono" style={{ display: 'flex', justifyContent: 'space-between', fontSize: 8, color: MC.textMute, marginTop: 6, letterSpacing: 1 }}>
              <span>−24h</span><span>−18</span><span>−12</span><span>−06</span><span>now</span>
            </div>
          </MCCard>
        ))}
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// RCON ONBOARDING
// ───────────────────────────────────────────────
function MCRcon({ accent }) {
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <div style={{ padding: '54px 18px 0', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <button className="sans" style={{ border: 0, background: 'transparent', color: MC.textDim, fontSize: 14, cursor: 'pointer' }}>Cancel</button>
        <div className="mono" style={{ fontSize: 10, color: MC.textMute, letterSpacing: 2 }}>STEP 2 / 3</div>
      </div>
      <MCHeader title="RCON Creds" sub="LINK YOUR CE SERVER" accent={accent}/>
      <div style={{ padding: '0 18px' }}>
        {/* Progress */}
        <div style={{ display: 'flex', gap: 6, marginBottom: 16 }}>
          {[1, 2, 3].map(n => (
            <div key={n} style={{ flex: 1, height: 4, borderRadius: 2, background: n <= 2 ? accent : MC.line, boxShadow: n <= 2 ? `0 0 6px ${accent}88` : 'none' }}/>
          ))}
        </div>

        <div className="sans" style={{ fontSize: 13, color: MC.textDim, lineHeight: 1.5, marginBottom: 16 }}>
          Adley connects via WebRCON. Paste your <code className="mono" style={{ color: accent, fontSize: 12, background: MC.card, padding: '1px 5px', borderRadius: 4 }}>rcon.port</code> and{' '}
          <code className="mono" style={{ color: accent, fontSize: 12, background: MC.card, padding: '1px 5px', borderRadius: 4 }}>rcon.password</code> from server.cfg.
        </div>

        {[
          { l: 'Host / IP', v: '185.244.218.42', mono: true },
          { l: 'RCON Port', v: '28016', mono: true },
          { l: 'Password', v: '••••••••••••', mono: true },
          { l: 'Nickname', v: 'EU 3X MAX', mono: false },
        ].map(f => (
          <div key={f.l} style={{ marginBottom: 10 }}>
            <div className="sans" style={{ fontSize: 11, color: MC.textDim, fontWeight: 600, marginBottom: 4 }}>{f.l}</div>
            <MCCard style={{ padding: 12, background: MC.cardHi }}>
              <div className={f.mono ? 'mono' : 'sans'} style={{ fontSize: 14, color: MC.text, letterSpacing: f.mono ? 0.5 : 0 }}>{f.v}</div>
            </MCCard>
          </div>
        ))}

        <MCCard glow accent={MC.ok} style={{ marginTop: 14, padding: 14, borderColor: `${MC.ok}66` }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
            <div style={{ width: 8, height: 8, borderRadius: 4, background: MC.ok, boxShadow: `0 0 8px ${MC.ok}`, animation: 'adley-pulse 1.5s infinite' }}/>
            <span className="sans" style={{ fontSize: 12, color: MC.ok, fontWeight: 700, letterSpacing: 0.5 }}>Handshake OK</span>
          </div>
          <div className="mono" style={{ fontSize: 10, color: MC.textDim, lineHeight: 1.6 }}>
            <div>→ rust 2503 · build 87642</div>
            <div>→ sse subscribed</div>
            <div>→ entities 4 · monuments 12</div>
          </div>
        </MCCard>

        <MCBtn primary accent={accent} full size="lg" style={{ marginTop: 18 }}>
          Link Server <Icon name="arrow-right" size={14}/>
        </MCBtn>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// FLOW WRAPPER
// ───────────────────────────────────────────────
function MCFlow({ accent, initial = 'home' }) {
  const [screen, setScreen] = React.useState(initial);
  const [serverOpen, setServerOpen] = React.useState(false);
  const view = serverOpen ? <MCSnapshot accent={accent} onBack={() => setServerOpen(false)} onOpenMap={() => { setServerOpen(false); setScreen('map'); }}/>
    : screen === 'home' ? <MCHome accent={accent} onOpenServer={() => setServerOpen(true)}/>
    : screen === 'map' ? <MCMap accent={accent}/>
    : screen === 'freqs' ? <MCFreqs accent={accent}/>
    : screen === 'events' ? <MCEvents accent={accent}/>
    : screen === 'squad' ? <MCSquad accent={accent}/>
    : <MCHome accent={accent}/>;
  return (
    <div style={{ height: '100%', position: 'relative', background: MC.bg }}>
      {view}
      <MCTabBar screen={serverOpen ? '' : screen} onChange={(id) => { setServerOpen(false); setScreen(id); }} accent={accent}/>
    </div>
  );
}

// ───────────────────────────────────────────────
// CHAT — live in-game chat with reply + moderation
// ───────────────────────────────────────────────
function MCChat({ accent }) {
  const lines = [
    { who: 'KOMA',     text: 'anyone seeing heli?', t: '02:13' },
    { who: 'WRAITH',   text: 'g11, taking fire', t: '02:13' },
    { who: 'P0LARIS',  text: 'rolling 30s', t: '02:14' },
    { who: 'SERVER',   text: 'cargo ship spawned at G06', t: '02:14', server: true },
    { who: 'you',      text: 'on the way', t: '02:14', mine: true },
    { who: 'STRMR',    text: 'gg ez', t: '02:15' },
  ];
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <MCHeader title="Server Chat" sub="EU 3X MAX · LIVE" accent={accent} right={
        <MCStatusPill color={MC.ok} label="LIVE"/>
      }/>
      <div style={{ padding: '0 18px 100px', overflow: 'auto', height: 'calc(100% - 140px)' }}>
        {lines.map((l, i) => {
          const color = l.mine ? accent : l.server ? MC.amber : MC.text;
          const prompt = l.mine ? '*' : '>';
          return (
            <div key={i} style={{
              display: 'grid', gridTemplateColumns: '14px 1fr auto', gap: 8, padding: '8px 4px',
              borderBottom: `1px solid ${MC.line}`, alignItems: 'baseline',
            }}>
              <span className="mono" style={{ fontSize: 12, color: MC.textMute, fontWeight: 700 }}>{prompt}</span>
              <div style={{ minWidth: 0 }}>
                <span className="mono" style={{ fontSize: 11, color: l.server ? MC.amber : MC.textDim, fontWeight: 600, marginRight: 6 }}>
                  {l.who}:
                </span>
                <span className="sans" style={{ fontSize: 13, color, letterSpacing: 0.1 }}>{l.text}</span>
              </div>
              <span className="mono" style={{ fontSize: 9, color: MC.textMute, fontVariantNumeric: 'tabular-nums' }}>{l.t}</span>
            </div>
          );
        })}
      </div>
      <div style={{
        position: 'absolute', left: 12, right: 12, bottom: 80,
        background: MC.card, border: `1px solid ${MC.line2}`, borderRadius: radius,
        padding: '10px 14px', display: 'flex', alignItems: 'center', gap: 10,
      }}>
        <span className="mono" style={{ fontSize: 11, color: MC.textMute }}>/say</span>
        <span className="sans" style={{ flex: 1, fontSize: 13, color: MC.textDim }}>type a message…</span>
        <span style={{
          padding: '4px 10px', background: accent, color: '#000',
          fontFamily: "ui-monospace, monospace", fontSize: 10, fontWeight: 700, letterSpacing: 1.5, borderRadius: 6,
        }}>SEND</span>
      </div>
    </div>
  );
}

// ───────────────────────────────────────────────
// AUTO-SAY — server-admin broadcast bot
// ───────────────────────────────────────────────
function MCAutoSay({ accent }) {
  const rules = [
    { evt: 'CARGO SPAWN',      tpl: 'cargo at {grid} — fight\'s on', on: true },
    { evt: 'PATROL HELI',      tpl: 'heli inbound, hold cover',      on: true },
    { evt: 'BRADLEY DOWN',     tpl: 'brad cracked at {grid}',         on: true },
    { evt: 'SUPPLY DROP',      tpl: 'supply dropping {grid}',         on: false },
    { evt: 'OILRIG TRIGGERED', tpl: 'oilrig hot — heli in 15m',       on: true },
  ];
  return (
    <div style={{ height: '100%', background: MC.bg, color: MC.text, position: 'relative' }}>
      <MCHeader title="Auto-Say" sub="ADMIN · BROADCASTS" accent={accent} right={
        <MCStatusPill color={MC.ok} label="ACTIVE"/>
      }/>
      <div style={{ padding: '0 18px 100px', overflow: 'auto', height: 'calc(100% - 140px)' }}>
        <div className="sans" style={{ fontSize: 11, color: MC.textDim, letterSpacing: 1, marginBottom: 14, textTransform: 'uppercase' }}>
          per-event rcon broadcasts
        </div>
        {rules.map((r, i) => (
          <div key={i} style={{
            display: 'grid', gridTemplateColumns: '1fr 42px', gap: 12, padding: '12px 4px',
            borderBottom: `1px solid ${MC.line}`, alignItems: 'center',
          }}>
            <div style={{ minWidth: 0 }}>
              <div className="mono" style={{ fontSize: 10, color: accent, letterSpacing: 2, fontWeight: 600, marginBottom: 4 }}>
                {r.evt}
              </div>
              <div className="sans" style={{ fontSize: 13, color: r.on ? MC.text : MC.textMute, letterSpacing: 0.1 }}>
                "{r.tpl}"
              </div>
            </div>
            <div style={{
              width: 36, height: 22, borderRadius: 999,
              background: r.on ? accent : MC.line2, position: 'relative',
              transition: 'background 0.15s',
            }}>
              <div style={{
                position: 'absolute', top: 2, left: r.on ? 16 : 2,
                width: 18, height: 18, borderRadius: 999, background: '#000',
                transition: 'left 0.15s',
              }}/>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

Object.assign(window, {
  MCFlow, MCHome, MCSnapshot, MCMap, MCRaidAlert, MCLockScreen,
  MCFreqs, MCSquad, MCEvents, MCStats, MCRcon, MCChat, MCAutoSay,
});
