  Context: The thermal and chemical structures of the upper atmospheres of
planets crucially influence losses to space and must be understood to constrain
the effects of losses on atmospheric evolution.
  Aims: We develop a 1D first-principles hydrodynamic atmosphere model that
calculates atmospheric thermal and chemical structures for arbitrary planetary
parameters, chemical compositions, and stellar inputs. We apply the model to
study the reaction of the Earth's upper atmosphere to large changes in the
CO$_2$ abundance and to changes in the input solar XUV field due to the Sun's
activity evolution from 3~Gyr in the past to 2.5~Gyr in the future.
  Methods: For the thermal atmosphere structure, we consider heating from the
absorption of stellar X-ray, UV, and IR radiation, heating from exothermic
chemical reactions, electron heating from collisions with non-thermal
photoelectrons, Joule heating, cooling from IR emission by several species,
thermal conduction, and energy exchanges between the neutral, ion, and electron
gases. For the chemical structure, we consider $\sim$500 chemical reactions,
including 56 photoreactions, eddy and molecular diffusion, and advection. In
addition, we calculate the atmospheric structure by solving the hydrodynamic
equations. To solve the equations in our model, we develop the Kompot code and
provide detailed descriptions of the numerical methods used in the appendices.
  Results: We verify our model by calculating the structures of the upper
atmospheres of the modern Earth and Venus. By varying the CO$_2$ abundances at
the lower boundary (65~km) of our Earth model, we show that the atmospheric
thermal structure is significantly altered. [Abstract Truncated]
