Theory of polytypism and the FCC/HCP transition