Desktop Rail With Scroll-Spy
The reference-article default: 240px of rail, reading-line highlighting, deep links that respect the header. Assumes the layout has a rail to give.
Create a sticky table of contents rail for a 4,000-word article: 240px wide, sticky 96px from the viewport top, built from the article's h2 elements with h3 children indented 16px. Highlight the current section using an IntersectionObserver with rootMargin '-96px 0px -66% 0px', rendering the active entry in indigo-600 semibold with a 2px left indicator bar that transitions between entries over 150ms. Each entry anchors to its heading's slug with 96px scroll-margin-top, and the active section's hash updates via history.replaceState to reflect reading position. Idle entries get a subtle hover state; keep the list internally scrollable if it outgrows the rail, and hide the rail below 1024px — the inline variant covers that case.


