Blynk.begin is a blocking function, so if the device can’t connect to either your WiFi or the Blynk server all code execution will halt at that point. This means that all of your online/offline code is irrelevant, and it won’t be executed because the sketch will be halted in your void setup.
You need to be manually managing your WiFi connection and using Blynk.config and Blynk.connect, along with a timed routine to periodically check if your device isn’t connected to either WiFi or Blynk and to attempt a reconnection.
The frequency of this reconnection attempt process, and the timeout period that you choose for the Blynk.connect command need to be adjusted to give you minimal disruption to your physical button functionality.
Also, you need to stop polling your button pins each time your void loop is executed, either by doing this via a BlynkTimer or using interrupts.
Here’s an example of how Blynk.config with the optional timeout and Blynk.begin can be used…
As you’re using Blynk Legacy you need to be running version 0.6.1 of the Blynk library, and preferably be running version 0.41.17 of local server if you want to avoid the Log4j2 Java vulnerability.
Pete.