Stepwise evolution of a butterfly supergene via duplication and inversion