4. Visual Geometry & Copy Gates

4.1 Stage 1: Deterministic DOM Geometry Gate

chinwag ui-gate --url http://localhost:8080 --surfaces 16

How chinwag ui-gate evaluates 11 mathematical bounding-box, typography, and contrast invariants across 8 viewports and 2 themes in under 900ms locally at 0 Cr.

4.1 Stage 1: Deterministic DOM Geometry Gate

chinwag ui-gate --url http://localhost:8080 --surfaces 16

✅ Available Now (v0.1.0 · CHWG-PUB-105): Stage 1 (verify-ui-geometry.py · 176/176 deterministic 12-tuple DOM physics assertions across 8 viewports and 2 color themes in <900ms at 0 Credits) is shipped and verified in v0.1.0. See /api/reality-matrix and the Chinwag Public Roadmap.

AI coding agents write valid JSX, Vue, and CSS that compiles without warnings and passes unit tests · yet renders broken layouts in a real browser. Hero headings wrap to four lines at 1024px, navigation pills collide on 768px tablets, sticky topbars obscure anchor targets, and light-mode muted text drops below WCAG AA contrast.

chinwag ui-gate solves this with a three-stage visual verification pipeline (WP-12). Stage 1 runs locally inside headless Chromium in under 900ms at 0 Cr (free), evaluating 11 deterministic DOM physics invariants across 8 standard viewports and 2 color themes (Midnight + Daylight) = 176 / 176 cell assertions.

chinwag ui-gate --url http://localhost:3000 --matrix 8x2 --stage 1

The 12-Tuple DOM Element Descriptor

Before evaluating layout invariants, Stage 1 injects a zero-dependency measurement probe into the live Chromium layout tree (document.querySelectorAll('*')) and extracts a compact 12-tuple geometric descriptor for every visible interactive, typographic, and container node:

pub struct DomGeometryTupleV1 {
    pub selector_hash: u64,          // 1. Canonical CSS path hash (BLAKE3-64)
    pub role_class: ElementRoleV1,   // 2. Heading | Body | Interactive | Nav | Sticky | Card | Media
    pub x: f32,                      // 3. Sub-pixel clientRect.left
    pub y: f32,                      // 4. Sub-pixel clientRect.top
    pub width: f32,                  // 5. Sub-pixel clientRect.width
    pub height: f32,                 // 6. Sub-pixel clientRect.height
    pub scroll_width: f32,           // 7. scrollWidth (horizontal overflow detector)
    pub line_box_count: u16,         // 8. Exact rendered text line count via getClientRects()
    pub font_size_px: f32,           // 9. Computed font-size in CSS pixels
    pub contrast_apca_wcag: f32,     // 10. Effective foreground/background WCAG 2.2 contrast ratio
    pub z_stack_tier: i32,           // 11. Effective stacking context & z-index tier
    pub hit_target_min_px: f32,      // 12. Minimum interactive touch/click dimension (min(w, h))
}

The 8 × 2 Viewport & Theme Matrix (16 Render Surfaces)

Every run sweeps 8 canonical device viewports across both Midnight (dark) and Daylight (light) color schemes:

Viewport IDDimensions (W × H)Device ClassPrimary Failure Modes Caught
V1_ULTRAWIDE1920 × 108027" Desktop MonitorUnbounded prose measure (> 75ch), stretched flex cards
V2_DESKTOP1440 × 90015"/16" LaptopSticky header height overflow (> 56px), multi-column card baseline drift
V3_LAPTOP_SM1280 × 80013" LaptopTopbar nav item collisions, sidebar + TOC squeeze
V4_TABLET_LAND1024 × 768Tablet LandscapeGrid-to-stack breakpoint orphans, 4-line hero wrapping
V5_TABLET_PORT768 × 1024Tablet PortraitHorizontal table overflow (scrollWidth > innerWidth)
V6_MOBILE_LG430 × 932Large PhoneFixed CTA bar covering footer links, clipped code blocks
V7_MOBILE_STD390 × 844Standard PhoneTouch targets < 32px, clipped modal dialogs
V8_MOBILE_SE375 × 812Compact PhoneLong unbroken tokens/URLs forcing horizontal scrollbars

The 11 Deterministic Invariants (16 Surfaces × 11 Invariants = 176/176)

For each of the 16 viewport-theme surfaces, Stage 1 verifies all 11 mathematical invariants:

#Invariant IDMathematical ContractDefault Threshold
1GEO-01-ZERO-HORIZ-BLEEDdocument.documentElement.scrollWidth <= window.innerWidth0px tolerance across all 8 viewports
2GEO-02-TOPBAR-BUDGETSticky <header> height H_header <= 56px and line_box_count == 1 on desktop<= 56px
3GEO-03-SIBLING-DISJOINTSibling interactive controls (a, button, input) have intersection area Area(A ∩ B) == 00 sq px overlap
4GEO-04-HEADING-LINE-CAPDisplay <h1> line count <= 3 (>= 1024px) and <= 4 (< 1024px)3 / 4 lines max
5GEO-05-PROSE-MEASUREBody copy <p> and <li> line width stays within readable measure [45ch, 78ch] on desktop45ch .. 78ch
6GEO-06-CONTRAST-FLOORBody text contrast >= 4.5:1 (WCAG AA) and large display text >= 3.0:1 in both Midnight and Daylight4.5:1 / 3.0:1
7GEO-07-HIT-TARGET-MINInteractive buttons, nav links, and toggles meet minimum target bounds (height >= 32px desktop, >= 36px mobile)32px / 36px
8GEO-08-CARD-GRID-ALIGNMENTEqual-row CSS Grid / Flex sibling cards align top/bottom edges within <= 1.5px sub-pixel tolerance<= 1.5px
9GEO-09-STICKY-OCCLUSIONFocused elements and :target anchors are never occluded by `position: stickyfixed chrome (scroll-margin-top` verified)
10GEO-10-CODE-TABLE-SCROLLWide <pre> and <table> containers capture horizontal scroll internally (overflow-x: auto) without stretching the page viewportContained scroll
11GEO-11-TABULAR-NUMERALSNumeric badges, prices, metrics, and table cells enforce font-variant-numeric: tabular-nums to prevent jittertabular-nums

Stage 1 CLI Output Example

When a layout bug occurs on a single breakpoint, chinwag ui-gate pinpoints the exact selector, viewport, theme, and sub-pixel coordinates:

$ chinwag ui-gate --url http://localhost:3000/pricing --stage 1
[ui-gate] Sweeping 8 viewports × 2 themes (16 surfaces × 11 invariants = 176 checks)...
  ✗ FAIL [GEO-01-ZERO-HORIZ-BLEED] at V8_MOBILE_SE (375×812 · Daylight)
    Selector: section.pricing-matrix > table.credit-schedule
    Measured: document.scrollWidth = 442px > window.innerWidth = 375px (+67px overflow)
  ✗ FAIL [GEO-06-CONTRAST-FLOOR] at V2_DESKTOP (1440×900 · Daylight)
    Selector: .tier-card .muted-footnote
    Measured: contrast = 3.41:1 < 4.50:1 required (#7A8291 on #F4F2ED)
[ui-gate] Result: 174/176 PASSED (2 deterministic geometry failures in 640ms · 0 Cr)

Next Step: Multimodal Vision-3 Inspection & Auto-Patch

Once Stage 1 (176/176) passes, chinwag ui-gate advances to Stage 2 and Stage 3 (Chinwag Vision-3 visual geometry audit and CSS auto-patch synthesis).