Precisely why and how this all happens is known as the problem of Color Confinement, and remains an unsolved problem to this day.
The new theory however is in terms of neutrons, protons, pions etc. and not of 'fundamental' quarks. That discussion will have to wait for another day.