It has nothing to do with social problems, it has everything to do with brain chemistry
Well, first of all, gender is a mental thing. It exists inside your mind, and is made up of hormonal balances usually based on your sex, aka, the parts "down there". Gender is a spectrum.
Sex is also a spectrum, though it is usually depicted as a binary. The majority of people are male or female, and sex is depicted as such though there are also plenty of intersex people in the world, and they're estimated to take up 1% of our world's population. Sex is physical biology while gender is mental biology.
TL;DR-
Gender = mind
Sex = body.