I'm trying to understand how difficulty works in bitcoin mining. I understand that as there are less and less bitcoins left to be mined, the amount you get for each new block is lowered.
The bit I don't get is how a block is mined every 10 minutes. The miners aren't connected to a single network and talking about how much mining power they have so how would the system itself be able to regulate itself to only spit out a new block every 10 minutes?
Also, does this mean that difficulty is really not only a function of how many bitcoins are left, but also how many miners are there in total? So say, if 90% of the miners decided to not mine bitcoins anymore, then would bitcoins be 90% easier to mine for the 10% of miners left? Likewise if bitcoin miners doubled, it would be 100% more difficult to mine? Simply due to the fact they would need to sustain the quota of a block per 10 minutes?