# Media Aspect Ratio System

## Objective

Give every thumbnail, avatar, and hero a shared, reserved shape so nothing jumps.

A small set of named aspect ratios applied to every image and video surface, with reserved space, a defined fit, and a defined fallback.

## 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. Catalogue the media surfaces already in the app — list thumbnails, card covers, avatars, hero banners, video embeds, attachment previews — and reduce them to a handful of named ratios rather than a per-component value.
2. Reserve the box before the media loads so the ratio holds space from first paint. Layout that settles after an image arrives moves whatever the user was about to click.
3. Set the fit per content type, not per component: faces and product shots crop to fill from a sensible focal point, diagrams and screenshots fit whole with padding, because cropping a diagram loses the content it exists to show.
4. Define what a missing, broken, or still-loading image looks like inside the reserved box, and make that fallback occupy the same shape so the layout is identical whether the media arrives or not.
5. Do not let a component override the ratio with a one-off value to make a particular image look better. That is how a system of four ratios becomes forty; if a surface genuinely needs a new shape, add it to the named set.

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

- Cropping to fill is right for photography and wrong for a diagram or a screenshot, where the cropped edges carry meaning. Choose by what the image is, not by where it sits.
- Some media must keep its own intrinsic ratio — an uploaded chart, a user's artwork, an embedded video from a provider that dictates its shape. Allow an explicit escape from the fixed ratios rather than distorting the source.
- A broken URL, a deleted file, or a slow network must resolve to a placeholder of the same shape, never to a zero-height gap or a browser's default broken-image icon.
- Captions, overlaid titles, play buttons, and duration badges must be positioned against the reserved box, so they stay aligned when the image is cropped or replaced by a fallback.
- Avatars are a ratio and a mask; a square source in a round frame must crop centrally rather than being squashed to fit.
- Ratios must not change under a density or compact setting — spacing shrinks, shapes do not.
- Column count and gutters between cards are owned by Responsive Card Grid; this system owns only the shape of the media inside them.

## 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 media surface uses one of a named, documented set of ratios.
- [ ] Space is reserved before load and no layout shift occurs when media arrives.
- [ ] Fit and crop behaviour is chosen by content type and is consistent across the app.
- [ ] Broken, missing, and loading media all occupy the same box as a successful load.
- [ ] Overlays, badges, and captions remain aligned across every state.
- [ ] Media that must keep its intrinsic ratio does so without distortion.
- [ ] 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.
