I just wrote the same codes. You can do one thing, instead of using hex codes for colours use the name of the color, like “black” or “white”. seems easier and might probably work
P.S. I wish I could also show you the results but they’re allowing me to upload one image only