You were trying to gain muscle and lose fat at the same time, and trying so hard at both you failed. Sort of like having two girlfriends at the same time. The harder you try to keep both of them happy the bigger the failure.
1: Squats are your friend. I did a 21 day squat challenge, and while I gained 15 pounds people complimented me on losing weight, because all that weight gain was muscle.
2: High volume is your friend. At your age and with your goals, you should look up “German Volume training” and “star complexes.” I think articles on both plans are on this website.
3: Pasta and rice are not your friends. Meat, eggs, vegetables, and fruit are your friends.