Mechanisms for Inhmogeneity in Earth's Crust

Mix cream in coffee and it never unmixes. Even though the cup of coffee is not a closed system, the second law of thermodynamics seems to apply anyhow.

The Earth was once a molten ball. I presume that it was well mixed. It is not a closed system either.
But today's Earth seems very unlike the creamed coffee; especially in the crust.

I am wondering how we can find so many rich mineral deposits all over. Both light and heavy minerals. We find veins of gold and other metals. We find ores with concentrated amounts of aluminum, or lithium or hundreds of other minerals. We even find pockets of helium. A visit to the Grand Canyon made me appreciate the incredible diversity of rock.

I understand stratification by density. But mineral finds are both light and dense. I understand that chemical reactions can cause precipitates to fall out of a liquid such as sea water, but I have a hard time visualizing that in viscous magma. Distillation? Yet even distillation sounds wrong because there are so many diverse minerals found concentrated in so few places. I would expect that a single mechanism acting world wide would produce homogeneous results, not diversity.

I am also interested in the timing of unmixing. Whether it happened before or after the crust solidified. Could the planetesimals that formed the earth have been enriched before becoming part of the earth such that their mass never did get thoroughly mixed?

I can't find anything useful on Wikipedia. Wikipedia is great, but only if you can guess the right terms to search for.

Can anyone help point me to articles or publicly available sources where I could study this subject more?