How do I change :before element to match changing background color

How do I change :before element to match changing background color

I am trying to change a :before element to match the color of the changing background element but I am unsuccessful, can anyone provide some working code to make this work, I have been working on it for hours, here is my codepen:


It is for that first row of gray elements, the second row is hard coded, trying to automate.