A mortal sin requires
- Grave matter
- Free consent of the will
- Full knowledge
If any of these conditions is missing, you have not committed a mortal sin. You have to perform a grave action, do so willfully, and do so with sufficient reflection upon and knowledge of the gravity of the action. Impure thoughts are not necessarily a grave matter and you didn’t conjure them up or dwell on them willfully, and you don’t indicate that you’re aware of the gravity (or lack thereof) of the action.
Thoughts in most cases aren’t a sin of themselves, since we don’t necessarily have control of when they come along–you even indicate that they were involuntary. You can’t offend God without meaning to. Be at peace, and perhaps talk to a good priest about scrupulosity and how to work through it, especially since online you’re going to get a multitude of opinions, ranging from the cool-headed, rational keeping of things in perspective, all the way to those saying that you’ve incurred all kinds of guilt, which may not be true. Asking these sorts of things online may only intensify your scrupulosity, in other words; only your confessor knows your soul and can help you through things like this.
Know of my prayers for you, and may the Lord God give you his peace.