This stuff can get as complicated as you want it to. I question the business value proposition though (i.e., how much fun it is to be this precise).
That said, I would pay good money to look at the source code of some of the production MTG rule systems.
https://mtg.fandom.com/wiki/Layer
https://media.wizards.com/2026/downloads/MagicCompRules%2020...