In the end, you are looking for a command pattern. This might describe it: Command Pattern in Unity - Infallible Code
This game has a replay mechanism, wondering if it can be jury-rigged from that: https://itch.io/jam/gamedevtv-jam-2022/rate/1554340 another one that does this is https://itch.io/jam/gamedevtv-jam-2022/rate/1550919 ... Both use the system for other means, but you might be able to build something that allows you to go back a move.