/* A11yMenu core styles (AO-A11Y-MENU-001), used with a11y-menu.js. Two parts: the effects of the reader's choices (attributes on <html>) and the
   menu itself. A site adapter themes the menu through the --a11ym-* custom properties below and tunes effects for its own markup; see docs/A11Y_MENU.md.
   The effects use !important on purpose: a reader's choice must win over the site's own styles. Inline SVG drawings are left as drawn. */

/* ---------- Effects ---------- */

/* Text size: a multiple of the browser's own default text size (a site whose root size is not 100% sets --a11ym-base-size). Pages sized in rem scale. */
html[data-a11y-text="125"] { font-size: calc(var(--a11ym-base-size, 100%) * 1.25) !important; }
html[data-a11y-text="150"] { font-size: calc(var(--a11ym-base-size, 100%) * 1.5) !important; }
html[data-a11y-text="175"] { font-size: calc(var(--a11ym-base-size, 100%) * 1.75) !important; }
html[data-a11y-text="200"] { font-size: calc(var(--a11ym-base-size, 100%) * 2) !important; }

/* Larger text or spacing makes long words wider than a narrow screen: they may then break inside the word rather than run off the page. */
html[data-a11y-text] body *:not(svg *), html[data-a11y-spacing] body *:not(svg *) { overflow-wrap: anywhere !important; }

/* Letter and word spacing; "wider" uses the WCAG 1.4.12 text-spacing values (letter 0.12em, word 0.16em). */
html[data-a11y-spacing="wide"] body *:not(svg *) { letter-spacing: 0.06em !important; word-spacing: 0.08em !important; }
html[data-a11y-spacing="wider"] body *:not(svg *) { letter-spacing: 0.12em !important; word-spacing: 0.16em !important; }

/* Line height. */
html[data-a11y-line="1.5"] body *:not(svg *) { line-height: 1.5 !important; }
html[data-a11y-line="1.8"] body *:not(svg *) { line-height: 1.8 !important; }
html[data-a11y-line="2"] body *:not(svg *) { line-height: 2 !important; }

/* Highlight links: a thick underline and a dashed outline on every link (a focused link keeps the site's focus indicator instead of the outline). */
html[data-a11y-links="highlight"] a[href] {
  text-decoration-line: underline !important; text-decoration-style: solid !important; text-decoration-thickness: max(2px, 0.1em) !important;
  text-underline-offset: 0.2em !important; text-decoration-skip-ink: none !important;
}
html[data-a11y-links="highlight"] a[href]:not(:focus-visible) { outline: 2px dashed var(--a11ym-link-outline, currentColor) !important; outline-offset: 2px !important; }

/* Pause animations: CSS animations and transitions finish at once and smooth scrolling stops. Scripted animations read the same choice from the store. */
html[data-a11y-motion="paused"], html[data-a11y-motion="paused"] *, html[data-a11y-motion="paused"] *::before, html[data-a11y-motion="paused"] *::after {
  animation-duration: 0.001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important; transition-delay: 0s !important; scroll-behavior: auto !important;
}

/* High contrast: every element (except images, video, canvas, frames and inline SVG drawings) gets one text colour on one solid background, with no
   background images, shadows or text shadows; links and the focus indicator get their own high-contrast colours. Tested ratios: docs/A11Y_MENU.md. */
html[data-a11y-contrast="high-light"] { --a11ym-hc-fg: #000000; --a11ym-hc-bg: #ffffff; --a11ym-hc-link: #0a2fb3; --a11ym-hc-focus: #b00060; color-scheme: light !important; }
html[data-a11y-contrast="high-dark"] { --a11ym-hc-fg: #ffffff; --a11ym-hc-bg: #000000; --a11ym-hc-link: #ffe45c; --a11ym-hc-focus: #5ce1ff; color-scheme: dark !important; }
html[data-a11y-contrast^="high-"],
html[data-a11y-contrast^="high-"] body,
html[data-a11y-contrast^="high-"] body *:not(img, picture, video, canvas, iframe, object, embed, svg, svg *) {
  color: var(--a11ym-hc-fg) !important; background-color: var(--a11ym-hc-bg) !important; background-image: none !important;
  border-color: var(--a11ym-hc-fg) !important; text-shadow: none !important; box-shadow: none !important;
}
html[data-a11y-contrast^="high-"] body a[href],
html[data-a11y-contrast^="high-"] body a[href] *:not(svg, svg *) { color: var(--a11ym-hc-link) !important; }
html[data-a11y-contrast^="high-"] ::placeholder { color: var(--a11ym-hc-fg) !important; opacity: 0.8 !important; }
html[data-a11y-contrast^="high-"] :focus-visible { outline: 3px solid var(--a11ym-hc-focus) !important; outline-offset: 2px !important; }

/* ---------- The menu ---------- */

.a11ym {
  --_bg: var(--a11ym-bg, Canvas);
  --_fg: var(--a11ym-fg, CanvasText);
  --_muted: var(--a11ym-muted, color-mix(in srgb, var(--_fg) 75%, var(--_bg)));
  --_line: var(--a11ym-line, color-mix(in srgb, var(--_fg) 22%, var(--_bg)));
  --_control: var(--a11ym-control, color-mix(in srgb, var(--_fg) 60%, var(--_bg)));
  --_accent: var(--a11ym-accent, #0b5d66);
  --_accent-fg: var(--a11ym-accent-fg, #ffffff);
  --_focus: var(--a11ym-focus, #c26a00);
  --_radius: var(--a11ym-radius, 12px);
  --_font: var(--a11ym-font, inherit);
  --_title-font: var(--a11ym-title-font, var(--_font));
}
/* A side panel at the inline end of the window, the full window height; its content scrolls inside it. */
dialog.a11ym {
  box-sizing: border-box; position: fixed; inset: 0 0 0 auto; width: min(26rem, 100vw); max-width: 100vw; height: 100%; max-height: 100%;
  margin: 0 0 0 auto; padding: 0; border: 0; border-inline-start: 1px solid var(--_line); border-radius: 0;
  background: var(--_bg); color: var(--_fg); font-family: var(--_font); font-size: 1rem; line-height: 1.45; text-align: start;
  overflow-y: auto; overscroll-behavior: contain;
}
dialog.a11ym:dir(rtl) { inset: 0 auto 0 0; margin: 0 auto 0 0; }
dialog.a11ym::backdrop { background: rgba(4, 12, 16, 0.42); }
.a11ym [hidden] { display: none !important; }
.a11ym *, .a11ym *::before, .a11ym *::after { box-sizing: border-box; }
.a11ym-panel { padding: 0.75rem 1.25rem 1.5rem; }
.a11ym-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-bottom: 0.25rem; }
.a11ym-title { margin: 0; font-family: var(--_title-font); font-size: 1.3rem; font-weight: 700; line-height: 1.2; letter-spacing: 0.01em; }
.a11ym-intro { margin: 0 0 0.25rem; color: var(--_muted); font-size: 0.9rem; }
.a11ym-section { margin: 0; padding: 0.85rem 0; border: 0; border-top: 1px solid var(--_line); min-width: 0; }
.a11ym-legend { float: left; width: 100%; margin: 0 0 0.55rem; padding: 0; font-weight: 600; }
.a11ym-legend + * { clear: both; }
.a11ym-hint { margin: 0.45rem 0 0; color: var(--_muted); font-size: 0.85rem; }

/* Buttons share one shape: at least 44 by 44 CSS pixels, no transitions. */
/* Zero specificity, so each button's own rules (weight, size) win. */
:where(.a11ym) button { font: inherit; color: inherit; cursor: pointer; }
.a11ym :focus-visible { outline: 3px solid var(--_focus); outline-offset: 2px; }
.a11ym-close { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 2.75rem; height: 2.75rem; padding: 0; border: 0; border-radius: 50%; background: transparent; }
.a11ym-close:hover { background: var(--_line); }
.a11ym-close svg { width: 1.25rem; height: 1.25rem; }

/* On/off switch: the label at the start; at the end the state in words and a track whose thumb moves (not colour alone). */
.a11ym-switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; min-height: 2.75rem; padding: 0.25rem 0; border: 0; background: transparent; text-align: start; font-weight: 600; }
.a11ym-switch-control { display: inline-flex; align-items: center; gap: 0.6rem; flex: none; }
.a11ym-switch-state { min-width: 1.9em; font-size: 0.85rem; font-weight: 600; color: var(--_muted); text-align: end; }
.a11ym-switch-track { position: relative; display: inline-block; width: 3rem; height: 1.6rem; border: 2px solid var(--_control); border-radius: 999px; background: transparent; }
.a11ym-switch-thumb { position: absolute; top: 0.15rem; left: 0.15rem; width: 1rem; height: 1rem; border-radius: 50%; background: var(--_control); }
.a11ym-switch[aria-checked="true"] .a11ym-switch-track { background: var(--_accent); border-color: var(--_accent); }
.a11ym-switch[aria-checked="true"] .a11ym-switch-thumb { left: auto; right: 0.15rem; background: var(--_accent-fg); }
.a11ym-switch[aria-checked="true"] .a11ym-switch-state { color: var(--_fg); }

/* Choices: native radio buttons drawn as pills; the selected pill is filled and carries a check mark (not colour alone). */
.a11ym-options { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.a11ym-option { position: relative; display: inline-flex; }
.a11ym-radio { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.a11ym-option-text { display: inline-flex; align-items: center; gap: 0.35em; min-height: 2.75rem; padding: 0 0.95rem; border: 2px solid var(--_control); border-radius: 999px; font-size: 0.95rem; white-space: nowrap; }
.a11ym-radio:checked + .a11ym-option-text { background: var(--_accent); border-color: var(--_accent); color: var(--_accent-fg); font-weight: 700; }
.a11ym-radio:checked + .a11ym-option-text::before { content: ""; width: 0.38em; height: 0.7em; margin: -0.15em 0.15em 0 0; border: solid currentColor; border-width: 0 0.14em 0.14em 0; transform: rotate(45deg); }
.a11ym-radio:focus-visible + .a11ym-option-text { outline: 3px solid var(--_focus); outline-offset: 2px; }
.a11ym-option:hover .a11ym-option-text { border-color: var(--_fg); }

.a11ym-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem 1rem; }
.a11ym-reset { min-height: 2.75rem; padding: 0 1.1rem; border: 2px solid var(--_fg); border-radius: 999px; background: transparent; font-weight: 700; }
.a11ym-reset:hover { background: var(--_line); }
.a11ym-statement { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 0.2em; padding: 0.6rem 0; }
.a11ym-status { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }

/* In high contrast the menu keeps its states visible: the selected pill and an "on" switch are drawn in reverse. */
html[data-a11y-contrast^="high-"] .a11ym .a11ym-radio:checked + .a11ym-option-text,
html[data-a11y-contrast^="high-"] .a11ym .a11ym-switch[aria-checked="true"] .a11ym-switch-track { background-color: var(--a11ym-hc-fg) !important; color: var(--a11ym-hc-bg) !important; }
html[data-a11y-contrast^="high-"] .a11ym .a11ym-switch-thumb { background-color: var(--a11ym-hc-fg) !important; }
html[data-a11y-contrast^="high-"] .a11ym .a11ym-switch[aria-checked="true"] .a11ym-switch-thumb { background-color: var(--a11ym-hc-bg) !important; }

/* Windows high contrast and other forced colours: system colours, and the selected pill keeps its fill. */
@media (forced-colors: active) {
  .a11ym-radio:checked + .a11ym-option-text { forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight; }
  .a11ym-switch-thumb { forced-color-adjust: none; background: ButtonText; }
  .a11ym-switch[aria-checked="true"] .a11ym-switch-track { forced-color-adjust: none; background: Highlight; border-color: Highlight; }
  .a11ym-switch[aria-checked="true"] .a11ym-switch-thumb { background: HighlightText; }
}
