To be quite true, the bitcoins are stored in the blockchain. In order to spend those coins, you need to sign with your private keys. The wallet and block explorers are just a graphical user interface which helps you to view the balances as they get updated over the nodes.
Whenever you are trying to spend the coins, the outputs and inputs will be checked and verified by the nodes before the transactions are being added to the blockchain. If the input value is less than output value, the transaction is rejected. Hence you can never have a negative balance.
Negative balances can be created only when the inputs are less than output value and such transactions are being confirmed which isn't really possible.
Here is the code to prevent transactions that has negative balances
const CAmount value_out = tx.GetValueOut();
if (nValueIn < value_out) {
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-txns-in-belowout",
strprintf("value in (%s) < value out (%s)", FormatMoney(nValueIn), FormatMoney(value_out)));
}