As an example of both "full song in head" and "crap recording equipment" i present a 25 year old track and also ringtone of mine(1 "F" bomb in the track): https://soundcloud.com/djoutcold/showerbassline
https://soundcloud.com/djoutcold/showerringtone
if you scroll all the way down my track list, there's a track called "greenocide" which is written similarly, inspiration, transcription, then field audio recordings and telephone tap recordings, but much higher quality overall!
The proper term is hypnagogia.
Studies showed better math solving after hypnogagia state: https://pmc.ncbi.nlm.nih.gov/articles/PMC8654287/ https://www.science.org/doi/10.1126/sciadv.abj5866