# Text Measure Guardrails

## Objective

Hold long-form text to a readable line length instead of letting it run the full width.

A maximum measure applied to the app's prose containers, with named exceptions for content that needs the whole width.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Find every surface that renders more than a couple of sentences — help articles, changelog entries, terms pages, long empty-state explanations, in-app announcements — and cap the measure on the text container itself rather than on the page shell.
2. Express the cap in units that scale with the type, so a larger heading or a user who has raised their base font size gets a proportionally wider column instead of a cramped four-word line.
3. Declare which elements are allowed to break out of the measured column — tables, code blocks, images, video, diagrams, full-bleed callouts — and let them span the container while the paragraphs around them stay narrow.
4. Do not centre long-form copy to make the narrow column look deliberate. A ragged left edge makes the eye hunt for the start of every line, which is the cost the measure was meant to remove.
5. Keep this entry to width only. Text Wrapping Rules owns what happens inside a line — where it breaks, when it truncates, how it hyphenates — so the two briefs do not both try to define overflow behaviour.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Tables, code samples, and media that are forced into the prose measure become unreadable or scroll horizontally. Let them break out to the container width while the surrounding paragraphs stay capped.
- A measure tuned for body text is too narrow for large display type and too wide for small print. Adjust the cap per step of the type scale rather than applying one number to everything.
- Centred long-form paragraphs cost the reader a fixation on every line return. Reserve centring for single lines such as a page title or an empty-state message.
- The cap must be a maximum, not a fixed width. On a narrow viewport the column has to shrink and keep its gutters, or the text runs into the screen edge.
- Nested containers that each apply the cap compound it and produce a column half the intended width. Apply the measure once, at the outermost prose wrapper.
- In right-to-left locales the column must align to the right edge, not stay pinned left.
- A user who zooms the browser or enlarges their default font must get fewer characters per line, not a horizontally scrolling page.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Every long-form surface renders its paragraphs within a bounded measure rather than the full page width.
- [ ] The measure scales with the type size instead of being a single fixed value across the app.
- [ ] Tables, code blocks, and media render at the container width while adjacent paragraphs stay measured.
- [ ] No long-form body copy is centred.
- [ ] On narrow viewports the column shrinks and retains its gutters, with no horizontal scrolling.
- [ ] Nesting two prose containers does not halve the column width.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
