etBoundingClientRect();
          const mouseX = event.clientX - rect.left;
          const mouseY = event.clientY - rect.top;
          const clickedRow = Math.floor(mouseY / cellSize);
          const clickedCol = Math.floor(mouseX / cellSize);
          grid[clickedRow][clickedCol] = !grid[clickedRow][clickedCol];
          drawGrid();
        }
      }

      function countNeighbors(x, y) {
        let count = 0;
        const dx = [-1, -1, -1, 0, 0, 1, 1, 1];
        const dy = [-1, 0, 1, 