How the British Empire rewrote the rules for gender, race and sexuality in South Africa