Thermodynamic Foundations of the Earth System