Section colour crossfade
Scroll. Each section brings its own full-screen colour layer, which fades in when the section's top crosses the middle of the screen.
Post it to the back
Every layer is position: fixed at z-index: -1. They stack in document order, so a later section's colour sits over an earlier one, and all of them sit under the content. There's no z-index to juggle.
A flag, a query, a fade
A one-step scroll-driven animation flips --in on the section when its top crosses the entry line. The property is registered with inherits: false, so the flip stays on the section.
@container section style(--in: 1) sets the layer's opacity to 1. That comes from the cascade rather than the animation, so an ordinary opacity transition runs, on the compositor.
Scrolling decides when. A transition decides how.
The nav blends
The nav uses mix-blend-mode against whatever is behind it: color-dodge in dark mode, multiply in light. It follows every fade without knowing which section is showing, and it costs nothing extra while scrolling.
The current link
A small IntersectionObserver marks the current link with aria-current. The marker scales up and the label slides over, so both move on the compositor.
A short one.
No scroll-driven animations?
Then the same observer flips the layers as well, with a data-entered attribute on each section that's past the line. The fade is the same opacity transition.
Tune it
Move the entry line with --entry-line on :root. The CSS and the observer both read it. Each section's colour comes from its --hue.