# Link Styling System

## Objective

Give links one set of rules so they read as links wherever they appear.

Defined treatments for links in prose, in navigation, in muted contexts, for external destinations, and for destructive actions.

## 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. Separate links by the job they do — inline prose links, navigation links, muted or secondary links, external links, and destructive ones — and give each a treatment that holds in every theme the app supports.
2. Underline links that sit inside a paragraph of text. Colour alone is not enough to distinguish them, and a reader scanning body copy has no other signal.
3. Mark links leaving the app for another domain, and make that marker part of the accessible name so it is announced rather than only drawn.
4. Decide deliberately where visited styling helps and where it misleads. It is useful in documentation and search results; it is noise on a list of records where every row has been opened once.
5. Do not render a disabled-looking link. A link that cannot be followed should either not be a link at all or should lead somewhere that explains why access is unavailable — a greyed anchor is still focusable, still clickable, and explains nothing.

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

- Links distinguished only by colour disappear for colourblind readers and in greyscale printing. Every link style needs a second signal, usually an underline or a weight change.
- Visited styling applied indiscriminately makes an application look stale and can leak browsing history in shared-screen contexts, so it belongs on content links rather than on record navigation.
- Forced-colours and high-contrast modes override custom colours but respect text decoration, so a link whose only distinction is colour becomes invisible there.
- A link styled to look disabled remains in the tab order and remains activatable, which produces a control that appears inert and then navigates anyway.
- Link colours must clear the contrast threshold against their own background and remain distinguishable from surrounding body text, not merely legible.
- Underlines must not run through descenders illegibly, and must not be removed on hover in a way that makes the link harder to identify than at rest.
- Links opening in a new tab or window must say so, since an unannounced context switch strands users who expect the back button to work.

## 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 link in the app maps to one of the defined link roles.
- [ ] Inline prose links are distinguishable without relying on colour.
- [ ] External links are marked visually and in their accessible name.
- [ ] Visited styling is applied only where it was deliberately chosen.
- [ ] No disabled-looking anchors remain; unavailable destinations are handled explicitly.
- [ ] Link styles survive forced-colours and high-contrast modes with their distinction intact.
- [ ] 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.
