Planck 2018 results: XII. Galactic astrophysics using polarized dust emission