so just now I died and won almost at the same time (dying animation first with all the icons+buttons on the screen disappearing, shortly afterwards my troops stopped hitting, then comes winning animation), and it counted as a win
That has happened to me at least twice.
Had this very often. Mostly it is count as a Win but sometimes you lose.
It depends on your type of spell, when a lasting spell is activated before hero died and it takes down the gate, then you still win.
That, Dena, does make Sense! Thanks!