/* =========================================================
   Accessibility Widget — self-contained, no external deps
   ========================================================= */
:root {
    --a11y-accent: #2563eb;
    --a11y-accent-dark: #1d4ed8;
    --a11y-bg: #ffffff;
    --a11y-text: #1f2430;
    --a11y-border: #e6e8ee;
    --a11y-muted: #6b7280;
    --a11y-radius: 16px;
}

#a11y-toggle-btn {
    position: fixed;
    bottom: 22px;
    inset-inline-end: 22px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--a11y-accent), var(--a11y-accent-dark));
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35), 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 999998;
    transition: transform .25s ease, box-shadow .25s ease;
}

#a11y-toggle-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.45), 0 4px 10px rgba(0, 0, 0, 0.18);
}

#a11y-toggle-btn:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 3px;
}

#a11y-toggle-btn svg {
    width: 28px;
    height: 28px;
    fill: #fff;
}

#a11y-panel {
    position: fixed;
    bottom: 90px;
    inset-inline-end: 22px;
    width: 340px;
    max-width: calc(100vw - 24px);
    max-height: min(640px, calc(100vh - 120px));
    background: var(--a11y-bg);
    color: var(--a11y-text);
    border-radius: var(--a11y-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22), 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 999999;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.97);
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--a11y-border);
}

#a11y-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.a11y-header {
    background: linear-gradient(135deg, var(--a11y-accent), var(--a11y-accent-dark));
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.a11y-header h2 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.a11y-header h2 svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

#a11y-close-btn {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    transition: background .2s ease;
}

#a11y-close-btn:hover {
    background: rgba(255, 255, 255, 0.32);
}

.a11y-body {
    padding: 14px 16px 8px;
    overflow-y: auto;
    flex: 1;
}

.a11y-body::-webkit-scrollbar {
    width: 6px;
}

.a11y-body::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

.a11y-group-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--a11y-muted);
    margin: 14px 0 8px;
}

.a11y-group-title:first-child {
    margin-top: 0;
}

.a11y-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.a11y-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #f6f7fb;
    border: 1.5px solid transparent;
    border-radius: 12px;
    padding: 10px 6px;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--a11y-text);
    transition: all .18s ease;
    text-align: center;
    line-height: 1.25;
}

.a11y-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--a11y-accent-dark);
}

.a11y-btn:hover {
    background: #ecf1ff;
}

.a11y-btn:focus-visible {
    outline: 2px solid var(--a11y-accent);
    outline-offset: 1px;
}

.a11y-btn.active {
    background: var(--a11y-accent);
    border-color: var(--a11y-accent-dark);
    color: #fff;
}

.a11y-btn.active svg {
    fill: #fff;
}

.a11y-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f6f7fb;
    border-radius: 12px;
    padding: 6px 10px;
}

.a11y-stepper span {
    font-size: 12.5px;
    font-weight: 600;
}

.a11y-stepper .a11y-step-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.a11y-step-controls button {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: none;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
    font-size: 16px;
    font-weight: 700;
    color: var(--a11y-accent-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.a11y-step-controls button:hover {
    background: #ecf1ff;
}

.a11y-step-val {
    min-width: 32px;
    text-align: center;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--a11y-muted);
}

.a11y-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--a11y-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.a11y-reset-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #f6f7fb;
    border: none;
    border-radius: 10px;
    padding: 10px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    color: #ef4444;
    cursor: pointer;
}

.a11y-reset-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: #ef4444;
}

.a11y-reset-btn:hover {
    background: #fee2e2;
}

.a11y-statement {
    flex: 1;
    background: #f6f7fb;
    border-radius: 10px;
    padding: 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--a11y-accent-dark);
    text-decoration: none;
    text-align: center;
    cursor: pointer;
}

.a11y-statement:hover {
    background: #ecf1ff;
}

/* ---- Applied states on <html> ---- */
html.a11y-grayscale {
    filter: grayscale(1) !important;
}

html.a11y-contrast-dark body {
    background: #0b0b0e !important;
    color: #f5f5f5 !important;
}

html.a11y-contrast-dark body * {
    background-color: #0b0b0e !important;
    color: #f5f5f5 !important;
    border-color: #444 !important;
}

html.a11y-contrast-dark img,
html.a11y-contrast-dark video,
html.a11y-contrast-dark svg,
html.a11y-contrast-dark iframe {
    filter: brightness(.85) !important;
}

html.a11y-contrast-light body * {
    background-color: #fff !important;
    color: #111 !important;
    border-color: #000 !important;
}

html.a11y-high-saturation body {
    filter: saturate(1.6) !important;
}

html.a11y-low-saturation body {
    filter: saturate(.4) !important;
}

html.a11y-underline-links a {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
}

html.a11y-highlight-links a {
    outline: 2px solid #f59e0b !important;
    background: rgba(245, 158, 11, .18) !important;
}

html.a11y-highlight-headings h1,
html.a11y-highlight-headings h2,
html.a11y-highlight-headings h3,
html.a11y-highlight-headings h4,
html.a11y-highlight-headings h5,
html.a11y-highlight-headings h6 {
    outline: 2px dashed #2563eb !important;
    background: rgba(37, 99, 235, .1) !important;
}

html.a11y-readable-font body,
html.a11y-readable-font body * {
    font-family: Arial, Helvetica, sans-serif !important;
}

html.a11y-pause-animations *,
html.a11y-pause-animations *::before,
html.a11y-pause-animations *::after {
    animation-play-state: paused !important;
    transition: none !important;
    scroll-behavior: auto !important;
}

html.a11y-big-cursor,
html.a11y-big-cursor * {
    cursor: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24'%3E%3Cpath fill='%232563eb' stroke='%23fff' stroke-width='1' d='M3 2l7.07 16.97 2.51-6.94 6.94-2.51z'/%3E%3C/svg%3E") 2 2, auto !important;
}

#a11y-reading-guide {
    position: fixed;
    left: 0;
    right: 0;
    height: 40px;
    background: rgba(255, 235, 59, .35);
    border-top: 2px solid #f59e0b;
    border-bottom: 2px solid #f59e0b;
    pointer-events: none;
    z-index: 999997;
    display: none;
}

html.a11y-reading-guide-on #a11y-reading-guide {
    display: block;
}

html.a11y-hide-images img,
html.a11y-hide-images picture,
html.a11y-hide-images video {
    visibility: hidden !important;
}

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

/* ---- Mobile ---- */
@media (max-width: 480px) {
    #a11y-toggle-btn {
        width: 50px;
        height: 50px;
        bottom: 14px;
        inset-inline-end: 14px;
    }

    #a11y-panel {
        bottom: 0;
        inset-inline-end: 0;
        inset-inline-start: 0;
        width: 100%;
        max-width: 100%;
        max-height: 82vh;
        border-radius: 20px 20px 0 0;
    }

    #a11y-panel.open {
        transform: translateY(0);
    }

    .a11y-grid {
        grid-template-columns: 1fr 1fr;
    }
}
