When I added a 'Midnight Notebook' Dark Mode and did a deep accessibility pass on this portfolio, I wanted to answer two concrete questions: Can a blind or keyboard-only visitor navigate every section effortlessly? And does every single card, folder, modal button, and paper note maintain real WCAG 2.1 AA/AAA contrast when the theme flips?
It turns out that simply inverting `--color-navy` (dark ink) and `--color-blush` (light paper) in CSS looks fine on the hero section—and quietly breaks half a dozen secondary surfaces across the site. Instead of hunting contrast bugs by eye after every CSS edit, I built an automated Node test suite (`tests/accessibility-and-contrast.test.mjs`) that mathematically verifies WCAG luminance ratios and accessibility invariants in ~100ms.

1. The 4 Dark Mode Contrast Traps That CSS Variable Inversion Misses
In Light Mode, `--color-navy` (`#0e1627`) is the primary ink color and `--color-blush` (`#f4e1e0`) is the warm notebook paper background. When `html[data-theme='dark']` activates, `--color-blush` becomes midnight slate (`#0f1523`) and `--color-navy` becomes warm cream ink (`#f3e3e2`). That works until you hit four real-world UI patterns:
- Hardcoded Yellow Note Slips (`.travel-file-inside` & `.folder-technical-slip`): The travelling project folder and technical note cards had a hardcoded `#f1e4bd` cream-yellow background paired with `color: var(--color-navy)`. In Dark Mode, `--color-navy` turned light cream (`#f3e3e2`) on top of `#f1e4bd` yellow paper—dropping contrast to ~1.1:1. Extracting `--color-note-paper` (`#f1e4bd` in light mode, `#1c263d` deep slate in dark mode) restored 11.2:1 AAA contrast.
- Mid-Tone Pastel Card Surfaces (`.bg-mauve` & `.bg-[#E9B93F]`): A pastel mauve or yellow card background works behind dark `#0e1627` text in Light Mode, but fails behind light `#f3e3e2` text in Dark Mode. Remapping `.bg-mauve` cards to deep plum (`#36202b`) and yellow folder cards to deep bronze (`#382a12`) in Dark Mode pushed text contrast above 9:1 AAA while keeping `.text-mauve` bright rose (`#e2aba6`).
- Unscoped Element Selectors Colliding in Modals (`footer` vs. `footer#contact`): To keep the main site footer dark obsidian in Dark Mode, an unscoped `html[data-theme='dark'] footer .text-blush` rule accidentally matched `<footer className='folder-dossier-footer'>` inside the project dossier modal. Because the modal's CTA button used `bg-navy text-blush`, forcing `.text-blush` to `#f3e3e2` on a `#f3e3e2` button made the label invisible. Scoping the rule strictly to `footer#contact` fixed the collision immediately.
- WebGL Canvas Page Turns (`PaperBend.tsx`) & Form Inputs (`ContactPage.tsx`): The Three.js canvas that bends notebook pages inside the project dossier was painting hardcoded `#f4e1e0` paper during page turns, and contact form inputs had hardcoded `bg-[#fffaf0]`. Making both read the active theme eliminated every last light-on-light flash.
"Dark mode isn't a filter: invert(1). Every surface has a role—background paper, elevated card, accent badge, or inverted button—and each needs an explicit luminance contract."
2. Engineering the Circular Ink-Bloom View Transition
Rather than an abrupt full-screen color snap, toggling between Light Paper (`☀ paper`) and Midnight Ink (`☾ night`) in `ThemeToggle.tsx` captures the exact `(x, y)` click coordinates of the button and computes the Euclidean distance (`Math.hypot`) to the furthest corner of the viewport.
Using the browser's View Transitions API (`document.startViewTransition`), it animates `::view-transition-new(root)` with an expanding circular `clipPath` (`circle(0px at x y)` → `circle(maxRadius at x y)`) over `680ms cubic-bezier(0.22, 1, 0.36, 1)`, so the new theme spreads across the notebook like a drop of ink—while falling back gracefully or disabling motion entirely when `prefers-reduced-motion: reduce` is enabled.
3. Making Split-Word Animations & Landmarks Screen-Reader Friendly
Visual portfolios often break screen readers in two ways: splitting headings into dozens of `<span>` tags for letter/word animations (causing VoiceOver or NVDA to spell out words fragment by fragment), and replacing the native OS cursor with a lagging custom JavaScript cursor.
- Dual-Layer Accessible Typography (`InkText.tsx` & `ScrollInkText.tsx`): Both our 3D letterpress headings and scroll-scrubbed ink paragraphs wrap their animated word/letter spans inside `aria-hidden='true'` while rendering a single, unbroken paragraph inside `<div className='sr-only'>`. Assistive technologies and search crawlers read natural prose, while sighted users see the 3D ink animation.
- Direct DOM Scroll Scrubbing (`requestAnimationFrame` Without React Re-Renders): `ScrollInkText.tsx` updates word opacity, 3D tilt, highlighter sweeps, and SVG underline `strokeDashoffset` directly on DOM refs inside `requestAnimationFrame`—keeping React state re-renders at zero during scroll.
- Keyboard & Screen-Reader Navigation: We removed the custom pencil cursor (`CursorGate` / `cursor: none`) so the native OS cursor is always responsive, added a high-contrast 'Skip to main content' link (`#main-content`), added global `2.5px dashed` `:focus-visible` rings, marked active navigation links with `aria-current='page'`, labelled star ratings (`aria-label='5 out of 5 stars'`), and wired an `aria-live='polite'` status region that announces theme switches aloud.
4. Inside the 100ms Automated Test Suite (`npm test`)
To make sure none of these fixes ever regress, `tests/accessibility-and-contrast.test.mjs` runs 8 automated assertions across 3 suites using Node's built-in test runner (`node --test`):
- Suite 1 — WCAG 2.1 Relative Luminance & Contrast Audit: Converts every Light Mode and Dark Mode hex token pair to sRGB relative luminance (`0.2126 * R + 0.7152 * G + 0.0722 * B`) and asserts that every surface/ink combination clears strict AA and AAA thresholds (from `7.5:1` on accent text up to `14:1` on dark surfaces).
- Suite 2 — CSS & Component Regression Guards: Parses `ScrollStory.css`, `ConversionNotes.css`, `ContactPage.tsx`, and `globals.css` to ensure hardcoded `#f1e4bd`, `bg-[#fffaf0]`, dark-only `rgb(14 22 39)` text, or unscoped `footer .text-blush` selectors can never sneak back in.
- Suite 3 — Native Cursor & Screen-Reader Invariants: Verifies that `cursor: none` stays removed, the `#main-content` skip link and `:focus-visible` rings are intact, `ThemeToggle` exposes `aria-pressed` and `aria-live='polite'`, and `InkText` / `ScrollInkText` always pair `aria-hidden='true'` visual nodes with `.sr-only` text.
