did you try and separate the 2?
you can merge mods (so that answer is yes)
example:
card_mod:
class: class-header-margin-no-color
style: |
.card-header {
background: {{states('sensor.uv_alert_color_name')}};
color: {{'var(--text-color-off)' if states('sensor.current_uv_index')|float(0) > 2
else 'var(--primary-color)'}};
}
Can also use a separate mod and inject that, or, set a mod in the card_mod_theme. many options at your disposal
but you should really try first and post the results. you will never know until you do anyways.