/* ============================================================================
 * MCOS accessibility base (WCAG 2.2 AA)
 * ----------------------------------------------------------------------------
 * Standalone like mobile-shell.css and dark-mode.css (not a webpack entry), so
 * it also loads on the ~26 template branches that wp_dequeue_style() the global
 * style.min.css. Enqueued in functions.php before dark-mode.css; dark mode keeps
 * its own focus rule there (html.mcos-dark … :focus-visible, --d-focus).
 *
 * Colours, spacing and radii come from the design tokens only
 * (.claude/rules/design-tokens.md): the --mcos-* bridge in dark-mode.css and
 * the palette in assets/sass/common/_colors.scss.
 * ========================================================================== */

/* ---- Focus (2.4.7) ------------------------------------------------------- *
 * The light twin of dark-mode.css's focus rule. The theme removes the focus
 * ring in light mode in many places (common/_general.scss `input{outline:none}`
 * and `a,input:focus{outline-color:transparent}`, and about 25 page stylesheets
 * repeat it), so a keyboard user could not see where they were. `!important`
 * for the same reason as the dark rule: those resets sit at every specificity.
 * :focus-visible only, so mouse and touch focus look exactly as before.
 * --mcos-focus is $green4 #274446: 10.49:1 on white, 9.71:1 on #f6f6f6. */
:is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--mcos-focus, #274446) !important;
  outline-offset: 2px !important;
}

/* The footers are dark green in light mode too ($green4 / $green5), where a
 * $green4 ring would vanish. $green22 #85e7aa: 7.00:1 on #274446, 8.6:1 on
 * #203839. In dark mode dark-mode.css's rule wins (higher specificity, later). */
:is(#colophon, .stealth-footer, .webinar-ads-footer) :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline-color: #85e7aa !important;
}

/* ---- Skip link (2.4.1) --------------------------------------------------- *
 * First focusable element on every page (template-parts/skip-link.php). Off
 * screen until focused, then shown above the fixed header (z-index 9999).
 * White on --mcos-brand #407360: 5.47:1; dark: white on --d-brand 4.61:1. */
.mcos-skip-link {
  position: absolute;
  /* In the app the native glass top bar covers the first ~131px. */
  top: var(--mcos-top-inset, 0px);
  left: 0;
  z-index: 100000;
  padding: 12px 16px;
  border-radius: 0 0 8px 0;
  background: var(--mcos-brand, #407360);
  color: var(--mcos-on-brand, #ffffff);
  font-family: "Poppins", "Poppins Fallback", Arial, Helvetica, sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.5;
  text-decoration: none;
}
/* Hidden by clipping, not by moving it up: the app's top inset would leave a
 * translated link peeking out below the native bar. */
.mcos-skip-link:not(:focus) {
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.mcos-skip-link:focus {
  color: var(--mcos-on-brand, #ffffff);
  opacity: 1;
}
.mcos-skip-link:focus-visible {
  outline-color: var(--mcos-on-brand, #ffffff) !important;
  outline-offset: -4px !important;
}

/* The skip link focuses <main> (tabindex -1, assets/js/a11y.js) only so the
 * next Tab starts there; a ring around the whole page would be noise. */
#main-content:focus {
  outline: none !important;
}

/* ---- Screen-reader-only text --------------------------------------------- */
.mcos-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Dialog boxes and reading targets ------------------------------------ *
 * [data-mcos-focus-target]: a heading or question label that takes focus after
 * a view or step changes (forgot-password-v2.js, prescreening.js), so it is
 * read next. Same reasoning as a dialog box: not a control, no ring.
 * Dialog boxes (assets/js/a11y-dialogs.js):
 * A modal's box takes focus when it opens (tabindex -1) so a screen reader
 * reads its name first. It is not a control, so it gets no ring; the controls
 * inside keep theirs. Doubled attribute: beats dark-mode.css's focus rule
 * (html.mcos-dark :is(…, [tabindex]):focus-visible, also !important). */
:root [data-mcos-dialog][data-mcos-dialog][tabindex="-1"]:focus,
:root [data-mcos-dialog][data-mcos-dialog][tabindex="-1"]:focus-visible,
:root [data-mcos-focus-target][data-mcos-focus-target][tabindex="-1"]:focus,
:root [data-mcos-focus-target][data-mcos-focus-target][tabindex="-1"]:focus-visible {
  outline: none !important;
}

/* ---- Reduced motion (2.2.2, 2.3.3) --------------------------------------- *
 * The pulses, glows and slides across the landing pages run forever and
 * each page sheet handles reduced motion on its own, or not at all. For
 * people who asked their system for less motion, every animation and
 * transition finishes at once and smooth scrolling is off. 0.01ms rather
 * than none, so transitionend and animationend still fire for the code that
 * waits on them. Loading spinners keep turning: a frozen spinner reads as a
 * hung page. Script-driven motion (the sponsored carousel, the guide clips,
 * the anchor scroll) checks the same query in its own code. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }
  :not([class*="spin"]):not([class*="loader"]),
  :not([class*="spin"]):not([class*="loader"])::before,
  :not([class*="spin"]):not([class*="loader"])::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
