/* 
 * Accessibility (WCAG 2.1 AA) Global Variables 
 */
:root {
  --a11y-bg: #1e293b; /* Restored Dark Tradition */
  --a11y-text: #f8fafc;
  --a11y-primary: var(--primary, #8b5cf6);
  --a11y-focus: var(--primary-hover, #fbbf24);
}

/* Skip to Main Content Link for Keyboard Users */
#a11y-skip-link {
    position: absolute;
    top: -100px;
    left: 20px;
    background: var(--a11y-primary);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 9999999;
    font-weight: bold;
    text-decoration: none;
    transition: top 0.2s ease;
}
#a11y-skip-link:focus {
    top: 20px;
    outline: 3px solid var(--a11y-focus);
    outline-offset: 3px;
}

/* Floating Action Button (FAB) */
.a11y-widget-toggle {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 3.5rem;
    height: 3.5rem;
    background-color: var(--a11y-primary);
    color: var(--a11y-text);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    z-index: 999999;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.2s, box-shadow 0.2s;
}
@media (min-width: 640px) {
    .a11y-widget-toggle {
        bottom: 2rem;
        right: 2rem;
        width: 4rem;
        height: 4rem;
    }
}
.a11y-widget-toggle svg {
    pointer-events: none;
}
.a11y-widget-toggle:focus-visible {
    outline: none;
    border-color: var(--a11y-focus);
    box-shadow: 0 0 0 5px rgba(251, 191, 36, 0.4);
}
.a11y-widget-toggle {
    transition: all 0.3s ease;
}
.a11y-widget-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    background-color: var(--primary-hover) !important;
    filter: brightness(1.05);
    color: #fff !important;
}

.a11y-widget-toggle[aria-expanded="true"] {
    background-color: var(--primary-hover) !important;
    box-shadow: 0 0 0 4px rgba(255,255,255,0.2);
}
.a11y-widget-toggle[aria-expanded="true"] svg {
    color: #ffffff !important;
    fill: #ffffff !important;
}

/* Main Accessibility Control Panel */
.a11y-panel {
    position: fixed;
    bottom: 5.5rem;
    right: 1rem;
    width: calc(100vw - 2rem);
    max-width: 360px;
    max-height: 80vh;
    overflow-y: auto;
    background-color: var(--a11y-bg);
    color: #ffffff !important; /* Force high contrast white */
    border-radius: 1rem;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 999999;
    padding: 1.25rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
    font-family: sans-serif;
}
.a11y-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.a11y-panel h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 0.5rem;
    font-weight: bold;
    color: #ffffff !important; /* Force heading white */
}
.a11y-grid {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 15px;
}
.a11y-grid-3 { grid-template-columns: repeat(3, 1fr); }
.a11y-grid-2 { grid-template-columns: repeat(2, 1fr); }

.a11y-category-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.6) !important; /* Soft white label */
    margin-bottom: 8px;
    font-weight: 600;
}

/* Interactive Buttons */
.a11y-btn {
    background: rgba(255,255,255,0.08); /* Slightly brighter for visibility */
    border: 1px solid rgba(255,255,255,0.1);
    color: #ffffff !important; /* Force button text white */
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1.2;
    text-align: center;
    transition: all 0.2s;
}
.a11y-btn:hover { 
    background: var(--primary-hover) !important; 
    color: #fff !important;
}

/* Reset Button - Specific Branding */
.a11y-btn-reset {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #ffffff !important;
    font-weight: bold;
    opacity: 0.9;
}
.a11y-btn-reset:hover {
    opacity: 1;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.a11y-btn.is-active {
    background: var(--a11y-primary);
    border-color: var(--a11y-primary);
    font-weight: bold;
}
.a11y-btn:focus-visible, .a11y-panel:focus-visible {
    outline: 2px solid var(--a11y-focus);
    outline-offset: 2px;
}

/* ==================================================
   STATE MODIFIERS APPLIED TO HTML ROOT 
   ================================================== */

html.a11y-high-contrast {
    filter: contrast(160%) saturate(120%) brightness(85%);
}
html.a11y-negative-contrast {
    filter: invert(100%) hue-rotate(180deg);
}
html.a11y-grayscale {
    filter: grayscale(100%);
}
/* Dyslexia override: Use established native fallbacks since we aren't loading external WOFF files synchronously */
html.a11y-dyslexic * {
    font-family: 'Comic Sans MS', 'OpenDyslexic', 'Arial', sans-serif !important;
}
/* Pause Animations overriding */
html.a11y-pause-animations * {
    animation-play-state: paused !important;
    transition: none !important;
    scroll-behavior: auto !important;
}
html.a11y-highlight-links a {
    text-decoration: underline !important;
    text-decoration-color: var(--a11y-focus) !important;
    text-decoration-thickness: 3px !important;
    background-color: #000 !important;
    color: var(--a11y-focus) !important;
}

/* ==================================================
   READING AIDS 
   ================================================== */
#a11y-reading-guide {
    position: fixed;
    left: 0; right: 0;
    height: 4px;
    background: var(--a11y-focus);
    z-index: 999998;
    pointer-events: none;
    display: none;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
#a11y-reading-mask-top, #a11y-reading-mask-bottom {
    position: fixed;
    left: 0; right: 0;
    background: rgba(0,0,0,0.85);
    z-index: 999997;
    pointer-events: none;
    display: none;
}
