Keep a pad and paper on your bedside table. I can't count the number of times I've woken up to find that somebody with my handwriting has solved something that was bothering me.
Just hope they don't try to replace you, and claim your life too.
The pen-light idea mentioned elsewhere is a nice addition to the notepad idea.
Most of my solutions so far usually regard trivialities. When a train of thought was genuinely worth finding in the morning, I would usually leave a relevant web search open on my phone (along with all the other things to not forget, or check later. Quite devastating is the browser choked...). Also, the display would be jarringly bright... Although, if it was a compelling enough idea, it would be enough to win me away from sleep.
(Also fun, if you think of too many altogether... Complicates the above even further.)