Ca2+ and Mg2+ bind tetracycline with distinct stoichiometries and linked deprotonation.