The opponent just had a lucky attack. You underestimated his knight/bishop/queen attack and that's what went down. Next time try to keep your king save and trade of pieces that are getting to close to your king.
I find 12. g4 pretty unneccesary. Better was Nh4? (if you really felt like moving that bishop away)
14. Ne4 I think looks better.
And those checks at move 22 were random lol. Why didnt you do something more productive, like 22. Bc3? You wanna keep it fianchetto'd bro <3
Post your games in which you were winning and then lost badly.
Here is mine:
Analysis is appreciated