Maybe something you're missing is the concept of "evolvability". You can see the book "Resolving Darwin's Dilemma" (review here: https://academic.oup.com/bioscience/article/56/9/772/263015). An important concept in the evolution of novelty (creating new, advanced functions out of "random" mutations) is that all the living systems we observe today are highly evolvable. Evolvability is an emergent property of some evolving systems, and it enables surprising leaps in functionality.