Confinement and activity regulate bacterial motion in porous media