# Typography Scale

## Objective

Replace ad-hoc font sizes with a small set of named type steps.

A fixed set of type steps, each pairing a size with its weight, line height, and letter spacing.

## 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. Collect every distinct font size, weight, and line height currently used in the app and reduce them to a small set of steps. A codebase with nineteen sizes almost always has six real ones and thirteen accidents.
2. Bind line height and letter spacing to each step rather than leaving them to be set per component, because the same size at two different line heights reads as two different styles.
3. Keep adjacent steps far enough apart to be told apart at a glance. Steps a single pixel apart give authors a decision they cannot make correctly and produce inconsistency by themselves.
4. Separate the semantic element from the visual step: a heading level is about document structure, and the step it renders at is a layout decision. A section heading that needs to look small must not become a lower heading level to get there.
5. How each step behaves between viewport sizes is owned by Fluid Typography; this feature owns which steps exist and what belongs to each. Define the steps first, then let the fluid rules interpolate them.

## 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

- Steps that sit too close together are indistinguishable in use, so authors pick arbitrarily and the scale stops meaning anything.
- Translated copy runs longer than the English it replaced, so every step must be checked with long German compounds and with scripts that need more vertical space than Latin.
- Heading levels convey structure and must not be chosen for their size; the scale has to make it possible to render an h3 at a small step without demoting it to h5.
- Line height and weight that read well on a light background can look thin or heavy inverted, so each step needs checking in every theme rather than only the default one.
- Scripts with tall ascenders and deep descenders, and text with diacritics, will clip in any step whose line height was tuned to lowercase Latin.
- User-generated content arrives with its own markup and must be mapped onto the scale, or a pasted document introduces sizes that exist nowhere in the system.
- The scale must survive the browser's own text-size setting and page zoom, which rules out expressing steps in units that ignore the user's preference.

## 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

- [ ] The app renders text from a fixed set of named steps with no ad-hoc font sizes remaining in components.
- [ ] Each step defines its size, weight, line height, and letter spacing together.
- [ ] Adjacent steps are visually distinguishable side by side.
- [ ] Heading level and visual step are chosen independently of one another.
- [ ] Every step is legible in each theme and does not clip diacritics or descenders.
- [ ] The scale responds to browser text-size settings and zoom.
- [ ] Viewport interpolation is delegated to Fluid Typography rather than duplicated here.
- [ ] 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.
