Why flying dogs are rare: A general theory of luck in evolutionary transitions.