It seems obvious but also: don’t drink anything with caffeine before bed and don’t eat a good couple of hours before sleep too.
I’ve had many friends who’d have a tea before going to sleep to ‘calm’ them without realising most have quite a lot still. Or guzzling down a soda too.
That seems a bit much. Then you shouldn’t have a coffee after 10am. Most people are perfectly fine with having coffee in the afternoon.
It might seem like that but I’ve seen it recommended by doctors more than once. Caffeine stays in our system longer than most expect.