Well mvaneijgen, thank you so much. Not just for an answer, but such a generous one. I had read the 'common mistakes' and other 'before you post' things but clearly hadn't grasped some core stuff. You've helped me do that and more.
From your example I've got my code working as I want and in a much more reliable way. Very much appreciate the help.
Switching the panel CSS to display:grid was a crucial bit of help that I hadn't even realised was a path to the solution.
Thanks again.