Theory of electromagnetic scattering from a layered medium with a laterally varying substrate | Synapse