# High-Contrast Theme

## Objective

Offer a stronger-separation theme for users the default palette does not serve.

An additional theme raising the separation between text, surfaces, borders, and every interactive state.

## 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. Build the mode as another theme on the app's existing token layer so it inherits every component automatically. An override stylesheet layered on top will drift the moment a new component ships.
2. Raise non-text contrast alongside text: icon strokes, input borders, table rules, chart lines, focus rings, and the boundary between a card and the page all need to survive the change.
3. Keep focus, selection, hover, error, and disabled visually distinct from one another in the high-contrast theme. Cranking everything to maximum separation is a common way to make selected and focused look identical.
4. Detect and honour the operating system's forced-colours setting where it exists, and let the system palette win rather than fighting it with the app's own colours.
5. Do not reach for contrast by thickening borders alone. Heavier borders change the box size and reflow the layout, and they do nothing for the text sitting inside the box.

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

- Focus, selection, and error must stay tellable apart, which means differing in more than intensity — position, thickness, and shape carry the distinction when colour has been pushed to its limits.
- The system forced-colours mode replaces the app's colours wholesale, so anything drawn with backgrounds, shadows, or gradients disappears there and needs a border or outline to remain visible.
- Thicker borders alone are not sufficient and are actively harmful when they shift layout; contrast must come from the colours themselves.
- Charts and icons must remain interpretable, which usually means direct labels and pattern fills rather than a legend keyed to twelve near-identical high-contrast hues.
- Images, logos, and screenshots carry their own contrast and cannot be themed — supply an alternative asset or a bounding outline so they do not float on the background.
- Shadows used as the only boundary between an overlay and the page vanish in high contrast; give every overlay a real border in this theme.
- The choice must persist per user and apply before first paint, or every reload flashes the default theme at the person least able to tolerate it.

## 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 high-contrast mode is defined as a theme in the token layer and covers every component with no per-screen patching.
- [ ] Text and non-text elements both meet the raised contrast target, including borders, icons, and chart strokes.
- [ ] Focus, selection, hover, error, and disabled remain mutually distinguishable in the mode.
- [ ] The app renders correctly under the operating system's forced-colours setting.
- [ ] Every overlay and card has a visible boundary that does not depend on a shadow.
- [ ] The preference persists and is applied before the first paint.
- [ ] 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.
