Nature Materials, Published online: 28 August 2026; doi:10.1038/s41563-026-02744-xLight propagation can be controlled at the nanoscale by forming surface polaritons in two-dimensional layers of van der Waals crystals stacked with a relative twist. Now, a neural network that works backwards from a target light path identifies structures that produce a desired propagation across visible to terahertz operating frequencies.