/* ============================================================
   Accessibility Widget - أداة إمكانية الوصول
   ============================================================ */

/* ---- Toggle Button ---- */
#accessibility-toggle {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 99999;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #1a1a2e;
    border: 2px solid #3b82f6;
    cursor: pointer;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35), 0 3px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    outline: none;
    padding: 0;
}

[dir="rtl"] #accessibility-toggle {
    left: 30px;
    right: auto;
}

#accessibility-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.5), 0 4px 16px rgba(0, 0, 0, 0.35);
}

#accessibility-toggle svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

#accessibility-toggle .acc-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #f59e0b;
    font-size: 9px;
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    opacity: 0;
    transition: opacity 0.3s;
}

#accessibility-toggle.acc-active .acc-badge {
    opacity: 1;
}

/* ---- Panel ---- */
#accessibility-panel {
    position: fixed;
    bottom: 100px;
    left: 30px;
    z-index: 99998;
    width: 310px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

[dir="rtl"] #accessibility-panel {
    left: 30px;
    right: auto;
}

#accessibility-panel.acc-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* ---- Panel Header ---- */
.acc-panel-header {
    background: linear-gradient(135deg, #1a56a4, #2e7fd9);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.acc-panel-header h3 {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.acc-panel-header h3 svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

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

.acc-close-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* ---- Panel Body ---- */
.acc-panel-body {
    padding: 14px;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

.acc-panel-body::-webkit-scrollbar {
    width: 4px;
}

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

/* ---- Section Title ---- */
.acc-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    margin: 10px 0 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid #f1f5f9;
}

/* ---- Grid of Buttons ---- */
.acc-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 6px;
}

.acc-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 10px 6px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 10px;
    color: #475569;
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
    position: relative;
    outline: none;
}

.acc-btn svg {
    width: 22px;
    height: 22px;
    fill: #64748b;
    transition: fill 0.2s;
    flex-shrink: 0;
}

.acc-btn:hover {
    border-color: #1a56a4;
    background: #eff6ff;
    color: #1a56a4;
}

.acc-btn:hover svg {
    fill: #1a56a4;
}

.acc-btn.acc-btn-active {
    border-color: #1a56a4;
    background: #1a56a4;
    color: #fff;
}

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

/* ---- Font Size Control ---- */
.acc-font-control {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 6px;
}

.acc-font-control label {
    font-size: 11px;
    color: #475569;
    font-weight: 600;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

.acc-font-control label svg {
    width: 18px;
    height: 18px;
    fill: #64748b;
}

.acc-font-control .acc-stepper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.acc-stepper button {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #1a56a4;
    background: #fff;
    color: #1a56a4;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s;
    outline: none;
}

.acc-stepper button:hover {
    background: #1a56a4;
    color: #fff;
}

.acc-stepper .acc-font-val {
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
    min-width: 28px;
    text-align: center;
}

/* ---- Color Scheme Picker ---- */
.acc-color-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.acc-color-dot {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    outline: none;
}

.acc-color-dot:hover,
.acc-color-dot.acc-color-active {
    border-color: #1a56a4;
    transform: scale(1.15);
}

.acc-color-dot[data-scheme="default"] {
    background: linear-gradient(135deg, #1a56a4, #2e7fd9);
}

.acc-color-dot[data-scheme="high-contrast-black"] {
    background: #000000;
}

.acc-color-dot[data-scheme="high-contrast-yellow"] {
    background: #f5e642;
}

.acc-color-dot[data-scheme="night"] {
    background: #1e293b;
}

.acc-color-dot[data-scheme="inverted"] {
    background: linear-gradient(135deg, #0ff, #ff0);
}

.acc-color-dot[data-scheme="brownish"] {
    background: #8B4513;
}

/* ---- Reset Button ---- */
.acc-reset-btn {
    width: 100%;
    padding: 10px;
    border: 2px solid #ef4444;
    border-radius: 10px;
    background: #fff;
    color: #ef4444;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
    margin-top: 8px;
    outline: none;
}

.acc-reset-btn svg {
    width: 16px;
    height: 16px;
    fill: #ef4444;
    transition: fill 0.2s;
}

.acc-reset-btn:hover {
    background: #ef4444;
    color: #fff;
}

.acc-reset-btn:hover svg {
    fill: #fff;
}

/* ---- Panel Footer ---- */
.acc-panel-footer {
    padding: 8px 14px;
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
    border-top: 1px solid #f1f5f9;
    flex-shrink: 0;
}

/* ============================================================
   Accessibility STATE CLASSES applied to <html> or <body>
   ============================================================ */

/* Larger cursor */
body.acc-big-cursor,
body.acc-big-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cpath d='M5 2l30 18-14 2-8 14z' fill='%231a56a4' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 5 2, auto !important;
}

/* Highlight Links */
body.acc-highlight-links a {
    background: #ffff00 !important;
    color: #000 !important;
    text-decoration: underline !important;
    outline: 2px solid #ff6600 !important;
    border-radius: 2px;
}

/* Reading Guide */
#acc-reading-guide {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 60px;
    background: rgba(255, 255, 0, 0.15);
    border-top: 2px solid rgba(255, 165, 0, 0.8);
    border-bottom: 2px solid rgba(255, 165, 0, 0.8);
    pointer-events: none;
    z-index: 999999;
    display: none;
}

body.acc-reading-guide-on #acc-reading-guide {
    display: block;
}

/* Readable Font */
body.acc-readable-font,
body.acc-readable-font * {
    font-family: Arial, Helvetica, sans-serif !important;
    letter-spacing: 0.03em !important;
    word-spacing: 0.1em !important;
}

/* High Contrast - Black */
body.acc-scheme-high-contrast-black {
    background: #000 !important;
    color: #fff !important;
}

body.acc-scheme-high-contrast-black *:not(#accessibility-panel):not(#accessibility-panel *):not(#accessibility-toggle):not(#accessibility-toggle *):not(#acc-reading-guide) {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
}

body.acc-scheme-high-contrast-black a {
    color: #ff0 !important;
}

/* High Contrast - Yellow */
body.acc-scheme-high-contrast-yellow {
    background: #f5e642 !important;
    color: #000 !important;
}

body.acc-scheme-high-contrast-yellow *:not(#accessibility-panel):not(#accessibility-panel *):not(#accessibility-toggle):not(#accessibility-toggle *):not(#acc-reading-guide) {
    background-color: #f5e642 !important;
    color: #000 !important;
    border-color: #000 !important;
}

/* Night / Dark Mode */
body.acc-scheme-night {
    background: #0f172a !important;
    color: #e2e8f0 !important;
}

body.acc-scheme-night *:not(#accessibility-panel):not(#accessibility-panel *):not(#accessibility-toggle):not(#accessibility-toggle *):not(#acc-reading-guide) {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
    border-color: #334155 !important;
}

/* Inverted */
body.acc-scheme-inverted {
    filter: invert(100%) hue-rotate(180deg);
}

body.acc-scheme-inverted img,
body.acc-scheme-inverted video,
body.acc-scheme-inverted iframe {
    filter: invert(100%) hue-rotate(180deg);
}

/* Don't invert the widget itself */
body.acc-scheme-inverted #accessibility-panel,
body.acc-scheme-inverted #accessibility-toggle {
    filter: invert(100%) hue-rotate(180deg);
}

/* Brownish (sepia-like) */
body.acc-scheme-brownish {
    filter: sepia(80%);
}

body.acc-scheme-brownish #accessibility-panel,
body.acc-scheme-brownish #accessibility-toggle {
    filter: sepia(0%);
}

/* Text Spacing */
body.acc-text-spacing * {
    letter-spacing: 0.12em !important;
    word-spacing: 0.2em !important;
    line-height: 1.9 !important;
}

/* Animations Off */
body.acc-stop-animations *,
body.acc-stop-animations *::before,
body.acc-stop-animations *::after {
    animation: none !important;
    transition: none !important;
}

/* Dyslexia Font */
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/OpenDyslexic-Regular.otf') format('opentype');
    font-weight: normal;
}

body.acc-dyslexia-font,
body.acc-dyslexia-font *:not(#accessibility-panel):not(#accessibility-panel *) {
    font-family: 'OpenDyslexic', Arial, sans-serif !important;
}

/* Focus Indicators */
body.acc-focus-visible *:focus {
    outline: 3px solid #f59e0b !important;
    outline-offset: 2px !important;
}

/* Muted colors / Saturation */
body.acc-mute-colors {
    filter: saturate(0.2);
}

body.acc-mute-colors #accessibility-panel,
body.acc-mute-colors #accessibility-toggle {
    filter: saturate(1);
}

/* Hide images */
body.acc-hide-images img:not(#accessibility-panel img) {
    visibility: hidden !important;
}

/* Tooltip on acc buttons */
.acc-btn[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 999;
}

/* Skip to content link */
#acc-skip-link {
    position: fixed;
    top: -100px;
    left: 20px;
    z-index: 999999;
    background: #1a56a4;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    text-decoration: none;
    transition: top 0.3s;
}

#acc-skip-link:focus {
    top: 10px;
}

[dir="rtl"] #acc-skip-link {
    left: auto;
    right: 20px;
}

/* Mobile responsive */
@media (max-width: 480px) {
    #accessibility-panel {
        width: calc(100vw - 20px);
        left: 10px;
        right: 10px;
        bottom: 70px;
    }

    [dir="rtl"] #accessibility-panel {
        left: 10px;
        right: 10px;
    }

    #accessibility-toggle {
        bottom: 20px;
        left: 20px;
    }

    [dir="rtl"] #accessibility-toggle {
        left: 20px;
        right: auto;
    }
}