Russia has been very firm that its response to any substantive invasion of its territory will get a nuclear response. To the point where they explicitly told a nuclear armed China that if they tried anything in Siberia, Russia would nuke Beijing as its first response.
en.wikipedia.org
They both play shouting games like that.
As the war in Ukraine is about to head into its sixth month, the ferocity with which it is fought shows no signs of abating – neither on the battlefield
asiatimes.com
Note that Russia has formally annexed 4 Ukrainian oblasts and Crimea and already considers it Russian territory (and Russian laws naturally make no distinction between pre-2014 territory and the rest unlike westerners), even if hardly any other country recognized that, and Ukraine has recovered some portions of those, like Kherson, the "Russian" city.
Yet no nukes flying so far...
The point is, we have seen many, many times that Russian leadership loves making over the top threats that they have little to no intention of actually following through with. And it makes sense, threats cost nothing, they have no reputation with those who care about those to lose anyway, so why not? Either the threat works, in which case they get the enemy to back down at no cost, or they don't, in which case it costs them nothing for that nothing, it's like a lottery ticket you got for free. Russians do not include the safetyist concerns over risks and "optics" involved in their consideration for they are not safetyists and "optics" fans like westerners are.
Bluntly, Russia can't afford not to go nuclear in the event that its territory is invaded. The stone cold certainty that Russia will go nuclear in response is at the very core of Russian national security. The only excuse not to do so is if they 1) can crush the invasion immediately with conventional force and 2) can compel the invading power to make public, and extreme, recompense.
There would be threats, warnings, counterattacks, negotiations... Nuclear response would be on the table, but in case of a minor territorial loss, far from certain.
If Ukraine is in a position to send forces into Russia then Russia won't be in a position to crush those forces conventionally. Ukraine would then be faced with either immediately surrending and being humiliated or getting, at a minimum, those forces nuked.
As for a coup, again this is seen (correctly) by the entire Russian leadership as an existential war. If Putin got replaced it would be because the other powers that be think he has gone senile and can't effectively persecute the war, not because they want an out from the war.
If Ukraine win's, it will be by outlasting the Russian ability to throw military force at them while simultaneously avoiding any excuse for Russia to go nuclear.
It is seen as an existential war because Putin sees it as such (and even that involves layers upon layers of questionable assumptions, word games and not so reliable theories). Once Putin's opinion ceases to be the opinion everyone who wants to have any deals with or in government follows, all sorts of turnarounds can happen.
On the other hand, if Putin or his replacement decides that he wants to go nuclear (or do anything at all in general), you can rest assured that his propaganda department will effortlessly find at least a half-assed excuse for him, that's part of their job after all.
It is unrealistic to assume the whole leadership would have the same opinion on such a controversial and troublesome matter, though in Russian system pretending that they do is absolutely expected.