The origin of chemical elements heavier than iron, such as gold, has been a long-standing puzzle. About half of the heavy-element abundances are expected to be produced by the astrophysical rapid neutron capture process, the r process. Its astrophysical site has been one of the biggest outstanding questions in physics. The observation of the binary neutron-star merger GW170817 and the associated kilonova in August 2017 gave the first direct evidence that the r process takes place at least in such neutron-star mergers. However, there are still several open questions related to the r process. Can neutron-star mergers explain all observed r-process abundances? What is the role of supernovae in the production of heavier elements? How to interpret the observed kilonova? In order to better model the r process, accurate nuclear physics input data are needed. Nuclear masses are one of the most important nuclear physics inputs for the r process and for studying the chemical evolution in the Cosmos. In this project, high-precision mass measurements are performed for the r process employing novel production and measurement techniques. Long-living isomeric states, which also play a role in the r process, are resolved from the ground states to obtain accurate mass values. Post-trap decay spectroscopy will be performed to confirm which state has been measured in order to avoid systematic uncertainties in the mass values. Decay properties of neutron-rich nuclei are also relevant for the r-process calculations. The new data gathered in this project will be compared with theoretical nuclear models and included in the r-process calculations performed for different astrophysical conditions. The improved r-process calculations are essential to fully benefit from the anticipated new multimessenger observations from neutron-star mergers. This project will advance our knowledge of nuclear structure far from stability and reduce nuclear data uncertainties in the r-process calculations, which can potentially constrain the astrophysical site for the r process and help to understand the origin of heavier elements.