- Use getBoundingClientRect() in the scroll listener so the active-page
threshold is measured relative to the content container rather than
the document body, fixing off-by-one page detection.
- Replace history.replaceState with pushState for user-initiated
navigation (sidebar, prev/next, keyboard) and add a popstate listener
so the browser back/forward buttons work correctly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>