I teach a university course called Hormones and Behaviour. What surprises students is that biological sex is not produced by a single switch. What surprises me is that many students have never been taught this before. It is basic biology, but it helps explain life.
Sex emerges through a sequence of events before birth and continues at puberty. Chromosomes help direct the formation of gonads, the body parts that usually become ovaries or testes. Gonads make hormones. The body then has to respond to those hormones. In most people, these steps flow in the same direction. But in rare cases, they do not.