Custome-button card - dynamic button color

Hi all - I have a custom-button card that I use to control one of my air filters:

I would like the card to change the color of the button that is currently active (say to blue), while the other buttons retain their white text on a black background. Ideally the button color should change whether the mode is changed via the UI or on the device itself. (I have created a template sensor - sensor.clean_air_fan_speed which has the current fan state 33/66/100/off/sleep)

Current code looks like:

type: custom:button-card
icon: mdi:fan-speed-1
size: 30%
tap_action:
  action: call-service
  service: fan.set_percentage
  service_data:
    percentage: 33
    entity_id: fan.cleanair

Any thoughts? Thanks in advance!

Got it sorted. Mods can close/delete original post.