/* ── OpenDyslexic Font ────────────────────────────────────────────────────── */

@font-face {
    font-family: 'OpenDyslexic';
    src: url('/assets/fonts/OpenDyslexic.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* ── AX CSS Variables ─────────────────────────────────────────────────────── */

:root {
    --ax-font-size:      1rem;
    --ax-letter-spacing: 0em;
    --ax-word-spacing:   0em;
    --ax-line-height:    normal;
}

/* WCAG 1.4.4 — font size via root rem so all rem/em units scale */
html { font-size: var(--ax-font-size); }

/* WCAG 1.4.12 — text spacing overrides cascade through all elements */
body, body * {
    letter-spacing: var(--ax-letter-spacing) !important;
    word-spacing:   var(--ax-word-spacing)   !important;
}

body p, body li, body td, body th,
body dt, body dd, body blockquote {
    line-height: var(--ax-line-height) !important;
}

/* ── Skip Link (WCAG 2.4.1) ──────────────────────────────────────────────── */

.ax-skip-link {
    position: fixed;
    top: -100%;
    left: 0;
    z-index: 100000;
    padding: 12px 20px;
    background: #000;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    text-decoration: none;
    border-radius: 0 0 6px 0;
    transition: top 0.1s;
}

.ax-skip-link:focus {
    top: 0;
    outline: 3px solid #ffbf00;
    outline-offset: 0;
}

/* ── Screen-reader only utility (WCAG 1.3.1) ─────────────────────────────── */

.ax-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Global Focus Indicator (WCAG 2.4.7, 2.4.11) ────────────────────────── */

:focus-visible {
    outline: 3px solid #005fcc;
    outline-offset: 2px;
    border-radius: 2px;
}

:focus:not(:focus-visible) { outline: none; }

/* ── Trigger Button ───────────────────────────────────────────────────────── */

.ax-trigger {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9000;
    width: 48px;
    height: 48px;
    font-size: 1.3rem;
    line-height: 1;
    background: #fff;
    color: #212529;
    border: 2px solid #ced4da;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
    transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ax-trigger:hover,
.ax-trigger:focus-visible {
    background: #f0f4ff;
    border-color: #005fcc;
    box-shadow: 0 4px 16px rgba(0, 95, 204, .22);
}

.ax-trigger[aria-expanded="true"] {
    background: #005fcc;
    color: #fff;
    border-color: #005fcc;
}

/* ── Scroll-to-top Button — stacks above AX trigger ─────────────────────── */

.scroll-to-top {
    position: fixed;
    bottom: 76px;           /* 20px base + 48px trigger + 8px gap */
    right: 20px;
    z-index: 8800;
    width: 48px;
    height: 48px;
    font-size: 1.4rem;
    line-height: 1;
    background: #fff;
    color: #495057;
    border: 2px solid #ced4da;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.2s ease, transform 0.2s ease,
                background 0.14s, border-color 0.14s;
}

.scroll-to-top--hidden {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    visibility: hidden;
}

.scroll-to-top:hover,
.scroll-to-top:focus-visible {
    background: #f0f4ff;
    border-color: #005fcc;
    color: #005fcc;
}

/* ── Panel ────────────────────────────────────────────────────────────────── */

.ax-panel {
    position: fixed;
    bottom: 76px;           /* sits just above the trigger */
    right: 16px;
    z-index: 9100;
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100vh - 100px);
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: opacity 0.15s, transform 0.15s;
    transform-origin: bottom right;
}

.ax-panel--hidden {
    opacity: 0;
    transform: scale(0.93) translateY(8px);
    pointer-events: none;
    visibility: hidden;
}

/* ── Panel Header ─────────────────────────────────────────────────────────── */

.ax-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px;
    border-bottom: 1px solid #e2e6ea;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
}

.ax-panel-title {
    font-size: 0.9rem !important;
    font-weight: 700 !important;
    color: #212529 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
}

.ax-panel-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #6c757d;
    flex-shrink: 0;
    transition: background 0.12s, border-color 0.12s;
}

.ax-panel-close:hover { background: #f8f9fa; border-color: #ced4da; }

/* ── Panel Body & Sections ────────────────────────────────────────────────── */

.ax-panel-body { display: flex; flex-direction: column; }

.ax-section {
    padding: 10px 14px 12px;
    border-bottom: 1px solid #e2e6ea;
}

.ax-section:last-child { border-bottom: none; }

.ax-section-title {
    font-size: 0.65rem !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    letter-spacing: 0.07em !important;
    color: #868e96 !important;
    margin: 0 0 8px !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
}

/* ── Step controls (font-size, letter-spacing, etc.) ─────────────────────── */

.ax-row-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: #6c757d;
    margin: 6px 0 2px;
    letter-spacing: 0.03em !important;
}

.ax-row-label:first-of-type { margin-top: 0; }

.ax-btn-group {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.ax-btn-group--wrap { flex-wrap: wrap; }
.ax-btn-group--top  { margin-top: 8px; }

/* Progress track for step controls */
.ax-step-track {
    flex: 1;
    height: 4px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.ax-step-fill {
    height: 100%;
    background: #005fcc;
    border-radius: 4px;
    width: 50%;           /* set dynamically by JS */
    transition: width 0.18s;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.ax-btn {
    padding: 6px 10px;
    background: #f8f9fa;
    color: #212529;
    border: 1px solid #ced4da;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.3;
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
    min-height: 32px;        /* touch/click target */
}

.ax-btn:hover { background: #e9ecef; border-color: #adb5bd; }

/* ± step buttons */
.ax-btn--step {
    width: 32px;
    min-width: 32px;
    padding: 4px 0;
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Toggle (radio/switch) — unchecked */
.ax-btn--toggle {
    padding: 5px 10px;
    font-size: 0.75rem;
}

/* Toggle — checked */
.ax-btn--toggle[aria-checked="true"] {
    background: #005fcc;
    color: #fff;
    border-color: #004ab5;
    font-weight: 600;
}

.ax-btn--toggle[aria-checked="true"]:hover { background: #004ab5; }

/* Reset */
.ax-btn--reset {
    background: #fff8e1;
    color: #664d03;
    border-color: #ffe082;
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
}

.ax-btn--reset:hover { background: #fff3cd; border-color: #ffd54f; }

/* ── Contrast Modes ───────────────────────────────────────────────────────── */

/* Dark mode */
html[data-ax-contrast="dark"] {
    color-scheme: dark;
}

html[data-ax-contrast="dark"] body {
    background: #12151a !important;
    color: #d4dce8 !important;
}

html[data-ax-contrast="dark"] .wiki-header,
html[data-ax-contrast="dark"] .wiki-toolbar,
html[data-ax-contrast="dark"] .wiki-sidebar {
    background: #1a1f2b !important;
    border-color: #2d3545 !important;
    color: #d4dce8 !important;
}

html[data-ax-contrast="dark"] :is(h1, h2, h3, h4, h5, h6) {
    color: #e8edf5 !important;
    border-color: #2d3545 !important;
}

html[data-ax-contrast="dark"] a {
    color: #7eb9f5 !important;
}

html[data-ax-contrast="dark"] code,
html[data-ax-contrast="dark"] pre {
    background: #1e2636 !important;
    color: #c9d8f0 !important;
    border-color: #2d3e5a !important;
}

html[data-ax-contrast="dark"] table,
html[data-ax-contrast="dark"] td,
html[data-ax-contrast="dark"] th {
    border-color: #2d3545 !important;
}

html[data-ax-contrast="dark"] th {
    background: #1a1f2b !important;
    color: #d4dce8 !important;
}

/* Inverted — hue-rotate keeps images looking natural */
html[data-ax-contrast="invert"] body {
    filter: invert(100%) hue-rotate(180deg);
}

html[data-ax-contrast="invert"] img,
html[data-ax-contrast="invert"] video,
html[data-ax-contrast="invert"] canvas {
    filter: invert(100%) hue-rotate(180deg);
}

/* Grayscale */
html[data-ax-contrast="grayscale"] body {
    filter: grayscale(100%);
}

/* High contrast — targets ≥7:1 ratio (WCAG AAA, above AA requirement) */
html[data-ax-contrast="high-contrast"] body {
    background: #fff !important;
    color: #000 !important;
}

html[data-ax-contrast="high-contrast"] :is(h1, h2, h3, h4, h5, h6) {
    color: #000 !important;
    border-color: #000 !important;
}

html[data-ax-contrast="high-contrast"] a {
    color: #00008b !important;
    text-decoration: underline !important;
    font-weight: 700 !important;
}

html[data-ax-contrast="high-contrast"] code,
html[data-ax-contrast="high-contrast"] pre {
    background: #f0f0f0 !important;
    color: #000 !important;
    border: 2px solid #000 !important;
}

html[data-ax-contrast="high-contrast"] :focus-visible {
    outline: 4px solid #ffbf00 !important;
    outline-offset: 2px;
}

/* ── Text Alignment (readability, WCAG 1.4.8 guidance) ───────────────────── */

html[data-ax-align="left"] p,
html[data-ax-align="left"] li,
html[data-ax-align="left"] td,
html[data-ax-align="left"] th,
html[data-ax-align="left"] dd {
    text-align: left !important;
}

/* ── Link Highlighting (WCAG 1.4.1) ──────────────────────────────────────── */

html[data-ax-links="on"] a {
    color: #b50000 !important;       /* dark red on white = 7.1:1 */
    font-weight: 700 !important;
    text-decoration: underline !important;
    text-underline-offset: 3px;
}

/* ── Font Family ──────────────────────────────────────────────────────────── */

html[data-ax-font="Helvetica"] * {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
}

html[data-ax-font="Arial"] * {
    font-family: Arial, 'Arial Narrow', sans-serif !important;
}

html[data-ax-font="OpenDyslexic"] * {
    font-family: 'OpenDyslexic', sans-serif !important;
}

/* ── Reduced Motion (WCAG 2.3.3) ─────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    *, ::before, ::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

html[data-ax-motion="on"] *,
html[data-ax-motion="on"] ::before,
html[data-ax-motion="on"] ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* Panel keeps its own transitions regardless */
html[data-ax-motion="on"] .ax-panel,
html[data-ax-motion="on"] .ax-step-fill { transition: none; }

/* ── Screen Ruler ─────────────────────────────────────────────────────────── */

.ax-screen-ruler {
    position: fixed;
    top: 100px;
    left: 0;
    width: 100%;
    height: 40px;
    background: rgba(255, 220, 0, 0.25);
    border-top: 2px solid rgba(180, 140, 0, 0.5);
    border-bottom: 2px solid rgba(180, 140, 0, 0.5);
    pointer-events: none;
    z-index: 8900;
    box-sizing: border-box;
}

.ax-screen-ruler--draggable {
    pointer-events: auto;
    cursor: ns-resize;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .ax-panel {
        bottom: 76px;
        right: 8px;
        left: 8px;
        width: auto;
        max-height: 72vh;
    }

    .ax-trigger    { bottom: 20px; right: 14px; }
    .scroll-to-top { bottom: 76px; right: 14px; }
}

@media (max-width: 400px) {
    .cookie-trigger { right: 68px; }   /* tighter gap on very small screens */
}

/* ── Print ────────────────────────────────────────────────────────────────── */

@media print {
    .ax-trigger, .cookie-trigger, .ax-panel, .ax-screen-ruler,
    .ax-skip-link, .scroll-to-top { display: none !important; }
}
