Higher contrast accent color in both light and dark modes (CSS snippet)

It’s hard to find an accent color that has good contrast in both light and dark modes, which is a problem if you change modes on a schedule. This snippet fixes that by making the accent color darker in light mode and lighter in dark mode. Obviously this works best with colors of middle brightness.

The first draft was kindly written by #appearance wizard @Anubis. Discord

Here’s the default accent color (left) with the snippet applied (right):

A downside of this snippet is that it reduces contrast in a few places in Settings that use white text atop the accent color in dark mode. This should be fixable but at the moment it’s not worth the effort to me because I don’t spend most of my time in Settings. EDIT: This also affects pop-up messages.

/*
	# Higher contrast accent color
	
	Increase contrast of accent color by making it darker in light mode and lighter in dark mode.
	
	https://forum.obsidian.md/t/higher-contrast-accent-color-in-both-light-and-dark-modes-css-snippet/46512
*/

body {
	--accent-l-diff: 13%;
}

.theme-light {
	--accent-l-mod: calc(var(--accent-l) - var(--accent-l-diff));
    --color-accent-hsl: var(--accent-h), var(--accent-s), var(--accent-l-mod);
    --color-accent: hsl(var(--accent-h), var(--accent-s), var(--accent-l-mod)); 
	--color-accent-1: hsl(var(--accent-h), var(--accent-s), calc(var(--accent-l-mod) + 2.5%));
    --color-accent-2: hsl(var(--accent-h), var(--accent-s), calc(var(--accent-l-mod) + 5%));
}

.theme-dark {
	--accent-l-mod: calc(var(--accent-l) + var(--accent-l-diff));
    --color-accent-hsl: var(--accent-h), var(--accent-s), var(--accent-l-mod);
    --color-accent: hsl(var(--accent-h), var(--accent-s), var(--accent-l-mod));
	--color-accent-1: hsl(var(--accent-h), var(--accent-s), calc(var(--accent-l-mod) + 2.5%));
    --color-accent-2: hsl(var(--accent-h), var(--accent-s), calc(var(--accent-l-mod) + 5%));
}

Reducing --accent-l-diff to 10% or 11% gives a little more contrast against the body text and a little more color in dark mode.