I'm new to posting on stack exchange, although I've read a lot of it before. This question seems like it might end up being marked as a duplicate, but I've looked through a lot of the similar questions and I feel like I'm still not getting it (most answers end up just explaining that the octet rule is wrong).
I'm currently taking AP Chemistry and we've been talking about electron configuration. As I understand it, atoms generally are at a lowest energy state when they fill their outermost s and p subshells (resulting in the octet rule, as the 2 + 6 electrons in these shells add up to 8). As far as I can tell, this is mostly due to Coulomb's Law being stronger with a smaller radius and the shielding effect impacting how much protons pull on electrons. But what I don't understand, then, is why an atom would tend to gain electrons in order to fill its valence shell. Wouldn't the lowest energy state be to lose a whole shell and decrease the radius and the shielding effect? It would make the atom very positively charged, but that doesn't seem to be a problem for something like Si4+. For that matter, why have any electrons at all? Wouldn't the most stable state be for an atom to repeatedly lose electrons and just be a nucleus? Presumably this has to do with the ionization energy being too high, but why is that the case? If it's just as simple as because the electrons are attracted to the nucleus, why can any electrons be removed at all? What am I missing or where is the flaw in this reasoning?
P.S. I've found electron configuration really interesting so far, but we haven't been doing much of anything with the math that explains it. I'm taking multivariate calculus right now, and I would really like to learn about the math behind it all. Is it too early for me to start? If not, does anyone have any good introductory sources to learn about that?