---
name: koi-design-laws
description: Shared design-law base for every koi skill — UX laws, Gestalt, interaction rules, grid and alignment measurement, color theory, typography and brand perception, plus one measurable checklist. Read before designing, redesigning or critiquing any screen (code or FigCraft), and run reference/checklist.md before calling a screen done.
---

# koi-design-laws

Shared rulebook for all koi design skills (`koi-page`, `koi-new-page`, `koi-critique`, `koi-distill`, `koi-bolder`, `koi-figcraft-screen`, `koi-craft`, `koi-taste`). Those skills decide *what* to build; this skill decides *whether it is correct*.

Every rule here has a stable id (`L3`, `G1`, `R7`...), a measurable check, and a common violation. Cite ids in every critique and every self-review. A rule without a measured value in the report does not count as checked.

Laws are product-agnostic. Examples use a generic operational e-commerce tool (dense tables, product cards, prices in BRL, SKUs, multiple sales channels) only to make checks concrete. When a product design system exists, its tokens override the generic numbers here as long as they still pass the measurable floor (contrast, target size, grid).

## When to read

| Situation | Read |
|---|---|
| Critique / review / audit of an existing screen | `reference/checklist.md` first, then the files named by failing lines |
| New screen from scratch | `laws-of-ux.md` -> `gestalt.md` -> `grid-alignment.md` -> `color-theory.md` -> `typography.md` -> `interaction.md` -> `brand-perception.md`, then `checklist.md` |
| Redesign of a screen | `checklist.md` on the current screen (baseline), then the new-screen order, then `checklist.md` again (delta) |
| Small tweak (spacing, one component) | `grid-alignment.md` measurement procedure + affected checklist group |
| Before saying "done" | `checklist.md` in full. Always. |
| FigCraft frame | `grid-alignment.md` measurement procedure using `absoluteBounds` |
| Code (Next.js / shadcn) | Same procedure using `getBoundingClientRect()` at 1440, 1280 and 375 widths |

## Reference files

| File | Ids | Covers |
|---|---|---|
| `reference/laws-of-ux.md` | L1-L19 | Fitts, Hick, Jakob, Miller, Tesler, Doherty, Von Restorff, serial position, peak-end, goal-gradient, Zeigarnik, aesthetic-usability, Occam, Pareto, Postel, Parkinson, selective attention, cognitive load |
| `reference/gestalt.md` | G1-G11 | Proximity, similarity, common region, continuity, closure, figure-ground, common fate, uniform connectedness, Pragnanz, spacing ratio rule |
| `reference/interaction.md` | I1-I30 | Nielsen heuristics, Norman principles, component states, target sizes, focus, undo, destructive actions, disclosure, latency, forms, keyboard, motion |
| `reference/grid-alignment.md` | R1-R20 | 4/8pt grid, columns, content width, keylines, baseline, rhythm, spacing hierarchy, optical alignment, numeric alignment, measurement procedure |
| `reference/color-theory.md` | C1-C18 | Models, OKLCH scales, 60-30-10, neutrals first, semantic color, contrast WCAG + APCA, dark mode, data-viz palettes, brand limits |
| `reference/typography.md` | T1-T16 | Scale, hierarchy, measure, line-height, tracking, tabular figures, families/weights, truncation, number formatting |
| `reference/brand-perception.md` | B1-B12 | First impression, consistency, distinctiveness vs convention, trust signals, voice, brand carriers, restraint, premium |
| `reference/checklist.md` | all | Single pass/fail checklist + report template |

## Hard floor (non-negotiable)

A screen with any hard-floor failure is not done, regardless of how good it looks.

1. **R1** Every position, size, gap and padding is a multiple of 4px (exceptions: 1px strokes, text line boxes, optical nudges logged as such).
2. **R9** Siblings in a row/column share an edge or a center within 0px; equal-role gaps are identical.
3. **G10** Space inside a group is smaller than space between groups by at least 1.5x (target 2x).
4. **C7/C8** Body text contrast >= 4.5:1 (APCA |Lc| >= 75 for dense body); large text and UI boundaries/icons >= 3:1.
5. **C6** Color is never the only signal: every status also has text, icon or shape.
6. **C5** Semantic colors mean one thing only: green = money/success/opportunity, amber = warning/stale, red = destructive/error. No decorative use.
7. **T7** Numbers that are compared (tables, KPIs, prices) use tabular figures and are right-aligned (or decimal-aligned) in columns.
8. **T12** Money always uses the locale format in full (BRL: `R$ 1.234,56`, non-breaking space after `R$`); no mixed formats on one screen.
9. **I4** Every interactive component defines default, hover, focus-visible, active, disabled; every data surface defines loading, empty, error (and stale when data can age).
10. **I8** Targets >= 24x24px with spacing (WCAG 2.2 AA); touch targets >= 44x44px on mobile.
11. **I14** Destructive actions are never the primary-styled default, are visually separated from safe actions, and offer undo or an explicit confirmation naming the object.
12. **I27** All motion respects `prefers-reduced-motion`; no animation > 400ms on routine UI; nothing moves layout under the cursor.
13. **L1/L17** One primary action per view region; the primary task's elements win the first glance (squint test).

## How to measure

1. Collect bounds of every relevant layer: FigCraft `absoluteBounds {x, y, width, height}` or DOM `el.getBoundingClientRect()` (round to 0.5px; anything fractional beyond that is a fail by itself).
2. Collect computed styles: font-size, line-height, weight, letter-spacing, color, background, border, radius.
3. Run the procedure in `reference/grid-alignment.md` section "Measurement procedure".
4. Compute contrast for each text/background pair using the formula in `reference/color-theory.md`.
5. Walk interaction states by forcing them (`:hover`, `:focus-visible`, disabled prop, empty dataset, thrown error, slow network 3G).
6. Fill the report template in `reference/checklist.md`.

Never eyeball a value you can measure. Never report "looks off" without a number.

## How to report violations

One line per violation, sorted by severity (hard floor first), then by screen position (top-left to bottom-right):

```
[SEV] RULE-ID | element (layer name or selector) | measured | expected | fix
```

- `SEV`: `BLOCK` (hard floor), `MAJOR` (hurts task or trust), `MINOR` (polish).
- `element`: FigCraft layer path (`Page/Table/Header/Cell-Price`) or CSS selector / component name (`KoiDataTable > th:nth-child(4)`).
- `measured`: the actual number(s) - `gap 14px`, `contrast 3.2:1`, `x=37`.
- `expected`: the rule target - `gap 16px (token space-4)`, `>= 4.5:1`, `x=40 (keyline)`.
- `fix`: one concrete change - `set gap-4`, `text-muted-foreground -> text-foreground/80`, `move 3px right`.

Examples:

```
[BLOCK] R1  | ProductCard/Price         | y=203, h=21        | multiples of 4         | snap y=204, line-height 20
[BLOCK] C7  | th "Margem" on bg-muted   | 3.9:1              | >= 4.5:1               | text #5b6170 -> #464c59
[MAJOR] G10 | Filters / chip rows       | in=12px, out=12px  | out >= 18px (1.5x)     | row gap 12 -> 24
[MINOR] R14 | Toolbar search icon       | geometric center   | optical center +1px x  | nudge icon 1px right, log as optical
```

End the report with: total by severity, hard-floor pass/fail, and the top 3 fixes by impact. A screen passes when there are zero `BLOCK` and the remaining `MAJOR` count is justified in writing.

## Conflicts between rules

- Accessibility (C6, C7, I8, I27) beats brand (B*) and aesthetics.
- Product design-system tokens beat generic numbers here, unless they break the hard floor.
- Convention (L3 Jakob) beats novelty for core controls (tables, forms, nav); distinctiveness belongs in brand carriers (B7), not in how a checkbox works.
- Density (operational tools) beats whitespace generosity, but never at the cost of G10 grouping or I8 targets.
