Magic wavelengths for terahertz clock transitions