Multilayer modal method for diffraction gratings of arbitrary profile, depth, and permittivity | Synapse