// draftView.jsx — sorteio (cards ricos) + formação por posições
const { useState: useSt } = React;

const SLOT_ORDER = ['IGL','AWP','ENT','SUP','FLEX'];

// Posições no "campo" tático (% do quadro)
const FORMATION = {
  IGL: { x: 50, y: 20, label: 'In-Game Leader' },
  AWP: { x: 19, y: 42, label: 'AWPer' },
  SUP: { x: 81, y: 42, label: 'Support' },
  ENT: { x: 31, y: 73, label: 'Entry Fragger' },
  FLEX: { x: 50, y: 82, label: 'Rifler / Lurker' },
};

const ATTRS = [
  ['AIM','aim'], ['ENT','entry'], ['CLU','clutch'], ['UTL','util'],
  ['MOV','move'], ['AWP','awp'], ['IGL','igl'], ['CON','cons'],
];

function makeDraftRerollRand(seed) {
  let s = (seed ^ 0x9E3779B9) >>> 0;
  return () => {
    s = (Math.imul(1664525, s) + 1013904223) >>> 0;
    return s / 0x100000000;
  };
}

function rolePrimaryMetric(role) {
  return role === 'AWP' ? 'awp'
       : role === 'IGL' ? 'igl'
       : role === 'ENT' ? 'entry'
       : role === 'SUP' ? 'util'
       : role === 'LRK' ? 'clutch'
       : 'aim';
}

function avgMetric(players, key) {
  if (!players.length) return 0;
  return Math.round(players.reduce((sum, p) => sum + p.s[key], 0) / players.length);
}

function avgRoleFit(players) {
  if (!players.length) return 0;
  return Math.round(players.reduce((sum, p) => sum + p.s[rolePrimaryMetric(p.role)], 0) / players.length);
}

function countrySummary(players) {
  const counts = {};
  players.forEach(p => { counts[p.country] = (counts[p.country] || 0) + 1; });
  return Object.entries(counts).sort((a, b) => b[1] - a[1]);
}

function eraSummary(players) {
  const counts = {};
  players.forEach(p => { counts[p.era] = (counts[p.era] || 0) + 1; });
  return Object.entries(counts).sort((a, b) => b[1] - a[1]);
}

function styleProfile(players) {
  const firepower = avgMetric(players, 'aim');
  const aggression = avgMetric(players, 'entry');
  const utility = avgMetric(players, 'util');
  const clutch = avgMetric(players, 'clutch');
  const consistency = avgMetric(players, 'cons');
  const awp = avgMetric(players, 'awp');
  const igl = avgMetric(players, 'igl');
  const roleFit = avgRoleFit(players);
  const spread = Math.max(firepower, utility, clutch, consistency, roleFit)
    - Math.min(firepower, utility, clutch, consistency, roleFit);
  const tags = [];
  tags.push(spread <= 12 ? 'Equilibrado' : aggression >= 84 ? 'Pressão alta' : 'Ritmo controlado');
  tags.push(firepower >= 84 ? 'Rifles como base' : awp >= 84 ? 'AWP como eixo' : 'Apoio como base');
  tags.push(utility >= 84 || igl >= 84 ? 'Base tática' : 'Sistema reativo');
  tags.push(clutch >= 88 ? 'Clutch forte' : 'Clutch médio');
  return { firepower, aggression, utility, clutch, consistency, awp, igl, roleFit, tags };
}

function teamOverallBreakdown(players) {
  const line = window.getLineBreakdown(players);
  const overall = line.strength;
  const style = styleProfile(players);
  return {
    overall,
    line,
    style,
    metrics: [
      { label:'Base individual', value:line.baseOverall, detail:'média simples antes dos ajustes de slot, química e estrelas' },
      { label:'Firepower', value:style.firepower, detail:'média de AIM; define duelo seco e troca direta' },
      { label:'Encaixe de slot', value:line.roleFit, detail:'métrica principal de cada função escolhida' },
      { label:'Estrutura', value:line.tactical, detail:'granadas, IGL e suporte para sustentar rounds longos' },
      { label:'Clutch', value:style.clutch, detail:'capacidade de converter round quebrado' },
      { label:'Consistência', value:style.consistency, detail:'reduz mapas apagados e mortes em sequência' },
      { label:'AWP', value:style.awp, detail:'peso do impacto com sniper no mapa' },
    ],
  };
}

// ── Rich draft card ──────────────────────────────────────────────────────────
function DraftCard({ player, state, onRecruit, hideRatings = false, compact = false, blockLabel = 'SLOT OCUPADO' }) {
  const [hov, setHov] = useSt(false);
  const isBlocked   = state === 'blocked';
  const isRecruited = state === 'recruited';
  const canClick    = state === 'available';
  const tier = window.TIER_META[player.tier] || window.TIER_META.GN;

  const border = isRecruited ? 'rgba(244,165,35,0.55)'
               : hov && canClick ? (hideRatings ? 'var(--border-3)' : tier.color)
               : 'var(--border-2)';
  const bg = isRecruited ? 'rgba(244,165,35,0.06)'
           : hov && canClick ? 'var(--bg-3)'
           : 'var(--bg-2)';

  if (compact) {
    const roleColor = window.ROLE_META[player.role]?.color || 'var(--accent)';
    const topStats = [
      ['AIM', player.s.aim],
      ['CLT', player.s.clutch],
      player.role === 'AWP' ? ['AWP', player.s.awp] : ['UTL', player.s.util],
    ];
    return (
      <div
        data-sound={canClick ? 'pick' : undefined}
        onClick={() => canClick && onRecruit(player)}
        onMouseEnter={() => setHov(true)}
        onMouseLeave={() => setHov(false)}
        style={{ position:'relative', minHeight:58, background:bg,
          border:`1px solid ${border}`, borderRadius:'var(--r-md)',
          overflow:'hidden', cursor: canClick ? 'pointer' : 'default',
          opacity: isBlocked ? 0.36 : 1,
          transform: hov && canClick ? 'translateX(2px)' : 'none',
          transition:'all 140ms ease', userSelect:'none',
          display:'grid', gridTemplateColumns:'3px minmax(0,1fr) auto',
          alignItems:'stretch' }}>
        <span style={{ background:isRecruited ? 'var(--accent)' : hideRatings ? 'var(--border-3)' : roleColor,
          opacity:hideRatings ? 0.7 : 1 }} />

        {isBlocked && (
          <div style={{ position:'absolute', inset:0, zIndex:3, display:'flex',
            alignItems:'center', justifyContent:'flex-end', paddingRight:12,
            background:'rgba(11,12,13,0.54)' }}>
            <span style={{ fontFamily:'var(--font-cond)', fontSize:9, fontWeight:800,
              color:'var(--text-2)', letterSpacing:'0.12em', padding:'3px 8px',
              border:'1px solid var(--border-3)', borderRadius:'var(--r-sm)',
              background:'var(--bg-2)' }}>{blockLabel}</span>
          </div>
        )}

        <div style={{ padding:'8px 9px', minWidth:0, display:'grid', gap:3 }}>
          <div style={{ display:'flex', alignItems:'center', gap:7, minWidth:0 }}>
            <window.RoleBadge role={player.role} />
            <window.Flag value={player.country} size={13} />
            <span style={{ fontFamily:'var(--font-cond)', fontWeight:800,
              fontSize:17, color:isRecruited ? 'var(--accent)' : 'var(--text-1)',
              overflow:'hidden', textOverflow:'ellipsis', whiteSpace:'nowrap',
              minWidth:0, flex:1 }}>
              {player.name}
            </span>
            <span style={{ fontFamily:'var(--font-cond)', fontSize:9, fontWeight:800,
              color:'var(--text-3)', letterSpacing:'0.08em', textTransform:'uppercase',
              whiteSpace:'nowrap' }}>
              {player.era}
            </span>
          </div>
          <div style={{ display:'flex', alignItems:'center', gap:5, minWidth:0 }}>
            {hideRatings ? (
              <>
                <span style={{ fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
                  color:'var(--text-3)', letterSpacing:'0.1em', textTransform:'uppercase',
                  padding:'2px 6px', border:'1px solid var(--border-2)',
                  borderRadius:'var(--r-sm)', background:'var(--bg-3)' }}>
                  Scout
                </span>
                <span style={{ fontFamily:'var(--font-cond)', fontSize:10,
                  color:'var(--text-3)', overflow:'hidden', textOverflow:'ellipsis',
                  whiteSpace:'nowrap' }}>
                  {window.ROLES[player.role] || player.role} - {player.country}
                </span>
              </>
            ) : (
              topStats.map(([label, value]) => (
                <span key={label} style={{ display:'inline-flex', alignItems:'baseline', gap:3,
                  padding:'2px 5px', borderRadius:'var(--r-sm)',
                  background:'rgba(255,255,255,0.035)', border:'1px solid var(--border-1)' }}>
                  <span style={{ fontFamily:'var(--font-cond)', fontSize:8, fontWeight:800,
                    color:'var(--text-3)', letterSpacing:'0.06em' }}>{label}</span>
                  <span style={{ fontFamily:'var(--font-mono)', fontSize:10,
                    color:value >= 90 ? 'var(--accent)' : 'var(--text-2)' }}>{value}</span>
                </span>
              ))
            )}
          </div>
        </div>

        <div style={{ display:'flex', flexDirection:'column', alignItems:'flex-end',
          justifyContent:'center', gap:4, padding:'7px 9px 7px 0', minWidth:hideRatings ? 58 : 48 }}>
          {!hideRatings && (
            <span style={{ fontFamily:'var(--font-mono)', fontSize:22, fontWeight:800,
              color:isRecruited ? 'var(--accent)' : tier.color, lineHeight:1 }}>
              {player.overall}
            </span>
          )}
          <span style={{ fontFamily:'var(--font-cond)', fontSize:9, fontWeight:800,
            color:hov && canClick ? 'var(--accent)' : isRecruited ? 'var(--accent)' : 'var(--text-3)',
            letterSpacing:'0.08em', textTransform:'uppercase', whiteSpace:'nowrap' }}>
            {isRecruited ? 'OK' : canClick ? 'Pick' : '-'}
          </span>
        </div>
      </div>
    );
  }

  return (
    <div
      data-sound={canClick ? 'pick' : undefined}
      onClick={() => canClick && onRecruit(player)}
      onMouseEnter={() => setHov(true)}
      onMouseLeave={() => setHov(false)}
      style={{ position:'relative', background:bg,
        border:`1px solid ${border}`, borderRadius:'var(--r-lg)',
        overflow:'hidden', cursor: canClick ? 'pointer' : 'default',
        opacity: isBlocked ? 0.34 : 1,
        transform: hov && canClick ? 'translateY(-3px)' : 'none',
        transition:'all 160ms ease', userSelect:'none',
        display:'flex', flexDirection:'column' }}>

      {/* Tier strip is neutral in Scout mode so rank is not leaked. */}
      <div style={{ height:3,
        background: isRecruited ? 'var(--accent)' : hideRatings ? 'var(--border-3)' : tier.color,
        opacity: hideRatings ? 0.55 : 0.85 }} />

      {isBlocked && (
        <div style={{ position:'absolute', inset:0, zIndex:3, display:'flex',
          alignItems:'center', justifyContent:'center', background:'rgba(11,12,13,0.5)' }}>
          <span style={{ fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
            color:'var(--text-2)', letterSpacing:'0.14em', padding:'3px 10px',
            border:'1px solid var(--border-3)', borderRadius:'var(--r-sm)',
            background:'var(--bg-2)' }}>{blockLabel}</span>
        </div>
      )}

      {/* Header */}
      <div style={{ display:'flex', alignItems:'flex-start', justifyContent:'space-between',
        padding:'10px 13px 7px', gap:8 }}>
        <div style={{ display:'flex', flexDirection:'column', alignItems:'flex-start', gap:2 }}>
          <span style={{ fontFamily: hideRatings ? 'var(--font-cond)' : 'var(--font-mono)',
            fontSize: hideRatings ? 10 : 34, fontWeight:800, lineHeight: hideRatings ? 1.1 : 0.9,
            color: hideRatings ? 'var(--text-3)' : isRecruited ? 'var(--accent)' : tier.color,
            letterSpacing: hideRatings ? '0.12em' : 0,
            textTransform: hideRatings ? 'uppercase' : 'none',
            padding: hideRatings ? '2px 6px' : 0,
            border: hideRatings ? '1px solid var(--border-2)' : 'none',
            borderRadius: hideRatings ? 'var(--r-sm)' : 0,
            background: hideRatings ? 'var(--bg-3)' : 'transparent' }}>
            {hideRatings ? 'SCOUT' : player.overall}
          </span>
          <span style={{ fontFamily:'var(--font-cond)', fontSize:9, fontWeight:700,
            color:'var(--text-3)', letterSpacing:'0.1em', textTransform:'uppercase' }}>
            {hideRatings ? 'sem overall' : 'Overall'}
          </span>
        </div>
        <div style={{ display:'flex', flexDirection:'column', alignItems:'flex-end', gap:4 }}>
          <window.RoleBadge role={player.role} size="lg" />
          {!hideRatings && <window.TierBadge tier={player.tier} short />}
        </div>
      </div>

      {/* Name */}
      <div style={{ padding:'0 13px 10px', borderBottom:'1px solid var(--border-1)' }}>
        <div style={{ display:'flex', alignItems:'center', gap:6, minWidth:0 }}>
          <window.Flag value={player.country} size={15} />
          <span style={{ fontFamily:'var(--font-cond)', fontWeight:800, fontSize: hideRatings ? 19 : 17,
            color: isRecruited ? 'var(--accent)' : 'var(--text-1)', letterSpacing:'0.01em',
            overflow:'hidden', textOverflow:'ellipsis', whiteSpace:'nowrap', flex:1, minWidth:0 }}>
            {player.name}
          </span>
        </div>
        <span style={{ fontFamily:'var(--font-cond)', fontSize:9, color:'var(--text-3)',
          letterSpacing:'0.1em', textTransform:'uppercase' }}>{player.era}</span>
      </div>

      {hideRatings ? (
        <div style={{ padding:'11px 13px', flex:1, borderBottom:'1px solid var(--border-1)' }}>
          <div style={{ display:'grid', gap:6 }}>
            {[
              ['Time', player.team],
              ['Função', window.ROLES[player.role] || player.role],
              ['Era', player.era],
              ['País', player.country],
            ].map(([label, value]) => (
              <div key={label} style={{ display:'flex', alignItems:'center', justifyContent:'space-between', gap:10 }}>
                <span style={{ fontFamily:'var(--font-cond)', fontSize:8, fontWeight:800,
                  color:'var(--text-3)', letterSpacing:'0.1em', textTransform:'uppercase' }}>{label}</span>
                <span style={{ fontFamily:'var(--font-cond)', fontSize:11, fontWeight:700,
                  color:'var(--text-2)', whiteSpace:'nowrap', overflow:'hidden', textOverflow:'ellipsis' }}>{value}</span>
              </div>
            ))}
          </div>
        </div>
      ) : (
        <div style={{ padding:'9px 13px 11px', display:'grid', gridTemplateColumns:'1fr 1fr',
          gap:'6px 14px', flex:1 }}>
          {ATTRS.map(([label, key]) => {
            const v = player.s[key];
            const pct = Math.round((v / 99) * 100);
            const c = v >= 90 ? 'var(--accent)' : v >= 78 ? '#8a9cb4' : 'var(--text-3)';
            return (
              <div key={key} style={{ display:'flex', alignItems:'center', gap:6 }}>
                <span style={{ fontFamily:'var(--font-cond)', fontSize:8, fontWeight:700,
                  color:'var(--text-3)', letterSpacing:'0.06em', width:20 }}>{label}</span>
                <div style={{ flex:1, height:3, background:'var(--bg-5)', borderRadius:2 }}>
                  <div style={{ height:'100%', width:`${pct}%`, background:c, borderRadius:2 }} />
                </div>
                <span style={{ fontFamily:'var(--font-mono)', fontSize:9, color:c, width:14,
                  textAlign:'right' }}>{v}</span>
              </div>
            );
          })}
        </div>
      )}

      {/* Recruit CTA */}
      <div style={{ padding:'0 13px 13px' }}>
        <div style={{ padding:'8px 0', textAlign:'center', borderRadius:'var(--r-md)',
          background: hov && canClick ? 'var(--accent)' : isRecruited ? 'rgba(244,165,35,0.12)' : 'var(--bg-4)',
          border:`1px solid ${hov && canClick ? 'var(--accent)' : isRecruited ? 'rgba(244,165,35,0.3)' : 'var(--border-2)'}`,
          fontFamily:'var(--font-cond)', fontSize:11, fontWeight:800, letterSpacing:'0.1em',
          textTransform:'uppercase',
          color: hov && canClick ? '#15110a' : isRecruited ? 'var(--accent)' : 'var(--text-3)',
          transition:'all 140ms ease' }}>
          {isRecruited ? '✓ Recrutado' : canClick ? 'Recrutar' : '—'}
        </div>
      </div>
    </div>
  );
}

// ── Formation board ───────────────────────────────────────────────────────────
function FormationBoard({ players, overall, hideRatings = false, summary = false }) {
  const eras = [...new Set(players.map(p => p.era))];
  const isMobile = window.useIsMobileView?.(760) || false;
  return (
    <div style={{ background:'var(--bg-2)', border:'1px solid var(--border-2)',
      borderRadius:'var(--r-lg)', overflow:'hidden',
      boxShadow: summary ? '0 14px 42px rgba(0,0,0,0.24)' : 'none' }}>
      {/* Header */}
      <div style={{ padding: summary ? (isMobile ? '12px 13px' : '13px 18px') : '9px 16px', background:'var(--bg-3)',
        borderBottom:'1px solid var(--border-1)',
        display:'flex', alignItems:'center', justifyContent:'space-between', gap:10 }}>
        <div style={{ display:'flex', alignItems:'center', gap:10, minWidth:0, flexWrap:'wrap' }}>
          <span style={{ fontFamily:'var(--font-cond)', fontWeight:800, fontSize:12,
            color:'var(--text-1)', letterSpacing:'0.12em', textTransform:'uppercase' }}>
            Sua Line
          </span>
          <span style={{ fontFamily:'var(--font-mono)', fontSize:11, color:'var(--text-3)' }}>
            {players.length}/5
          </span>
          {eras.length > 0 && (
            <div style={{ display:'flex', gap:4 }}>
              {eras.map(e => (
                <span key={e} style={{ padding: summary ? '2px 8px' : '1px 6px',
                  background:'var(--bg-4)',
                  border:'1px solid var(--border-2)', borderRadius:'var(--r-sm)',
                  fontSize:8, fontWeight:700, color:'var(--text-3)',
                  fontFamily:'var(--font-cond)', letterSpacing:'0.06em' }}>{e}</span>
              ))}
            </div>
          )}
        </div>
        <div style={{ display:'flex', alignItems:'center', gap:6 }}>
          <span style={{ fontFamily:'var(--font-cond)', fontSize:9, color:'var(--text-3)',
            letterSpacing:'0.1em', textTransform:'uppercase' }}>{hideRatings ? 'Scout' : 'Overall'}</span>
          <span style={{ fontFamily:'var(--font-mono)', fontSize:20, fontWeight:700,
            color: overall > 0 ? 'var(--accent)' : 'var(--text-3)', lineHeight:1 }}>
            {hideRatings ? '??' : (overall || '—')}
          </span>
        </div>
      </div>

      {/* Pitch */}
      <div style={{ position:'relative', height: summary ? (isMobile ? 320 : 290) : (isMobile ? 260 : 232),
        background:
          'radial-gradient(circle at 51% 56%, rgba(244,165,35,0.075), transparent 38%),' +
          'linear-gradient(90deg, rgba(255,255,255,0.012), rgba(255,255,255,0.02) 50%, rgba(255,255,255,0.012)),' +
          'repeating-linear-gradient(0deg, transparent, transparent 35px, rgba(255,255,255,0.022) 35px, rgba(255,255,255,0.022) 36px),' +
          'repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(255,255,255,0.02) 39px, rgba(255,255,255,0.02) 40px)' }}>
        {/* center divider */}
        <div style={{ position:'absolute', left:'50%', top:'8%', bottom:'8%', width:1,
          background:'rgba(255,255,255,0.035)' }} />
        <div style={{ position:'absolute', left:'50%', top:'50%', width: summary ? 62 : 64, height: summary ? 62 : 64,
          transform:'translate(-50%,-50%)', borderRadius:'50%',
          border:'1px dashed rgba(255,255,255,0.12)' }} />

        {SLOT_ORDER.map(slot => {
          const pos = FORMATION[slot];
          const player = players.find(p => window.getLineSlot(p) === slot);
          return <PositionNode key={slot} slot={slot} pos={pos} player={player}
            hideRatings={hideRatings} summary={summary} mobile={isMobile} />;
        })}
      </div>
    </div>
  );
}

function PositionNode({ slot, pos, player, hideRatings = false, summary = false, mobile = false }) {
  const meta = window.ROLE_META[slot] || { color:'var(--text-3)', label:slot };
  const filled = !!player;
  return (
    <div style={{ position:'absolute', left:`${pos.x}%`, top:`${pos.y}%`,
      transform:'translate(-50%,-50%)', width: mobile ? 104 : summary ? 146 : 128, textAlign:'center' }}>
      {filled ? (
        <div>
          <div style={{ display:'inline-flex', flexDirection:'column', alignItems:'center',
            padding: mobile ? '6px 8px 7px' : summary ? '8px 13px 9px' : '7px 12px 8px',
            background:'rgba(29,32,34,0.93)',
            border:`1px solid ${meta.color}55`, borderRadius:'var(--r-lg)',
            boxShadow: summary ? '0 10px 24px rgba(0,0,0,0.42)' : '0 4px 14px rgba(0,0,0,0.4)',
            minWidth: mobile ? 82 : summary ? 120 : 96 }}>
            <div style={{ display:'flex', alignItems:'center', gap:5, marginBottom:3 }}>
              <span style={{ fontFamily:'var(--font-mono)', fontSize: mobile ? 14 : summary ? 19 : 17, fontWeight:700,
                color:'var(--accent)', lineHeight:1 }}>{hideRatings ? '??' : player.overall}</span>
              <window.RoleBadge role={player.role} />
            </div>
            <div style={{ display:'flex', alignItems:'center', gap:4 }}>
              <window.Flag value={player.country} size={mobile ? 11 : summary ? 14 : 12} />
              <span style={{ fontFamily:'var(--font-cond)', fontWeight:800, fontSize: mobile ? 11 : summary ? 15 : 13,
                color:'var(--text-1)', whiteSpace:'nowrap', overflow:'hidden', textOverflow:'ellipsis',
                maxWidth:mobile ? 70 : 110 }}>{player.name}</span>
            </div>
          </div>
        </div>
      ) : (
        <div style={{ display:'inline-flex', flexDirection:'column', alignItems:'center', gap:5 }}>
          <div style={{ width: mobile ? 42 : summary ? 54 : 44, height: mobile ? 42 : summary ? 54 : 44, borderRadius:'50%',
            border:`1.5px dashed ${meta.color}66`, display:'flex',
            alignItems:'center', justifyContent:'center',
            background:'rgba(0,0,0,0.2)' }}>
            <span style={{ fontFamily:'var(--font-cond)', fontWeight:800, fontSize:11,
              color:`${meta.color}`, letterSpacing:'0.04em', opacity:0.85 }}>{meta.label}</span>
          </div>
          <span style={{ fontFamily:'var(--font-cond)', fontSize:8, fontWeight:700,
            color:'var(--text-3)', letterSpacing:'0.08em', textTransform:'uppercase' }}>
            {pos.label}
          </span>
        </div>
      )}
    </div>
  );
}

// ── Draft view ────────────────────────────────────────────────────────────────
function MetricRow({ label, value, detail }) {
  const color = value >= 90 ? 'var(--accent)' : value >= 82 ? '#8a9cb4' : 'var(--text-3)';
  return (
    <div style={{ padding:'11px 0', borderBottom:'1px solid var(--border-1)' }}>
      <div style={{ display:'grid', gridTemplateColumns:'1fr 42px', gap:12,
        alignItems:'start', marginBottom:6 }}>
        <div style={{ minWidth:0 }}>
          <div style={{ fontFamily:'var(--font-cond)', fontSize:13, fontWeight:800,
            color:'var(--text-1)', letterSpacing:'0.045em', textTransform:'uppercase',
            lineHeight:1.05 }}>
            {label}
          </div>
          <div style={{ fontSize:11, color:'var(--text-3)', lineHeight:1.35, marginTop:2 }}>{detail}</div>
        </div>
        <span style={{ fontFamily:'var(--font-mono)', fontSize:18, fontWeight:700,
          color, textAlign:'right', lineHeight:1 }}>{value}</span>
      </div>
      <div style={{ height:4, background:'var(--bg-5)', borderRadius:4, overflow:'hidden' }}>
        <div style={{ width:`${Math.max(4, Math.min(100, value))}%`, height:'100%',
          background:color, borderRadius:4 }} />
      </div>
    </div>
  );
}

function SummaryStatCell({ label, value }) {
  return (
    <div style={{ textAlign:'right' }}>
      <div style={{ fontFamily:'var(--font-mono)', fontSize:15, fontWeight:700,
        color: value >= 90 ? 'var(--accent)' : 'var(--text-2)', lineHeight:1 }}>
        {value}
      </div>
      <div style={{ fontFamily:'var(--font-cond)', fontSize:8, fontWeight:800,
        color:'var(--text-3)', letterSpacing:'0.08em', textTransform:'uppercase',
        marginTop:3 }}>
        {label}
      </div>
    </div>
  );
}

function DraftSummaryView({ players, onStartMajor, teamName = 'Meu Time' }) {
  const isMobile = window.useIsMobileView?.(760) || false;
  const breakdown = teamOverallBreakdown(players);
  const countries = countrySummary(players);
  const eras = eraSummary(players);
  const overall = breakdown.overall;
  function handleStartMajor() {
    onStartMajor();
  }

  return (
    <main style={{ maxWidth:1380, margin:'0 auto', padding:isMobile ? '16px 14px 42px' : '28px 30px 48px' }}>
      <div style={{ marginBottom:20 }}>
        <h2 style={{ fontFamily:'var(--font-cond)', fontWeight:800, fontSize:27,
          color:'var(--text-1)', letterSpacing:'0.045em', textTransform:'uppercase',
          marginBottom:2, lineHeight:1 }}>
          Elenco fechado
        </h2>
        <p style={{ color:'var(--text-3)', fontSize:12 }}>
          {teamName} - revise o rating do time antes de entrar no Major.
        </p>
      </div>

      <div style={{ display:'grid', gridTemplateColumns:isMobile ? '1fr' : 'minmax(0,2.1fr) minmax(360px,450px)',
        gap:18, alignItems:'start' }}>
        <div style={{ display:'grid', gap:14 }}>
          <FormationBoard players={players} overall={overall} summary />

          <div style={{ background:'var(--bg-2)', border:'1px solid var(--border-2)',
            borderRadius:'var(--r-lg)', overflow:'hidden' }}>
            <div style={{ padding:'12px 18px', background:'var(--bg-3)',
              borderBottom:'1px solid var(--border-1)', display:'flex',
              alignItems:'center', justifyContent:'space-between', gap:10 }}>
              <span style={{ fontFamily:'var(--font-cond)', fontSize:12, fontWeight:800,
                color:'var(--text-1)', letterSpacing:'0.1em', textTransform:'uppercase' }}>
                Lineup
              </span>
              <span style={{ fontFamily:'var(--font-cond)', fontSize:9, fontWeight:800,
                color:'var(--text-3)', letterSpacing:'0.1em', textTransform:'uppercase' }}>
                OVR - AIM - ROLE - UTL - CON
              </span>
            </div>
            {players.map((p, i) => (
              <div key={p.id} style={{ display:'grid',
                gridTemplateColumns:isMobile ? 'minmax(0,1fr) repeat(5,36px)' : 'minmax(0,1fr) repeat(5,64px)',
                gap:isMobile ? 7 : 12, alignItems:'center', padding:isMobile ? '11px 10px' : '13px 18px',
                borderBottom: i < players.length - 1 ? '1px solid var(--border-1)' : 'none',
                background: i % 2 ? 'rgba(0,0,0,0.10)' : 'transparent' }}>
                <div style={{ display:'flex', alignItems:'center', gap:10, minWidth:0 }}>
                  <window.RoleBadge role={p.role} />
                  <window.Flag value={p.country} size={15} />
                  <span style={{ fontFamily:'var(--font-cond)', fontSize:16, fontWeight:800,
                    color:'var(--text-1)', whiteSpace:'nowrap', overflow:'hidden',
                    textOverflow:'ellipsis' }}>{p.name}</span>
                </div>
                {[
                  ['OVR', p.overall],
                  ['AIM', p.s.aim],
                  ['ROLE', p.s[rolePrimaryMetric(p.role)]],
                  ['UTL', p.s.util],
                  ['CON', p.s.cons],
                ].map(([label, value]) => (
                  <SummaryStatCell key={label} label={label} value={value} />
                ))}
              </div>
            ))}
          </div>
        </div>

        <aside style={{ display:'grid', gap:12 }}>
          <button data-sound="major" onClick={handleStartMajor}
            style={{ width:'100%', height:58, background:'var(--accent)', border:'none',
              borderRadius:'var(--r-md)', cursor:'pointer', fontFamily:'var(--font-cond)',
              fontSize:15, fontWeight:800, letterSpacing:'0.11em', textTransform:'uppercase',
              color:'#15110a', whiteSpace:'nowrap', boxShadow:'0 10px 24px rgba(244,165,35,0.16)' }}>
            INICIAR MAJOR &rarr;
          </button>

          <div style={{ background:'linear-gradient(180deg, rgba(244,165,35,0.08), rgba(244,165,35,0.02))',
            border:'1px solid rgba(244,165,35,0.25)', borderRadius:'var(--r-lg)',
            padding:'20px 22px 18px' }}>
            <div style={{ fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
              color:'var(--text-3)', letterSpacing:'0.2em', textTransform:'uppercase', marginBottom:8 }}>
              Overall do time
            </div>
            <div style={{ display:'grid', gridTemplateColumns:'92px 1fr', alignItems:'center', gap:16 }}>
              <span style={{ fontFamily:'var(--font-mono)', fontSize:isMobile ? 58 : 72, fontWeight:700,
                color:'var(--accent)', lineHeight:0.9 }}>{overall}</span>
              <span style={{ color:'var(--text-2)', fontSize:isMobile ? 12 : 14, lineHeight:1.45 }}>
                Força da line: base individual ajustada por slots, estrutura,
                química e limite de estrelas.
              </span>
            </div>
          </div>

          <div style={{ background:'var(--bg-2)', border:'1px solid var(--border-2)',
            borderRadius:'var(--r-lg)', padding:'18px 20px' }}>
            <div style={{ fontFamily:'var(--font-cond)', fontSize:12, fontWeight:800,
              color:'var(--text-3)', letterSpacing:'0.16em', textTransform:'uppercase', marginBottom:14 }}>
              Identidade
            </div>
            <div style={{ display:'flex', alignItems:'center', gap:12, flexWrap:'wrap', marginBottom:12 }}>
              {countries.map(([country, count]) => (
                <span key={country} style={{ display:'inline-flex', alignItems:'center', gap:5,
                  color:'var(--text-2)', fontFamily:'var(--font-mono)', fontSize:12 }}>
                  <window.Flag value={country} size={18} />
                  <span>x{count}</span>
                </span>
              ))}
              <div style={{ flex:1 }} />
              {eras.map(([era, count]) => (
                <span key={era} style={{ padding:'4px 9px', background:'var(--bg-4)',
                  border:'1px solid var(--border-2)', borderRadius:'var(--r-sm)',
                  fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
                  color:'var(--text-2)', letterSpacing:'0.08em', textTransform:'uppercase' }}>
                  {era} x{count}
                </span>
              ))}
            </div>
            <div style={{ display:'flex', gap:7, flexWrap:'wrap' }}>
              {breakdown.style.tags.map(tag => (
                <span key={tag} style={{ padding:'5px 11px', background:'rgba(244,165,35,0.08)',
                  border:'1px solid rgba(244,165,35,0.24)', borderRadius:'var(--r-sm)',
                  fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
                  color:'var(--accent)', letterSpacing:'0.08em', textTransform:'uppercase' }}>
                  {tag}
                </span>
              ))}
            </div>
          </div>

          <div style={{ background:'var(--bg-2)', border:'1px solid var(--border-2)',
            borderRadius:'var(--r-lg)', padding:'18px 20px 4px' }}>
            <div style={{ fontFamily:'var(--font-cond)', fontSize:12, fontWeight:800,
              color:'var(--text-3)', letterSpacing:'0.16em', textTransform:'uppercase', marginBottom:10 }}>
              Por que esse overall?
            </div>
            {breakdown.metrics.map(m => <MetricRow key={m.label} {...m} />)}
          </div>
        </aside>
      </div>
    </main>
  );
}

function RerollControls({ currentTeam, rerollsLeft, maxRerolls, disabled,
  sameYearAvailable, otherYearAvailable, onReroll }) {
  const isMobile = window.useIsMobileView?.(760) || false;
  return (
    <div style={{ display:'flex', flexDirection:'row',
      alignItems:'center', justifyContent:'space-between',
      gap:isMobile ? 8 : 10, margin:isMobile ? '0 0 7px' : '-2px 0 10px',
      padding:isMobile ? '6px 8px' : '8px 10px',
      background:'rgba(255,255,255,0.025)', border:'1px solid var(--border-2)',
      borderRadius:'var(--r-lg)' }}>
      <div style={{ minWidth:0 }}>
        <div style={{ fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
          color:'var(--text-3)', letterSpacing:'0.14em', textTransform:'uppercase' }}>
          Reroll de sorteio
        </div>
        <div style={{ fontSize:11, color:'var(--text-3)', whiteSpace:'nowrap',
          overflow:'hidden', textOverflow:'ellipsis' }}>
          {rerollsLeft}/{maxRerolls} restantes · ano atual: {currentTeam.year}
        </div>
      </div>
      <div style={{ display:'flex', gap:6, flexShrink:0, minWidth:isMobile ? 154 : 'auto' }}>
        <RerollButton
          label="Mesmo ano"
          hint={String(currentTeam.year)}
          disabled={disabled || !sameYearAvailable}
          onClick={() => onReroll('same-year')}
        />
        <RerollButton
          label="Outro ano"
          hint="nova era"
          disabled={disabled || !otherYearAvailable}
          onClick={() => onReroll('other-year')}
        />
      </div>
    </div>
  );
}

function RerollButton({ label, hint, disabled, onClick }) {
  const [hov, setHov] = useSt(false);
  const isMobile = window.useIsMobileView?.(760) || false;
  return (
    <button
      data-sound="option"
      disabled={disabled}
      onClick={disabled ? undefined : onClick}
      onMouseEnter={() => setHov(true)}
      onMouseLeave={() => setHov(false)}
      style={{ display:'inline-flex', alignItems:'center', gap:8,
        padding:isMobile ? '6px 7px' : '7px 10px',
        minWidth:isMobile ? 0 : 114, flex:isMobile ? 1 : '0 0 auto',
        background:disabled ? 'var(--bg-2)' : hov ? 'rgba(244,165,35,0.14)' : 'var(--bg-3)',
        border:`1px solid ${disabled ? 'var(--border-1)' : hov ? 'rgba(244,165,35,0.38)' : 'var(--border-2)'}`,
        borderRadius:'var(--r-md)', cursor:disabled ? 'not-allowed' : 'pointer',
        opacity:disabled ? 0.42 : 1, color:disabled ? 'var(--text-3)' : hov ? 'var(--accent)' : 'var(--text-2)',
        transition:'background 140ms ease, border-color 140ms ease, color 140ms ease' }}>
      <DiceIcon active={hov && !disabled} />
      <span style={{ display:'flex', flexDirection:'column', alignItems:'flex-start',
        lineHeight:1 }}>
        <span style={{ fontFamily:'var(--font-cond)', fontSize:11, fontWeight:800,
          letterSpacing:'0.1em', textTransform:'uppercase' }}>
          {isMobile ? label.replace(' ano', '') : label}
        </span>
        <span style={{ display:isMobile ? 'none' : 'inline', marginTop:3, fontSize:9, color:'var(--text-3)' }}>
          {hint}
        </span>
      </span>
    </button>
  );
}

function DiceIcon({ active }) {
  const dot = (x, y) => (
    <span style={{ position:'absolute', left:x, top:y, width:3, height:3,
      borderRadius:'50%', background:'currentColor' }} />
  );
  return (
    <span style={{ position:'relative', width:20, height:20, flexShrink:0,
      border:'1px solid currentColor', borderRadius:5,
      transform:active ? 'rotate(18deg) translateY(-1px)' : 'rotate(0deg)',
      boxShadow:active ? '0 0 12px rgba(244,165,35,0.26)' : 'none',
      transition:'transform 160ms ease, box-shadow 160ms ease' }}>
      {dot(4,4)}
      {dot(13,4)}
      {dot(8.5,8.5)}
      {dot(4,13)}
      {dot(13,13)}
    </span>
  );
}

function DraftView({ session, onDraftComplete, draftMode = 'scout', defaultMatchFormat = 'MR16', onSummaryStateChange, teamName = 'Meu Time' }) {
  const isMobile = window.useIsMobileView?.(760) || false;
  const [round, setRound] = useSt(0);
  const [drawTeams, setDrawTeams] = useSt(() => session.teams);
  const [myPlayers, setMyPlayers] = useSt([]);
  const [slotsTaken, setSlotsTaken] = useSt({});
  const [picked, setPicked] = useSt(null);
  const [animating, setAnimating] = useSt(false);
  const [complete, setComplete] = useSt(false);
  const [matchFormat, setMatchFormat] = useSt(defaultMatchFormat || 'MR16');
  const [rerollsLeft, setRerollsLeft] = useSt(draftMode === 'scout' ? 1 : 3);
  const hideRatings = draftMode === 'scout';

  React.useEffect(() => {
    if (!onSummaryStateChange) return;
    onSummaryStateChange(complete && myPlayers.length === 5);
    return () => onSummaryStateChange(false);
  }, [complete, myPlayers.length, onSummaryStateChange]);

  React.useEffect(() => {
    window.scrollToTopOnMobile?.();
  }, [round, complete]);

  const currentTeam = drawTeams[round];
  const teamPlayers = window.getTeamPlayers(currentTeam.id);
  const starPlayer = teamPlayers.find(p => p.id === currentTeam.starPlayerId);
  const iconPlayer = teamPlayers.find(p => p.id === currentTeam.iconPlayerId);
  const starCount = myPlayers.filter(p => p.overall >= window.DRAFT_STAR_THRESHOLD).length;

  function isSlotTaken(player) {
    return !!slotsTaken[window.getLineSlot(player)];
  }

  function isStarSoftBlocked(player, candidates = teamPlayers) {
    if (player.overall < window.DRAFT_STAR_THRESHOLD || starCount < window.DRAFT_STAR_CAP) return false;
    return candidates.some(candidate =>
      !isSlotTaken(candidate) && candidate.overall < window.DRAFT_STAR_THRESHOLD
    );
  }

  function canRecruitPlayer(player, candidates = teamPlayers) {
    return !isSlotTaken(player) && !isStarSoftBlocked(player, candidates);
  }

  function blockReason(player) {
    if (isSlotTaken(player)) return 'SLOT OCUPADO';
    if (isStarSoftBlocked(player)) return 'LIMITE DE ESTRELAS';
    return 'BLOQUEADO';
  }

  const hasAvailable = teamPlayers.some(p => canRecruitPlayer(p));
  const teamOverall = window.calcTeamOverall(teamPlayers);

  function handleRecruit(player) {
    if (!canRecruitPlayer(player) || animating) return;
    setPicked(player);
    setAnimating(true);
    setTimeout(() => {
      const next = [...myPlayers, player];
      setMyPlayers(next);
      setSlotsTaken({ ...slotsTaken, [window.getLineSlot(player)]: true });
      setPicked(null);
      setAnimating(false);
      if (next.length === 5) {
        setComplete(true);
      } else if (round < drawTeams.length - 1) {
        setRound(r => r + 1);
      }
    }, 460);
  }

  function handleSkip() {
    if (round < drawTeams.length - 1) setRound(r => r + 1);
  }

  function rerollCandidates(mode) {
    const blockedIds = new Set(drawTeams.map(t => t.id));
    blockedIds.delete(currentTeam.id);
    myPlayers.forEach(p => blockedIds.add(p.team));
    const pool = session.opponentTeams?.length ? session.opponentTeams : window.DRAFT_TEAMS;
    const bandPool = currentTeam.draftBand
      ? pool.filter(t => t.draftBand === currentTeam.draftBand)
      : pool;
    const scopedPool = bandPool.length ? bandPool : pool;
    return scopedPool
      .filter(t => t.id !== currentTeam.id)
      .filter(t => !blockedIds.has(t.id))
      .filter(t => mode === 'same-year' ? t.year === currentTeam.year : t.year !== currentTeam.year)
      .filter(t => {
        const players = window.getTeamPlayers(t.id);
        return players.some(p => canRecruitPlayer(p, players));
      });
  }

  function handleReroll(mode) {
    if (rerollsLeft <= 0 || animating || picked) return;
    const candidates = rerollCandidates(mode);
    if (!candidates.length) return;
    const seed = (Date.now() + round * 997 + rerollsLeft * 131 + (mode === 'same-year' ? 17 : 41)) % 0xFFFFFF;
    const nextTeam = candidates[Math.floor(makeDraftRerollRand(seed)() * candidates.length)];
    setDrawTeams(teams => teams.map((team, i) => i === round ? nextTeam : team));
    setRerollsLeft(n => Math.max(0, n - 1));
  }

  const myOverall = myPlayers.length > 0
    ? window.calcTeamOverall(myPlayers) : 0;

  if (complete && myPlayers.length === 5) {
    return <DraftSummaryView players={myPlayers}
      teamName={teamName}
      onStartMajor={() => onDraftComplete(myPlayers, matchFormat)} />;
  }

  return (
    <main style={{ maxWidth:1140, margin:'0 auto', padding:isMobile ? '10px 10px 30px' : '18px 20px 32px' }}>

      {/* Top bar */}
      <div style={{ display:'flex', flexDirection:isMobile ? 'column' : 'row',
        alignItems:isMobile ? 'stretch' : 'flex-end', justifyContent:'space-between',
        gap:isMobile ? 7 : 0, marginBottom:isMobile ? 8 : 16 }}>
        <div>
          <h2 style={{ fontFamily:'var(--font-cond)', fontWeight:800, fontSize:isMobile ? 15 : 17,
            color:'var(--text-1)', letterSpacing:'0.05em', textTransform:'uppercase', marginBottom:2 }}>
            Sorteio · Recrutamento
          </h2>
          <p style={{ display:isMobile ? 'none' : 'block', color:'var(--text-3)', fontSize:11 }}>
            Um lineup histórico por vez - recrute 1 jogador para cada slot da line
          </p>
        </div>
        <div className={isMobile ? 'touch-scroll' : undefined}
          style={{ display:'flex', alignItems:'center', gap:6, maxWidth:'100%' }}>
          {drawTeams.map((_, i) => (
            <div key={i} style={{ width: i === round ? 22 : 7, height:7, borderRadius:4,
              transition:'all 220ms ease',
              background: i <= round ? 'var(--accent)' : 'var(--bg-5)',
              opacity: i <= round ? 1 : 0.5 }} />
          ))}
          <span style={{ fontFamily:'var(--font-mono)', fontSize:11, color:'var(--text-3)', marginLeft:4 }}>
            {round + 1}/{drawTeams.length}
          </span>
        </div>
      </div>

      {/* Team draw header */}
      <div key={`${round}-${currentTeam.id}`} className="deal-header deal-sweep" style={{ position:'relative', overflow:'hidden',
        display:'flex', flexDirection:'row',
        alignItems:'center', justifyContent:'space-between',
        padding:isMobile ? '8px 10px' : '11px 16px',
        marginBottom:isMobile ? 7 : 10, gap:isMobile ? 9 : 16,
        background:'linear-gradient(90deg, rgba(244,165,35,0.06), transparent 60%)',
        border:'1px solid var(--border-2)', borderRadius:'var(--r-lg)' }}>
        <div style={{ display:'flex', alignItems:'center',
          gap:isMobile ? 8 : 12, minWidth:0 }}>
          <span style={{ fontFamily:'var(--font-cond)', fontSize:isMobile ? 8 : 9, fontWeight:700,
            color:'var(--accent)', letterSpacing:'0.14em', textTransform:'uppercase',
            padding:isMobile ? '2px 6px' : '3px 8px', background:'rgba(244,165,35,0.08)',
            border:'1px solid rgba(244,165,35,0.22)', borderRadius:'var(--r-sm)', whiteSpace:'nowrap' }}>
            Sorteado
          </span>
          <div style={{ display:'flex', flexWrap:'wrap', alignItems:'baseline', gap:9, minWidth:0 }}>
            <span style={{ fontFamily:'var(--font-cond)', fontWeight:800, fontSize:isMobile ? 18 : 22,
              color:'var(--text-1)', letterSpacing:'0.01em', whiteSpace:'nowrap', flexShrink:0 }}>
              {currentTeam.name}
            </span>
            <span style={{ fontFamily:'var(--font-mono)', fontSize:isMobile ? 11 : 13, color:'var(--accent)', flexShrink:0 }}>
              '{String(currentTeam.year).slice(2)}
            </span>
            <span style={{ display:isMobile ? 'none' : 'inline', fontSize:11, color:'var(--text-3)', whiteSpace:'nowrap',
              overflow:'hidden', textOverflow:'ellipsis', flex:1, minWidth:0 }}>
              <window.Flag value={currentTeam.region.split(' ')[0]} size={12} /> {currentTeam.region.replace(/^\S+\s*/, '')} · {currentTeam.achievement}
            </span>
          </div>
        </div>
        <div style={{ textAlign:'right', flexShrink:0 }}>
          <div style={{ fontFamily:'var(--font-mono)', fontSize:isMobile ? 20 : 24, fontWeight:700,
            color:'var(--accent)', lineHeight:1 }}>{hideRatings ? '??' : teamOverall}</div>
          <div style={{ fontSize:8, color:'var(--text-3)', fontFamily:'var(--font-cond)',
            letterSpacing:'0.1em', textTransform:'uppercase' }}>{hideRatings ? 'scout' : 'overall'}</div>
        </div>
      </div>

      {!isMobile && !hideRatings && (starPlayer || iconPlayer) && (
        <div style={{ display:'flex', gap:6, flexWrap:'wrap', margin:'-3px 0 10px' }}>
          {starPlayer && (
            <span style={{ padding:'3px 8px', background:'rgba(244,165,35,0.08)',
              border:'1px solid rgba(244,165,35,0.22)', borderRadius:'var(--r-sm)',
              fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
              color:'var(--accent)', letterSpacing:'0.08em', textTransform:'uppercase' }}>
              Estrela: {starPlayer.name}
            </span>
          )}
          {iconPlayer && (
            <span style={{ padding:'3px 8px', background:'var(--bg-3)',
              border:'1px solid var(--border-2)', borderRadius:'var(--r-sm)',
              fontFamily:'var(--font-cond)', fontSize:10, fontWeight:800,
              color:'var(--text-2)', letterSpacing:'0.08em', textTransform:'uppercase' }}>
              Ícone: {iconPlayer.name}
            </span>
          )}
        </div>
      )}

      <RerollControls
        currentTeam={currentTeam}
        rerollsLeft={rerollsLeft}
        maxRerolls={draftMode === 'scout' ? 1 : 3}
        disabled={animating || !!picked || rerollsLeft <= 0}
        sameYearAvailable={rerollCandidates('same-year').length > 0}
        otherYearAvailable={rerollCandidates('other-year').length > 0}
        onReroll={handleReroll}
      />

      {/* All-blocked notice */}
      {!hasAvailable && (
        <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between',
          padding:'9px 14px', marginBottom:10,
          background:'rgba(239,68,68,0.06)', border:'1px solid rgba(239,68,68,0.2)',
          borderRadius:'var(--r-md)' }}>
          <span style={{ fontSize:12, color:'#f08080', fontFamily:'var(--font-cond)', fontWeight:700 }}>
            Todos os slots válidos deste lineup estão ocupados ou travados pelo limite de estrelas.
          </span>
          {round < drawTeams.length - 1 && (
            <button onClick={handleSkip} style={{ padding:'5px 14px',
              background:'var(--bg-3)', border:'1px solid var(--border-3)', borderRadius:'var(--r-sm)',
              cursor:'pointer', fontFamily:'var(--font-cond)', fontSize:10, fontWeight:700,
              color:'var(--text-1)', letterSpacing:'0.08em', textTransform:'uppercase' }}>
              Próximo sorteio →
            </button>
          )}
        </div>
      )}

      {/* Player cards */}
      <div style={{ display:'grid', gridTemplateColumns:isMobile ? '1fr' : 'repeat(5,1fr)',
        gap:isMobile ? 6 : 8, marginBottom:isMobile ? 10 : 12 }}>
        {teamPlayers.map((p, i) => (
          <div key={`${round}-${p.id}`} className="deal-card" style={{ animationDelay:`${i * 65}ms` }}>
            <DraftCard player={p}
              state={!canRecruitPlayer(p) ? 'blocked' : picked?.id === p.id ? 'recruited' : 'available'}
              blockLabel={blockReason(p)}
              onRecruit={handleRecruit}
              hideRatings={hideRatings}
              compact={isMobile} />
          </div>
        ))}
      </div>

      {/* Formation board */}
      <FormationBoard players={myPlayers} overall={myOverall} hideRatings={hideRatings} />
    </main>
  );
}

window.DraftView = DraftView;
