A first-order logic characterization of safety and co-safety languages (Logical Methods in Computer Science, 2023)