/* Main Widget Container */
.wcag-widget-container {
    position: fixed !important;
    bottom: 20px !important;
    bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    right: 20px !important;
    z-index: 2147483647 !important;
    /* Max allowed z-index to ensure it stays on top */
    font-family: 'Arial', sans-serif;
    font-size: 16px;
}

/* Floating Toggle Button */
.wcag-toggle-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background-color: #0056b3;
    color: #ffffff;
    border: 2px solid #ffffff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    transition: transform 0.3s ease, background-color 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
    touch-action: manipulation;
}

.wcag-toggle-btn .dashicons {
    font-size: 40px;
    width: auto;
    height: auto;
}

.wcag-toggle-btn:hover,
.wcag-toggle-btn:focus {
    background-color: #003d80;
    transform: scale(1.1);
    outline: 3px solid #ffcc00;
    /* High visibility focus */
}

/* Accessibility Panel */
.wcag-panel {
    position: absolute;
    bottom: 85px;
    /* Adjusted for larger button */
    right: 0;
    width: 280px;
    /* Slightly narrower */
    background-color: #ffffff;
    border: 2px solid #0056b3;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    display: none;
    /* Hidden by default */
    flex-direction: column;
    padding: 12px;
    color: #333;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

.wcag-panel.active {
    display: flex;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom scrollbar for the panel */
.wcag-panel::-webkit-scrollbar {
    width: 6px;
}
.wcag-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}
.wcag-panel::-webkit-scrollbar-thumb {
    background: #0056b3;
    border-radius: 10px;
}
.wcag-panel::-webkit-scrollbar-thumb:hover {
    background: #003d80;
}

/* Panel Header */
.wcag-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #eee;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.wcag-panel-header h3 {
    margin: 0;
    font-size: 18px;
    color: #0056b3;
}

.wcag-close-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #333;
}

.wcag-close-btn:hover,
.wcag-close-btn:focus {
    color: #d9534f;
    outline: 2px solid #ffcc00;
}

/* Tools Grid */
.wcag-tools-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.wcag-tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 8px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    min-height: 70px;
}

.wcag-tool-btn .icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.wcag-tool-btn .label {
    font-size: 13px;
    text-align: center;
    line-height: 1.2;
}

/* Only apply hover on devices that truly support it */
@media (hover: hover) {
    .wcag-tool-btn:hover {
        background-color: #e2e6ea;
        border-color: #0056b3;
        outline: 2px solid #ffcc00;
    }
}

/* Focus styles - mainly for keyboard navigation */
.wcag-tool-btn:focus-visible {
    background-color: #e2e6ea;
    border-color: #0056b3;
    outline: 2px solid #ffcc00;
}

/* Remove styled focus for mouse/touch clicks to prevent "stuck" highlight */
.wcag-tool-btn:focus:not(:focus-visible) {
    outline: none;
}

.wcag-tool-btn.active {
    background-color: #0056b3 !important;
    color: #ffffff !important;
    border-color: #004494 !important;
}

.wcag-tool-btn.full-width {
    grid-column: span 2;
}

/* 
   ---------------------------
   Global Accessibility Styles 
   (Applied to body or overlay)
   ---------------------------
*/

/* Filter Overlay (Backdrop Filter) */
.wcag-filter-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Click-through */
    z-index: 2147483646;
    /* Just below widget (MAX-1) */
    display: none;
}

/* Grayscale */
body.wcag-grayscale .wcag-filter-overlay {
    display: block;
    backdrop-filter: grayscale(100%);
    -webkit-backdrop-filter: grayscale(100%);
}

/* Fallback for browsers without backdrop-filter? */
/* We can't use body filter because it breaks fixed positioning. Acceptance: Grayscale might not work on very old browsers, but widget stays fixed. */


/* High Contrast */
body.wcag-high-contrast * {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

body.wcag-high-contrast img,
body.wcag-high-contrast svg {
    filter: brightness(0.8) contrast(1.2) !important;
}

/* Negative Contrast */
body.wcag-negative-contrast .wcag-filter-overlay {
    display: block;
    backdrop-filter: invert(100%);
    -webkit-backdrop-filter: invert(100%);
}

body.wcag-negative-contrast img,
body.wcag-negative-contrast video {
    filter: invert(100%) !important;
    /* Re-invert media to look normal-ish */
}

/* Light Background */
body.wcag-light-background {
    background-color: #ffffff !important;
    color: #000000 !important;
}

body.wcag-light-background * {
    background-color: #ffffff !important;
    color: #000000 !important;
}

/* Underline Links */
body.wcag-underline-links a {
    text-decoration: underline !important;
}

/* Readable Font */
body.wcag-readable-font {
    font-family: 'Arial', 'Helvetica', sans-serif !important;
    letter-spacing: 0.05em !important;
    word-spacing: 0.1em !important;
    line-height: 1.6 !important;
}

body.wcag-readable-font h1,
body.wcag-readable-font h2,
body.wcag-readable-font h3,
body.wcag-readable-font h4,
body.wcag-readable-font h5,
body.wcag-readable-font h6 {
    font-family: 'Arial', 'Helvetica', sans-serif !important;
}

/* Big Cursor */
body.wcag-big-cursor,
body.wcag-big-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 24 24' fill='%23000000' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z'/%3E%3C/svg%3E"), auto !important;
}

/* Reading Guide */
#wcag-reading-guide {
    position: fixed;
    left: 0;
    width: 100%;
    height: 60px;
    /* Wysokość obszaru czytania (ok. 2-3 linie tekstu) */
    background-color: transparent !important;
    /* Przezroczyste wnętrze */
    border-top: 2px solid #ffcc00;
    border-bottom: 2px solid #ffcc00;
    border-left: none;
    border-right: none;
    pointer-events: none;
    /* Umożliwia klikanie przez maskę */
    z-index: 2147483647;
    /* Najwyższa warstwa */
    transform: translateY(-50%);
    box-shadow: 0 0 0 9999vh rgba(0, 0, 0, 0.6);
    /* Przyciemnienie reszty ekranu */
}

/* TTS Reading Highlight */
.wcag-reading-highlight {
    background-color: rgba(255, 255, 0, 0.3) !important;
    outline: 2px solid #ffcc00 !important;
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

/* TTS Active Cursor Mode (Desktop) */
body.wcag-tts-active {
    cursor: help !important;
}

body.wcag-tts-active p,
body.wcag-tts-active h1,
body.wcag-tts-active h2,
body.wcag-tts-active h3,
body.wcag-tts-active h4,
body.wcag-tts-active h5,
body.wcag-tts-active h6,
body.wcag-tts-active li,
body.wcag-tts-active span,
body.wcag-tts-active div,
body.wcag-tts-active a,
body.wcag-tts-active img {
    cursor: help !important;
}

/* Reset Cursor for Widget interactions */
body.wcag-tts-active .wcag-widget-container,
body.wcag-tts-active .wcag-widget-container * {
    cursor: default !important;
}

body.wcag-tts-active .wcag-tool-btn {
    cursor: pointer !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .wcag-widget-container {
        right: 15px;
        bottom: 15px;
        bottom: calc(15px + env(safe-area-inset-bottom));
    }

    .wcag-toggle-btn {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .wcag-panel {
        width: calc(100vw - 30px);
        /* Full width minus margins */
        right: auto;
        /* Offset to align with screen edge if needed, or adjust based on container position */
        bottom: 65px;
        bottom: calc(65px + env(safe-area-inset-bottom));
        position: fixed;
        /* Fixed relative to screen, not container */
        left: 15px;
        /* Center horizontally */
        max-height: 70vh;
        overflow-y: auto;
        z-index: 10001;
        /* Above toggle button if needed, or same level */
    }

    .wcag-tools-grid {
        grid-template-columns: 1fr 1fr;
    }

    .wcag-tool-btn {
        min-height: 70px;
        /* Smaller touch targets if needed, but 70px is good */
    }
}

/* Hide Big Cursor on Touch Devices */
@media (hover: none) and (pointer: coarse) {
    [data-action="big-cursor"] {
        display: none !important;
    }
}