Fill 3/8" gap between wood and wall
Just wrap a small encasement around the board and last couple inches of wall. Three boards finished to match the rails. I doubt you would even need to do 45s, just drop the side boards from the top board by cutting it longer than the wall is wide/thick by twice the thickness of a side board.