All of the things you're thinking of trying sound good.
Try moving your magnesium to the morning. If that doesn't work, you might want to try a different type of magnesium, the oxide form is poorly absorbed.
If you can, move your second workout of the day as early in the afternoon as you can, so that you aren't wired from adrenaline before bed.
No nightshades, they tend to cause a middle-of-the-night wakeup like you are describing.