Adaptive Web Toolkit · Zero Dependencies (< 6 KB)

Device Posture API & Foldable CSS SDK

Quick Answer · Drop-In Adaptation

Use this free foldable CSS SDK (foldcheck-adapt.js + foldcheck-base.css, under 6 KB combined) to ship Viewport Segments CSS, Device Posture API fallbacks, crease-safe two-pane grids, and short-viewport sticky rules across all 8 official Apple, Samsung, and Huawei foldables (iPhone Duo, Galaxy Z Fold 8/7, Galaxy Z Flip 7, Huawei Mate X8/X7, Mate XT, and Pura X)—plus an in-page DevTools Inspector for localhost, Shopify preview themes, and VPN staging.

Who This CSS SDK & Inspector Is Built For

Frontend Engineers

React, Vue & Next.js

Subscribe to the native-fallback foldchange event and style dual-pane layouts with data-fold-state without UA sniffing.

E-Commerce Merchants

Shopify & WooCommerce

Drop two lightweight assets into theme.liquid or your child theme to keep product galleries and checkout footers off the crease.

Enterprise QA

VPN & Auth Dashboards

Run the zero-upload DevTools Inspector bookmarklet directly on internal staging URLs and hydrated single-page apps.

AI Coding Teams

Cursor, Claude & Gemini

Commit our .cursor/rules/foldable-web.mdc rule file so generated UI components pass all 12 checks from day one.

Four Core Repair Kit Components

1. Drop-in Adaptive Runtime & CSS (< 6 KB)

Exposes data-fold-state, Viewport Segments CSS variables (--fc-crease-x, --fc-hinge-gutter), and crease-safe two-column utilities with automatic Safari 27.1 and Chrome fallback.

2. In-Page DevTools Inspector (Localhost / VPN)

Auditing a staging storefront, private dashboard, or hydrated SPA behind enterprise login? Drag the bookmarklet to your bookmarks bar or paste the inspector into Chrome/Safari DevTools Console.

4. AI Coding Rules (Cursor / Claude / Gemini)

Drop our engineering rules file into your repo so AI-authored pages automatically enforce 356–466px cover safety, 750–924px hinge gutters, 44px touch targets, and 100dvh.

Download Rule (.mdc)

Quick Integration: HTML, Shopify Liquid & React / Next.js

Include the stylesheet and deferred runtime helper in your document <head> (for Shopify, upload both files to assets/ and load them in layout/theme.liquid):

<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link rel="stylesheet" href="./foldcheck-base.css">
<script src="./foldcheck-adapt.js" defer></script>

Apply crease-safe layout classes to hero splits, sticky headers, checkout modals, and pricing or sizing tables:

<header class="fc-sticky-safe">...</header>
<main class="fc-container fc-full-height">
  <section class="fc-fold-split">
    <article>Left pane (product media / nav)</article>
    <article>Right pane (pricing / Buy CTA)</article>
  </section>
  <div class="fc-table-wrap"><table>...</table></div>
</main>
<aside class="fc-dialog-safe">Stays inside one pane, never on the hinge</aside>

Listening to Posture Changes in React, Vue, or Next.js

Listen for the custom foldchange event on window whenever the screen shifts between cover, unfolded inner, Split View, landscape, or tri-fold postures:

window.addEventListener('foldchange', (event) => {
  const { state, segments, creaseX, width, height } = event.detail;
  // state: 'cover' | 'inner' | 'split' | 'landscape' | 'trifold'
  console.log('Active posture:', state, segments, creaseX, `${width}x${height}`);
});

DevTools Console Loader (Localhost, Staging & Hydrated SPAs)

When auditing private URLs, Shopify draft themes, or client-rendered SPAs, paste the inspector source into Chrome or Safari DevTools Console to audit and live-patch the live DOM with zero network uploads:

// 1) Open DevTools -> Console on localhost, staging, or an authenticated storefront
// 2) Click "Copy Inspector Source" above and paste into Console
// 3) Press Enter to mount the floating Inspector & Live CSS Patcher
// Prefer one click? Drag the bookmarklet button above to your bookmarks bar.

Browser Compatibility & Progressive Enhancement

Native dual-screen web APIs differ between Android Chrome, Samsung Internet, and Safari 27.1 on iOS 27. This foldable CSS SDK reads native window.viewport.segments first and falls back cleanly to aspect-ratio and width heuristics:

Web StandardChrome / Samsung InternetSafari 27.1 (iOS 27)SDK Automatic Fallback
horizontal-viewport-segments & env(viewport-segment-*)Supported on dual-pane AndroidDeveloper Feature FlagComputes --fc-crease-x & --fc-pane-w automatically
Device Posture API (device-posture)Supported (Chromium)Developer Feature FlagSets data-fold-state via resize & aspect-ratio heuristics
100dvh & env(safe-area-inset-*)Full supportFull support (with viewport-fit=cover)Paired with 100vh fallback in the base stylesheet

Complete Source Inspection (Zero Telemetry)

Every asset is plain, auditable JavaScript, CSS, or Markdown with zero external network calls. Pair with our no-device testing guide and 12-point QA checklist for full release coverage.

View Runtime JS Source (5 KB)
/**
 * FoldCheck web Adaptive Runtime SDK v1.0.0
 * Zero-dependency browser helper (< 3 KB) that exposes foldable posture state,
 * viewport segment geometry, and hinge-safe CSS custom properties to web apps.
 *
 * Usage:
 *   <link rel="stylesheet" href="./foldcheck-base.css">
 *   <script src="./foldcheck-adapt.js" defer></script>
 */
(function initFoldCheckAdapt(global) {
  if (typeof window === 'undefined' || typeof document === 'undefined') return;

  const root = document.documentElement;
  const scriptEl = document.currentScript;
  const enableOverflowGuard = Boolean(scriptEl && scriptEl.dataset.fcGuard === 'true');
  let lastStateKey = '';

  function detectGeometry() {
    const w = Math.round(window.innerWidth || root.clientWidth || 0);
    const h = Math.round(window.innerHeight || root.clientHeight || 0);
    const segments =
      (window.viewport && Array.isArray(window.viewport.segments) && window.viewport.segments) ||
      (window.visualViewport && Array.isArray(window.visualViewport.segments) && window.visualViewport.segments) ||
      null;

    let segmentCount = 1;
    let axis = 'none';
    let creaseX = Math.round(w / 2);
    let creaseY = Math.round(h / 2);
    let state = 'cover';

    if (segments && segments.length >= 2) {
      segmentCount = segments.length;
      const first = segments[0];
      const second = segments[1];
      if (second.left >= first.right) {
        axis = 'vertical';
        creaseX = Math.round((first.right + second.left) / 2);
        state = segmentCount >= 3 ? 'trifold' : 'inner';
      } else {
        axis = 'horizontal';
        creaseY = Math.round((first.bottom + second.top) / 2);
        state = w > h ? 'landscape' : 'inner';
      }
    } else {
      const ratio = w / Math.max(1, h);
      if (w >= 1020 && ratio > 1.2) {
        state = 'trifold';
        segmentCount = 3;
        axis = 'vertical';
      } else if (w >= 720 && ratio >= 0.8 && ratio <= 1.18) {
        // Unfolded book displays (iPhone Duo 890x626, Z Fold 8 924x698, Z Fold 7 750x832, Mate X8 851x881, Mate X7 804x879)
        state = w > h ? 'landscape' : 'inner';
        segmentCount = 2;
        axis = w > h ? 'horizontal' : 'vertical';
      } else if (w > h && h <= 460) {
        state = 'landscape';
        segmentCount = 2;
        axis = 'vertical';
      } else if (w <= 360 || (w <= 425 && h >= 760 && ratio < 0.48)) {
        state = w <= 340 ? 'split' : 'cover';
      } else if (w <= 460) {
        state = 'cover';
      } else {
        state = w > h ? 'landscape' : 'inner';
      }
    }

    return { width: w, height: h, state, segments: segmentCount, axis, creaseX, creaseY };
  }

  function applyGeometry() {
    const info = detectGeometry();
    const key = `${info.state}:${info.segments}:${info.axis}:${info.width}x${info.height}`;
    if (key === lastStateKey) return;
    lastStateKey = key;

    root.setAttribute('data-fold-state', info.state);
    root.setAttribute('data-fold-segments', String(info.segments));
    root.setAttribute('data-fold-axis', info.axis);

    root.style.setProperty('--fc-viewport-w', `${info.width}px`);
    root.style.setProperty('--fc-viewport-h', `${info.height}px`);
    root.style.setProperty('--fc-crease-x', `${info.creaseX}px`);
    root.style.setProperty('--fc-crease-y', `${info.creaseY}px`);
    root.style.setProperty('--fc-pane-w', `${info.segments >= 2 && info.axis === 'vertical' ? Math.round(info.width / info.segments) : info.width}px`);
    root.style.setProperty('--fc-hinge-gutter', info.segments >= 2 ? '32px' : '16px');

    if (enableOverflowGuard && document.body) {
      const overflow = Math.max(root.scrollWidth, document.body.scrollWidth) - info.width;
      if (overflow > 2) {
        console.warn(`[FoldCheck] Horizontal overflow detected (+${Math.round(overflow)}px) in ${info.state} (${info.width}x${info.height}).`);
      }
    }

    window.dispatchEvent(new CustomEvent('foldchange', { detail: info }));
  }

  let rafId = 0;
  function scheduleApply() {
    if (rafId) cancelAnimationFrame(rafId);
    rafId = requestAnimationFrame(applyGeometry);
  }

  window.addEventListener('resize', scheduleApply, { passive: true });
  window.addEventListener('orientationchange', scheduleApply, { passive: true });
  if (window.visualViewport) {
    window.visualViewport.addEventListener('resize', scheduleApply, { passive: true });
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', applyGeometry, { once: true });
  } else {
    applyGeometry();
  }

  global.FoldCheckAdapt = {
    version: '1.0.0',
    getState: detectGeometry,
    refresh: applyGeometry
  };
})(window);
View Adaptive CSS Source (3 KB)
/**
 * FoldCheck web Base Adaptive Stylesheet v1.0.0
 * Drop-in CSS primitives for foldable cover (356-466px), unfolded inner (480-924px),
 * split-screen / flex (372-565px), and tri-fold (1137px) web apps.
 */

:root {
  --fc-hinge-gutter: 32px;
  --fc-safe-top: env(safe-area-inset-top, 0px);
  --fc-safe-bottom: env(safe-area-inset-bottom, 0px);
  --fc-safe-left: env(safe-area-inset-left, 0px);
  --fc-safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  max-width: 100%;
  overflow-x: clip;
}

img, svg, video, iframe, canvas {
  max-width: 100%;
  height: auto;
}

/* Dynamic viewport height safe across cover <-> inner transitions */
.fc-full-height {
  min-height: 100vh;
  min-height: 100dvh;
}

/* Fluid container that never overflows narrow split panes */
.fc-container {
  width: min(100% - 2rem, 960px);
  margin-inline: auto;
  padding-inline: var(--fc-safe-left) var(--fc-safe-right);
}

/* Crease-safe two-pane layout: 1 column on cover/split, 2 crease-aware panes when unfolded */
.fc-fold-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.fc-fold-split > * {
  min-width: 0;
}

@media (min-width: 700px) {
  .fc-fold-split {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: var(--fc-hinge-gutter, 32px);
    row-gap: 1.25rem;
  }
}

html[data-fold-state="trifold"] .fc-fold-split {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: var(--fc-hinge-gutter, 32px);
}

/* Native CSS Viewport Segments enhancement when supported */
@media (horizontal-viewport-segments: 2) {
  .fc-fold-split {
    grid-template-columns: env(viewport-segment-width 0 0) env(viewport-segment-width 1 0);
    column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
  }
}

/* Keep dialogs and floating CTAs off the center vertical hinge crease */
.fc-dialog-safe {
  width: min(calc(100vw - 2rem), 360px);
}

html[data-fold-state="inner"] .fc-dialog-safe,
html[data-fold-state="trifold"] .fc-dialog-safe {
  left: auto;
  right: 1.5rem;
  transform: none;
  max-width: calc(50vw - var(--fc-hinge-gutter, 32px));
}

/* Sticky header that respects safe areas and unsticks on short clamshell/landscape viewports */
.fc-sticky-safe {
  position: sticky;
  top: 0;
  padding-top: max(0.5rem, var(--fc-safe-top));
  max-height: 72px;
}

@media (max-height: 500px) {
  .fc-sticky-safe {
    position: static;
  }
}

/* Comfortable touch targets across compact cover & split screens */
.fc-touch {
  min-height: 44px;
  min-width: 44px;
}

/* Safe horizontal wrapper for wide data tables */
.fc-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Wrapping flex row that prevents narrow split-pane clipping */
.fc-flex-safe {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.fc-flex-safe > * {
  min-width: 0;
}
View .cursor/rules/foldable-web.mdc
---
description: Foldable web Web Layout & Responsive Adaptation Rules (FoldCheck)
globs: ["**/*.html", "**/*.css", "**/*.scss", "**/*.tsx", "**/*.jsx", "**/*.vue"]
alwaysApply: true
---

# Foldable web Engineering Rules (FoldCheck)

When generating or modifying web / web layouts, ensure clean rendering across simulated foldable CSS viewports:

1. **Target Simulated Viewports (8 Official Devices · 32 Postures)**
   - Apple iPhone Duo: Cover `466x678`, Inner `890x626`, Split `442x626`, Rotate `626x890`
   - Samsung Galaxy Z Fold 8: Cover `436x689`, Inner `924x698`, Split `459x698`, Rotate `698x924`
   - Samsung Galaxy Z Fold 7: Cover `412x960`, Inner `750x832`, Split `372x832`, Rotate `832x750`
   - Samsung Galaxy Z Flip 7: Cover `361x300`, Inner `411x960`, Flex Split `411x474`, Rotate `960x411`
   - Huawei Mate X8: Cover `412x889`, Inner `851x881`, Split `423x881`, Rotate `881x851`
   - Huawei Mate X7: Cover `393x889`, Inner `804x879`, Split `399x879`, Rotate `879x804`
   - Huawei Mate XT (Tri-Fold): Cover `360x797`, Inner `1137x797`, Split `565x797`, Rotate `797x1137`
   - Huawei Pura X (16:10 Wide-Fold): Cover `356x356`, Inner `480x771`, Flex Split `480x382`, Rotate `771x480`

2. **Viewport & Safe Areas**
   - Always declare `<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">`.
   - Never set `user-scalable=no` or `maximum-scale=1`.
   - Pad fixed edge bars with `env(safe-area-inset-top)` and `env(safe-area-inset-bottom)`.

3. **Zero Overflow & Fluid Reflow**
   - Never hardcode container `width` or `min-width` above `320px`; use `width: min(100% - 2rem, <max>px)`.
   - Apply `img, svg, video, iframe { max-width: 100%; height: auto; }` and wrap wide data tables in `overflow-x: auto`.
   - Add `flex-wrap: wrap` and `min-width: 0` on flex children so 372px-459px split panes never clip text.

4. **Fold Crease Safety**
   - On unfolded dual-pane displays (`min-width: 700px`), use a 2-column grid with `column-gap >= 32px` (or CSS `env(viewport-segment-*)`) so buttons, inputs, and dialogs never straddle the center fold crease.

5. **Touch Targets, Sticky Budget & Dynamic Height**
   - Keep interactive buttons, inputs, and navigation links `>= 44x44px`.
   - Keep sticky/fixed bars under 22% of viewport height and switch to `position: static` under `@media (max-height: 500px)`.
   - Pair `100vh` with `100dvh` (`min-height: 100vh; min-height: 100dvh;`) so cover-to-inner height transitions never clip hero content.
   - Keep readable labels `>= 12px` and body prose at `16px`.

Recommended Official API Documentation

Frequently Asked Questions

Does this foldable CSS SDK work on Safari 27.1, Chrome, and desktop browsers?

Yes. The runtime helper checks native window.viewport.segments and Device Posture APIs first, then falls back cleanly to resize and aspect-ratio heuristics so data-fold-state and hinge variables work across iOS Safari, Android Chrome, and desktop preview windows.

Can e-commerce merchants install the CSS SDK on Shopify or WooCommerce themes?

Yes. Upload the two lightweight assets into your Shopify theme assets folder (or WordPress child theme) and load them in layout/theme.liquid. Total weight stays under 6 KB with zero third-party network beacons.

How do I audit localhost, VPN staging, or an authenticated SPA?

Drag the Live Inspector bookmarklet to your bookmarks bar—or copy its full source into Chrome/Safari DevTools Console—to inspect the live hydrated DOM, highlight overflowing elements, and preview CSS patches without uploading page HTML.

Will the adaptive stylesheet conflict with Tailwind CSS, Bootstrap, or an existing design system?

No. Utility classes are strictly namespaced with the .fc- prefix (.fc-fold-split, .fc-dialog-safe, .fc-sticky-safe, .fc-table-wrap), while base rules only apply safe box-sizing, max-width: 100% media bounds, and overflow-x: clip.

How do teams use the .cursor/rules AI rule file?

Commit the downloaded .mdc rule file inside your repository's .cursor/rules/ directory (or reference it in CLAUDE.md / GEMINI.md). Coding agents then enforce cover, inner, split, hinge-gutter, and 44px touch rules automatically.