Dark mode means different values, not different markup. Branch your {% style %} block on the setting and emit a different set of CSS variables. The static CSS that reads var(--bg) stays the same.
{% style %}
.panel {
{% if settings.dark_mode %}
--bg: #1c1410; --text: #f5efe6;
{% else %}
--bg: #ffffff; --text: #1c1410;
{% endif %}
}
{% endstyle %}
Set the color-scheme property (color-scheme: dark) so form inputs, scrollbars, and date pickers go dark too. Most hand-rolled dark modes miss this.