Context. The evolution of interstellar clouds of gas and dust establishes the prerequisites for star formation. The pathway to the formation of stars can be studied in regions that have formed stars, but which at the same time also display the earliest phases of stellar evolution, i.e. pre-collapse/collapsing cores (Class-1), protostars (Class 0), and young stellar objects (Class I, II, III). Aims. We investigate to what degree local physical and chemical conditions are related to the evolutionary status of various objects in star-forming media. Methods. ρ Oph A displays the entire sequence of low-mass star formation in a small volume of space. Using spectrophotometric line maps of H 2 , H 2 O, NH 3 , N 2 H + , O 2 , O I, CO, and CS, we examine the distribution of the atomic and molecular gas in this dense molecular core. The physical parameters of these species are derived, as are their relative abundances in ρ Oph A. Using radiative transfer models, we examine the infall status of the cold dense cores from their resolved line profiles of the ground state lines of H 2 O and NH 3 , where for the latter no contamination from the VLA 1623 outflow is observed and line overlap of the hyperfine components is explicitly taken into account. Results. The stratified structure of this photon dominated region (PDR), seen edge-on, is clearly displayed. Polycyclic aromatic hydrocarbons (PAHs) and O I are seen throughout the region around the exciting star S 1. At the interface to the molecular core 0.05 pc away, atomic hydrogen is rapidly converted into H 2 , whereas O I protrudes further into the molecular core. This provides oxygen atoms for the gas-phase formation of O 2 in the core SM 1, where X(O 2) ∼ 5 × 10 −8. There, the ratio of the O 2 to H 2 O abundance [X(H 2 O) ∼ 5 × 10 −9 ] is significantly higher than unity. Away from the core, O 2 experiences a dramatic decrease due to increasing H 2 O formation. Outside the molecular core ρ Oph A, on the far side as seen from S 1, the intense radiation from the 0.5 pc distant early B-type star HD 147889 destroys the molecules. Conclusions. Towards the dark core SM 1, the observed abundance ratio X(O 2)/X(H 2 O) > 1, which suggests that this object is extremely young, which would explain why O 2 is such an elusive molecule outside the solar system.