  We study the redshift evolution of the gas-phase O/H and N/O abundances, both
(i) for individual ISM regions within single spatially-resolved galaxies and
(ii) when dealing with average abundances in the whole ISM of many unresolved
galaxies. We make use of a cosmological hydrodynamical simulation including
detailed chemical enrichment, which properly takes into account the variety of
different stellar nucleosynthetic sources of O and N in galaxies. We identify
$33$ galaxies in the simulation, lying within dark matter halos with virial
mass in the range $10^{11}\le M_{\text{DM}} \le 10^{13}\,\text{M}_{\odot}$ and
reconstruct how they evolved with redshift. For the local and global
measurements, the observed increasing trend of N/O at high O/H can be
explained, respectively, (i) as the consequence of metallicity gradients which
have settled in the galaxy interstellar medium, where the innermost galactic
regions have the highest O/H abundances and the highest N/O ratios, and (ii) as
the consequence of an underlying average mass-metallicity relation that
galaxies obey as they evolve across cosmic epochs, where -- at any redshift --
less massive galaxies have lower average O/H and N/O ratios than the more
massive ones. We do not find a strong dependence on the environment. For both
local and global relations, the predicted N/O--O/H relation is due to the
mostly secondary origin of N in stars. We also predict that the O/H and N/O
gradients in the galaxy interstellar medium gradually flatten as functions of
redshift, with the average N/O ratios being strictly coupled with the galaxy
star formation history. Because N production strongly depends on O abundances,
we obtain a universal relation for the N/O--O/H abundance diagram whether we
consider average abundances of many unresolved galaxies put together or many
abundance measurements within a single spatially-resolved galaxy.
