/* ============================================================
   WCAG 2.1 AA – Accessibility Toolkit
   United Super Alliance Party (USAP)
   ============================================================
   Provides:
     1. Skip-to-content link
     2. Global focus-visible ring
     3. Floating accessibility panel (right-side drawer)
     4. Granular toggle controls (font size, contrast, spacing,
        animations, cursor, links, screen-reader helpers)
     5. Persistent user preferences via localStorage
   ============================================================ */

/* ---- 1. Skip-to-content ---- */
.a11y-skip {
    position: absolute;
    top: -100%;
    left: 16px;
    z-index: 100000;
    background: var(--primary-color, #6A2C91);
    color: #fff;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    text-decoration: none;
    transition: top 0.2s ease;
}
.a11y-skip:focus {
    top: 0;
    outline: 3px solid #FFD700;
    outline-offset: 2px;
}

/* ---- 2. Global focus ring (WCAG 2.4.7) ---- */
:focus-visible {
    outline: 3px solid var(--primary-color, #6A2C91);
    outline-offset: 2px;
}

/* ---- 3. Floating accessibility trigger button ---- */
.a11y-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99990;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--primary-color, #6A2C91);
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
.a11y-trigger:hover {
    background: var(--dark-violet, #4a1d63);
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
}
.a11y-trigger:focus-visible {
    outline: 3px solid #FFD700;
    outline-offset: 3px;
}
.a11y-trigger .a11y-trigger-icon {
    pointer-events: none;
    line-height: 1;
}

/* ---- 4. Panel (right-side drawer) ---- */
.a11y-panel-overlay {
    position: fixed;
    inset: 0;
    z-index: 99991;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.a11y-panel-overlay.open {
    opacity: 1;
    visibility: visible;
}

.a11y-panel {
    position: fixed;
    top: 0;
    right: -400px;
    z-index: 99992;
    width: 370px;
    max-width: 92vw;
    height: 100vh;
    background: #fff;
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}
.a11y-panel.open {
    right: 0;
}

/* Header */
.a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: var(--primary-color, #6A2C91);
    color: #fff;
    flex-shrink: 0;
}
.a11y-panel-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}
.a11y-panel-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
    line-height: 1;
}
.a11y-panel-close:hover {
    background: rgba(255, 255, 255, 0.2);
}
.a11y-panel-close:focus-visible {
    outline: 2px solid #FFD700;
}

/* Scrollable body */
.a11y-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 24px;
}

/* Section group */
.a11y-section {
    margin-bottom: 20px;
}
.a11y-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6c757d;
    margin: 0 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e9ecef;
}

/* Toggle row (each feature) */
.a11y-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    gap: 12px;
}
.a11y-row + .a11y-row {
    border-top: 1px solid #f0f0f0;
}
.a11y-row-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.92rem;
    font-weight: 500;
    color: #212529;
    flex: 1;
    min-width: 0;
}
.a11y-row-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.95rem;
    background: #f0edff;
    color: var(--primary-color, #6A2C91);
}

/* Custom toggle switch (WCAG-sized 44×24) */
.a11y-switch {
    position: relative;
    flex-shrink: 0;
    width: 46px;
    height: 26px;
}
.a11y-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.a11y-switch-track {
    position: absolute;
    inset: 0;
    background: #ced4da;
    border-radius: 13px;
    cursor: pointer;
    transition: background 0.2s;
}
.a11y-switch-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.a11y-switch input:checked + .a11y-switch-track {
    background: var(--primary-color, #6A2C91);
}
.a11y-switch input:checked + .a11y-switch-track::after {
    transform: translateX(20px);
}
.a11y-switch input:focus-visible + .a11y-switch-track {
    outline: 3px solid var(--primary-color, #6A2C91);
    outline-offset: 2px;
}

/* Font-size stepper */
.a11y-stepper {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.a11y-stepper button {
    width: 32px;
    height: 32px;
    border: 2px solid var(--primary-color, #6A2C91);
    border-radius: 6px;
    background: #fff;
    color: var(--primary-color, #6A2C91);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}
.a11y-stepper button:hover {
    background: var(--primary-color, #6A2C91);
    color: #fff;
}
.a11y-stepper button:focus-visible {
    outline: 3px solid #FFD700;
    outline-offset: 2px;
}
.a11y-stepper-value {
    min-width: 42px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #212529;
}

/* Reset button */
.a11y-panel-footer {
    padding: 14px 20px;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}
.a11y-reset-btn {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--danger-color, #dc3545);
    border-radius: 8px;
    background: #fff;
    color: var(--danger-color, #dc3545);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.a11y-reset-btn:hover {
    background: var(--danger-color, #dc3545);
    color: #fff;
}
.a11y-reset-btn:focus-visible {
    outline: 3px solid var(--danger-color, #dc3545);
    outline-offset: 2px;
}

/* ---- 5. Applied accessibility modes ---- */

/* Font scaling */
html.a11y-font-1 { font-size: 112.5%; }
html.a11y-font-2 { font-size: 125%; }
html.a11y-font-3 { font-size: 137.5%; }

/* High contrast */
body.a11y-high-contrast {
    filter: contrast(1.35);
}
body.a11y-high-contrast .card,
body.a11y-high-contrast .form-control,
body.a11y-high-contrast .form-select {
    border-width: 2px !important;
    border-color: #000 !important;
}

/* Line & letter spacing (WCAG 1.4.12) */
body.a11y-spacing {
    letter-spacing: 0.05em;
    word-spacing: 0.12em;
}
body.a11y-spacing p,
body.a11y-spacing li,
body.a11y-spacing td,
body.a11y-spacing label,
body.a11y-spacing .form-help-text {
    line-height: 2;
}

/* Pause animations (WCAG 2.3.1) */
body.a11y-pause-animations,
body.a11y-pause-animations * {
    animation-duration: 0s !important;
    animation-delay: 0s !important;
    transition-duration: 0s !important;
    scroll-behavior: auto !important;
}
body.a11y-pause-animations .carousel-item {
    transition: none !important;
}

/* Big cursor */
body.a11y-big-cursor,
body.a11y-big-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Cpath d='M5 2l20 14-9 2 5 10-4 2-5-10-7 7z' fill='%23000' stroke='%23fff' stroke-width='1.5'/%3E%3C/svg%3E") 5 2, auto !important;
}

/* Highlight links */
body.a11y-highlight-links a {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
    font-weight: 600 !important;
}
body.a11y-highlight-links a:hover {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Dyslexia-friendly font */
body.a11y-dyslexia-font,
body.a11y-dyslexia-font * {
    font-family: 'OpenDyslexic', 'Comic Sans MS', 'Arial', sans-serif !important;
    letter-spacing: 0.05em;
    word-spacing: 0.15em;
}

/* Reading guide (applied via JS overlay) */
.a11y-reading-guide {
    position: fixed;
    left: 0;
    width: 100%;
    height: 40px;
    border-top: 3px solid var(--primary-color, #6A2C91);
    border-bottom: 3px solid var(--primary-color, #6A2C91);
    background: rgba(106, 44, 145, 0.06);
    pointer-events: none;
    z-index: 99989;
    display: none;
    transition: top 0.05s linear;
}
body.a11y-reading-guide-on .a11y-reading-guide {
    display: block;
}

/* Screen-reader live region */
.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;
}

/* ---- 6. Responsive ---- */
@media (max-width: 480px) {
    .a11y-panel {
        width: 100vw;
    }
    .a11y-trigger {
        bottom: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
        font-size: 1.3rem;
    }
}
