No-one likes to hear this but it's true. Cut out caffeine in the afternoons (it has a ~6hr half-life in your system) and install F.lux or something to lower the colour temperature of your monitors.
(Anecdatum: When I want to stay up late, I turn off F.lux and it adds probably 2 hrs before I start feeling tired.)
Plenty of people know this, and do it, and still struggle. I limit myself to maximum of 2 coffees a day, no later than 3pm, and no phone/games after 10:00 and I still find myself lying in bed awake at 3am regularly
Because it's not enough to do one thing, you have to do all the things: exercise, go outdoors, socialize, live. It's like a chain: it only works when all the links are intact. A 99.99% chain is as good as a 1% chain.
Worth adding that there is great variability of the half-life of caffeine in different people, in part due to different phenotypes of the enzymes responsible for its metabolism (among other variables). For instance, I metabolize it slightly slower (if you can trust 23andMe SNP data enough for that kind of a prediction), so it could be even longer for me. iirc nicotine has also been shown to speed up caffeine's metabolism.
(Anecdatum: When I want to stay up late, I turn off F.lux and it adds probably 2 hrs before I start feeling tired.)