Counting Complexity and Phase Transitions