Thermodynamic model identifies how gold reaches Earth's surface