correct idea, wrong interpretation
The problem with youtube is not necessarily that the source is lossy because if you for example download youtube music uploaded videos, which are the most music related videos, thats not really the case since they act like a streaming service effectively encoding the audio stream for youtube from the lossless source. Those would in general be the lesser evil IF and thats a big if, you dont reencode lossy audio they provide to u again.
Firstly ur "spectrum analysis" aint really a spectrum analysis, its just an audio spectrum. Well in any way its garbage since the comparison is just not fair? I mean any point ur trying to make here just gets blown out of proportion since u literally took a 112kbps cbr mp3 at 48khz to compare to a different song in flac thats only at 44.1khz instead of a real AAC or Opus audio from youtube. Since its a different song at a different samplerate and just way quieter then the other example file u pulled up this is not prooving anything other than "this lossy song is really quiet and hella lossy and this other lossless song is like lossless u know?" so im gonna give a better example:
Lossless 24bit 48.0kHz:
Youtube Opus VBR 160kbps~:

I mean hate on youtube all u want, im on ur side but... thats just not a remotely realistic illustration of what ur trying to say.
Also generally speaking looking at a spectrogram can tell u if ur music is somewhat lossy 50% of the time. It works as long as you have a Lossy codec at a low bitrate. MP3 is by far the worst offender in its CBR settings because even at its "Insane" setting it just has a straight cutoff at 20.5 kHz literally specified in the encoding settings. But take for example Spotifys OGG Vorbis at a bitrate of 320kbps.
Ogg Vorbis 320kbps:

No straight cutoff to be found and without having a reference spectrogram of the lossless file you cant just spot it. There is other indicators but i dont want this to be even longer then it already is.
Also these "shelves" as u call em' are not really an indicator of it being constantly reencoded. These are just general signs that it is somewhat lossy. If we take for example MP3 CBR at a bitrate of 320kbps even after multiple encodings you wont see any "shelves" but more of a straight cutoff. Inspecting it in the spectrogram wont really show any further audio degradation it will be audible at some point tho.
And even if we take MP3 it doesnt have to be a straight cutoff or look boxy at the peaks. Take for example MP3 v0 which is the best VBR setting.
MP3 CBR 320kbps [the most common "HQ" mp3]:
Straight cutoff with wierd peaks above 20.5kHz
MP3 v0 VBR 272kbps~:
Lower bitrate, higher peaks, no blocks to be seen.
Even checking if parts of the audio exceed some part of the spectrogram wont really help you analyze anything as even professional masters of songs may not go to the top of the spectrogram.
Lossless 24bit 44.1kHz:
And now just for fun lets do a v0 MP3 encode

I mean people could assume that the Lossless file may be lossy measured by it not completely peaking to 22.05. The other way around you could think the v0 was Lossless if you didnt have the reference of the Lossless Spectrogram.
I've seen people introducing noise to make the spectrogram appear blue in places where the lossy version was empty. Cant really go into details but he basically used those to authenticate some software he provided is legit with witch he then scammed people and even worse introduced tons of faked lossless versions of songs into the wild.
what im trying to say is dont overanalyze a spectrogram. Listen with your ears not ur eyes.
Also keeping anything over 24bit 96khz is a waste of harddrive space and even that is pushing it. The sweetspot in my opinion is 24 bit 48khz. With stereo audio that makes 24khz per ear and is somewhat at the end of whats audible in terms of high frequencies. [Use sox (Sound eXchange) to downsample as it produces the best results]
Another tip, avoid MQA as that is basically Lossy Audio in a Proprietary Codec sold to u as "Better than Lossless" since they cannot say it is Lossless anymore because it factually is not.