/* ==========================================================================
   a11y.css — WCAG 2.2 AA corrections.

   INTEGRATOR: this file needs one line in Pages/Shared/_Layout.cshtml and one
   in Pages/Admin/_AdminLayout.cshtml, LAST in <head> after dea.css:

       <link rel="stylesheet" href="~/css/a11y.css" />

   It must load last: several rules here correct a colour or a border that an
   earlier sheet set, and they win on source order rather than on !important
   wherever that is possible.

   Every ratio quoted below was measured, not estimated — sampled out of the
   rendered page with getComputedStyle and, for the parallax band, out of a
   canvas composite of the real photograph under the real scrim gradient.

   Colour and type come from tokens.css. Nothing here hard-codes a hex value:
   the corrected colours are derived from the existing tokens with color-mix,
   so the palette still has one source of truth.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. THE ACCENT COLOURS, CORRECTED PER GROUND

   NOTE ON OVERLAP: the audit opened with --color-sun (#D98F4E) failing 1.4.3
   everywhere it was used as label text — 2.41:1 on sand, 2.63:1 on shell,
   2.16:1 on dune, against a 4.5 requirement. While this slice was running the
   design slice landed --color-sun-ink (#8A5216) in tokens.css and rewired
   every light-ground use of the accent onto it (5.83 / 6.37 / 5.22 measured),
   keeping plain --color-sun for the dark surfaces. That is the better fix and
   it is in files this slice may not touch, so the correction that used to live
   here has been removed rather than layered on top of it. What is left below
   is what that change does not reach.

   Still failing, and corrected here:
     --color-sage  3.00:1 on shell as .tag--good, 2.74 on sand   (needs 4.5)
     --color-dusk  4.39:1 on dune as body copy in .panel--raised (needs 4.5)
                   3.02:1 on deep plum in .footer__base          (needs 4.5)
   Neither has an -ink counterpart, and neither can take one value for every
   ground: dusk has to go darker on the light grounds and lighter on the deep.
   The original is captured on <html> and the corrected value set on <body>,
   which is what keeps the two declarations out of a custom-property cycle.
   -------------------------------------------------------------------------- */
html {
  --a11y-sun-source: var(--color-sun);
  --a11y-sage-source: var(--color-sage);
  --a11y-dusk-source: var(--color-dusk);

  /* A boundary colour for interactive controls. --color-haze is 1.35–1.47:1
     against the light grounds, which is fine for a decorative hairline and far
     under the 3:1 that 1.4.11 asks of the edge that identifies a control. */
  --a11y-line: color-mix(in srgb, var(--color-haze) 45%, var(--color-ink));
}

body {
  /* sand 5.38 · shell 5.88 · dune 4.82 */
  --color-sage: color-mix(in srgb, var(--a11y-sage-source) 55%, var(--color-ink));
  /* sand 5.40 · shell 5.90 · dune 4.84 */
  --color-dusk: color-mix(in srgb, var(--a11y-dusk-source) 90%, var(--color-ink));
}

/* The dark surfaces, where the corrected values would fail instead. Sage is
   5.39:1 on deep plum as it stands, so it simply goes back. */
.panel--deep,
.on-deep,
.section--deep,
.footer,
.member-card,
.sale-hero--deep,
.film,
.dir-card.panel--deep {
  --color-sage: var(--a11y-sage-source);
  /* dusk is 3.02:1 on deep; lifted toward the deep-ink it measures 5.20:1 */
  --color-dusk: color-mix(in srgb, var(--a11y-dusk-source) 70%, var(--color-deep-ink));
}

/* The parallax band is the one place a photograph shows through the scrim, so
   its ground is lighter than flat plum and the untouched accent is not quite
   enough there either. Composited against the real poster at a 560px viewport
   .film__body .eyebrow measured 4.49:1 — a hair under 4.5. Lifted toward the
   deep-ink it measures 5.63:1 against that same worst pixel, and 7.31:1 where
   the band falls back to flat plum. */
.film {
  --color-sun: color-mix(in srgb, var(--a11y-sun-source) 80%, var(--color-deep-ink));
}

/* Three one-off measurements no token reaches.
   .art-meta__sep sets the haze token as TEXT: 1.47:1.
   .gth-steps__n is the bolt on dune: 4.43:1, under by 0.07.
   The portal day marks are a state graphic in the untouched accent on shell —
   2.63:1 against a 3:1 requirement for a graphic that carries meaning. */
.art-meta__sep { color: var(--color-dusk); }
.gth-steps__n { color: color-mix(in srgb, var(--color-bolt) 90%, var(--color-ink)); }
.boltcell.is-open .boltcell__mark,
.lessonrow.is-open .lessonrow__mark { background: var(--color-sun-ink); }

/* --------------------------------------------------------------------------
   2. FOCUS

   The site's single ring is `2px solid var(--color-bolt)`. Measured, it fails
   on both of the surfaces it has to survive:

       bolt ring on a crimson .btn--primary   1.00:1
       bolt ring on a deep plum panel/footer  2.99:1   (needs 3)

   No single colour clears every ground here, so the indicator is built from
   two: a sand ring hugging the control, then the bolt outline, then a deep
   plum ring outside it. The two ring colours contrast 4.94:1 with EACH OTHER,
   so whatever the indicator lands on, part of it is always visible:

       sand vs crimson button 4.94 · sand vs deep 14.79
       bolt vs sand 4.94 · bolt vs shell 5.40 · bolt vs dune 4.43
       deep vs sand 13.10 · deep vs shell 14.30

   !important because several components (.bell, .charge__btn, .boltcell a)
   declare their own single-colour ring at a higher specificity, and a focus
   indicator is not something a component should be able to quietly weaken.
   -------------------------------------------------------------------------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
details:focus-visible,
[tabindex]:focus-visible,
[contenteditable]:focus-visible {
  outline: 2px solid var(--color-bolt) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 2px var(--color-sand), 0 0 0 6px var(--color-deep) !important;
  border-radius: var(--radius-sm);
}

/* On the dark surfaces the sandwich is inverted so the inner ring is the one
   that separates the control from its ground. */
.panel--deep :focus-visible,
.on-deep :focus-visible,
.section--deep :focus-visible,
.footer :focus-visible,
.member-card :focus-visible,
.film :focus-visible,
.sale-hero--deep :focus-visible {
  box-shadow: 0 0 0 2px var(--color-sand), 0 0 0 6px var(--color-deep-ink) !important;
}

/* The skip link only reads as "skip" if it is visible the moment it takes
   focus. It already is; this keeps it above the sticky masthead, which has
   z-index 40, and clear of the ring. */
.skip:focus,
.skip:focus-visible {
  z-index: 100;
  outline-offset: 3px !important;
}

/* Landing on <main> from the skip link should not paint a ring around the
   whole page. It still needs tabindex="-1" in the layout to move focus at all
   — see the note at the top of this file and in the slice report. */
main:focus,
main:focus-visible,
[role="main"]:focus,
[role="main"]:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

/* --------------------------------------------------------------------------
   3. CONTROL BOUNDARIES  (1.4.11, 3:1)

   Text inputs, selects, textareas, .btn--ghost, .nav__toggle and .bell all
   draw their edge in --color-haze. Measured that edge is 1.35:1 on sand,
   1.47:1 on shell — the control has no perceivable boundary at all.

   Rather than darken --color-haze globally (which would also thicken every
   panel edge, table rule and .rule hairline on the site) the token is
   redefined ON the controls themselves, so only a boundary that belongs to an
   interactive thing changes. Anything else whose border happens to use the
   token inside a control gets the same correction for free.
   -------------------------------------------------------------------------- */
input:not([type="hidden"]),
textarea,
select,
button,
summary,
a,
.btn,
.bell,
.charge__btn,
[role="button"] {
  --color-haze: var(--a11y-line);
}

/* A styled control with a transparent or absent border has no boundary to
   correct — these are the ones the audit found relying on the fill alone. */
.field input,
.field textarea,
.field select {
  border-color: var(--a11y-line);
}

/* --------------------------------------------------------------------------
   4. STATE THAT IS CARRIED BY COLOUR ALONE  (1.4.1) AND STATE GRAPHICS (1.4.11)

   The charge bolt is the one real case on the site. Resting it is the haze
   token — 1.47:1 against the card, so the control's own glyph is close to
   invisible; charged it is the crimson. Nothing but hue separates the two
   states for a sighted user (aria-pressed already carries it for assistive
   tech, and the count beside it is not a state).

   Resting is moved onto the boundary colour (4.49:1) and the charged state
   gains a bar under the bolt, so the difference is a shape and not only a hue.

   The .tag chips were checked and are NOT a 1.4.1 failure: every chip in the
   codebase carries its own word — "Unpublished", "Not synced", "All live
   prices synced", "Cancelled" — and the colour is redundant to that text. Only
   their contrast needed correcting, which section 1 did.
   -------------------------------------------------------------------------- */
.charge__bolt { background: var(--a11y-line); }
.charge__btn { position: relative; }
.charge__btn.is-charged::after {
  content: "";
  position: absolute;
  inset-inline: 25%;
  inset-block-end: .35rem;
  block-size: 2px;
  border-radius: 1px;
  background: var(--color-bolt);
}

/* Validation. The site marks an invalid field by changing a border colour and
   nothing else. aria-invalid is the programmatic half (added in the page
   markup); this is the visual half — a thicker edge, so the state survives
   both a colour-blind reader and a monochrome print. */
[aria-invalid="true"],
.pg-consent--invalid,
.input-validation-error {
  border-color: var(--color-bolt) !important;
  border-width: 2px !important;
  outline: 1px solid var(--color-bolt);
  outline-offset: -3px;
}

/* The error message that goes with it, marked so it is not read as body copy.
   The glyph is decorative punctuation, not content: it is generated, so it
   never reaches the accessible name of anything. */
.field .error:not(:empty)::before,
span.error:not(:empty)::before,
.field-validation-error:not(:empty)::before {
  content: "\26A0\FE0E\00A0";
  font-family: var(--font-body);
}

/* --------------------------------------------------------------------------
   5. TARGET SIZE  (2.5.8, 24x24 CSS px)

   Measured failures:
       native checkbox                        13 x 13
       .boltcell a  (the 21 day marks)        14 x 28   — and the 7.2px gap
                                              leaves the 24px circles
                                              overlapping, so the spacing
                                              exception does not rescue it
       .admin-mark / .admin-who a             18px and 17px tall
       breadcrumb, table-of-contents and
       signal-filter links                    17–23px tall
   -------------------------------------------------------------------------- */
input[type="checkbox"],
input[type="radio"],
/* pages.css sets `width: auto` on the consent box at a higher specificity, so
   it has to be named here or the box comes out 13 wide and 24 tall. */
.pg-consent input[type="checkbox"],
.check input[type="checkbox"],
.field input[type="checkbox"] {
  inline-size: 1.5rem;
  block-size: 1.5rem;
  accent-color: var(--color-bolt);
}
/* The wrapping labels align to the first text line; the taller box needs to
   come back up to meet it. */
.check input[type="checkbox"],
.pg-consent input[type="checkbox"] { margin-block-start: 0; }

.boltcell { min-inline-size: 1.5rem; }
.boltcell a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 1.5rem;
  min-block-size: 1.5rem;
}

/* Footer links measure 94 x 22.4 with a 7.2px gap, so the 24px circles clear
   each other and 2.5.8's spacing exception already rescues them. Two pixels of
   height is cheaper than relying on an exception. */
.footer ul a,
.film__links a,
.admin-mark,
.admin-who a,
.admin-nav a,
.sig-filter a,
.faq-toc__list a,
.legal__toc a,
.art-crumbs a,
.circle-crumbs a,
.valley-crumbs a,
.portal-crumb a,
.gth-crumbs a,
.evt-crumbs a,
.pager a,
.dir-pager a,
.mod-tabs a {
  display: inline-flex;
  align-items: center;
  min-block-size: 24px;
}

/* --------------------------------------------------------------------------
   6. SCROLLABLE TABLE REGIONS  (2.1.1)

   .table-scroll is a horizontally scrolling box. Without a tab stop there is
   no way to scroll it from the keyboard alone. The markup carries
   tabindex="0" and role="region"; this stops the tab stop from looking like a
   selected block and keeps the ring outside the scrolling content.
   -------------------------------------------------------------------------- */
.table-scroll:focus-visible {
  outline-offset: -2px !important;
  box-shadow: none !important;
}

/* --------------------------------------------------------------------------
   7. REDUCED MOTION  (2.3.3)

   dea.css already collapses every duration and turns off smooth scrolling,
   and film.js refuses to translate the parallax band or load its video. This
   closes the two gaps that rule leaves: a delay is not a duration, and an
   iteration count is not either.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
  .film__media { transform: none !important; }
  .film__media video { display: none !important; }
  .charge__btn.is-charged:hover .charge__bolt,
  .boltcell a:hover .boltcell__mark { transform: none !important; }
}

/* --------------------------------------------------------------------------
   8. FORCED COLOURS

   In a high-contrast mode the system palette replaces everything here, and a
   focus ring drawn with box-shadow is dropped entirely. Restate it with the
   system's own highlight so the ring survives.
   -------------------------------------------------------------------------- */
@media (forced-colors: active) {
  a:focus-visible,
  button:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  summary:focus-visible,
  [tabindex]:focus-visible {
    outline: 3px solid Highlight !important;
    outline-offset: 2px !important;
  }
  .charge__btn.is-charged::after { background: Highlight; forced-color-adjust: none; }
}

/* --------------------------------------------------------------------------
   4. TOUCH TARGET SIZE on the two controls that actually needed it

   Measured at 375px: .nav__toggle is 61x32 and .btn--quiet is 125x33.

   Neither FAILS WCAG 2.5.8 (AA), which asks for 24x24 — both clear that. This
   is the 44x44 figure from the iOS and Android guidance instead, applied only
   where the control is both small and important:

     .nav__toggle is the primary navigation on every page below 68rem. It is
     the single most-tapped thing on the mobile site and it was 32px tall.
     .btn--quiet is a real call to action ("See the options"), styled quietly
     but not meant to be hard to hit.

   Deliberately NOT applied to every link. Inline links in prose are exempt
   from 2.5.8 for good reason: padding them to 44px would space paragraphs out
   and make the reading worse to fix a problem nobody has.
   -------------------------------------------------------------------------- */
@media (max-width: 68rem) {   /* in step with the nav collapse in dea.css */
  .nav__toggle {
    min-height: 2.75rem;
    /* Centres the label in the taller box rather than leaving it top-aligned
       with dead space beneath. */
    display: inline-flex;
    align-items: center;
  }
}

.btn--quiet {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
}
