# Background Video Hero

## Objective

A muted looping video behind the headline that stays readable and loads politely.

A decorative looping video layer behind hero content, with a still image fallback and strict load conditions.

## 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. Treat the video as decoration. The headline, subheading, and call to action must be fully legible and functional if the video never loads at all.
2. Give the hero a fixed height or aspect ratio through the app's Media Aspect Ratio System before anything loads, so the page does not reflow when the video or the poster arrives.
3. Always set a poster image that is the first frame of the loop, so the transition from still to motion is invisible rather than a visible swap.
4. Load the video only after the page is interactive and only on connections and screens where it makes sense. Everywhere else, the poster image is the hero.
5. Do not add controls, sound, or a pause button that does nothing. A background video must be muted, must loop, and must carry no audio track at all so it cannot compete with anything the user is playing.

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

- Honour reduced motion and data saver preferences by showing the still image and never requesting the video. Reuse the app's Reduced Motion Support rather than checking the preference again in this component.
- Text over moving video loses contrast at unpredictable frames. Put a fixed overlay or gradient between the video and the text and verify contrast against the brightest frame in the loop, not against an average.
- Do not download the video on small screens or metered connections. A hero video is the largest asset on most marketing pages, and a phone on cellular data pays for it before seeing a word of the copy.
- A loop whose last frame does not match its first produces a visible jump every few seconds. Either cut the source so the seam matches or cross-fade the restart.
- Pause playback when the hero scrolls out of view and resume when it returns. A video decoding off-screen drains battery for nothing.
- The video element must be hidden from assistive technology and excluded from the tab order. It carries no information and should not be announced or focusable.
- Encode a small, short loop rather than a long high-bitrate clip scaled down in the browser. Compress the source through whatever the app already uses for media rather than uploading a raw export.
- If the video fails to load or decode, the poster must remain rather than collapsing to a blank or black hero.

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

- [ ] Hero text and calls to action are legible and functional with the video absent.
- [ ] The hero reserves its dimensions before any media loads and the page does not shift.
- [ ] Reduced motion and data saver preferences result in the still image with no video request.
- [ ] No video is requested on small screens or metered connections.
- [ ] Text meets contrast requirements against the brightest frame of the loop.
- [ ] The loop restarts without a visible seam, and playback pauses when the hero leaves the viewport.
- [ ] The video is muted, has no audio track, and is hidden from assistive technology and the tab order.
- [ ] 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.
