Change color of card based on text number

Hi,
Im using the nightscout integration to keep track of my blood sugar numbers. I would like the card to change colors based on my glucose numbers. example:
1 to 150 = Green
151 to 250 = Yellow
251+ = Red

Im using card_mod and I have found this code:

card_mod:
  style: |
    ha-card {
    font-size: 25px;
      {% if is_state('sensor.example_sensor', 'on') %}
        background-color: green;
      {% else %}
        background-color: red;
      {% endif %}
    }

is it possible for it to read the numbers on the card so it can display the colors? Any help would be greatly appreciated.

I was able to get this to work with the help of Chatgpt. Here is what I ended up with for anyone who is interested in the same

type: entities
entities:
  - entity: sensor.blood_sugar
    name: Blood Sugar
card_mod:
  style: |
    ha-card {
      {% set glucose = states('sensor.blood_sugar') | float %}
      {% if glucose <= 150 %}
        background-color: green;
        color: white; /* Ensures text is readable on green background */
      {% elif glucose <= 293 %}
        background-color: yellow;
        color: black; /* Ensures text is readable on yellow background */
      {% else %}
        background-color: red;
        color: white; /* Ensures text is readable on red background */
      {% endif %}
      font-weight: bold; /* Makes text bold */
      font-size: 25px;
    }

What card are you talking about?
Check this list of examples: main card-mod thread → 1st post → link at the bottom titled “fantastic”

Update: good that you sorted this out.