A Foundation for Synthetic Algebraic Geometry