Text this: Generating long-distance magnetic couplings with flat bands