Why did I lose this engagement/how can I not lose it in future


I just fought a PVP and when our armies clashed, I had a similar amount of units to him except I had 7 colossus to his 5, and I had ~1 less of everything else. Both sides supply capped. My upgrades were 2 1 2 or something like that, his were 0 0 2, and I got thrashed pretty hard. I am hoping someone can take a look at this replay and tell me why I lost and how to avoid losing like this in future, all I can think of is that my gateway units ran in first so they got in range of the enemy colossus before his units got in range of mine. How should I micro in future to avoid this kind of thing?