De Villiers’s fighting century, Rabada’s wickets give South Africa the edge on day three