Why AI-built frontends accumulate visual debt so fast
Even experienced teams shipping rapidly with AI coding assistants quickly notice their stylesheets fragmenting after three or four sprints: one page uses bg-dr-paper, another uses bg-stone-50, a third invents text-dr-muted, and an inline SVG icon disappears completely when dark mode turns on. Once arbitrary colors and magic pixel widths scatter across 40 components, every redesign turns into a brittle find-and-replace exercise.
This workflow gives you a deterministic 45-minute cleanup loop that locks a 3-tier semantic token architecture in Tailwind CSS v4 and gates every future visual edit through Playwright MCP and an isolated UI Design Critic subagent.
Step 1: Run the baseline leak scan
Copy audit-design-tokens.sh from the box below and execute it at your project root. In five seconds, it exposes four real design-system leaks that standard TypeScript checks ignore:
- Arbitrary hex Tailwind utilities (
bg-dr-paper,text-dr-muted,border-dr-text) that bypass your token system and break dark mode. - Inline hex styles hidden inside JSX or Astro template strings.
<img>elements lacking explicitwidthandheight, which trigger Cumulative Layout Shift (CLS) on slower mobile connections.- Hardcoded black SVG icon strokes (
stroke="#000000") that vanish against dark surfaces instead of inheriting CSScurrentColor.
Save the output count as your starting baseline—your target at the end of Step 4 is 0 leaks across all four checks.
Step 2: Consolidate a 3-tier token contract in Tailwind v4
Install Skill 32: CSS Design Tokens and Tailwind v4 Theme Skill (and Skill 03: Figma MCP Design-to-Code Sync if syncing directly from Figma Variables). Consolidate all color, border, typography, and radius decisions into one clean cascade:
| Token Tier | Where It Lives | Allowed in Component JSX? | Example |
|---|---|---|---|
| Tier 1: Primitive Scale | :root raw palette block | Never | --raw-stone-50: #F7F7F5; |
| Tier 2: Semantic Intent | :root + [data-theme="dark"] | Indirectly via Tier 3 | --surface-canvas: var(--raw-stone-50); |
Tier 3: Tailwind v4 @theme inline | @theme inline { ... } | Yes (Exclusive API) | class="bg-canvas text-ink border-hairline" |
Verify that every muted foreground token (--ink-muted) paired against both --surface-canvas and --surface-card exceeds WCAG 2.1 AA contrast (>= 4.5:1) in light and dark modes before touching component markup.
Step 3: Sweep components, SVGs, and media assets cleanly
Refactor components directory by directory rather than rewriting your entire repository in one massive diff:
- Replace raw color classes with semantic utilities: Map every off-white background to
bg-canvasorbg-surface, every subtle border toborder-hairline, every secondary paragraph totext-ink-muted, and every primary brand accent totext-signal/bg-signal. - Unify SVG icon ownership: Optimize generated or exported vector icons (such as brand sets produced in Recraft V4.1) using Skill 30: SVG Optimization and Brand Icon System Skill, removing flat background
<rect>elements and switching monochrome strokes tocurrentColor. - Standardize raster media: Re-encode oversized raw PNG hero banners (such as high-res Black Forest Labs FLUX 3 Image 2K–4K renders) into responsive WebP/AVIF sets with exact numeric
widthandheightdimensions via Skill 31: Sharp WebP, AVIF and Responsive Image Skill. - Guard mobile overflow: Wrap every data
<table>and<pre>code block insideoverflow-x-autoand addmin-w-0onto flex and grid children that contain long code strings or URLs.
Step 4: Gate both light/dark and 1440px/390px via Playwright MCP + Subagent
Never sign off a CSS migration solely on a clean npm run build. Start your local preview server (npm run dev or npm run preview) and wire Skill 26: Playwright Visual QA MCP Server alongside Skill 35: UI Design Critic and Accessibility Subagent.
Delegate your primary pages (/, /pricing, detail pages) to @ui-design-critic:
- Captures real rendered screenshots at
1440×900desktop and390×844mobile (in both light and dark modes if supported). - Asserts
document.documentElement.scrollWidth <= window.innerWidthso zero horizontal scrollbar leaks onto mobile phones. - Confirms
0browser console errors,0failed image/font network responses (>= 400), visible keyboard:focus-visibleoutlines, and clean WCAG AA contrast. - Re-runs
audit-design-tokens.shconfirming0arbitrary hex utilities remain.
Pair this migration guide with Guide 10: AI Design-to-Code: Figma MCP, Tokens and Visual QA and Workflow 04: Figma Design to Production Astro Landing Section via MCP to keep every new section locked to your design system permanently.