It literally started with an explosion in a can, and then progressively enhanced that idea step-by-step: add a lid to the can to capture the energy, add a lever to keep the can lid from flying away, and then attach the lever to a wheel so that it returns the lid to the top of the can for another explosion, add walls to guide the lid, ta-da! Piston.
It goes on like that, adding each piece of the puzzle in a logical way, until you have a mental model of an internal combustion engine. You definitely feel like you could build one from scratch (if you had the metallurgy skill.)