The foundation of agency: An exploration of how minimal organisms emerge from and adapt to their environments