There is one section here where the page turns over: black type on bone instead of bone on black. The tempting way to build it is a variant prop threaded through every component in that subtree, or a parallel set of classes. Both mean every component now knows about a context it has no business knowing about, and both mean the next inverted section is the same work again.
Invert the tokens, not the components
If every colour in the app is read through a custom property at runtime, inversion is a scoped redefinition of those properties. One selector, no component changes, and it composes — anything dropped inside the scope is already correct.
[data-invert] {
--color-bg: #ece9e2;
--color-fg: #0b0b0d;
--color-line: rgba(11, 11, 13, 0.16);
/* Darkened deliberately: the ember that carries on near-black is
under-contrasted on bone. Inversion is not always symmetric. */
--color-accent: #b23e1d;
background-color: var(--color-bg);
color: var(--color-fg);
}That last point is the one worth keeping. A token swap is not a filter. Inverting lightness mechanically will pass every automated check and still look wrong, because contrast is not symmetric — an accent tuned to glow on near-black is muddy on bone. Each side gets its own value.
What escapes the scope
That is the real constraint on this technique: it works exactly as far as the cascade reaches. Fixed and portalled elements need to be told. Everything else is free.
The same trick, one level up
If one scoped redefinition can turn a section over, the same move at the document root is a theme. The site ships four, and not one component knows about any of them — the only new code is a store that writes an attribute onto the html element and an inline script that writes it before the first paint, because setting it from React means every load flashes the previous ground.
What is not free is the interaction between the two. An inversion that hardcodes a light palette works right up until the ground underneath it is already light, at which point the section inverts to itself and the page quietly stops turning over. Inversion has to be relative to what is in force, so each ground names its own opposite.
/* The fallback: no attribute set, so this is the base theme's. */
[data-invert] { --color-bg: #ece9e2; --color-fg: #0b0b0d; }
/* Already bone. Turning over here means going dark, not going light. */
html[data-theme='bone'] [data-invert] {
--color-bg: #08080a;
--color-fg: #ece9e2;
}