// Champion takeover — full-screen dramatic reveal with confetti const { useState: useCState, useEffect: useCEffect, useRef: useCRef } = React; function ConfettiCanvas({ color, anims }) { const ref = useCRef(null); useCEffect(() => { if (!anims) return; const canvas = ref.current; const ctx = canvas.getContext('2d'); const dpr = window.devicePixelRatio || 1; function resize() { canvas.width = canvas.clientWidth * dpr; canvas.height = canvas.clientHeight * dpr; ctx.scale(dpr, dpr); } resize(); const colors = [color, '#FFFFFF', '#F4F5F7', '#8B919C']; const W = canvas.clientWidth; const H = canvas.clientHeight; const particles = []; for (let i = 0; i < 140; i++) { particles.push({ x: Math.random() * W, y: -20 - Math.random() * H * 0.5, vx: (Math.random() - 0.5) * 1.2, vy: 1.2 + Math.random() * 2.5, r: 3 + Math.random() * 4, rot: Math.random() * Math.PI * 2, vr: (Math.random() - 0.5) * 0.15, c: colors[Math.floor(Math.random() * colors.length)], shape: Math.random() < 0.5 ? 'rect' : 'circle', }); } let raf; function tick() { ctx.clearRect(0, 0, W, H); particles.forEach(p => { p.x += p.vx; p.y += p.vy; p.vy += 0.015; p.rot += p.vr; if (p.y > H + 20) { p.y = -20; p.x = Math.random() * W; p.vy = 1.2 + Math.random() * 2.5; } ctx.save(); ctx.translate(p.x, p.y); ctx.rotate(p.rot); ctx.fillStyle = p.c; if (p.shape === 'rect') { ctx.fillRect(-p.r, -p.r * 0.4, p.r * 2, p.r * 0.8); } else { ctx.beginPath(); ctx.arc(0, 0, p.r * 0.6, 0, Math.PI * 2); ctx.fill(); } ctx.restore(); }); raf = requestAnimationFrame(tick); } tick(); return () => cancelAnimationFrame(raf); }, [color, anims]); return ; } function ChampionTakeover({ tournament, onClose, onNew, anims }) { const champ = getChampion(tournament.bracket); const [phase, setPhase] = useCState(0); const c = champ ? fighterColor(champ.seed, champ.name) : SEED_PALETTE[2]; useCEffect(() => { if (!anims) { setPhase(3); return; } const t1 = setTimeout(() => setPhase(1), 250); const t2 = setTimeout(() => setPhase(2), 900); const t3 = setTimeout(() => setPhase(3), 1500); return () => { clearTimeout(t1); clearTimeout(t2); clearTimeout(t3); }; }, [anims]); // Build path the champion took const path = []; if (champ) { tournament.bracket.rounds.forEach((round, ri) => { round.matches.forEach(m => { if (m.status !== 'done') return; const isInMatch = (m.a && m.a.name === champ.name && m.a.seed === champ.seed) || (m.b && m.b.name === champ.name && m.b.seed === champ.seed); if (isInMatch && m.winner && m.winner.name === champ.name) { const opp = m.a?.name === champ.name && m.a?.seed === champ.seed ? m.b : m.a; if (opp && !opp.bye) path.push({ round: round.name, opponent: opp }); } }); }); } if (!champ) return null; return (