Why mineral veins?

Why are minerals found in Earth veins? Given the violent beating and mixing the Earth has had to endure why aren’t the minerals more or less evenly distributed throughout the Earth? Or alternatively the lightest on top and the heavier further down?

I’m not a geologist, so I hope others will correct or expound.

When igneous rock is in liquid form, minerals are distributed rather evenly. As it cools, the various minerals become solid at different times, and are deposited as veins. The whole blob of igneous rock doesn’t cool all at once.

IANAG either, but also, fluids (either solutions or lava) are often forced through fissures in existing rocks, depositing minerals along the way, or transforming the composition of the immediately surrounding rock.

Here’s a link that explains some of the ways that veins form.