/* ===== Accessibility toolbar ===== */
:root {
    --a11y-navy: #002147;
    --a11y-navy-2: #003366;
    --a11y-gold: #c9a227;
    --a11y-tile: #f6f7f9;
    --a11y-tile-border: #e3e6eb;
    --a11y-text: #1f2937;
}

#a11y-toggle {
    position: fixed;
    bottom: 22px;
    inset-inline-end: 22px;
    z-index: 99990;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: var(--a11y-navy);
    color: #fff;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 33, 71, .35);
    transition: transform .15s ease, background .15s ease;
}
#a11y-toggle:hover { background: var(--a11y-navy-2); transform: scale(1.06); }
#a11y-toggle:focus-visible,
#a11y-panel button:focus-visible { outline: 3px solid var(--a11y-gold); outline-offset: 2px; }
#a11y-toggle .a11y-dot {
    position: absolute;
    top: 2px;
    inset-inline-end: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--a11y-gold);
    border: 2px solid #fff;
    display: none;
}
#a11y-toggle.has-active .a11y-dot { display: block; }

#a11y-panel {
    position: fixed;
    bottom: 90px;
    inset-inline-end: 22px;
    z-index: 99991;
    width: 320px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
    font-family: 'Cairo', Tahoma, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--a11y-text);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
}
#a11y-panel.open { opacity: 1; visibility: visible; transform: none; }

#a11y-panel .a11y-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--a11y-navy);
    color: #fff;
    padding: 12px 16px;
    border-radius: 16px 16px 0 0;
    position: sticky;
    top: 0;
}
#a11y-panel .a11y-head h2 { margin: 0; font-size: 16px; font-weight: 700; color: #fff; }
#a11y-panel .a11y-close {
    background: none;
    border: 0;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
}
#a11y-panel .a11y-close:hover { background: rgba(255, 255, 255, .12); }

#a11y-panel .a11y-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 14px;
}
#a11y-panel .a11y-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 82px;
    padding: 12px 8px;
    background: var(--a11y-tile);
    border: 1.5px solid var(--a11y-tile-border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    color: var(--a11y-text);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
#a11y-panel .a11y-tile:hover { border-color: var(--a11y-navy-2); }
#a11y-panel .a11y-tile i { font-size: 20px; color: var(--c, var(--a11y-navy)); }
#a11y-panel .a11y-tile[aria-pressed="true"] {
    background: #eef3fa;
    border-color: var(--a11y-navy);
    box-shadow: inset 0 0 0 1px var(--a11y-navy);
}
#a11y-panel .a11y-tile[aria-pressed="true"]::after {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    top: 6px;
    inset-inline-start: 8px;
    font-size: 11px;
    color: #fff;
    background: var(--a11y-navy);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
#a11y-panel .a11y-level { display: flex; gap: 4px; }
#a11y-panel .a11y-level span { width: 14px; height: 4px; border-radius: 2px; background: #cfd5dd; }
#a11y-panel .a11y-level span.on { background: var(--a11y-navy); }

#a11y-panel .a11y-reset {
    display: block;
    width: calc(100% - 28px);
    margin: 0 14px 14px;
    padding: 11px;
    background: #fdecec;
    border: 1.5px solid #f5c2c2;
    border-radius: 12px;
    color: #b42318;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
#a11y-panel .a11y-reset:hover { background: #fbdcdc; }

#a11y-toast {
    position: fixed;
    bottom: 96px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99992;
    background: var(--a11y-navy);
    color: #fff;
    padding: 10px 18px;
    border-radius: 10px;
    font-family: 'Cairo', Tahoma, sans-serif;
    font-size: 14px;
    max-width: calc(100vw - 32px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
#a11y-toast.show { opacity: 1; }

/* Reading ruler */
#a11y-ruler {
    position: fixed;
    left: 0;
    right: 0;
    height: 44px;
    z-index: 99980;
    pointer-events: none;
    display: none;
    border-top: 3px solid var(--a11y-gold);
    border-bottom: 3px solid var(--a11y-gold);
    background: rgba(201, 162, 39, .10);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
}
html.a11y-ruler #a11y-ruler { display: block; }

/* ===== Modes (scoped to page content so the toolbar itself is unaffected) ===== */

/* High contrast */
html.a11y-contrast body,
html.a11y-contrast :is(header, #main, footer),
html.a11y-contrast :is(header, #main, footer) * {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
    text-shadow: none !important;
    box-shadow: none !important;
}
html.a11y-contrast :is(header, #main, footer) a,
html.a11y-contrast :is(header, #main, footer) a * { color: #ffe600 !important; }
html.a11y-contrast :is(header, #main, footer) :is(img, video, iframe) { filter: contrast(1.1); }

/* Grayscale */
html.a11y-grayscale :is(header, #main, footer) { filter: grayscale(1); }

/* Highlight links */
html.a11y-links :is(header, #main, footer) a {
    text-decoration: underline !important;
    text-underline-offset: 3px;
    outline: 2px solid #c9a227 !important;
    outline-offset: 2px;
    background-color: rgba(255, 230, 0, .25) !important;
}

/* Readable font (keep icon fonts intact) */
html.a11y-font :is(header, #main, footer) *:not(i):not([class*="fa-"]):not(.fa):not([class*="material-symbols"]):not([class*="icon"]) {
    font-family: Tahoma, Arial, sans-serif !important;
}

/* Text spacing (no letter-spacing: it breaks Arabic joining) */
html.a11y-spacing :is(header, #main, footer) :is(p, li, span, a, td, th, div, h1, h2, h3, h4, h5, h6, label) {
    line-height: 1.9 !important;
    word-spacing: .16em !important;
}
html.a11y-spacing :is(header, #main, footer) p { margin-bottom: 1.2em !important; }

/* Stop animations */
html.a11y-motion *,
html.a11y-motion *::before,
html.a11y-motion *::after {
    animation-duration: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
    scroll-behavior: auto !important;
}

/* Big cursor */
html.a11y-cursor,
html.a11y-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M6 3l30 24-13 2 8 15-6 3-8-15-11 9z' fill='%23000' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E") 6 3, auto !important;
}
html.a11y-cursor :is(a, button, [role="button"]),
html.a11y-cursor :is(a, button, [role="button"]) * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M6 3l30 24-13 2 8 15-6 3-8-15-11 9z' fill='%23c9a227' stroke='%23000' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E") 6 3, pointer !important;
}

/* Text-to-speech: show what is readable */
html.a11y-tts :is(#main, footer) :is(p, h1, h2, h3, h4, h5, h6, li, td, a, span):hover {
    outline: 2px dashed #c9a227;
    outline-offset: 2px;
}
.a11y-speaking { background-color: rgba(201, 162, 39, .3) !important; }

@media (max-width: 480px) {
    #a11y-toggle { bottom: 16px; inset-inline-end: 16px; width: 50px; height: 50px; font-size: 23px; }
    #a11y-panel { bottom: 76px; inset-inline-end: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    #a11y-panel, #a11y-toggle { transition: none; }
}
