 drawGrid() {
        ctx.clearRect(0, 0, canvas.width, canvas.height);

        for (let i = 0; i < rows; i++) {
          for (let j = 0; j < cols; j++) {
            ctx.beginPath();
            ctx.rect(j * cellSize, i * cellSize, cellSize, cellSize);
            ctx.fillStyle = grid[i][j] ? "black" : "white";
            ctx.fill();
            ctx.stroke();
          }
        }
      }

      function handleCanvasClick(event) {
        if (!isRunning) {
          const rect = canvas.g