// screens-team.jsx — Full team/sport detail page (6 tabs).
// Reached by tapping a sport from the Sports chapter. Matches the modern
// sport-app reference: tenant-color hero, scrollable tab strip, dense content.
//   HOME · SCORES · SCHEDULE · STATS · ROSTER · STANDINGS

function ScreenTeam({ sportId, onBack, onOpenGame, onOpenGameDay, onOpenPlayer }) {
  const sport = (window.SPORT_BY_ID && window.SPORT_BY_ID[sportId]) || (SPORTS[0] || {});
  const fireReward = (typeof useRewardPopup === 'function') ? useRewardPopup() : (() => {});
  const [tab, setTab] = React.useState('home');

  const iconUrl = window.sportIconUrl ? window.sportIconUrl(sportId) : null;
  const tabs = ['Home','Scores','Schedule','Stats','Roster','Standings'];

  // Generated data (memoized per sport+tenant)
  const roster = React.useMemo(() => genRoster(sportId, WVU.id, 16), [sportId, WVU.id]);
  const schedule = React.useMemo(() => genSchedule(sportId, WVU.id), [sportId, WVU.id]);
  const standings = React.useMemo(() => genStandings(sportId, WVU.id, WVU.conf), [sportId, WVU.id]);

  return (
    <div style={{
      position: 'absolute', inset: 0, overflow: 'auto',
      background: WVU.ink, color: WVU.cream,
      paddingBottom: 120,
    }} className="mtn-scrollbar">

      {/* ─── HERO STRIP ─── */}
      <div style={{
        position: 'relative',
        paddingTop: 56, paddingBottom: 14, paddingLeft: 16, paddingRight: 16,
        background: `linear-gradient(135deg, ${WVU.gold} 0%, ${_teamHeroDark()} 92%)`,
        boxShadow: '0 4px 20px rgba(0,0,0,0.4)',
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
          <button onClick={onBack} style={{
            width: 34, height: 34, borderRadius: 17,
            background: 'rgba(0,0,0,0.25)', border: '0.5px solid rgba(255,255,255,0.25)',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            cursor: 'pointer', color: '#fff', padding: 0, flexShrink: 0,
          }}>
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M9 2L4 7l5 5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/></svg>
          </button>
          {iconUrl && (
            <div style={{
              width: 40, height: 40, flexShrink: 0,
              display: 'flex', alignItems: 'center', justifyContent: 'center',
              filter: 'drop-shadow(0 2px 5px rgba(0,0,0,0.4))',
            }}>
              <img src={iconUrl} alt="" style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
            </div>
          )}
          <div style={{
            fontFamily: DS.display, fontSize: 26, fontWeight: 900,
            color: '#fff', letterSpacing: '0.01em', textTransform: 'uppercase',
            textShadow: '0 1px 3px rgba(0,0,0,0.35)',
          }}>{sport.name || 'Team'}</div>
        </div>
      </div>

      {/* ─── TAB STRIP (scrollable) ─── */}
      <div style={{
        position: 'sticky', top: 0, zIndex: 10,
        display: 'flex', gap: 0, overflowX: 'auto',
        padding: '0 8px',
        background: WVU.ink,
        borderBottom: `1px solid rgba(255,255,255,0.08)`,
      }} className="mtn-scrollbar">
        {tabs.map(tb => {
          const id = tb.toLowerCase();
          const on = id === tab;
          return (
            <button key={id} onClick={() => setTab(id)} style={{
              flexShrink: 0, padding: '14px 14px 12px',
              background: 'transparent', border: 'none', cursor: 'pointer',
              fontFamily: DS.sans, fontSize: 13, fontWeight: 700,
              color: on ? '#fff' : 'rgba(255,255,255,0.5)',
              letterSpacing: '0.02em', textTransform: 'uppercase',
              borderBottom: on ? `3px solid ${WVU.gold}` : '3px solid transparent',
              transition: 'color 140ms ease',
            }}>{tb}</button>
          );
        })}
      </div>

      {/* ─── TAB BODY ─── */}
      <div style={{ padding: '16px 0 0' }}>
        {tab === 'home'      && <TeamHomeTab sport={sport} onOpenGame={onOpenGame} fireReward={fireReward} />}
        {tab === 'scores'    && <TeamScoresTab schedule={schedule} sport={sport} fireReward={fireReward} />}
        {tab === 'schedule'  && <TeamScheduleTab schedule={schedule} sport={sport} onOpenGameDay={onOpenGameDay} fireReward={fireReward} />}
        {tab === 'stats'     && <TeamStatsTab roster={roster} sport={sport} onOpenPlayer={onOpenPlayer} />}
        {tab === 'roster'    && <TeamRosterTab roster={roster} sport={sport} onOpenPlayer={onOpenPlayer} />}
        {tab === 'standings' && <TeamStandingsTab standings={standings} sport={sport} />}
      </div>
    </div>
  );
}

function _teamHeroDark() {
  // Derive a near-black tint of the tenant gold so the hero reads as a brand wash
  const h = (WVU.gold || '#F2A900').replace('#','');
  const n = parseInt(h, 16);
  const r = ((n>>16)&255)*0.18, g = ((n>>8)&255)*0.18, b = (n&255)*0.18;
  return `rgb(${Math.round(r)},${Math.round(g)},${Math.round(b)})`;
}

// ═══════════════════════════════════════════════════════════════════
// HOME TAB — latest news videos + sponsor + top headlines
// ═══════════════════════════════════════════════════════════════════
function TeamHomeTab({ sport, onOpenGame, fireReward }) {
  const news = [
    { id: 'n1', dur: '2:33', title: `${WVU.name} Wins Series Finale ${20 + (sport.id.length % 8)}-17`, sub: `${WVU.name} closed the regular season strong in conference play.`, age: '2d', likes: '2,023' },
    { id: 'n2', dur: '1:55', title: `Inside the Locker Room: ${sport.name} Celebration`, sub: 'Raw reactions after the statement win this weekend.', age: '2d', likes: '1,440' },
    { id: 'n3', dur: '3:08', title: `${sport.name} Mic'd Up: Rivalry Week`, sub: 'Wired for sound on the sideline.', age: '4d', likes: '980' },
  ];
  const headlines = [
    { id: 'h1', title: `${WVU.name} ${sport.name} Clinches Series Win`, age: '1w', src: `${WVU.short} News` },
    { id: 'h2', title: `${sport.name} Ace Throws No-Hitter in Opener`, age: '2w', src: `${WVU.name} Athletics` },
    { id: 'h3', title: `Freshman Phenom Named ${WVU.conf} Player of the Week`, age: '2w', src: 'ESPN' },
    { id: 'h4', title: `${sport.name} Cracks National Rankings`, age: '3w', src: `${WVU.short} Sports Net` },
  ];
  return (
    <div>
      {/* LATEST NEWS rail */}
      <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', padding: '0 16px 12px' }}>
        <div style={{ fontFamily: DS.display, fontSize: 22, fontWeight: 900, color: WVU.cream, letterSpacing: '-0.01em' }}>LATEST NEWS</div>
        <div style={{ fontFamily: DS.mono, fontSize: 12, color: WVU.creamDim }}>11/13</div>
      </div>
      <div style={{ display: 'flex', gap: 12, overflowX: 'auto', padding: '0 16px 4px' }} className="mtn-scrollbar">
        {news.map((n, i) => (
          <div key={n.id} onClick={() => { onOpenGame && onOpenGame(); }} style={{
            width: 270, flexShrink: 0, cursor: 'pointer',
            borderRadius: DS.r.md, overflow: 'hidden',
            background: '#15151B', border: `0.5px solid ${WVU.line}`,
          }}>
            <div style={{ position: 'relative', height: 160 }}>
              <WarmHero h={160} variant={['stadium','court','dusk'][i % 3]} imgIndex={i * 3 + 2} caption={null} />
              <div style={{
                position: 'absolute', top: 10, right: 10,
                width: 26, height: 26, borderRadius: 13,
                background: WVU.gold, display: 'flex', alignItems: 'center', justifyContent: 'center',
                boxShadow: '0 2px 6px rgba(0,0,0,0.4)',
              }}>
                <svg width="13" height="13" viewBox="0 0 16 16" fill="none"><path d="M4 2h8v12l-4-3-4 3V2z" fill={WVU.blueDim}/></svg>
              </div>
              <div style={{
                position: 'absolute', bottom: 8, left: 8,
                padding: '2px 6px', borderRadius: 3,
                background: 'rgba(0,0,0,0.75)',
                fontFamily: DS.mono, fontSize: 11, fontWeight: 600, color: '#fff', letterSpacing: '0.04em',
              }}>{n.dur}</div>
            </div>
            <div style={{ padding: 12 }}>
              <div style={{ fontFamily: DS.sans, fontSize: 15, fontWeight: 800, color: WVU.cream, lineHeight: 1.2, letterSpacing: '-0.01em' }}>{n.title}</div>
              <div style={{ fontFamily: DS.sans, fontSize: 12, color: WVU.creamDim, marginTop: 6, lineHeight: 1.4 }}>{n.sub}</div>
              <div style={{ fontFamily: DS.mono, fontSize: 11, color: 'rgba(255,255,255,0.4)', marginTop: 8, letterSpacing: '0.04em' }}>{n.age} · {n.likes} likes</div>
            </div>
          </div>
        ))}
      </div>

      {/* Sponsor band */}
      <div style={{ padding: '18px 16px' }}>
        <div style={{
          height: 54, borderRadius: DS.r.md,
          background: 'linear-gradient(135deg, #0B2545, #15314F)',
          display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10,
          border: '0.5px solid rgba(255,255,255,0.08)',
        }}>
          <svg width="22" height="16" viewBox="0 0 32 22"><path d="M2 2 L7 20 L13 6 L16 20 L19 6 L25 20 L30 2" fill="none" stroke="#D4A537" strokeWidth="2.4" strokeLinecap="square"/></svg>
          <span style={{ fontFamily: '"Inter", sans-serif', fontSize: 13, fontWeight: 800, color: '#fff', letterSpacing: '0.16em' }}>AMERICA FIRST</span>
        </div>
      </div>

      {/* TOP HEADLINES */}
      <div style={{ padding: '0 16px' }}>
        <div style={{ fontFamily: DS.display, fontSize: 22, fontWeight: 900, color: WVU.cream, letterSpacing: '-0.01em', marginBottom: 12 }}>TOP HEADLINES</div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
          {headlines.map((h, i) => (
            <div key={h.id} style={{
              display: 'flex', alignItems: 'center', gap: 12,
              padding: 10, borderRadius: DS.r.md,
              background: '#15151B', border: `0.5px solid ${WVU.line}`, cursor: 'pointer',
            }}>
              <div style={{ width: 56, height: 56, borderRadius: DS.r.sm, overflow: 'hidden', flexShrink: 0 }}>
                <WarmHero h={56} variant={['court','stadium','dusk','field'][i % 4]} imgIndex={i * 4 + 1} caption={null} />
              </div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ fontFamily: DS.sans, fontSize: 13.5, fontWeight: 700, color: WVU.cream, lineHeight: 1.25, letterSpacing: '-0.005em' }}>{h.title}</div>
                <div style={{ fontFamily: DS.mono, fontSize: 11, color: 'rgba(255,255,255,0.4)', marginTop: 5, letterSpacing: '0.04em' }}>{h.age} · {h.src}</div>
              </div>
              <div style={{ width: 8, height: 8, borderRadius: 4, background: WVU.gold, flexShrink: 0 }} />
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

// ═══════════════════════════════════════════════════════════════════
// SCORES TAB — past results + season record + year dropdown
// ═══════════════════════════════════════════════════════════════════
function TeamScoresTab({ schedule, sport, fireReward }) {
  const [year, setYear] = React.useState('2024');
  const past = schedule.filter(g => g.past);
  const w = past.filter(g => g.won).length;
  const l = past.length - w;
  return (
    <div style={{ padding: '0 16px' }}>
      <YearDropdown year={year} setYear={setYear} />
      <SeasonRecordCard w={w} l={l} sport={sport} year={year} />
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 14 }}>
        {past.map(g => <ScoreCard key={g.id} game={g} sport={sport} fireReward={fireReward} />)}
      </div>
    </div>
  );
}

function ScoreCard({ game, sport, fireReward }) {
  return (
    <div style={{ borderRadius: DS.r.md, overflow: 'hidden', background: '#15151B', border: `0.5px solid ${WVU.line}` }}>
      <div style={{
        padding: '6px 12px', fontFamily: DS.mono, fontSize: 11, fontWeight: 600,
        color: WVU.creamDim, letterSpacing: '0.1em',
        background: 'rgba(255,255,255,0.03)', borderBottom: `0.5px solid ${WVU.line}`,
      }}>{game.date} · {game.isHome ? 'HOME' : 'AWAY'}</div>
      <div style={{ display: 'flex', alignItems: 'center', padding: '14px 12px', gap: 10 }}>
        <TeamMini name={WVU.short || 'US'} record={`${game.usScore > game.themScore ? 'W' : 'L'}`} accent={WVU.gold} />
        <div style={{ fontFamily: DS.display, fontSize: 26, fontWeight: 900, color: game.won ? WVU.gold : WVU.cream, fontVariantNumeric: 'tabular-nums', minWidth: 34, textAlign: 'center' }}>{game.usScore}</div>
        <div style={{ flex: 1, textAlign: 'center', fontFamily: DS.mono, fontSize: 11, color: WVU.creamDim, letterSpacing: '0.08em' }}>FINAL</div>
        <div style={{ fontFamily: DS.display, fontSize: 26, fontWeight: 900, color: !game.won ? WVU.cream : WVU.creamDim, fontVariantNumeric: 'tabular-nums', minWidth: 34, textAlign: 'center' }}>{game.themScore}</div>
        <TeamMini name={game.opp} record={game.oppRecord} accent="rgba(255,255,255,0.5)" right />
      </div>
      <div style={{ display: 'flex', borderTop: `0.5px solid ${WVU.line}` }}>
        <GameCTA label="▶ Watch Highlights" onClick={() => fireReward({ pts: 75, reason: 'Watched highlights', label: '+75 pts' })} />
        <div style={{ width: '0.5px', background: WVU.line }} />
        <GameCTA label="⚡ View Stats" />
      </div>
    </div>
  );
}

// ═══════════════════════════════════════════════════════════════════
// SCHEDULE TAB — upcoming + past, with live/today highlighting
// ═══════════════════════════════════════════════════════════════════
function TeamScheduleTab({ schedule, sport, onOpenGameDay, fireReward }) {
  const [year, setYear] = React.useState('2024');
  const w = schedule.filter(g => g.past && g.won).length;
  const l = schedule.filter(g => g.past && !g.won).length;
  // Schedule leads with upcoming/live games, then completed below.
  const upcoming = schedule.filter(g => !g.past);
  const completed = schedule.filter(g => g.past);
  return (
    <div style={{ padding: '0 16px' }}>
      <YearDropdown year={year} setYear={setYear} />
      <SeasonRecordCard w={w} l={l} sport={sport} year={year} />
      <div style={{ fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.gold, letterSpacing: '0.11em', textTransform: 'uppercase', margin: '16px 0 10px' }}>Upcoming</div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
        {upcoming.map(g => <UpcomingCard key={g.id} game={g} sport={sport} onOpenGameDay={onOpenGameDay} fireReward={fireReward} />)}
      </div>
      <div style={{ fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.creamDim, letterSpacing: '0.11em', textTransform: 'uppercase', margin: '20px 0 10px' }}>Completed</div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
        {completed.map(g => <ScoreCard key={g.id} game={g} sport={sport} fireReward={fireReward} />)}
      </div>
    </div>
  );
}

function UpcomingCard({ game, sport, onOpenGameDay, fireReward }) {
  const isNext = game.live;
  return (
    <div style={{ borderRadius: DS.r.md, overflow: 'hidden', background: '#15151B', border: `0.5px solid ${isNext ? hexA(WVU.gold, 0.4) : WVU.line}` }}>
      <div style={{
        padding: '6px 12px', fontFamily: DS.mono, fontSize: 11, fontWeight: 700,
        color: isNext ? WVU.gold : WVU.creamDim, letterSpacing: '0.1em',
        background: isNext ? hexA(WVU.gold, 0.12) : 'rgba(255,255,255,0.03)',
        borderBottom: `0.5px solid ${WVU.line}`,
      }}>{isNext ? '● UP NEXT · ' : ''}{game.date} · {game.isHome ? 'HOME' : 'AWAY'}</div>
      <div style={{ display: 'flex', alignItems: 'center', padding: '14px 12px', gap: 10 }}>
        <TeamMini name={WVU.short || 'US'} record="" accent={WVU.gold} />
        <div style={{ flex: 1, textAlign: 'center' }}>
          <div style={{ fontFamily: DS.display, fontSize: 18, fontWeight: 800, color: WVU.cream }}>{game.time}</div>
          <div style={{ fontFamily: DS.mono, fontSize: 10.5, color: WVU.creamDim, letterSpacing: '0.08em', marginTop: 2 }}>{game.isHome ? 'AT HOME' : 'ON THE ROAD'}</div>
        </div>
        <TeamMini name={game.opp} record={game.oppRecord} accent="rgba(255,255,255,0.5)" right />
      </div>
      <div style={{ display: 'flex', borderTop: `0.5px solid ${WVU.line}` }}>
        {isNext
          ? <GameCTA label="▶ Watch Live" highlight onClick={() => onOpenGameDay && onOpenGameDay('watch', null)} />
          : <GameCTA label="⚡ Buy Tickets" onClick={() => fireReward({ pts: 50, reason: 'Saved for game day', label: '+50 pts' })} />
        }
        <div style={{ width: '0.5px', background: WVU.line }} />
        <GameCTA label="🏆 Earn Rewards" onClick={() => onOpenGameDay && onOpenGameDay('rewards', null)} />
      </div>
    </div>
  );
}

// ═══════════════════════════════════════════════════════════════════
// STATS TAB — sport-specific table
// ═══════════════════════════════════════════════════════════════════
function TeamStatsTab({ roster, sport, onOpenPlayer }) {
  const { players, schema } = roster;
  const [sortCol, setSortCol] = React.useState(null);
  let rows = players;
  if (sortCol != null) {
    rows = [...players].sort((a, b) => parseFloat(String(b.stats[sortCol]).replace(/[^0-9.]/g,'')) - parseFloat(String(a.stats[sortCol]).replace(/[^0-9.]/g,'')));
  }
  return (
    <div style={{ padding: '0 16px' }}>
      <div style={{ display: 'flex', gap: 8, marginBottom: 14, flexWrap: 'wrap' }}>
        <FilterChip label="2024" /><FilterChip label={schema.label} /><FilterChip label="Individual" /><FilterChip label="Overall" />
      </div>
      <div style={{ fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.gold, letterSpacing: '0.11em', textTransform: 'uppercase', marginBottom: 10 }}>
        Player {schema.label} Stats
      </div>
      <div style={{ borderRadius: DS.r.md, overflow: 'hidden', border: `0.5px solid ${WVU.line}` }}>
        {/* header */}
        <div style={{ display: 'grid', gridTemplateColumns: `1.6fr repeat(${schema.cols.length}, 1fr)`, background: 'rgba(255,255,255,0.05)', padding: '8px 10px', gap: 4 }}>
          <div style={{ fontFamily: DS.mono, fontSize: 10.5, fontWeight: 700, color: WVU.creamDim, letterSpacing: '0.06em' }}>PLAYER</div>
          {schema.cols.map((c, i) => (
            <div key={c} onClick={() => setSortCol(i)} style={{ fontFamily: DS.mono, fontSize: 10.5, fontWeight: 700, color: sortCol===i ? WVU.gold : WVU.creamDim, letterSpacing: '0.04em', textAlign: 'right', cursor: 'pointer' }}>{c}</div>
          ))}
        </div>
        {rows.map((p, ri) => (
          <div key={p.id} onClick={() => onOpenPlayer && onOpenPlayer(p, sport)} style={{
            display: 'grid', gridTemplateColumns: `1.6fr repeat(${schema.cols.length}, 1fr)`, gap: 4,
            padding: '10px', alignItems: 'center', cursor: 'pointer',
            background: ri % 2 ? 'rgba(255,255,255,0.02)' : 'transparent',
            borderTop: `0.5px solid ${WVU.line}`,
          }}>
            <div style={{ minWidth: 0 }}>
              <div style={{ fontFamily: DS.sans, fontSize: 12.5, fontWeight: 800, color: WVU.gold, letterSpacing: '-0.01em', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{p.name}</div>
              <div style={{ fontFamily: DS.mono, fontSize: 10.5, color: WVU.creamDim, letterSpacing: '0.06em' }}>#{p.num} · {p.pos}</div>
            </div>
            {p.stats.map((s, ci) => (
              <div key={ci} style={{ fontFamily: DS.sans, fontSize: 12, fontWeight: ci===0?700:600, color: ci===0?WVU.cream:WVU.creamDim, textAlign: 'right', fontVariantNumeric: 'tabular-nums' }}>{s}</div>
            ))}
          </div>
        ))}
      </div>
    </div>
  );
}

// ═══════════════════════════════════════════════════════════════════
// ROSTER TAB — player cards
// ═══════════════════════════════════════════════════════════════════
function TeamRosterTab({ roster, sport, onOpenPlayer }) {
  const { players } = roster;
  const [sort, setSort] = React.useState('num');
  const sorted = [...players].sort((a, b) => sort === 'name' ? a.lastName.localeCompare(b.lastName) : a.num - b.num);
  return (
    <div style={{ padding: '0 16px' }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 14 }}>
        <FilterChip label="Players" />
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <span style={{ fontFamily: DS.sans, fontSize: 12, color: WVU.creamDim }}>Sort:</span>
          <button onClick={() => setSort(sort === 'num' ? 'name' : 'num')} style={{
            padding: '6px 12px', borderRadius: DS.r.pill, cursor: 'pointer',
            background: '#15151B', border: `0.5px solid ${WVU.lineBold}`,
            fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.cream,
          }}>{sort === 'num' ? 'Number ▾' : 'Name ▾'}</button>
        </div>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
        {sorted.map(p => (
          <div key={p.id} onClick={() => onOpenPlayer && onOpenPlayer(p, sport)} style={{
            display: 'flex', alignItems: 'center', gap: 12,
            padding: 10, borderRadius: DS.r.md, cursor: 'pointer',
            background: '#15151B', border: `0.5px solid ${WVU.line}`,
          }}>
            <div style={{ position: 'relative', width: 52, height: 52, flexShrink: 0 }}>
              <div style={{ width: 52, height: 52, borderRadius: 26, overflow: 'hidden', background: WVU.ink, border: `2px solid ${hexA(WVU.gold, 0.5)}` }}>
                <img src={p.avatar} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
              </div>
              <div style={{
                position: 'absolute', bottom: -2, right: -2,
                minWidth: 22, height: 18, padding: '0 4px', borderRadius: 9,
                background: WVU.gold, color: WVU.blueDim,
                fontFamily: DS.mono, fontSize: 11, fontWeight: 800,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                border: `1.5px solid ${WVU.ink}`,
              }}>{p.num}</div>
            </div>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontFamily: DS.sans, fontSize: 14.5, fontWeight: 800, color: WVU.cream, letterSpacing: '-0.01em' }}>{p.name}</div>
              <div style={{ fontFamily: DS.mono, fontSize: 11, color: WVU.creamDim, letterSpacing: '0.06em', marginTop: 2 }}>{p.pos} · {p.ht} · {p.wt} lb · {p.cls}</div>
            </div>
            <svg width="8" height="14" viewBox="0 0 8 14" style={{ flexShrink: 0, opacity: 0.4 }}><path d="M1 1l6 6-6 6" stroke={WVU.cream} strokeWidth="1.6" fill="none" strokeLinecap="round"/></svg>
          </div>
        ))}
      </div>
    </div>
  );
}

// ═══════════════════════════════════════════════════════════════════
// STANDINGS TAB
// ═══════════════════════════════════════════════════════════════════
function TeamStandingsTab({ standings, sport }) {
  return (
    <div style={{ padding: '0 16px' }}>
      <div style={{ fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.gold, letterSpacing: '0.11em', textTransform: 'uppercase', marginBottom: 12 }}>
        {WVU.conf} Standings
      </div>
      <div style={{ borderRadius: DS.r.md, overflow: 'hidden', border: `0.5px solid ${WVU.line}` }}>
        <div style={{ display: 'grid', gridTemplateColumns: '24px 1.8fr 0.5fr 0.5fr 0.7fr', gap: 6, background: 'rgba(255,255,255,0.05)', padding: '8px 12px' }}>
          {['#','TEAM','W','L','PCT'].map((c, i) => (
            <div key={c} style={{ fontFamily: DS.mono, fontSize: 10.5, fontWeight: 700, color: WVU.creamDim, letterSpacing: '0.06em', textAlign: i > 1 ? 'center' : 'left' }}>{c}</div>
          ))}
        </div>
        {standings.map((t, i) => {
          const mine = t.name === WVU.name || t.name === WVU.full;
          return (
            <div key={t.name} style={{
              display: 'grid', gridTemplateColumns: '24px 1.8fr 0.5fr 0.5fr 0.7fr', gap: 6,
              padding: '11px 12px', alignItems: 'center',
              background: mine ? hexA(WVU.gold, 0.12) : (i % 2 ? 'rgba(255,255,255,0.02)' : 'transparent'),
              borderTop: `0.5px solid ${WVU.line}`,
            }}>
              <div style={{ fontFamily: DS.mono, fontSize: 12, fontWeight: 700, color: mine ? WVU.gold : WVU.creamDim }}>{t.rank}</div>
              <div style={{ fontFamily: DS.sans, fontSize: 12.5, fontWeight: mine ? 800 : 600, color: mine ? WVU.gold : WVU.cream, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{t.name}</div>
              <div style={{ fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.cream, textAlign: 'center', fontVariantNumeric: 'tabular-nums' }}>{t.w}</div>
              <div style={{ fontFamily: DS.sans, fontSize: 12, color: WVU.creamDim, textAlign: 'center', fontVariantNumeric: 'tabular-nums' }}>{t.l}</div>
              <div style={{ fontFamily: DS.mono, fontSize: 12, color: WVU.creamDim, textAlign: 'center' }}>{t.pct}</div>
            </div>
          );
        })}
      </div>
    </div>
  );
}

// ─── Shared sub-components ───────────────────────────────────────────
function YearDropdown({ year, setYear }) {
  const [open, setOpen] = React.useState(false);
  const years = ['2024','2023','2022','2021'];
  return (
    <div style={{ position: 'relative', marginBottom: 12, display: 'inline-block' }}>
      <button onClick={() => setOpen(o => !o)} style={{
        padding: '8px 14px', borderRadius: DS.r.sm, cursor: 'pointer',
        background: '#15151B', border: `0.5px solid ${WVU.lineBold}`,
        fontFamily: DS.sans, fontSize: 14, fontWeight: 800, color: WVU.cream,
        display: 'flex', alignItems: 'center', gap: 8,
      }}>{year} <span style={{ fontSize: 11, color: WVU.creamDim }}>▾</span></button>
      {open && (
        <div style={{ position: 'absolute', top: '100%', left: 0, marginTop: 4, zIndex: 20, borderRadius: DS.r.sm, overflow: 'hidden', background: '#15151B', border: `0.5px solid ${WVU.lineBold}`, boxShadow: '0 8px 24px rgba(0,0,0,0.5)' }}>
          {years.map(y => (
            <div key={y} onClick={() => { setYear(y); setOpen(false); }} style={{ padding: '10px 18px', cursor: 'pointer', fontFamily: DS.sans, fontSize: 13, fontWeight: y===year?800:600, color: y===year?WVU.gold:WVU.cream, background: y===year?'rgba(255,255,255,0.04)':'transparent' }}>{y}</div>
          ))}
        </div>
      )}
    </div>
  );
}

function SeasonRecordCard({ w, l, sport, year }) {
  const conf = `${Math.max(0, w-2)}-${Math.max(0, l-1)}`;
  return (
    <div style={{ borderRadius: DS.r.md, background: '#15151B', border: `0.5px solid ${WVU.line}`, padding: 14 }}>
      <div style={{ fontFamily: DS.mono, fontSize: 10.5, fontWeight: 700, color: WVU.creamDim, letterSpacing: '0.12em', marginBottom: 10 }}>{year} SEASON RECORD</div>
      <div style={{ display: 'flex', gap: 0 }}>
        {[['OVERALL', `${w}-${l}`], ['CONF', conf], ['STREAK', w > l ? `W${1+(w%4)}` : `L${1+(l%3)}`]].map(([k, v], i) => (
          <div key={k} style={{ flex: 1, textAlign: 'center', borderLeft: i ? `0.5px solid ${WVU.line}` : 'none' }}>
            <div style={{ fontFamily: DS.display, fontSize: 22, fontWeight: 900, color: WVU.cream, fontVariantNumeric: 'tabular-nums' }}>{v}</div>
            <div style={{ fontFamily: DS.mono, fontSize: 10.5, color: WVU.creamDim, letterSpacing: '0.1em', marginTop: 3 }}>{k}</div>
          </div>
        ))}
      </div>
    </div>
  );
}

function TeamMini({ name, record, accent, right }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4, minWidth: 48 }}>
      <div style={{ width: 34, height: 34, borderRadius: 17, background: hexA(accent, 0.18), border: `1.5px solid ${accent}`, display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: DS.display, fontSize: 12, fontWeight: 900, color: accent === WVU.gold ? WVU.gold : WVU.cream }}>{(name||'')[0]}</div>
      <div style={{ fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.cream, maxWidth: 56, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', textAlign: 'center' }}>{name}</div>
      {record && <div style={{ fontFamily: DS.mono, fontSize: 10.5, color: WVU.creamDim }}>{record}</div>}
    </div>
  );
}

function GameCTA({ label, onClick, highlight }) {
  return (
    <button onClick={onClick} style={{
      flex: 1, padding: '12px 8px', border: 'none', cursor: 'pointer',
      background: highlight ? WVU.gold : 'transparent',
      color: highlight ? WVU.blueDim : WVU.creamDim,
      fontFamily: DS.sans, fontSize: 12.5, fontWeight: 700, letterSpacing: '0.02em',
    }}>{label}</button>
  );
}

function FilterChip({ label }) {
  return (
    <div style={{
      padding: '7px 13px', borderRadius: DS.r.pill,
      background: '#15151B', border: `0.5px solid ${WVU.lineBold}`,
      fontFamily: DS.sans, fontSize: 12, fontWeight: 700, color: WVU.cream,
      display: 'inline-flex', alignItems: 'center', gap: 6,
    }}>{label} <span style={{ fontSize: 10.5, color: WVU.creamDim }}>▾</span></div>
  );
}

Object.assign(window, { ScreenTeam });
