   const gradient = ctx.createRadialGradient(
                ball.x, ball.y, 0,
                ball.x, ball.y, ball.radius
            );
            gradient.addColorStop(0, '#FF8A80');
            gradient.addColorStop(1, '#D32F2F');
            ctx.fillStyle = gradient;
            
            ctx.fill();
            ctx.closePath();
        }
        
        // Calculate distance from point to line segment
        function distanceToSegment(point, lineStart, lineEnd) {
            const A = point.x 