// Sporda — Session 4 · Phase A: 16 power-user features as composable components.
// Each export pair: <Foo .../> the component (often with states), and
// <FooDemo/> the artboard that displays the component + its variants on a
// clean canvas. Composition examples (b) go inside their feature-specific
// example screens at the bottom of this file.

const { useState: useS } = React;

// ----- thin reusable artboard for component galleries --------------------
// Wraps demo content in a phone-width sheet so it sits well in the canvas.
const ComponentArtboard = ({ title, subtitle, children }) => (
  <div style={{ width: 390, minHeight: 600, padding: '24px 20px 32px', background: 'var(--bg-base)', color: 'var(--text-primary)', fontFamily: 'var(--font-ui)', display: 'flex', flexDirection: 'column', gap: 20 }}>
    <div>
      <div style={{ fontSize: 11, fontWeight: 700, color: 'var(--text-muted)', letterSpacing: '0.06em', textTransform: 'uppercase' }}>Component</div>
      <div style={{ fontSize: 22, fontWeight: 800, letterSpacing: '-0.01em', marginTop: 4 }}>{title}</div>
      {subtitle && <div style={{ fontSize: 12, color: 'var(--text-secondary)', marginTop: 4, textWrap: 'pretty' }}>{subtitle}</div>}
    </div>
    <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>{children}</div>
  </div>
);

const StateLabel = ({ children }) => (
  <div style={{ fontSize: 10, fontWeight: 700, color: 'var(--text-muted)', letterSpacing: '0.06em', textTransform: 'uppercase', marginBottom: 8 }}>{children}</div>
);

// ===========================================================================
// 076 — MATCH COUNTDOWN WIDGET
// ===========================================================================
const Countdown = ({ d, h, m, s, label = 'Kick-off in' }) => (
  <div style={{
    background: 'var(--hero-grad)',
    border: '1px solid var(--border-strong)',
    borderRadius: 18, padding: '14px 16px',
    display: 'flex', alignItems: 'center', gap: 14,
  }}>
    <div style={{ flex: 1, minWidth: 0 }}>
      <div style={{ fontSize: 10, fontWeight: 700, color: 'var(--text-secondary)', letterSpacing: '0.06em', textTransform: 'uppercase' }}>{label}</div>
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 8, marginTop: 6 }}>
        {[['D', d], ['H', h], ['M', m], ['S', s]].map(([u, v], i) => (
          <div key={u} style={{ display: 'flex', alignItems: 'baseline', gap: 2 }}>
            <span className="mono" style={{ fontSize: 22, fontWeight: 800, fontVariantNumeric: 'tabular-nums' }}>{String(v).padStart(2, '0')}</span>
            <span style={{ fontSize: 10, color: 'var(--text-muted)', fontWeight: 700 }}>{u}</span>
            {i < 3 && <span style={{ color: 'var(--text-muted)', fontSize: 16, padding: '0 2px' }}>:</span>}
          </div>
        ))}
      </div>
    </div>
    <button style={{ width: 36, height: 36, borderRadius: '50%', background: 'var(--accent)', color: 'var(--accent-ink)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
      <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 6v6l4 2"/><circle cx="12" cy="12" r="10"/></svg>
    </button>
  </div>
);

const CountdownDemo = () => (
  <ComponentArtboard title="076 · Match countdown widget" subtitle="Live ticker for upcoming matches. Belongs at the top of Home when there's a followed fixture within 24h.">
    <div>
      <StateLabel>2-day fixture</StateLabel>
      <Countdown d={2} h={4} m={32} s={11}/>
    </div>
    <div>
      <StateLabel>Imminent (≤1 hour) — pulses</StateLabel>
      <div style={{ animation: 'pulse 1.2s ease-in-out infinite' }}>
        <Countdown d={0} h={0} m={42} s={59} label="Starting in"/>
      </div>
    </div>
    <div>
      <StateLabel>In-app preview · embedded into Home</StateLabel>
      <div style={{ background: 'var(--bg-surface)', borderRadius: 16, padding: 14 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 10 }}>
          <Crest name="Arsenal" code="ARS" bg="#EF0107"/>
          <div style={{ fontSize: 12, color: 'var(--text-secondary)' }}>Arsenal vs Liverpool · Sat 21:00</div>
        </div>
        <Countdown d={1} h={11} m={32} s={11}/>
      </div>
    </div>
  </ComponentArtboard>
);

// ===========================================================================
// 077 — LIVE-NOW STICKY BANNER (in tab bar / under header)
// ===========================================================================
const LiveNowBanner = ({ count = 3, jump = true }) => (
  <div style={{
    background: 'linear-gradient(90deg, rgba(255,59,92,0.18) 0%, rgba(255,59,92,0.08) 100%)',
    border: '1px solid rgba(255,59,92,0.30)', borderRadius: 14,
    padding: '10px 14px',
    display: 'flex', alignItems: 'center', gap: 12,
  }}>
    <span style={{ width: 8, height: 8, borderRadius: '50%', background: 'var(--live)', animation: 'pulse 1.2s ease-in-out infinite' }}/>
    <div style={{ flex: 1 }}>
      <div style={{ fontSize: 13, fontWeight: 700 }}>{count} followed match{count === 1 ? '' : 'es'} live</div>
      <div style={{ fontSize: 11, color: 'var(--text-secondary)' }}>Arsenal · Lakers · F1 Monaco GP</div>
    </div>
    {jump && <button style={{ fontSize: 12, fontWeight: 700, color: 'var(--live)' }}>Jump in</button>}
  </div>
);

const LiveNowBannerDemo = () => (
  <ComponentArtboard title="077 · Live-now sticky banner" subtitle="Top-of-feed nudge when followed matches are in play. Tapping jumps to the most-watched of the bunch.">
    <div><StateLabel>3 live (default)</StateLabel><LiveNowBanner count={3}/></div>
    <div><StateLabel>1 live (singular copy)</StateLabel><LiveNowBanner count={1}/></div>
    <div><StateLabel>Composed · Home below header</StateLabel>
      <div style={{ background: 'var(--bg-surface)', borderRadius: 16, padding: 14 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: '50%', background: 'linear-gradient(135deg, #7158E2, #3D5AFE)' }}/>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 11, color: 'var(--text-secondary)' }}>Sunday afternoon</div>
            <div style={{ fontSize: 14, fontWeight: 700 }}>Ben Rascals</div>
          </div>
        </div>
        <LiveNowBanner count={3}/>
      </div>
    </div>
  </ComponentArtboard>
);

// ===========================================================================
// 078 — GOAL REACTIONS SHEET (🔥 💀 🐐) — emoji used only because part of UX
// ===========================================================================
const REACTIONS = [
  { e: '🔥', lbl: 'Fire',    count: 248, mine: true },
  { e: '🐐', lbl: 'GOAT',    count: 102 },
  { e: '😱', lbl: 'Shock',   count: 64 },
  { e: '💀', lbl: 'Skull',   count: 38 },
  { e: '👏', lbl: 'Clap',    count: 27 },
  { e: '🤡', lbl: 'Clown',   count: 12 },
];

const GoalReactBar = ({ rs = REACTIONS }) => (
  <div style={{ display: 'flex', gap: 6, padding: '4px 0', overflowX: 'auto', scrollbarWidth: 'none' }}>
    {rs.map(r => (
      <button key={r.e} style={{
        flex: 'none',
        display: 'inline-flex', alignItems: 'center', gap: 6,
        padding: '6px 10px', borderRadius: 999,
        background: r.mine ? 'rgba(200,255,62,0.10)' : 'var(--bg-inset)',
        border: '1px solid ' + (r.mine ? 'rgba(200,255,62,0.30)' : 'var(--border-hairline)'),
        color: r.mine ? 'var(--accent)' : 'var(--text-primary)',
        fontSize: 13, fontWeight: 700,
      }}>
        <span style={{ fontSize: 14 }}>{r.e}</span>
        <span className="mono">{r.count}</span>
      </button>
    ))}
  </div>
);

const GoalReactDemo = () => (
  <ComponentArtboard title="078 · Goal reactions" subtitle="One-tap reaction strip under live moments. Your reaction is lime-tinted; counts are global.">
    <div><StateLabel>Default (Fire active)</StateLabel><GoalReactBar/></div>
    <div><StateLabel>Composed · Event row in Match · Events</StateLabel>
      <div className="card">
        <div style={{ display: 'flex', alignItems: 'flex-start', gap: 10 }}>
          <span style={{ color: 'var(--positive)', display: 'flex', marginTop: 4 }}><I.goal/></span>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 13, fontWeight: 700 }}>J. Okonkwo · 67'</div>
            <div style={{ fontSize: 11, color: 'var(--text-secondary)', marginTop: 2 }}>Atlas FC · second goal</div>
            <div style={{ marginTop: 10 }}><GoalReactBar/></div>
          </div>
        </div>
      </div>
    </div>
  </ComponentArtboard>
);

// ===========================================================================
// 079 — SHARE-AS-IMAGE FRAME — branded card for export
// ===========================================================================
const ShareImageFrame = ({ variant = 'scoreline' }) => (
  <div style={{
    background: 'var(--hero-grad)',
    border: '1px solid var(--border-strong)',
    borderRadius: 20, padding: 22,
    aspectRatio: variant === 'square' ? '1' : '5 / 4',
    color: 'var(--text-primary)',
    position: 'relative',
    display: 'flex', flexDirection: 'column',
  }}>
    {/* Brand mark */}
    <div style={{ display: 'flex', alignItems: 'center', gap: 6, position: 'absolute', top: 16, left: 16, fontSize: 12, fontWeight: 700, color: 'var(--text-secondary)' }}>
      <div style={{ width: 16, height: 16, borderRadius: 4, background: 'var(--accent)' }}/> Sporda
    </div>
    <span className="pill live" style={{ position: 'absolute', top: 14, right: 14 }}><span className="dot"/>LIVE</span>

    {variant === 'scoreline' && (
      <div style={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center', textAlign: 'center', gap: 14 }}>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr auto 1fr', alignItems: 'center', gap: 10 }}>
          <div><Crest name="Arsenal" code="ARS" size="lg" bg="#EF0107"/><div style={{ fontSize: 13, fontWeight: 700, marginTop: 6 }}>ARS</div></div>
          <div style={{ display: 'flex', alignItems: 'baseline', gap: 6 }}><span className="score lg">3</span><span style={{ color: 'var(--text-muted)' }}>:</span><span className="score lg">1</span></div>
          <div><Crest name="Liverpool" code="LIV" size="lg" bg="#C8102E"/><div style={{ fontSize: 13, fontWeight: 700, marginTop: 6 }}>LIV</div></div>
        </div>
        <div style={{ fontSize: 11, color: 'var(--text-muted)', marginTop: 8 }}>67' · Emirates · Premier League · MW 13</div>
      </div>
    )}
    {variant === 'stat' && (
      <div style={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center', gap: 16 }}>
        <div style={{ fontSize: 28, fontWeight: 800, letterSpacing: '-0.02em' }}>Saka · 12 chances created</div>
        <div style={{ fontSize: 13, color: 'var(--text-secondary)' }}>Most by an Arsenal player in a single PL match since 2008.</div>
      </div>
    )}
  </div>
);

const ShareImageDemo = () => (
  <ComponentArtboard title="079 · Share-as-image frame" subtitle="Branded export frame for scorelines and stat callouts. Auto-applied when the user taps Share on any match card or stat panel.">
    <div><StateLabel>Scoreline (5:4)</StateLabel><ShareImageFrame variant="scoreline"/></div>
    <div><StateLabel>Stat callout (5:4)</StateLabel><ShareImageFrame variant="stat"/></div>
    <div><StateLabel>Square (Instagram 1:1)</StateLabel><ShareImageFrame variant="square"/></div>
  </ComponentArtboard>
);

// ===========================================================================
// 080 — LONG-PRESS TEAM QUICK-ACTION SHEET
// ===========================================================================
const QuickActions = ({ team = { name: 'Arsenal', code: 'ARS', bg: '#EF0107' } }) => (
  <div style={{ background: 'var(--bg-surface)', borderRadius: 18, border: '1px solid var(--border-hairline)', padding: 12, boxShadow: '0 16px 48px rgba(0,0,0,0.45)' }}>
    {/* Team chip */}
    <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: 10, marginBottom: 6, borderBottom: '1px solid var(--border-hairline)' }}>
      <Crest name={team.name} code={team.code} bg={team.bg}/>
      <div style={{ flex: 1 }}>
        <div style={{ fontSize: 14, fontWeight: 700 }}>{team.name}</div>
        <div style={{ fontSize: 11, color: 'var(--text-secondary)' }}>Premier League · 2nd</div>
      </div>
    </div>
    {[
      { icon: <I.star/>, lbl: 'Follow', meta: '+ Goal alerts' },
      { icon: <I.bell size={16}/>, lbl: 'Customize alerts', meta: 'Goals · Lineups · Final' },
      { icon: <I.cal size={16}/>, lbl: 'Add next match to calendar', meta: 'Sat 21:00 vs LIV' },
      { icon: <I.share size={14}/>, lbl: 'Share', meta: 'Send team page' },
      { icon: <I.x size={16}/>, lbl: 'Mute', meta: 'Hide from feed for 24h', danger: true },
    ].map(a => (
      <button key={a.lbl} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 10px', width: '100%', textAlign: 'left', borderRadius: 10 }}>
        <span style={{ width: 32, height: 32, borderRadius: 10, background: 'var(--bg-inset)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: a.danger ? 'var(--negative)' : 'var(--text-secondary)' }}>{a.icon}</span>
        <div style={{ flex: 1 }}>
          <div style={{ fontSize: 13, fontWeight: 600, color: a.danger ? 'var(--negative)' : 'var(--text-primary)' }}>{a.lbl}</div>
          <div style={{ fontSize: 11, color: 'var(--text-muted)' }}>{a.meta}</div>
        </div>
      </button>
    ))}
  </div>
);

const LongPressDemo = () => (
  <ComponentArtboard title="080 · Long-press team quick actions" subtitle="Floating sheet anchored to the pressed element. Same shape for players (with stats preview) and leagues (with bracket).">
    <div><StateLabel>Default</StateLabel><QuickActions/></div>
    <div><StateLabel>Already followed (Follow → Unfollow)</StateLabel>
      <div style={{ background: 'var(--bg-surface)', borderRadius: 18, border: '1px solid var(--border-hairline)', padding: 12 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: 10, marginBottom: 6, borderBottom: '1px solid var(--border-hairline)' }}>
          <Crest name="Lakers" code="LAL" bg="#552583"/>
          <div style={{ flex: 1 }}><div style={{ fontSize: 14, fontWeight: 700 }}>L.A. Lakers</div><div style={{ fontSize: 11, color: 'var(--accent)' }}>Following · 142 alerts sent</div></div>
        </div>
        <button style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '10px 10px', width: '100%', textAlign: 'left', borderRadius: 10 }}>
          <span style={{ width: 32, height: 32, borderRadius: 10, background: 'rgba(200,255,62,0.10)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--accent)' }}><I.check/></span>
          <div style={{ flex: 1 }}><div style={{ fontSize: 13, fontWeight: 700, color: 'var(--accent)' }}>Following</div><div style={{ fontSize: 11, color: 'var(--text-muted)' }}>Tap to unfollow</div></div>
        </button>
      </div>
    </div>
  </ComponentArtboard>
);

// ===========================================================================
// 081 — ADD-TO-CALENDAR SHEET
// ===========================================================================
const AddToCal = () => (
  <div style={{ background: 'var(--bg-surface)', borderRadius: 20, border: '1px solid var(--border-hairline)', padding: 20 }}>
    <div style={{ width: 40, height: 4, background: 'var(--text-muted)', borderRadius: 2, margin: '0 auto 16px' }}/>
    <div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 18 }}>
      <Crest name="Arsenal" code="ARS" bg="#EF0107"/>
      <div style={{ flex: 1 }}>
        <div style={{ fontSize: 14, fontWeight: 700 }}>Arsenal vs Liverpool</div>
        <div style={{ fontSize: 11, color: 'var(--text-secondary)' }}>Sat 28 May · 21:00 · Emirates</div>
      </div>
      <Crest name="Liverpool" code="LIV" bg="#C8102E"/>
    </div>
    {[
      { svc: 'Apple Calendar', glyph: '', bg: '#FFFFFF', fg: '#000' },
      { svc: 'Google Calendar', glyph: 'G', bg: '#1A73E8', fg: '#FFF' },
      { svc: 'Outlook', glyph: 'O', bg: '#0078D4', fg: '#FFF' },
      { svc: 'Download .ics', glyph: '⤓', bg: 'var(--bg-inset)', fg: 'var(--text-primary)' },
    ].map(s => (
      <button key={s.svc} style={{ width: '100%', display: 'flex', alignItems: 'center', gap: 14, padding: 12, marginBottom: 6, borderRadius: 12, background: 'var(--bg-inset)' }}>
        <span style={{ width: 36, height: 36, borderRadius: 10, background: s.bg, color: s.fg, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 14, fontWeight: 800 }}>{s.glyph || '📅'}</span>
        <span style={{ flex: 1, textAlign: 'left', fontSize: 14, fontWeight: 600 }}>{s.svc}</span>
        <I.chevR/>
      </button>
    ))}
    <div style={{ marginTop: 16, padding: '12px 14px', background: 'var(--bg-inset)', borderRadius: 12, display: 'flex', alignItems: 'center', gap: 10 }}>
      <I.bell size={16}/>
      <div style={{ flex: 1, fontSize: 13, fontWeight: 600 }}>Set reminder · 15 min before</div>
      <div className="toggle on"/>
    </div>
  </div>
);

const AddToCalDemo = () => (
  <ComponentArtboard title="081 · Add-to-calendar sheet" subtitle="Bottom sheet from match countdown or fixture row. iOS surfaces .ics; Android surfaces Google directly.">
    <AddToCal/>
  </ComponentArtboard>
);

// ===========================================================================
// 082 — TAP-SCORE xG FLIP CARD
// ===========================================================================
const XgFlipCard = () => {
  const [flipped, setFlipped] = useS(false);
  return (
    <div style={{ position: 'relative', height: 200, perspective: 1000 }}>
      <div onClick={() => setFlipped(!flipped)} style={{
        position: 'relative', width: '100%', height: '100%',
        transformStyle: 'preserve-3d', transition: 'transform 0.5s cubic-bezier(0.2,0,0,1)',
        transform: flipped ? 'rotateY(180deg)' : 'rotateY(0deg)',
        cursor: 'pointer',
      }}>
        {/* Front — scoreline */}
        <div style={{ position: 'absolute', inset: 0, backfaceVisibility: 'hidden', background: 'var(--hero-grad)', borderRadius: 18, padding: 18, display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
          <div style={{ fontSize: 11, color: 'var(--text-secondary)', textAlign: 'center', marginBottom: 10 }}>Tap to flip · xG view</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr auto 1fr', alignItems: 'center', textAlign: 'center' }}>
            <div><Crest name="Arsenal" code="ARS" bg="#EF0107" size="lg"/><div style={{ fontSize: 12, fontWeight: 700, marginTop: 6 }}>ARS</div></div>
            <div style={{ display: 'flex', alignItems: 'baseline', gap: 6 }}><span className="score">3</span><span style={{ color: 'var(--text-muted)' }}>:</span><span className="score">1</span></div>
            <div><Crest name="Liverpool" code="LIV" bg="#C8102E" size="lg"/><div style={{ fontSize: 12, fontWeight: 700, marginTop: 6 }}>LIV</div></div>
          </div>
        </div>
        {/* Back — xG */}
        <div style={{ position: 'absolute', inset: 0, backfaceVisibility: 'hidden', transform: 'rotateY(180deg)', background: 'linear-gradient(135deg, #1F2D26 0%, #182320 100%)', borderRadius: 18, padding: 18, display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
          <div style={{ fontSize: 11, color: 'var(--text-secondary)', textAlign: 'center', marginBottom: 10 }}>Tap to flip back · Expected goals (xG)</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr auto 1fr', alignItems: 'center', textAlign: 'center', gap: 10 }}>
            <div><div style={{ fontSize: 12, fontWeight: 700, marginBottom: 6 }}>ARS</div><span className="score" style={{ color: 'var(--accent)' }}>2.4</span></div>
            <span style={{ color: 'var(--text-muted)' }}>xG</span>
            <div><div style={{ fontSize: 12, fontWeight: 700, marginBottom: 6 }}>LIV</div><span className="score">1.6</span></div>
          </div>
          <div style={{ display: 'flex', height: 6, gap: 4, marginTop: 14 }}>
            <div style={{ flex: 2.4, background: 'var(--accent)', borderRadius: 3 }}/>
            <div style={{ flex: 1.6, background: 'var(--text-secondary)', opacity: 0.4, borderRadius: 3 }}/>
          </div>
        </div>
      </div>
    </div>
  );
};

const XgFlipDemo = () => (
  <ComponentArtboard title="082 · Tap-score xG flip" subtitle="Tapping the match hero flips the card to expose xG. Works on any sport panel — possession / accuracy / serve %, etc.">
    <div><StateLabel>Interactive (tap to flip)</StateLabel><XgFlipCard/></div>
  </ComponentArtboard>
);

// ===========================================================================
// 083 — AI "FOR YOU" DIGEST CARD
// ===========================================================================
const AIDigestCard = ({ size = 'normal' }) => (
  <div style={{
    background: 'linear-gradient(135deg, rgba(200,255,62,0.06) 0%, rgba(200,255,62,0.02) 50%, transparent 100%), var(--bg-surface)',
    border: '1px solid rgba(200,255,62,0.20)',
    borderRadius: 18, padding: size === 'compact' ? 14 : 18,
  }}>
    <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 10 }}>
      <span style={{ width: 26, height: 26, borderRadius: '50%', background: 'var(--accent)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--accent-ink)', fontSize: 12, fontWeight: 800 }}>✦</span>
      <div className="tag-micro" style={{ color: 'var(--accent)' }}>For you · digest</div>
      <span style={{ marginLeft: 'auto', fontSize: 11, color: 'var(--text-muted)' }}>just now</span>
    </div>
    <div style={{ fontSize: size === 'compact' ? 14 : 16, fontWeight: 700, lineHeight: 1.35, textWrap: 'pretty', letterSpacing: '-0.005em' }}>
      Arsenal beat Liverpool 3–1 at the Emirates. Saka created 12 chances, the most by any PL player this weekend. Saliba returned from injury after 6 matches out.
    </div>
    {size !== 'compact' && (
      <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginTop: 14, padding: '10px 12px', background: 'var(--bg-inset)', borderRadius: 12 }}>
        <div style={{ width: 28, height: 28, borderRadius: '50%', background: hashColor('Saka'), display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 700, fontSize: 11 }}>SA</div>
        <div style={{ flex: 1, fontSize: 12, color: 'var(--text-secondary)' }}>Bukayo Saka · 12 chances, 2 assists</div>
        <I.chevR/>
      </div>
    )}
    <div style={{ marginTop: 12, display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 11, color: 'var(--text-muted)' }}>
      <span>Auto-generated · sources: Opta, BBC Sport</span>
      <div style={{ display: 'flex', gap: 12 }}>
        <button style={{ color: 'var(--text-secondary)' }}>👍</button>
        <button style={{ color: 'var(--text-secondary)' }}>👎</button>
      </div>
    </div>
  </div>
);

const AIDigestDemo = () => (
  <ComponentArtboard title="083 · AI 'For You' digest" subtitle="Personalized recap card. Anchored at the top of Home after a followed match ends. Hour-fresh; pulls from licensed sources.">
    <div><StateLabel>Normal</StateLabel><AIDigestCard/></div>
    <div><StateLabel>Compact (in carousel)</StateLabel><AIDigestCard size="compact"/></div>
  </ComponentArtboard>
);

// ===========================================================================
// 084 — RIVALRY / DERBY SPLASH
// ===========================================================================
const RivalrySplash = () => (
  <div style={{
    position: 'relative', borderRadius: 24, padding: 24,
    background: 'linear-gradient(135deg, #C8102E 0%, #1A2320 35%, #1A2320 65%, #EF0107 100%)',
    overflow: 'hidden',
  }}>
    <div className="tag-micro" style={{ color: '#FFFFFF', opacity: 0.7, marginBottom: 4 }}>The North London Derby · Premier League</div>
    <div style={{ fontSize: 32, fontWeight: 900, lineHeight: 1.0, letterSpacing: '-0.03em', color: '#FFF', textWrap: 'balance' }}>Arsenal<br/>vs Tottenham</div>
    <div style={{ marginTop: 18, display: 'grid', gridTemplateColumns: '1fr auto 1fr', alignItems: 'center', gap: 12 }}>
      <div style={{ textAlign: 'center' }}>
        <Crest name="Arsenal" code="ARS" bg="#EF0107" size="lg"/>
        <div style={{ marginTop: 8, fontSize: 12, fontWeight: 700, color: '#FFF' }}>3rd · 28 pts</div>
      </div>
      <div style={{ fontSize: 11, fontWeight: 800, color: '#FFF', opacity: 0.8 }}>SAT<br/>17:30</div>
      <div style={{ textAlign: 'center' }}>
        <Crest name="Tottenham" code="TOT" bg="#132257"/>
        <div style={{ marginTop: 8, fontSize: 12, fontWeight: 700, color: '#FFF' }}>5th · 22 pts</div>
      </div>
    </div>
    <div style={{ marginTop: 16, padding: '10px 12px', background: 'rgba(0,0,0,0.35)', borderRadius: 12, fontSize: 11, color: '#FFF' }}>
      Head to head · ARS leads <span className="mono" style={{ fontWeight: 800 }}>87–55</span> across all competitions.
    </div>
  </div>
);

const RivalryDemo = () => (
  <ComponentArtboard title="084 · Rivalry / derby splash" subtitle="Replaces the standard hero whenever a followed rivalry fixture is on the schedule. Triggered by a hand-curated rivalry table.">
    <RivalrySplash/>
  </ComponentArtboard>
);

// ===========================================================================
// 085 — STREAK + ACHIEVEMENTS
// ===========================================================================
const StreakChip = ({ days = 14, today = true }) => (
  <div style={{ display: 'inline-flex', alignItems: 'center', gap: 6, padding: '6px 12px', background: today ? 'var(--accent)' : 'var(--bg-inset)', color: today ? 'var(--accent-ink)' : 'var(--text-primary)', borderRadius: 999, fontWeight: 800, fontSize: 13 }}>
    <span style={{ fontSize: 14 }}>🔥</span>
    <span className="mono">{days}</span>
    <span style={{ fontWeight: 600, fontSize: 11, opacity: 0.7 }}>day streak</span>
  </div>
);

const Achievement = ({ icon, name, prog, max, unlocked }) => (
  <div style={{ background: 'var(--bg-surface)', border: '1px solid ' + (unlocked ? 'rgba(200,255,62,0.20)' : 'var(--border-hairline)'), borderRadius: 14, padding: 12, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6 }}>
    <div style={{ width: 36, height: 36, borderRadius: 10, background: unlocked ? 'var(--accent)' : 'var(--bg-inset)', color: unlocked ? 'var(--accent-ink)' : 'var(--text-muted)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
      {icon}
    </div>
    <div style={{ fontSize: 11, fontWeight: 700, textAlign: 'center', minHeight: 28, color: unlocked ? 'var(--text-primary)' : 'var(--text-secondary)' }}>{name}</div>
    {prog !== undefined && (
      <div style={{ width: '100%', height: 3, background: 'var(--bg-inset)', borderRadius: 2 }}>
        <div style={{ width: `${(prog / max) * 100}%`, height: '100%', background: unlocked ? 'var(--accent)' : 'var(--text-secondary)', borderRadius: 2 }}/>
      </div>
    )}
    <div className="mono" style={{ fontSize: 10, color: 'var(--text-muted)' }}>{prog}/{max}</div>
  </div>
);

const StreakDemo = () => (
  <ComponentArtboard title="085 · Streak + achievements" subtitle="Streak chip lives next to the profile avatar. Achievements page is its own sub-screen in Profile.">
    <div><StateLabel>Streak chip (today extended)</StateLabel><StreakChip days={14}/></div>
    <div><StateLabel>Streak chip (yesterday — needs to check in)</StateLabel><StreakChip days={14} today={false}/></div>
    <div>
      <StateLabel>Achievement grid</StateLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 10 }}>
        <Achievement icon={<I.star size={18} fill/>} name="100 matches watched" prog={142} max={100} unlocked/>
        <Achievement icon={<I.bell size={18}/>} name="Notification king" prog={50} max={50} unlocked/>
        <Achievement icon={<I.trophy/>} name="Predicted 10 in a row" prog={4} max={10}/>
        <Achievement icon={<I.heart size={18} fill/>} name="Followed 25 teams" prog={8} max={25}/>
        <Achievement icon={<I.share size={18}/>} name="Shared 50 scorelines" prog={12} max={50}/>
        <Achievement icon={<I.cmt size={18}/>} name="100 reactions" prog={37} max={100}/>
      </div>
    </div>
  </ComponentArtboard>
);

// ===========================================================================
// 086, 087, 088 — Followed *managers* (Teams, Players, Leagues)
// ===========================================================================
const FollowManagerRow = ({ entity, type }) => (
  <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 4px', borderBottom: '1px solid var(--border-hairline)' }}>
    {type === 'player' ? (
      <div style={{ width: 40, height: 40, borderRadius: '50%', background: hashColor(entity.name), display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 700, fontSize: 13 }}>{entity.name.split(' ').map(n => n[0]).join('').slice(0, 2)}</div>
    ) : type === 'league' ? (
      <div style={{ width: 40, height: 40, borderRadius: 10, background: entity.bg || '#3D5AFE', display: 'flex', alignItems: 'center', justifyContent: 'center', fontWeight: 800, fontSize: 12 }}>{entity.code}</div>
    ) : (
      <Crest name={entity.name} code={entity.code} bg={entity.bg}/>
    )}
    <div style={{ flex: 1, minWidth: 0 }}>
      <div style={{ fontSize: 14, fontWeight: 700, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{entity.name}</div>
      <div style={{ fontSize: 11, color: 'var(--text-secondary)' }}>{entity.meta}</div>
    </div>
    {entity.live && <span style={{ width: 6, height: 6, borderRadius: '50%', background: 'var(--live)' }}/>}
    <div className="toggle on"/>
  </div>
);

const ManagerScreen = ({ title, sub, items, type }) => (
  <div className="phone">
    <div className="viewport">
      <StatusBar/>
      <div className="body">
        <Header left={<RoundBtn><I.chevL size={18}/></RoundBtn>} title={title} right={<RoundBtn><I.search size={18}/></RoundBtn>}/>
        {/* Followed only filter */}
        <div style={{ padding: '0 20px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <div style={{ fontSize: 12, color: 'var(--text-secondary)' }}>{sub}</div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
            <span style={{ fontSize: 11, fontWeight: 700, color: 'var(--text-secondary)' }}>Followed only</span>
            <div className="toggle on"/>
          </div>
        </div>
        {/* Reorder hint */}
        <div style={{ margin: '0 20px 12px', padding: '10px 12px', background: 'var(--bg-inset)', borderRadius: 10, fontSize: 11, color: 'var(--text-muted)' }}>
          Drag to reorder · top {type === 'team' ? 'teams' : type === 'player' ? 'players' : 'leagues'} prioritized in your feed.
        </div>
        <div style={{ padding: '0 20px' }}>
          {items.map(e => <FollowManagerRow key={e.name} entity={e} type={type}/>)}
        </div>
        <div style={{ padding: '16px 20px 24px' }}>
          <button style={{ width: '100%', height: 48, borderRadius: 999, background: 'var(--bg-surface)', border: '1px dashed var(--border-strong)', color: 'var(--text-secondary)', fontWeight: 600, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6 }}>
            <I.plus size={18}/> Add {type === 'team' ? 'team' : type === 'player' ? 'player' : 'league'}
          </button>
        </div>
      </div>
      <BottomNav active="profile"/>
    </div>
  </div>
);

const ScreenFolTeams = () => <ManagerScreen
  title="Followed teams"
  sub="8 teams · drag to reorder"
  type="team"
  items={[
    { name: 'Arsenal', code: 'ARS', bg: '#EF0107', meta: 'Premier League · live 67\u2032', live: true },
    { name: 'L.A. Lakers', code: 'LAL', bg: '#552583', meta: 'NBA · final · Q4' },
    { name: 'Real Madrid', code: 'RMA', bg: '#FFFFFF', meta: 'La Liga · 1st · 38 pts' },
    { name: 'New Zealand', code: 'NZL', bg: '#000000', meta: 'Rugby · 12 followed' },
    { name: 'Mumbai Indians', code: 'MI', bg: '#005DA0', meta: 'IPL · 4th' },
    { name: 'McLaren', code: 'MCL', bg: '#FF8000', meta: 'F1 · 2 races to go' },
    { name: 'T1', code: 'T1', bg: '#E2012D', meta: 'LCK · semis' },
    { name: 'Chiefs', code: 'KC', bg: '#E31837', meta: 'NFL · 14–3' },
  ]}/>;

const ScreenFolPlayers = () => <ManagerScreen
  title="Followed players"
  sub="6 players"
  type="player"
  items={[
    { name: 'Bukayo Saka', meta: 'Arsenal · Forward · live' , live: true },
    { name: 'LeBron James', meta: 'Lakers · Forward · 38 pts last game' },
    { name: 'Virat Kohli', meta: 'India · Batter · 67 vs AUS' },
    { name: 'Max Verstappen', meta: 'Red Bull · P1 in standings' },
    { name: 'Rory McIlroy', meta: 'PGA · −11 thru R3' },
    { name: 'Faker', meta: 'T1 mid · Worlds semifinal' },
  ]}/>;

const ScreenFolLeagues = () => <ManagerScreen
  title="Followed leagues"
  sub="4 leagues"
  type="league"
  items={[
    { name: 'Premier League', code: 'PL', bg: '#3D5AFE', meta: 'Matchweek 13 · 5 live' },
    { name: 'NBA', code: 'NBA', bg: '#C8102E', meta: 'Conference Finals · G4' },
    { name: 'Formula 1', code: 'F1', bg: '#FFFFFF', meta: 'Monaco GP · lap 45/78', live: true },
    { name: 'IPL', code: 'IPL', bg: '#FFA42B', meta: 'Group stage · 3 matches today' },
  ]}/>;

const FollowedTeamsDemo = () => <ScreenFolTeams/>;
const FollowedPlayersDemo = () => <ScreenFolPlayers/>;
const FollowedLeaguesDemo = () => <ScreenFolLeagues/>;

// ===========================================================================
// 089 — BLOCK / MUTE LIST
// ===========================================================================
const ScreenBlocks = () => (
  <div className="phone">
    <div className="viewport">
      <StatusBar/>
      <div className="body">
        <Header left={<RoundBtn><I.chevL size={18}/></RoundBtn>} title="Blocked & muted"/>
        <div style={{ padding: '0 20px 16px' }}>
          <div className="tag-micro" style={{ color: 'var(--text-secondary)', marginBottom: 10 }}>Muted teams · won't show in feed</div>
          {[
            { name: 'Chelsea',   code: 'CHE', bg: '#034694', until: '24 hours' },
            { name: 'Inter',     code: 'INT', bg: '#0068A8', until: 'permanently' },
          ].map(t => (
            <div key={t.code} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 0', borderBottom: '1px solid var(--border-hairline)' }}>
              <Crest name={t.name} code={t.code} bg={t.bg}/>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 14, fontWeight: 700 }}>{t.name}</div>
                <div style={{ fontSize: 11, color: 'var(--text-secondary)' }}>Muted {t.until}</div>
              </div>
              <button style={{ fontSize: 12, fontWeight: 700, color: 'var(--accent)' }}>Unmute</button>
            </div>
          ))}
        </div>
        <div style={{ padding: '0 20px 16px' }}>
          <div className="tag-micro" style={{ color: 'var(--text-secondary)', marginBottom: 10 }}>Hidden keywords</div>
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
            {['spoilers', 'transfers', 'gambling', 'VAR'].map(k => (
              <div key={k} className="pill outline" style={{ paddingRight: 8 }}>
                {k}
                <span style={{ marginLeft: 6, color: 'var(--text-muted)' }}><I.x size={12}/></span>
              </div>
            ))}
            <div className="pill outline" style={{ color: 'var(--text-muted)' }}>+ Add keyword</div>
          </div>
        </div>
        <div style={{ padding: '0 20px 16px' }}>
          <div className="tag-micro" style={{ color: 'var(--text-secondary)', marginBottom: 10 }}>Blocked users</div>
          <div style={{ padding: '12px 14px', background: 'var(--bg-inset)', borderRadius: 12, fontSize: 12, color: 'var(--text-muted)' }}>
            No blocked users. Blocked users won't be able to reply to your posts or send you DMs.
          </div>
        </div>
      </div>
      <BottomNav active="profile"/>
    </div>
  </div>
);

// ===========================================================================
// 090, 091 — HELP CENTER ROOT + ARTICLE
// ===========================================================================
const ScreenHelpRoot = () => (
  <div className="phone">
    <div className="viewport">
      <StatusBar/>
      <div className="body">
        <Header left={<RoundBtn><I.chevL size={18}/></RoundBtn>} title="Help center"/>
        <div style={{ padding: '0 20px 16px' }}>
          <div className="searchbar"><I.search size={18}/><input placeholder="Search help articles"/></div>
        </div>
        <div style={{ padding: '0 20px 20px' }}>
          <div className="tag-micro" style={{ color: 'var(--text-secondary)', marginBottom: 10 }}>Top topics</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
            {[
              { icon: <I.bell/>, lbl: 'Notifications' },
              { icon: <I.user/>, lbl: 'Account' },
              { icon: <I.play size={20}/>, lbl: 'Watch' },
              { icon: <I.share/>, lbl: 'Sharing' },
            ].map(t => (
              <div key={t.lbl} style={{ background: 'var(--bg-surface)', borderRadius: 14, padding: 14 }}>
                <div style={{ color: 'var(--accent)', marginBottom: 10 }}>{t.icon}</div>
                <div style={{ fontSize: 13, fontWeight: 700 }}>{t.lbl}</div>
              </div>
            ))}
          </div>
        </div>
        <div style={{ padding: '0 20px 20px' }}>
          <div className="tag-micro" style={{ color: 'var(--text-secondary)', marginBottom: 10 }}>Popular articles</div>
          <div style={{ background: 'var(--bg-surface)', borderRadius: 14 }}>
            {[
              'Why am I not getting goal alerts?',
              'How do I follow a team?',
              'What does "score reveal" do?',
              'Can I cast Sporda to my TV?',
              'How do I delete my account?',
            ].map((a, i, arr) => (
              <div key={a} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '14px 16px', borderBottom: i < arr.length - 1 ? '1px solid var(--border-hairline)' : 0 }}>
                <div style={{ flex: 1, fontSize: 14, fontWeight: 500 }}>{a}</div>
                <I.chevR/>
              </div>
            ))}
          </div>
        </div>
        <div style={{ padding: '0 20px 24px' }}>
          <button style={{ width: '100%', height: 48, borderRadius: 999, background: 'var(--accent)', color: 'var(--accent-ink)', fontWeight: 700, fontSize: 14 }}>Contact support</button>
        </div>
      </div>
      <BottomNav active="profile"/>
    </div>
  </div>
);

const ScreenHelpArticle = () => (
  <div className="phone">
    <div className="viewport">
      <StatusBar/>
      <div className="body">
        <Header left={<RoundBtn><I.chevL size={18}/></RoundBtn>} title="Article" right={<RoundBtn><I.share size={16}/></RoundBtn>}/>
        <div style={{ padding: '0 20px' }}>
          <div className="tag-micro" style={{ color: 'var(--accent)', marginBottom: 8 }}>Notifications</div>
          <h1 style={{ fontSize: 24, fontWeight: 800, lineHeight: 1.15, margin: 0, letterSpacing: '-0.01em', textWrap: 'balance' }}>
            Why am I not getting goal alerts?
          </h1>
          <div style={{ marginTop: 8, fontSize: 12, color: 'var(--text-muted)' }}>Updated 12 May 2026 · 2 min read</div>
        </div>
        <div style={{ padding: '20px 20px 0', fontSize: 14, color: 'var(--text-primary)', lineHeight: 1.6 }}>
          If you're not seeing alerts when a followed team scores, check these four things — in order.
          <ol style={{ paddingLeft: 18, marginTop: 16, display: 'flex', flexDirection: 'column', gap: 12 }}>
            <li>
              <strong>Open Settings → Notifications</strong>. Confirm Goal alerts is on. If it's not, this is most likely the cause.
            </li>
            <li>
              <strong>Check Quiet hours</strong>. By default, Sporda pauses alerts between midnight and 7 AM in your local time.
            </li>
            <li>
              <strong>System-level permission</strong>. iOS and Android both have a master notification switch. We open it for you from the Notifications screen.
            </li>
            <li>
              <strong>Followed list</strong>. Make sure the team you expected an alert from is on your followed list — see Followed teams in your profile.
            </li>
          </ol>
        </div>
        <div style={{ padding: '20px 20px 0' }}>
          <div style={{ padding: 14, background: 'var(--bg-inset)', borderRadius: 12, fontSize: 12, color: 'var(--text-secondary)' }}>
            <strong style={{ color: 'var(--text-primary)' }}>Still stuck?</strong> Send a screenshot and we'll dig in within 24h.
          </div>
        </div>
        <div style={{ padding: '20px 20px 24px', textAlign: 'center' }}>
          <div style={{ fontSize: 12, color: 'var(--text-muted)', marginBottom: 10 }}>Was this helpful?</div>
          <div style={{ display: 'flex', gap: 10, justifyContent: 'center' }}>
            <button className="pill outline">👍 Yes</button>
            <button className="pill outline">👎 No</button>
          </div>
        </div>
      </div>
      <BottomNav active="profile"/>
    </div>
  </div>
);

// Re-bind any earlier placeholders that lived under same names.
Object.assign(window, {
  // Components (Phase A primary deliverables)
  Countdown, LiveNowBanner, GoalReactBar, ShareImageFrame, QuickActions,
  AddToCal, XgFlipCard, AIDigestCard, RivalrySplash, StreakChip, Achievement,
  FollowManagerRow, ManagerScreen,
  // Demo artboards
  CountdownDemo, LiveNowBannerDemo, GoalReactDemo, ShareImageDemo,
  LongPressDemo, AddToCalDemo, XgFlipDemo, AIDigestDemo,
  RivalryDemo, StreakDemo, FollowedTeamsDemo, FollowedPlayersDemo, FollowedLeaguesDemo,
  ScreenBlocks, ScreenHelpRoot, ScreenHelpArticle,
  // Aliases per IA labels
  ScreenCountdown: CountdownDemo,
  ScreenLiveOverlay: LiveNowBannerDemo,
  ScreenGoalReact: GoalReactDemo,
  ScreenShareImage: ShareImageDemo,
  ScreenLongPress: LongPressDemo,
  ScreenAddCal: AddToCalDemo,
  ScreenXGFlip: XgFlipDemo,
  ScreenAIDigest: AIDigestDemo,
  ScreenRivalry: RivalryDemo,
  ScreenStreak: StreakDemo,
});
