// screens.jsx — Winio quiz funnel screens
// Original designs — team names are represented as original monograms, not real logos.

const NAVY = '#0d1117';
const NAVY_2 = '#141b24';
const NAVY_3 = '#1a2330';
const TEAL = '#14d1b8';
const TEAL_DIM = 'rgba(20, 209, 184, 0.14)';
const ORANGE = '#e85d33';
const ORANGE_DIM = 'rgba(232, 93, 51, 0.14)';
const MUTED = 'rgba(255,255,255,0.5)';
const MUTED_2 = 'rgba(255,255,255,0.35)';
const BORDER = 'rgba(255,255,255,0.08)';
const BORDER_TEAL = 'rgba(20, 209, 184, 0.28)';

// ──────────────────────────────────────────────────────────────
// Shared atoms
// ──────────────────────────────────────────────────────────────

function Mono({ children, style = {} }) {
  return (
    <span style={{
      fontFamily: 'JetBrains Mono, ui-monospace, monospace',
      letterSpacing: '0.06em',
      textTransform: 'uppercase',
      fontSize: 10,
      fontWeight: 500,
      ...style,
    }}>{children}</span>
  );
}

function ProgressBar({ step, total = 4 }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 8, padding: '0 24px' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between' }}>
        <Mono style={{ color: TEAL }}>QUESTION {String(step).padStart(2,'0')} / {String(total).padStart(2,'0')}</Mono>
        <Mono style={{ color: MUTED }}>{Math.round(step/total*100)}% COMPLETE</Mono>
      </div>
      <div style={{ display: 'flex', gap: 6 }}>
        {Array.from({ length: total }).map((_, i) => (
          <div key={i} style={{
            flex: 1, height: 3, borderRadius: 2,
            background: i < step ? TEAL : 'rgba(255,255,255,0.08)',
            boxShadow: i < step ? `0 0 10px ${TEAL}` : 'none',
            transition: 'all 0.4s',
          }} />
        ))}
      </div>
    </div>
  );
}

function TealButton({ children, onClick, full = true, glow = true, style = {}, id = '' }) {
  return (
    <button id={id} onClick={onClick} style={{
      width: full ? '100%' : 'auto',
      height: 56,
      border: 'none',
      borderRadius: 14,
      background: TEAL,
      color: NAVY,
      fontFamily: 'Wix Madefor Display, system-ui',
      fontWeight: 700,
      fontSize: 16,
      letterSpacing: '0.02em',
      cursor: 'pointer',
      boxShadow: glow ? `0 0 32px rgba(20, 209, 184, 0.45), 0 0 0 1px rgba(20, 209, 184, 0.4) inset` : 'none',
      textTransform: 'uppercase',
      display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
      ...style,
    }}>
      {children}
    </button>
  );
}

function OrangeButton({ children, onClick, full = true, style = {}, id = '' }) {
  return (
    <button id={id} onClick={onClick} style={{
      width: full ? '100%' : 'auto',
      height: 56,
      border: 'none',
      borderRadius: 14,
      background: ORANGE,
      color: '#fff',
      fontFamily: 'Wix Madefor Display, system-ui',
      fontWeight: 700,
      fontSize: 16,
      letterSpacing: '0.02em',
      cursor: 'pointer',
      boxShadow: `0 0 32px rgba(232, 93, 51, 0.45), 0 0 0 1px rgba(232, 93, 51, 0.4) inset`,
      textTransform: 'uppercase',
      display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
      ...style,
    }}>
      {children}
    </button>
  );
}

// Original monogram mark — hex shape with two-letter tag. NOT a real team logo.
function TeamMark({ abbr, accent, size = 44 }) {
  return (
    <div style={{
      width: size, height: size, position: 'relative',
      display: 'flex', alignItems: 'center', justifyContent: 'center',
    }}>
      <svg viewBox="0 0 44 44" width={size} height={size} style={{ position: 'absolute', inset: 0 }}>
        <defs>
          <linearGradient id={`g-${abbr}`} x1="0" y1="0" x2="1" y2="1">
            <stop offset="0" stopColor={accent} stopOpacity="0.9" />
            <stop offset="1" stopColor={accent} stopOpacity="0.3" />
          </linearGradient>
        </defs>
        <polygon
          points="22,2 40,12 40,32 22,42 4,32 4,12"
          fill="none"
          stroke={`url(#g-${abbr})`}
          strokeWidth="1.5"
        />
        <polygon
          points="22,6 36,14 36,30 22,38 8,30 8,14"
          fill={accent}
          fillOpacity="0.08"
        />
      </svg>
      <span style={{
        fontFamily: 'JetBrains Mono, ui-monospace, monospace',
        fontSize: size > 60 ? 18 : 11,
        fontWeight: 700,
        color: accent,
        letterSpacing: '0.04em',
        position: 'relative',
      }}>{abbr}</span>
    </div>
  );
}

// Tiny map glyph built from geometric shapes — not a real CS2 map icon
function MapGlyph({ kind, size = 48, color = TEAL }) {
  const s = size;
  const common = { width: s, height: s, viewBox: '0 0 48 48', fill: 'none', stroke: color, strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' };
  switch (kind) {
    case 'mirage':
      return <svg {...common}><rect x="6" y="6" width="36" height="36" rx="2"/><path d="M6 18h36M18 6v36M30 18v24"/><circle cx="12" cy="12" r="1.5" fill={color}/><circle cx="36" cy="36" r="1.5" fill={color}/></svg>;
    case 'inferno':
      return <svg {...common}><path d="M8 42V14l10-6 14 8v26"/><path d="M32 24l8 4v14H8"/><path d="M14 42V28h8v14M26 42V30h6v12"/></svg>;
    case 'anubis':
      return <svg {...common}><path d="M24 6l16 12v24H8V18z"/><path d="M24 6v36M8 30h32"/><path d="M18 42V30h12v12"/></svg>;
    case 'nuke':
      return <svg {...common}><circle cx="24" cy="24" r="16"/><circle cx="24" cy="24" r="8"/><circle cx="24" cy="24" r="2" fill={color}/><path d="M24 8v8M24 32v8M8 24h8M32 24h8"/></svg>;
    case 'ancient':
      return <svg {...common}><path d="M10 42V20l14-12 14 12v22"/><path d="M10 42h28M18 42V30h12v12"/><path d="M24 20l-6 6M24 20l6 6"/></svg>;
    case 'overpass':
      return <svg {...common}><path d="M8 38V18l16-10 16 10v20"/><path d="M8 28h32"/><path d="M18 38V28h12v10"/><circle cx="24" cy="22" r="3" fill={color} fillOpacity="0.3"/></svg>;
    default:
      return <svg {...common}><rect x="6" y="6" width="36" height="36"/></svg>;
  }
}

// ──────────────────────────────────────────────────────────────
// 1. Welcome
// ──────────────────────────────────────────────────────────────
function WelcomeScreen({ onStart }) {
  return (
    <div style={{
      height: '100%', position: 'relative', overflow: 'hidden',
      background: NAVY, color: '#fff',
      display: 'flex', flexDirection: 'column',
    }}>
      {/* Abstract blurred pro-match ambient background — NOT a real screenshot */}
      <div style={{ position: 'absolute', inset: 0, opacity: 0.55 }}>
        <div style={{
          position: 'absolute', width: 380, height: 380, borderRadius: '50%',
          background: `radial-gradient(circle, ${TEAL} 0%, transparent 65%)`,
          top: -120, left: -100, filter: 'blur(60px)',
        }} />
        <div style={{
          position: 'absolute', width: 320, height: 320, borderRadius: '50%',
          background: `radial-gradient(circle, ${ORANGE} 0%, transparent 65%)`,
          top: 180, right: -80, filter: 'blur(80px)',
        }} />
        <div style={{
          position: 'absolute', width: 260, height: 260, borderRadius: '50%',
          background: `radial-gradient(circle, #3b82f6 0%, transparent 70%)`,
          bottom: -40, left: 40, filter: 'blur(70px)',
        }} />
      </div>
      {/* scanline overlay */}
      <div style={{
        position: 'absolute', inset: 0,
        backgroundImage: 'repeating-linear-gradient(0deg, rgba(255,255,255,0.02) 0, rgba(255,255,255,0.02) 1px, transparent 1px, transparent 3px)',
        pointerEvents: 'none',
      }} />

      {/* Top brand bar */}
      <div style={{ padding: '64px 24px 0', position: 'relative', zIndex: 2, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <svg width="20" height="20" viewBox="0 0 20 20"><polygon points="10,1 19,6 19,14 10,19 1,14 1,6" fill="none" stroke={TEAL} strokeWidth="1.5"/><circle cx="10" cy="10" r="3" fill={TEAL}/></svg>
          <span style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 800, letterSpacing: '0.18em', fontSize: 13 }}>WINIO</span>
        </div>
        <Mono style={{ color: MUTED }}>CS2 · AI PREDICTIONS</Mono>
      </div>

      {/* Main content */}
      <div style={{ flex: 1, position: 'relative', zIndex: 2, padding: '0 24px', display: 'flex', flexDirection: 'column', justifyContent: 'center', gap: 24 }}>
        <div>
          <Mono style={{ color: TEAL, display: 'block', marginBottom: 12 }}>◆ 89% MODEL ACCURACY · 80+ FACTORS</Mono>
          <h1 style={{
            fontFamily: 'Wix Madefor Display, system-ui',
            fontSize: 52, fontWeight: 800,
            lineHeight: 0.95, letterSpacing: '-0.03em', margin: 0,
            textWrap: 'balance',
          }}>
            Think you<br/>know <span style={{ color: TEAL }}>CS2</span>?
          </h1>
        </div>
        <p style={{
          fontFamily: 'Wix Madefor Display, system-ui',
          fontSize: 17, lineHeight: 1.45, color: 'rgba(255,255,255,0.7)',
          margin: 0, maxWidth: 300,
        }}>
          Answer 4 questions. Get a free AI prediction on a live match.
        </p>

        {/* floating stat pills */}
        <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 4 }}>
          {['Team form', 'Map winrates', 'H2H history', 'Eco trends'].map(t => (
            <div key={t} style={{
              padding: '6px 10px', borderRadius: 999,
              border: `1px solid ${BORDER}`,
              background: 'rgba(255,255,255,0.03)',
              backdropFilter: 'blur(10px)',
            }}>
              <Mono style={{ color: 'rgba(255,255,255,0.75)' }}>{t}</Mono>
            </div>
          ))}
        </div>
      </div>

      {/* CTA + meta */}
      <div style={{ padding: '0 24px 48px', position: 'relative', zIndex: 2 }}>
        <TealButton id="btn-start-quiz" onClick={onStart}>
          Get my free prediction
          <svg width="16" height="16" viewBox="0 0 16 16"><path d="M2 8h12M9 3l5 5-5 5" stroke={NAVY} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </TealButton>
        <div style={{ marginTop: 14, display: 'flex', justifyContent: 'space-between' }}>
          <Mono style={{ color: MUTED }}>⏱ 60 SECONDS</Mono>
          <Mono style={{ color: MUTED }}>NEXT MATCH · 2H 14M</Mono>
        </div>
      </div>
    </div>
  );
}

// ──────────────────────────────────────────────────────────────
// 2. Q1 — best team
// ──────────────────────────────────────────────────────────────
const TEAMS = [
  { id: 'vit',    abbr: 'VIT',  name: 'Vitality', region: 'EU', rank: '#1', accent: '#ffd447' },
  { id: 'navi',   abbr: 'NAVI', name: 'NAVI',     region: 'EU', rank: '#2', accent: '#ffd21f' },
  { id: 'spirit', abbr: 'SPR',  name: 'Spirit',   region: 'EU', rank: '#3', accent: '#ff7a45' },
  { id: 'mouz',   abbr: 'MZ',   name: 'MOUZ',     region: 'EU', rank: '#4', accent: '#ef4444' },
  { id: 'faze',   abbr: 'FAZE', name: 'FaZe',     region: 'EU', rank: '#5', accent: '#dc2626' },
  { id: 'g2',     abbr: 'G2',   name: 'G2',       region: 'EU', rank: '#6', accent: '#e5e5e5' },
];

function Q1Screen({ onNext, onBack, value, setValue }) {
  return (
    <QuizShell step={1} onBack={onBack}>
      <QuizHeader
        kicker="POWER RANKING"
        title={<>Who's the strongest<br/>CS2 team right now?</>}
        sub="Pick your #1. We'll compare against the current HLTV-style global rating."
      />
      <div style={{ padding: '20px 24px', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
        {TEAMS.map(t => {
          const sel = value === t.id;
          return (
            <button key={t.id} onClick={() => setValue(t.id)} style={{
              padding: '16px 14px',
              border: `1px solid ${sel ? TEAL : BORDER}`,
              background: sel ? TEAL_DIM : 'rgba(255,255,255,0.02)',
              borderRadius: 14, cursor: 'pointer', textAlign: 'left',
              display: 'flex', flexDirection: 'column', gap: 12,
              position: 'relative', transition: 'all 0.2s',
              boxShadow: sel ? `0 0 0 3px rgba(20, 209, 184, 0.15)` : 'none',
            }}>
              <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                <TeamMark abbr={t.abbr} accent={t.accent} size={40} />
                <Mono style={{ color: sel ? TEAL : MUTED }}>{t.rank}</Mono>
              </div>
              <div>
                <div style={{ color: '#fff', fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 600, fontSize: 15 }}>{t.name}</div>
                <Mono style={{ color: MUTED_2, display: 'block', marginTop: 2 }}>{t.region} REGION</Mono>
              </div>
              {sel && <div style={{
                position: 'absolute', top: 10, right: 10,
                width: 16, height: 16, borderRadius: '50%',
                background: TEAL, display: 'flex', alignItems: 'center', justifyContent: 'center',
                boxShadow: `0 0 12px ${TEAL}`,
              }}>
                <svg width="9" height="7" viewBox="0 0 9 7"><path d="M1 3.5L3.5 6L8 1" stroke={NAVY} strokeWidth="1.8" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
              </div>}
            </button>
          );
        })}
      </div>
      <QuizFooter id="btn-q1-continue" onNext={onNext} disabled={!value} />
    </QuizShell>
  );
}

// ──────────────────────────────────────────────────────────────
// 3. Q2 — pick the winner
// ──────────────────────────────────────────────────────────────
function Q2Screen({ onNext, onBack, value, setValue }) {
  const A = { abbr: 'VIT',  name: 'Vitality', accent: '#ffd447', form: ['W','W','W','W','W'], odds: '1.30' };
  const B = { abbr: 'NAVI', name: 'NAVI',     accent: '#ffd21f', form: ['W','L','W','W','L'], odds: '3.25' };
  return (
    <QuizShell step={2} onBack={onBack}>
      <QuizHeader
        kicker="LIVE MATCH · IEM COLOGNE MAJOR 2026 · GROUP STAGE"
        title={<>Pick the winner.</>}
        sub="Starts in 2h 14m · BO3 on neutral server"
      />
      <div style={{ padding: '16px 24px' }}>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
          {[A, B].map((t, i) => {
            const sel = value === t.name;
            return (
              <button key={t.name} onClick={() => setValue(t.name)} style={{
                padding: '18px 14px 16px',
                border: `1px solid ${sel ? TEAL : BORDER}`,
                background: sel ? TEAL_DIM : 'rgba(255,255,255,0.02)',
                borderRadius: 16, cursor: 'pointer', textAlign: 'left',
                display: 'flex', flexDirection: 'column', gap: 14,
                position: 'relative', transition: 'all 0.2s',
                boxShadow: sel ? `0 0 24px rgba(20, 209, 184, 0.2)` : 'none',
              }}>
                <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
                  <TeamMark abbr={t.abbr} accent={t.accent} size={56} />
                  <div>
                    <div style={{ color: '#fff', fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 16 }}>{t.name}</div>
                    <Mono style={{ color: MUTED, display: 'block', marginTop: 2 }}>ODDS · {t.odds}</Mono>
                  </div>
                </div>
                {/* form */}
                <div>
                  <Mono style={{ color: MUTED_2, display: 'block', marginBottom: 6 }}>FORM · LAST 5</Mono>
                  <div style={{ display: 'flex', gap: 3 }}>
                    {t.form.map((r, j) => (
                      <div key={j} style={{
                        flex: 1, height: 22, borderRadius: 3,
                        background: r === 'W' ? TEAL : 'rgba(232, 93, 51, 0.8)',
                        display: 'flex', alignItems: 'center', justifyContent: 'center',
                        fontFamily: 'JetBrains Mono, ui-monospace, monospace', fontSize: 10,
                        fontWeight: 700, color: r === 'W' ? NAVY : '#fff',
                      }}>{r}</div>
                    ))}
                  </div>
                </div>
                {sel && <div style={{
                  position: 'absolute', top: 12, right: 12,
                  width: 18, height: 18, borderRadius: '50%',
                  background: TEAL,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  boxShadow: `0 0 14px ${TEAL}`,
                }}>
                  <svg width="10" height="8" viewBox="0 0 10 8"><path d="M1 4L4 7L9 1.5" stroke={NAVY} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
                </div>}
              </button>
            );
          })}
        </div>
        {/* VS badge */}
        <div style={{ display: 'flex', justifyContent: 'center', margin: '-36px 0 -12px', position: 'relative', zIndex: 2, pointerEvents: 'none' }}>
          <div style={{
            width: 48, height: 48, borderRadius: '50%',
            background: NAVY, border: `1px solid ${BORDER_TEAL}`,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontFamily: 'JetBrains Mono, ui-monospace, monospace',
            fontSize: 13, fontWeight: 700, color: TEAL, letterSpacing: '0.05em',
          }}>VS</div>
        </div>

        {/* H2H strip */}
        <div style={{
          marginTop: 20, padding: 14, borderRadius: 12,
          border: `1px solid ${BORDER}`, background: 'rgba(255,255,255,0.02)',
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }}>
            <Mono style={{ color: MUTED_2 }}>HEAD TO HEAD · LAST 12 MONTHS</Mono>
            <Mono style={{ color: TEAL }}>9 MEETS</Mono>
          </div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
            <Mono style={{ color: '#fff', fontSize: 12 }}>VIT · 7</Mono>
            <div style={{ flex: 1, height: 6, borderRadius: 4, background: 'rgba(232, 93, 51, 0.3)', overflow: 'hidden' }}>
              <div style={{ width: '78%', height: '100%', background: TEAL }} />
            </div>
            <Mono style={{ color: '#fff', fontSize: 12 }}>2 · NAVI</Mono>
          </div>
        </div>
      </div>
      <QuizFooter id="btn-q2-continue" onNext={onNext} disabled={!value} />
    </QuizShell>
  );
}

// ──────────────────────────────────────────────────────────────
// 4. Q3 — map picker
// ──────────────────────────────────────────────────────────────
const MAPS = [
  { id: 'mirage', name: 'Mirage', stat: '62% T-side' },
  { id: 'inferno', name: 'Inferno', stat: '54% CT' },
  { id: 'anubis', name: 'Anubis', stat: '58% T' },
  { id: 'nuke', name: 'Nuke', stat: '67% CT' },
  { id: 'ancient', name: 'Ancient', stat: '51% T' },
  { id: 'overpass', name: 'Overpass', stat: '55% CT' },
];

function Q3Screen({ onNext, onBack, value, setValue }) {
  return (
    <QuizShell step={3} onBack={onBack}>
      <QuizHeader
        kicker="MAP POOL · ACTIVE DUTY"
        title={<>Which map<br/>decides the series?</>}
        sub="Pick the map you think matters most — our model weighs veto patterns and win-rates."
      />
      <div style={{ padding: '20px 24px', display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: 10 }}>
        {MAPS.map(m => {
          const sel = value === m.id;
          return (
            <button key={m.id} onClick={() => setValue(m.id)} style={{
              aspectRatio: '1 / 1.2',
              padding: 12,
              border: `1px solid ${sel ? TEAL : BORDER}`,
              background: sel ? TEAL_DIM : 'rgba(255,255,255,0.02)',
              borderRadius: 12, cursor: 'pointer',
              display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
              position: 'relative', transition: 'all 0.2s',
              boxShadow: sel ? `0 0 20px rgba(20, 209, 184, 0.18)` : 'none',
            }}>
              <div style={{ display: 'flex', justifyContent: 'center', paddingTop: 4 }}>
                <MapGlyph kind={m.id} size={44} color={sel ? TEAL : 'rgba(255,255,255,0.75)'} />
              </div>
              <div style={{ textAlign: 'left' }}>
                <div style={{ color: '#fff', fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 600, fontSize: 13 }}>{m.name}</div>
                <Mono style={{ color: sel ? TEAL : MUTED_2, display: 'block', marginTop: 2, fontSize: 9 }}>{m.stat}</Mono>
              </div>
              {sel && <div style={{
                position: 'absolute', top: 8, right: 8,
                width: 14, height: 14, borderRadius: '50%',
                background: TEAL, boxShadow: `0 0 10px ${TEAL}`,
              }} />}
            </button>
          );
        })}
      </div>
      <QuizFooter id="btn-q3-continue" onNext={onNext} disabled={!value} />
    </QuizShell>
  );
}

// ──────────────────────────────────────────────────────────────
// 5. Q4 — confidence slider
// ──────────────────────────────────────────────────────────────
function Q4Screen({ onNext, onBack, value, setValue }) {
  const pct = value;
  const label = pct < 60 ? 'Shot in the dark' : pct < 75 ? 'Leaning' : pct < 90 ? 'Confident' : 'All-in';
  return (
    <QuizShell step={4} onBack={onBack}>
      <QuizHeader
        kicker="CONFIDENCE CHECK"
        title={<>How confident<br/>are you?</>}
        sub="We'll weight your answers against your self-assessed certainty."
      />
      <div style={{ padding: '8px 24px' }}>
        {/* Huge number */}
        <div style={{
          padding: '28px 0 20px', textAlign: 'center',
          fontFamily: 'Wix Madefor Display, system-ui',
          fontSize: 120, fontWeight: 800, lineHeight: 1,
          color: '#fff', letterSpacing: '-0.04em',
          background: `linear-gradient(180deg, ${TEAL} 0%, rgba(20, 209, 184, 0.4) 100%)`,
          WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent',
          textShadow: `0 0 40px rgba(20, 209, 184, 0.4)`,
        }}>
          {pct}<span style={{ fontSize: 52, color: TEAL, WebkitTextFillColor: TEAL }}>%</span>
        </div>
        <div style={{ textAlign: 'center', marginBottom: 28 }}>
          <Mono style={{ color: TEAL }}>◆ {label.toUpperCase()}</Mono>
        </div>

        {/* Custom slider */}
        <div style={{ position: 'relative', padding: '8px 0 28px' }}>
          <div style={{
            height: 8, borderRadius: 4,
            background: 'rgba(255,255,255,0.08)',
            position: 'relative', overflow: 'hidden',
          }}>
            <div style={{
              position: 'absolute', left: 0, top: 0, bottom: 0,
              width: `${(pct - 50) * 2}%`,
              background: `linear-gradient(90deg, rgba(20, 209, 184, 0.3), ${TEAL})`,
              boxShadow: `0 0 14px ${TEAL}`,
              transition: 'width 0.05s linear',
            }} />
          </div>
          <input
            type="range" min="50" max="100" step="1"
            value={pct}
            onChange={e => setValue(Number(e.target.value))}
            style={{
              position: 'absolute', inset: 0,
              width: '100%', appearance: 'none', background: 'transparent',
              cursor: 'pointer', margin: 0,
            }}
          />
          {/* tick labels */}
          <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 14 }}>
            {[50, 65, 80, 95, 100].map(n => (
              <Mono key={n} style={{ color: pct >= n ? TEAL : MUTED_2 }}>{n}%</Mono>
            ))}
          </div>
        </div>

        <div style={{
          padding: 16, borderRadius: 12,
          border: `1px solid ${BORDER_TEAL}`,
          background: TEAL_DIM,
          display: 'flex', gap: 12, alignItems: 'flex-start',
        }}>
          <div style={{
            width: 28, height: 28, borderRadius: '50%', flexShrink: 0,
            background: TEAL, display: 'flex', alignItems: 'center', justifyContent: 'center',
          }}>
            <svg width="14" height="14" viewBox="0 0 14 14"><path d="M7 1v13M1 7h13" stroke={NAVY} strokeWidth="2" strokeLinecap="round"/></svg>
          </div>
          <div>
            <div style={{ color: '#fff', fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 600, fontSize: 14, marginBottom: 2 }}>Lock in your prediction</div>
            <div style={{ color: MUTED, fontFamily: 'Wix Madefor Display, system-ui', fontSize: 12.5, lineHeight: 1.45 }}>AI will cross-check your picks against 80+ live factors.</div>
          </div>
        </div>
      </div>
      <QuizFooter id="btn-q4-analyze" onNext={onNext} ctaLabel="Analyze" />
    </QuizShell>
  );
}

// ──────────────────────────────────────────────────────────────
// Quiz shell / header / footer
// ──────────────────────────────────────────────────────────────
function QuizShell({ step, onBack, children }) {
  return (
    <div style={{ height: '100%', background: NAVY, color: '#fff', display: 'flex', flexDirection: 'column' }}>
      <div style={{ padding: '62px 24px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <button onClick={onBack} style={{
          width: 40, height: 40, borderRadius: 12,
          border: `1px solid ${BORDER}`, background: 'rgba(255,255,255,0.03)',
          display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer',
        }}>
          <svg width="12" height="12" viewBox="0 0 12 12"><path d="M7.5 2L3 6l4.5 4" stroke="#fff" strokeWidth="1.6" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </button>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <svg width="14" height="14" viewBox="0 0 20 20"><polygon points="10,1 19,6 19,14 10,19 1,14 1,6" fill="none" stroke={TEAL} strokeWidth="1.5"/><circle cx="10" cy="10" r="2.5" fill={TEAL}/></svg>
          <span style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, letterSpacing: '0.18em', fontSize: 11 }}>WINIO</span>
        </div>
        <div style={{ width: 40 }} />
      </div>
      <div style={{ marginBottom: 20 }}>
        <ProgressBar step={step} />
      </div>
      <div style={{ flex: 1, overflow: 'auto' }}>{children}</div>
    </div>
  );
}

function QuizHeader({ kicker, title, sub }) {
  return (
    <div style={{ padding: '8px 24px 0' }}>
      <Mono style={{ color: TEAL, display: 'block', marginBottom: 10 }}>◆ {kicker}</Mono>
      <h2 style={{
        fontFamily: 'Wix Madefor Display, system-ui',
        fontSize: 32, fontWeight: 800, lineHeight: 1.02,
        letterSpacing: '-0.025em', margin: 0, color: '#fff',
      }}>{title}</h2>
      {sub && <p style={{
        marginTop: 10, marginBottom: 0, color: MUTED,
        fontFamily: 'Wix Madefor Display, system-ui', fontSize: 13.5, lineHeight: 1.5,
        textWrap: 'pretty', maxWidth: 320,
      }}>{sub}</p>}
    </div>
  );
}

function QuizFooter({ onNext, disabled, ctaLabel = 'Continue', id = '' }) {
  return (
    <div style={{ padding: '16px 24px 28px' }}>
      <TealButton id={id} onClick={disabled ? undefined : onNext} style={{
        opacity: disabled ? 0.35 : 1,
        cursor: disabled ? 'not-allowed' : 'pointer',
        boxShadow: disabled ? 'none' : `0 0 32px rgba(20, 209, 184, 0.45), 0 0 0 1px rgba(20, 209, 184, 0.4) inset`,
      }}>
        {ctaLabel}
        <svg width="14" height="14" viewBox="0 0 16 16"><path d="M2 8h12M9 3l5 5-5 5" stroke={NAVY} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
      </TealButton>
    </div>
  );
}

// ──────────────────────────────────────────────────────────────
// 6. Loading / AI analyzing
// ──────────────────────────────────────────────────────────────
function LoadingScreen({ onDone, autoAdvance = true }) {
  const [tick, setTick] = React.useState(0);
  const [factorIdx, setFactorIdx] = React.useState(0);
  const factors = [
    'team form · 30 matches',
    'map winrate matrix',
    'player HLTV-style ratings',
    'head-to-head history',
    'economy & force-buy trends',
    'veto pattern analysis',
    'server latency modeling',
    'meta weapon shifts',
  ];
  const numbers = React.useMemo(() => Array.from({ length: 24 }, () => (Math.random() * 0.9 + 0.08).toFixed(3)), [tick]);

  React.useEffect(() => {
    const id = setInterval(() => setTick(t => t + 1), 140);
    return () => clearInterval(id);
  }, []);
  React.useEffect(() => {
    const id = setInterval(() => setFactorIdx(i => (i + 1) % factors.length), 500);
    return () => clearInterval(id);
  }, []);
  React.useEffect(() => {
    if (!autoAdvance) return;
    const t = setTimeout(onDone, 4200);
    return () => clearTimeout(t);
  }, [onDone, autoAdvance]);

  return (
    <div style={{ height: '100%', background: NAVY, color: '#fff', display: 'flex', flexDirection: 'column', position: 'relative', overflow: 'hidden' }}>
      {/* Top bar */}
      <div style={{ padding: '62px 24px 0', display: 'flex', justifyContent: 'space-between' }}>
        <Mono style={{ color: TEAL }}>◆ WINIO ENGINE v4.2</Mono>
        <Mono style={{ color: MUTED }}>{String(Math.min(99, Math.floor(tick * 3.5))).padStart(2,'0')}%</Mono>
      </div>

      {/* Center — pulsing ring + orbit factors */}
      <div style={{ flex: 1, position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
        {/* orbit rings */}
        {[180, 240, 300].map((d, i) => (
          <div key={i} style={{
            position: 'absolute', width: d, height: d, borderRadius: '50%',
            border: `1px solid ${TEAL}`,
            opacity: 0.08 + i * 0.04,
            animation: `winio-pulse-${i} ${2 + i}s ease-in-out infinite`,
          }} />
        ))}
        {/* pulse */}
        <div style={{
          position: 'absolute', width: 160, height: 160, borderRadius: '50%',
          background: `radial-gradient(circle, ${TEAL} 0%, transparent 70%)`,
          filter: 'blur(20px)',
          opacity: 0.4 + Math.sin(tick * 0.3) * 0.2,
        }} />
        {/* core */}
        <div style={{
          width: 120, height: 120, borderRadius: '50%',
          border: `1.5px solid ${TEAL}`,
          background: 'rgba(20, 209, 184, 0.06)',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          position: 'relative', zIndex: 2,
          boxShadow: `0 0 48px rgba(20, 209, 184, 0.5), inset 0 0 32px rgba(20, 209, 184, 0.15)`,
        }}>
          <svg width="40" height="40" viewBox="0 0 20 20">
            <polygon points="10,1 19,6 19,14 10,19 1,14 1,6" fill="none" stroke={TEAL} strokeWidth="1.2"/>
            <circle cx="10" cy="10" r="3" fill={TEAL}>
              <animate attributeName="r" values="3;4;3" dur="1.2s" repeatCount="indefinite"/>
            </circle>
          </svg>
        </div>
        {/* orbiting data points */}
        {factors.slice(0, 5).map((f, i) => {
          const angle = (tick * 0.04 + (i * Math.PI * 2) / 5) % (Math.PI * 2);
          const r = 130;
          const x = Math.cos(angle) * r;
          const y = Math.sin(angle) * r;
          return (
            <div key={i} style={{
              position: 'absolute',
              transform: `translate(${x}px, ${y}px)`,
              display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
            }}>
              <div style={{
                width: 6, height: 6, borderRadius: '50%',
                background: TEAL, boxShadow: `0 0 8px ${TEAL}`,
              }} />
              <Mono style={{ color: 'rgba(255,255,255,0.65)', fontSize: 8.5, whiteSpace: 'nowrap' }}>{f.split(' · ')[0]}</Mono>
            </div>
          );
        })}
      </div>

      {/* status text */}
      <div style={{ padding: '0 24px 24px', textAlign: 'center' }}>
        <h2 style={{
          fontFamily: 'Wix Madefor Display, system-ui',
          fontSize: 24, fontWeight: 700, margin: 0,
          letterSpacing: '-0.02em',
        }}>AI is analyzing 80+ factors…</h2>
        <div style={{ height: 18, marginTop: 10 }}>
          <Mono style={{ color: TEAL }}>&gt;&gt; {factors[factorIdx]}</Mono>
        </div>
      </div>

      {/* number grid */}
      <div style={{ padding: '0 24px 24px' }}>
        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(8, 1fr)', gap: 4,
          padding: 12, borderRadius: 10,
          border: `1px solid ${BORDER_TEAL}`,
          background: 'rgba(20, 209, 184, 0.04)',
          fontFamily: 'JetBrains Mono, ui-monospace, monospace', fontSize: 9.5,
          color: 'rgba(20, 209, 184, 0.85)',
          position: 'relative', overflow: 'hidden',
        }}>
          {numbers.map((n, i) => (
            <div key={i} style={{ textAlign: 'center', opacity: 0.4 + ((i + tick) % 8) / 10 }}>{n}</div>
          ))}
          <div style={{
            position: 'absolute', left: 0, right: 0,
            top: `${(tick * 4) % 100}%`, height: 2,
            background: `linear-gradient(90deg, transparent, ${TEAL}, transparent)`,
            opacity: 0.6,
          }} />
        </div>
      </div>

      {/* progress bar */}
      <div style={{ padding: '0 24px 32px' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 6 }}>
          <Mono style={{ color: MUTED }}>MODEL · STREAMING</Mono>
          <Mono style={{ color: TEAL }}>{String(Math.min(99, Math.floor(tick * 3.5))).padStart(2,'0')} / 80 FACTORS</Mono>
        </div>
        <div style={{ height: 2, background: 'rgba(255,255,255,0.08)', borderRadius: 2, overflow: 'hidden' }}>
          <div style={{
            height: '100%', width: `${Math.min(100, tick * 4)}%`,
            background: TEAL, boxShadow: `0 0 10px ${TEAL}`, transition: 'width 0.1s linear',
          }} />
        </div>
      </div>

      <style>{`
        @keyframes winio-pulse-0 { 0%,100% { transform: scale(1); opacity: 0.12 } 50% { transform: scale(1.05); opacity: 0.04 } }
        @keyframes winio-pulse-1 { 0%,100% { transform: scale(1); opacity: 0.1 } 50% { transform: scale(1.08); opacity: 0.03 } }
        @keyframes winio-pulse-2 { 0%,100% { transform: scale(1); opacity: 0.08 } 50% { transform: scale(1.1); opacity: 0.02 } }
      `}</style>
    </div>
  );
}

// ──────────────────────────────────────────────────────────────
// 7. Teaser
// ──────────────────────────────────────────────────────────────
function TeaserScreen({ onSignup, onBack, userPick }) {
  const aiPick = 'Vitality';
  const matches = aiPick === userPick;
  return (
    <div style={{ height: '100%', background: NAVY, color: '#fff', display: 'flex', flexDirection: 'column' }}>
      <div style={{ padding: '62px 24px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <button onClick={onBack} style={{
          width: 40, height: 40, borderRadius: 12,
          border: `1px solid ${BORDER}`, background: 'rgba(255,255,255,0.03)',
          display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer',
        }}>
          <svg width="12" height="12" viewBox="0 0 12 12"><path d="M7.5 2L3 6l4.5 4" stroke="#fff" strokeWidth="1.6" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </button>
        <Mono style={{ color: TEAL }}>◆ PREDICTION READY</Mono>
        <div style={{ width: 40 }} />
      </div>

      <div style={{ flex: 1, overflowY: 'auto', padding: '8px 24px 20px' }}>
        {/* Match / compare banner */}
        <div style={{
          padding: '14px 16px', borderRadius: 14,
          border: `1px solid ${matches ? BORDER_TEAL : 'rgba(232, 93, 51, 0.35)'}`,
          background: matches ? TEAL_DIM : ORANGE_DIM,
          display: 'flex', alignItems: 'center', gap: 12,
          marginBottom: 16,
        }}>
          <div style={{
            width: 32, height: 32, borderRadius: '50%', flexShrink: 0,
            background: matches ? TEAL : ORANGE,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            boxShadow: `0 0 16px ${matches ? TEAL : ORANGE}`,
          }}>
            {matches
              ? <svg width="14" height="11" viewBox="0 0 14 11"><path d="M1 5.5L5 9.5L13 1" stroke={NAVY} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
              : <svg width="14" height="14" viewBox="0 0 14 14"><path d="M2 2l10 10M12 2L2 12" stroke="#fff" strokeWidth="2" strokeLinecap="round"/></svg>}
          </div>
          <div>
            <div style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 14, color: matches ? TEAL : ORANGE }}>
              {matches ? 'Your pick matches the AI' : 'AI disagrees with you'}
            </div>
            <div style={{ color: MUTED, fontFamily: 'Wix Madefor Display, system-ui', fontSize: 12, marginTop: 2 }}>
              {matches ? 'Sharp read. See the breakdown.' : `Model leans ${aiPick}. See why.`}
            </div>
          </div>
        </div>

        {/* Blurred prediction */}
        <div style={{
          padding: 20, borderRadius: 16,
          border: `1px solid ${BORDER}`,
          background: `linear-gradient(160deg, rgba(20, 209, 184, 0.06), transparent 60%)`,
          position: 'relative', overflow: 'hidden',
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 16 }}>
            <Mono style={{ color: TEAL }}>AI FORECAST · BO3</Mono>
            <Mono style={{ color: MUTED }}>MODEL v4.2</Mono>
          </div>

          {/* teams row — PARTIALLY blurred (can see shape/split, not read) */}
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 14 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
              <TeamMark abbr="VIT" accent="#ffd447" size={36} />
              <div>
                <div style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 14 }}>Vitality</div>
                <Mono style={{ color: TEAL, fontSize: 18, letterSpacing: '0.04em', filter: 'blur(5px)', display: 'inline-block' }}>71%</Mono>
              </div>
            </div>
            <Mono style={{ color: MUTED_2 }}>VS</Mono>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
              <div style={{ textAlign: 'right' }}>
                <div style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 14 }}>NAVI</div>
                <Mono style={{ color: ORANGE, fontSize: 18, letterSpacing: '0.04em', filter: 'blur(5px)', display: 'inline-block' }}>29%</Mono>
              </div>
              <TeamMark abbr="NAVI" accent="#ffd21f" size={36} />
            </div>
          </div>

          {/* winprob bar */}
          <div style={{ height: 8, borderRadius: 4, overflow: 'hidden', display: 'flex', marginBottom: 18 }}>
            <div style={{ width: '71%', background: TEAL, boxShadow: `0 0 14px ${TEAL}` }} />
            <div style={{ width: '29%', background: ORANGE }} />
          </div>

          {/* BLURRED key factors */}
          <Mono style={{ color: MUTED_2, display: 'block', marginBottom: 8 }}>KEY FACTORS — LOCKED</Mono>
          <div style={{ filter: 'blur(9px) saturate(1.2)', userSelect: 'none', pointerEvents: 'none', opacity: 0.85 }}>
            {[
              ['Recent form rating', '+1.84'],
              ['Anti-eco efficiency', '+0.62'],
              ['Star duel winrate', '+0.31'],
              ['Map veto edge', 'Mirage +12%'],
            ].map(([k, v], i) => (
              <div key={i} style={{ display: 'flex', justifyContent: 'space-between', padding: '7px 0', borderBottom: i < 3 ? `1px dashed ${BORDER}` : 'none' }}>
                <span style={{ fontSize: 13 }}>{k}</span>
                <Mono style={{ color: TEAL }}>{v}</Mono>
              </div>
            ))}
          </div>

          {/* lock overlay */}
          <div style={{
            position: 'absolute', bottom: 20, left: 20, right: 20,
            display: 'flex', alignItems: 'center', gap: 10,
            padding: 10, borderRadius: 10,
            background: 'rgba(13, 17, 23, 0.85)',
            border: `1px solid ${BORDER}`,
            backdropFilter: 'blur(8px)',
          }}>
            <svg width="14" height="16" viewBox="0 0 14 16"><rect x="2" y="7" width="10" height="8" rx="1.5" fill="none" stroke={ORANGE} strokeWidth="1.4"/><path d="M4 7V4.5a3 3 0 016 0V7" stroke={ORANGE} strokeWidth="1.4" fill="none"/></svg>
            <Mono style={{ color: MUTED, fontSize: 10 }}>UNLOCK WITH FREE ACCOUNT</Mono>
          </div>
        </div>

        <div style={{ marginTop: 20 }}>
          <OrangeButton id="btn-signup-cta" onClick={onSignup}>
            Sign up to see full breakdown
            <svg width="14" height="14" viewBox="0 0 16 16"><path d="M2 8h12M9 3l5 5-5 5" stroke="#fff" strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
          </OrangeButton>
          <div style={{ textAlign: 'center', marginTop: 12 }}>
            <Mono style={{ color: MUTED_2 }}>FREE · NO CARD · 5 PREDICTIONS / MONTH</Mono>
          </div>
        </div>
      </div>
    </div>
  );
}

// ──────────────────────────────────────────────────────────────
// 8. Sign up
// ──────────────────────────────────────────────────────────────
function SignupScreen({ onSubmit, onBack }) {
  const [email, setEmail] = React.useState('');
  const [sending, setSending] = React.useState(false);

  const handleSubmit = () => {
    if (!email.includes('@') || sending) return;
    setSending(true);
    fetch('/api/lead', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ email: email }),
    }).then(() => {
      onSubmit(email);
    }).catch(() => {
      onSubmit(email);
    });
  };
  return (
    <div style={{ height: '100%', background: NAVY, color: '#fff', display: 'flex', flexDirection: 'column' }}>
      <div style={{ padding: '62px 24px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <button onClick={onBack} style={{
          width: 40, height: 40, borderRadius: 12,
          border: `1px solid ${BORDER}`, background: 'rgba(255,255,255,0.03)',
          display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer',
        }}>
          <svg width="12" height="12" viewBox="0 0 12 12"><path d="M7.5 2L3 6l4.5 4" stroke="#fff" strokeWidth="1.6" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </button>
        <Mono style={{ color: TEAL }}>◆ STEP · FINAL</Mono>
        <div style={{ width: 40 }} />
      </div>

      <div style={{ flex: 1, padding: '24px 24px 0', display: 'flex', flexDirection: 'column' }}>
        <Mono style={{ color: TEAL, display: 'block', marginBottom: 10 }}>◆ UNLOCK YOUR PREDICTION</Mono>
        <h2 style={{
          fontFamily: 'Wix Madefor Display, system-ui',
          fontSize: 34, fontWeight: 800, lineHeight: 1, margin: 0,
          letterSpacing: '-0.03em',
        }}>One field.<br/>Then it's yours.</h2>
        <p style={{
          marginTop: 10, color: MUTED, fontSize: 13.5, lineHeight: 1.5,
          fontFamily: 'Wix Madefor Display, system-ui', maxWidth: 300,
        }}>We'll send predictions, never spam. Opt out any time.</p>

        <div style={{ marginTop: 28 }}>
          <label style={{ display: 'block' }}>
            <Mono style={{ color: MUTED, display: 'block', marginBottom: 8 }}>EMAIL ADDRESS</Mono>
            <input
              type="email" placeholder="you@domain.gg"
              value={email} onChange={e => setEmail(e.target.value)}
              style={{
                width: '100%', boxSizing: 'border-box',
                padding: '16px 18px', borderRadius: 14,
                border: `1px solid ${BORDER}`,
                background: 'rgba(255,255,255,0.03)',
                color: '#fff', fontSize: 15,
                fontFamily: 'Wix Madefor Display, system-ui',
                outline: 'none',
              }}
              onFocus={e => e.target.style.borderColor = TEAL}
              onBlur={e => e.target.style.borderColor = BORDER}
            />
          </label>
        </div>

        <div style={{ marginTop: 20 }}>
          <OrangeButton id="btn-get-prediction" onClick={handleSubmit} style={{ opacity: email.includes('@') ? 1 : 0.6, cursor: sending ? 'wait' : 'pointer' }}>
            Get my prediction
            <svg width="14" height="14" viewBox="0 0 16 16"><path d="M2 8h12M9 3l5 5-5 5" stroke="#fff" strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
          </OrangeButton>
        </div>


        <div style={{ textAlign: 'center', marginTop: 16, marginBottom: 24 }}>
          <Mono style={{ color: MUTED_2 }}>FREE · NO CARD NEEDED · 5 PREDICTIONS / MONTH</Mono>
        </div>

        {/* trust markers */}
        <div style={{
          marginTop: 'auto', marginBottom: 24,
          padding: 14, borderRadius: 12,
          border: `1px solid ${BORDER}`,
          background: 'rgba(255,255,255,0.02)',
          display: 'flex', justifyContent: 'space-between',
        }}>
          <div>
            <Mono style={{ color: MUTED_2 }}>ACCURACY</Mono>
            <div style={{ color: TEAL, fontFamily: 'JetBrains Mono, monospace', fontSize: 18, fontWeight: 700, marginTop: 2 }}>89%</div>
          </div>
          <div>
            <Mono style={{ color: MUTED_2 }}>FACTORS</Mono>
            <div style={{ color: '#fff', fontFamily: 'JetBrains Mono, monospace', fontSize: 18, fontWeight: 700, marginTop: 2 }}>80+</div>
          </div>
          <div>
            <Mono style={{ color: MUTED_2 }}>USERS</Mono>
            <div style={{ color: '#fff', fontFamily: 'JetBrains Mono, monospace', fontSize: 18, fontWeight: 700, marginTop: 2 }}>42k</div>
          </div>
        </div>
      </div>
    </div>
  );
}

// ──────────────────────────────────────────────────────────────
// 9. Full result
// ──────────────────────────────────────────────────────────────
function ResultScreen({ onRestart }) {
  return (
    <div style={{ height: '100%', background: NAVY, color: '#fff', display: 'flex', flexDirection: 'column' }}>
      <div style={{ padding: '62px 24px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <svg width="14" height="14" viewBox="0 0 20 20"><polygon points="10,1 19,6 19,14 10,19 1,14 1,6" fill="none" stroke={TEAL} strokeWidth="1.5"/><circle cx="10" cy="10" r="2.5" fill={TEAL}/></svg>
          <span style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, letterSpacing: '0.18em', fontSize: 11 }}>WINIO</span>
        </div>
        <Mono style={{ color: TEAL }}>◆ FULL PREDICTION</Mono>
        <div style={{ width: 40 }} />
      </div>

      <div style={{ flex: 1, overflowY: 'auto', padding: '8px 24px 120px' }}>
        {/* match header */}
        <div style={{
          padding: 18, borderRadius: 16,
          border: `1px solid ${BORDER_TEAL}`,
          background: `linear-gradient(150deg, ${TEAL_DIM}, transparent 70%)`,
        }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 14 }}>
            <Mono style={{ color: TEAL }}>◆ IEM COLOGNE MAJOR 2026 · GROUP STAGE · BO3</Mono>
            <Mono style={{ color: MUTED }}>IN 2H 14M</Mono>
          </div>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 8, flex: 1 }}>
              <TeamMark abbr="VIT" accent="#ffd447" size={54} />
              <div style={{ textAlign: 'center' }}>
                <div style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 15 }}>Vitality</div>
                <Mono style={{ color: TEAL, fontSize: 26, letterSpacing: '0.02em', display: 'block', marginTop: 4 }}>71%</Mono>
              </div>
            </div>
            <Mono style={{ color: MUTED_2, fontSize: 14 }}>VS</Mono>
            <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 8, flex: 1 }}>
              <TeamMark abbr="NAVI" accent="#ffd21f" size={54} />
              <div style={{ textAlign: 'center' }}>
                <div style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 15 }}>NAVI</div>
                <Mono style={{ color: ORANGE, fontSize: 26, letterSpacing: '0.02em', display: 'block', marginTop: 4 }}>29%</Mono>
              </div>
            </div>
          </div>

          {/* winprob bar */}
          <div style={{ marginTop: 18, height: 10, borderRadius: 5, overflow: 'hidden', display: 'flex' }}>
            <div style={{ width: '71%', background: TEAL, boxShadow: `0 0 14px ${TEAL}`, display: 'flex', alignItems: 'center', justifyContent: 'flex-start', paddingLeft: 8 }}>
              <Mono style={{ color: NAVY, fontSize: 8.5 }}>VIT WIN</Mono>
            </div>
            <div style={{ width: '29%', background: ORANGE, display: 'flex', alignItems: 'center', justifyContent: 'flex-end', paddingRight: 8 }}>
              <Mono style={{ color: '#fff', fontSize: 8.5 }}>NAVI WIN</Mono>
            </div>
          </div>

          <div style={{ marginTop: 14, display: 'flex', justifyContent: 'space-between', paddingTop: 14, borderTop: `1px dashed ${BORDER}` }}>
            <div>
              <Mono style={{ color: MUTED_2 }}>AI CONFIDENCE</Mono>
              <div style={{ color: TEAL, fontFamily: 'JetBrains Mono, monospace', fontSize: 15, fontWeight: 700, marginTop: 2 }}>HIGH · 87%</div>
            </div>
            <div>
              <Mono style={{ color: MUTED_2 }}>MODEL v4.2</Mono>
              <div style={{ color: '#fff', fontFamily: 'JetBrains Mono, monospace', fontSize: 15, fontWeight: 700, marginTop: 2 }}>3.1s COMP.</div>
            </div>
          </div>
        </div>

        {/* Key factors */}
        <SectionLabel>Key factors</SectionLabel>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
          <FactorRow label="Team form rating (30d)" aVal="+2.14" bVal="+0.86" aPct={71} />
          <FactorRow label="Avg player rating (HLTV-style)" aVal="1.21" bVal="1.04" aPct={62} />
          <FactorRow label="Map pool win-rate" aVal="68%" bVal="49%" aPct={65} />
          <FactorRow label="Head-to-head · 12m" aVal="7W" bVal="2W" aPct={78} />
          <FactorRow label="Economy efficiency" aVal="+0.38" bVal="-0.12" aPct={60} />
        </div>

        {/* Map recommendation */}
        <SectionLabel>Map recommendations</SectionLabel>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
          <MapCard kind="mirage" label="Strongest" team="VIT +18%" tone="teal" />
          <MapCard kind="nuke" label="Weakest" team="VIT −7%" tone="orange" />
        </div>

        {/* Star player callout */}
        <SectionLabel>Star player rating</SectionLabel>
        <div style={{
          padding: 14, borderRadius: 14,
          border: `1px solid ${BORDER}`, background: 'rgba(255,255,255,0.02)',
          display: 'flex', alignItems: 'center', gap: 12,
        }}>
          <div style={{
            width: 44, height: 44, borderRadius: 10,
            background: `linear-gradient(135deg, rgba(20,209,184,0.18), rgba(20,209,184,0.04))`,
            border: `1px solid ${BORDER_TEAL}`,
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            fontFamily: 'JetBrains Mono, monospace', fontSize: 11, fontWeight: 700, color: TEAL,
          }}>VIT</div>
          <div style={{ flex: 1 }}>
            <div style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 14 }}>"v0idz" — AWP / Entry</div>
            <Mono style={{ color: MUTED, display: 'block', marginTop: 2 }}>RATING 1.31 · +14% VS TIER-1</Mono>
          </div>
          <div style={{ color: TEAL, fontFamily: 'JetBrains Mono, monospace', fontWeight: 700, fontSize: 20 }}>S+</div>
        </div>
      </div>

      {/* Sticky CTA */}
      <div style={{
        position: 'absolute', bottom: 0, left: 0, right: 0,
        padding: '16px 24px 40px',
        background: `linear-gradient(180deg, transparent, ${NAVY} 30%)`,
      }}>
        <TealButton id="btn-see-more" onClick={() => window.open('https://winio.ai/?utm_source=quiz&utm_medium=landing&utm_campaign=cs2_quiz_funnel&utm_content=see_more_predictions', '_blank')}>
          See more predictions
          <svg width="14" height="14" viewBox="0 0 16 16"><path d="M2 8h12M9 3l5 5-5 5" stroke={NAVY} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </TealButton>
        <div style={{ textAlign: 'center', marginTop: 10 }}>
          <Mono style={{ color: MUTED }}>UPCOMING MATCHES TODAY · 4</Mono>
        </div>
      </div>
    </div>
  );
}

function SectionLabel({ children }) {
  return (
    <div style={{ margin: '24px 0 10px', display: 'flex', alignItems: 'center', gap: 10 }}>
      <div style={{ width: 4, height: 4, borderRadius: 2, background: TEAL, boxShadow: `0 0 8px ${TEAL}` }} />
      <Mono style={{ color: TEAL }}>{children.toUpperCase ? children.toUpperCase() : children}</Mono>
      <div style={{ flex: 1, height: 1, background: BORDER }} />
    </div>
  );
}

function FactorRow({ label, aVal, bVal, aPct }) {
  return (
    <div style={{ padding: 12, borderRadius: 10, border: `1px solid ${BORDER}`, background: 'rgba(255,255,255,0.02)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
        <span style={{ fontSize: 12.5, fontFamily: 'Wix Madefor Display, system-ui' }}>{label}</span>
        <Mono style={{ color: TEAL }}>{aVal} <span style={{ color: MUTED_2 }}>/</span> <span style={{ color: ORANGE }}>{bVal}</span></Mono>
      </div>
      <div style={{ height: 4, borderRadius: 2, overflow: 'hidden', display: 'flex', background: 'rgba(255,255,255,0.06)' }}>
        <div style={{ width: `${aPct}%`, background: TEAL }} />
        <div style={{ width: `${100 - aPct}%`, background: 'rgba(232, 93, 51, 0.6)' }} />
      </div>
    </div>
  );
}

function MapCard({ kind, label, team, tone }) {
  const c = tone === 'teal' ? TEAL : ORANGE;
  return (
    <div style={{
      padding: 14, borderRadius: 12,
      border: `1px solid ${tone === 'teal' ? BORDER_TEAL : 'rgba(232, 93, 51, 0.3)'}`,
      background: tone === 'teal' ? TEAL_DIM : ORANGE_DIM,
      display: 'flex', flexDirection: 'column', gap: 10,
    }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <Mono style={{ color: c }}>◆ {label.toUpperCase()}</Mono>
        <MapGlyph kind={kind} size={28} color={c} />
      </div>
      <div>
        <div style={{ fontFamily: 'Wix Madefor Display, system-ui', fontWeight: 700, fontSize: 15, textTransform: 'capitalize' }}>{kind}</div>
        <Mono style={{ color: c, display: 'block', marginTop: 2 }}>{team}</Mono>
      </div>
    </div>
  );
}

Object.assign(window, {
  WelcomeScreen, Q1Screen, Q2Screen, Q3Screen, Q4Screen,
  LoadingScreen, TeaserScreen, SignupScreen, ResultScreen,
});
