/*
 * Accessibility Widget Stylesheet
 * Integrates customization tools and WCAG-compliant overrides.
 */

:root {
    --a11y-primary: #4364F7;
    --a11y-primary-hover: #3b59db;
    --a11y-bg: rgba(255, 255, 255, 0.85);
    --a11y-text: #1e293b;
    --a11y-border: rgba(0, 0, 0, 0.08);
    --a11y-shadow: 0 12px 30px rgba(0, 0, 0, 0.08), 0 2px 10px rgba(0, 0, 0, 0.04);
    --a11y-radius: 16px;
    --a11y-font-scale: 1;
    --a11y-letter-spacing: normal;
    --a11y-word-spacing: normal;
    --a11y-line-height: normal;
}

/* Base styles for the widget launcher & panel */
.a11y-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--a11y-primary);
    color: #ffffff;
    box-shadow: 0 1px 10px rgb(255 255 255 / 35%);
    cursor: pointer;
    z-index: 2147483640 !important;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
    outline: none;
}

.a11y-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 12px rgb(255 255 255 / 45%);
}

.a11y-launcher:focus-visible {
    outline: 3px solid #ffeb3b;
    outline-offset: 3px;
}

.a11y-launcher svg {
    width: 32px;
    height: 32px;
    fill: currentColor;
}

/* Floating widget panel styling */
.a11y-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 140px);
    background: var(--a11y-bg);
    color: var(--a11y-text);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--a11y-radius);
    box-shadow: var(--a11y-shadow);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 2147483645 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.a11y-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.a11y-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--a11y-border);
}

.a11y-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--a11y-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.a11y-header svg {
    width: 20px;
    height: 20px;
    fill: var(--a11y-primary);
}

.a11y-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--a11y-text);
    opacity: 0.6;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.2s;
    border-radius: 50%;
}

.a11y-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}

.a11y-close svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Body / Sections */
.a11y-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.a11y-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.a11y-section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--a11y-text);
    opacity: 0.6;
    margin: 0 0 4px 0;
}

/* Controls inside sections */
.a11y-control-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.a11y-control-card {
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid var(--a11y-border);
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
    position: relative;
    user-select: none;
}

.a11y-control-card:hover {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(67, 100, 247, 0.2);
}

.a11y-control-card.active {
    background: rgba(67, 100, 247, 0.06);
    border-color: var(--a11y-primary);
}

.a11y-control-card:focus-visible {
    outline: 2px solid var(--a11y-primary);
    outline-offset: 1px;
}

.a11y-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.a11y-card-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--a11y-primary);
}

.a11y-control-card.active .a11y-card-icon {
    background: var(--a11y-primary);
    color: #ffffff;
}

.a11y-card-icon svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.a11y-card-title {
    font-size: 13px;
    font-weight: 600;
}

/* Range sliders / multi-step controls */
.a11y-range-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid var(--a11y-border);
    border-radius: 12px;
    padding: 12px;
}

.a11y-range-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
}

.a11y-range-value {
    color: var(--a11y-primary);
    font-weight: 700;
}

.a11y-range-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.08);
    outline: none;
    margin: 8px 0;
}

.a11y-range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--a11y-primary);
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.a11y-range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

/* Segmented selector */
.a11y-segmented {
    display: flex;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 10px;
    padding: 2px;
    width: 100%;
}

.a11y-segmented-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--a11y-text);
    transition: background 0.2s, color 0.2s;
    outline: none;
}

.a11y-segmented-btn.active {
    background: #ffffff;
    color: var(--a11y-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.a11y-segmented-btn:focus-visible {
    outline: 2px solid var(--a11y-primary);
}

/* Footer / Reset button */
.a11y-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--a11y-border);
    display: flex;
    gap: 10px;
}

.a11y-btn {
    flex: 1;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: transform 0.1s, filter 0.2s;
    outline: none;
}

.a11y-btn:active {
    transform: scale(0.98);
}

.a11y-btn-reset {
    background: rgba(0, 0, 0, 0.05);
    color: var(--a11y-text);
}

.a11y-btn-reset:hover {
    background: rgba(0, 0, 0, 0.08);
}

.a11y-btn-statement {
    background: var(--a11y-primary);
    color: #ffffff;
}

.a11y-btn-statement:hover {
    filter: brightness(1.06);
}

/* Accessibility Statement Modal inside WordPress or frontend */
.a11y-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.a11y-modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.a11y-modal {
    background: #ffffff;
    color: #1e293b;
    border-radius: 20px;
    width: 550px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 80px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.a11y-modal-backdrop.open .a11y-modal {
    transform: scale(1);
}

.a11y-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.a11y-modal-header h4 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.a11y-modal-body {
    padding: 24px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.a11y-modal-body h5 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.a11y-modal-body p {
    margin: 0;
}

.a11y-modal-body ul {
    margin: 0;
    padding-left: 20px;
}

.a11y-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    justify-content: flex-end;
}

/* ==========================================================================
   SITE EFFECT OVERRIDES (Applied via body classes)
   ========================================================================== */

body.a11y-active {
    transition: letter-spacing 0.2s, word-spacing 0.2s, line-height 0.2s;
}

/* Dyslexia-Friendly Font Override */
body.a11y-dyslexia {
    font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important;
}
body.a11y-dyslexia * {
    font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important;
}

/* Spacing Override Options */
body.a11y-spacing-moderate {
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
    line-height: 1.65 !important;
}
body.a11y-spacing-moderate * {
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
    line-height: 1.65 !important;
}

body.a11y-spacing-maximum {
    letter-spacing: 0.15em !important;
    word-spacing: 0.25em !important;
    line-height: 1.85 !important;
}
body.a11y-spacing-maximum * {
    letter-spacing: 0.15em !important;
    word-spacing: 0.25em !important;
    line-height: 1.85 !important;
}



/* Keep widget from scaling font-size itself */
.a11y-panel, .a11y-launcher, .a11y-modal-backdrop {
    font-size: 14px !important;
}
.a11y-panel *, .a11y-launcher *, .a11y-modal-backdrop * {
    font-size: unset !important;
    letter-spacing: normal !important;
    word-spacing: normal !important;
    line-height: normal !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}
.a11y-panel .a11y-card-title { font-size: 13px !important; }
.a11y-panel .a11y-range-label { font-size: 13px !important; }
.a11y-panel .a11y-section-title { font-size: 11px !important; }
.a11y-panel h3 { font-size: 18px !important; }

/* Contrast Modes */
/* 1. Sleek Dark Mode Override */
body.a11y-contrast-dark {
    background: #0f172a !important;
    color: #f1f5f9 !important;
}
body.a11y-contrast-dark *:not(.a11y-launcher):not(.a11y-panel):not(.a11y-panel *):not(.a11y-modal-backdrop):not(.a11y-modal-backdrop *) {
    background-color: transparent !important;
    color: #f1f5f9 !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
}
body.a11y-contrast-dark a:not(.a11y-launcher):not(.a11y-panel *) {
    color: #60a5fa !important;
    text-decoration: underline !important;
}

/* 2. High Contrast (Yellow on Black) */
body.a11y-contrast-high {
    background: #000000 !important;
    color: #ffff00 !important;
}
body.a11y-contrast-high *:not(.a11y-launcher):not(.a11y-panel):not(.a11y-panel *):not(.a11y-modal-backdrop):not(.a11y-modal-backdrop *) {
    background-color: #000000 !important;
    color: #ffff00 !important;
    border-color: #ffff00 !important;
    outline-color: #ffff00 !important;
}
body.a11y-contrast-high a:not(.a11y-launcher):not(.a11y-panel *) {
    color: #ffff00 !important;
    text-decoration: underline !important;
    font-weight: bold !important;
}

/* 3. Inverted Colors (Applying filters with safety for media elements) */
html.a11y-contrast-inverted {
    filter: invert(1) hue-rotate(180deg) !important;
}
html.a11y-contrast-inverted img,
html.a11y-contrast-inverted video,
html.a11y-contrast-inverted iframe,
html.a11y-contrast-inverted .a11y-launcher,
html.a11y-contrast-inverted .a11y-panel,
html.a11y-contrast-inverted .a11y-modal-backdrop {
    filter: invert(1) hue-rotate(180deg) !important; /* Re-invert media back to original */
}

/* 4. Monochrome/Grayscale */
html.a11y-contrast-grayscale {
    filter: grayscale(1) !important;
}

/* Highlight Links only */
body.a11y-highlight-links a {
    outline: 2px solid #000000 !important;
    outline-offset: 1px !important;
    background-color: #ffeb3b !important;
    color: #000000 !important;
    text-decoration: underline !important;
    font-weight: bold !important;
}

/* Content Highlighting */
body.a11y-highlight a {
    outline: 3px solid #f59e0b !important;
    outline-offset: 2px !important;
    background-color: rgba(245, 158, 11, 0.15) !important;
    color: inherit !important;
}
body.a11y-highlight button,
body.a11y-highlight [role="button"],
body.a11y-highlight input[type="button"],
body.a11y-highlight input[type="submit"] {
    outline: 3px solid #ef4444 !important;
    outline-offset: 2px !important;
    background-color: rgba(239, 68, 68, 0.15) !important;
}
body.a11y-highlight h1,
body.a11y-highlight h2,
body.a11y-highlight h3,
body.a11y-highlight h4,
body.a11y-highlight h5,
body.a11y-highlight h6 {
    border-left: 6px solid var(--a11y-primary) !important;
    padding-left: 8px !important;
    background: rgba(67, 100, 247, 0.05) !important;
}

/* Animation Pausing */
body.a11y-pause * {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
    scroll-behavior: auto !important;
}

/* Image Hiding */
body.a11y-hide-images img,
body.a11y-hide-images [style*="background-image"] {
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Oversized Cursors */
/* Large Black Cursor with White Outline */
body.a11y-cursor-large,
body.a11y-cursor-large * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 32 32'%3E%3Cpath d='M0,0 L0,24 L6,18 L12,30 L16,28 L10,15 L17,15 Z' fill='black' stroke='white' stroke-width='2'/%3E%3C/svg%3E"), auto !important;
}

/* Large Yellow Cursor with Black Outline */
body.a11y-cursor-yellow,
body.a11y-cursor-yellow * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 32 32'%3E%3Cpath d='M0,0 L0,24 L6,18 L12,30 L16,28 L10,15 L17,15 Z' fill='%23ffff00' stroke='black' stroke-width='2'/%3E%3C/svg%3E"), auto !important;
}

/* Floating Keyboard Focus Ring */
#a11y-focus-ring {
    position: fixed;
    pointer-events: none;
    z-index: 10000002; /* Higher than skip links and widget elements */
    border: 3px solid #ef4444 !important;
    box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.3) !important;
    transition: top 0.1s ease, left 0.1s ease, width 0.1s ease, height 0.1s ease, opacity 0.1s ease, border-radius 0.1s ease;
    opacity: 0;
    display: none;
    box-sizing: border-box !important;
}

/* Skip Link styling */
.a11y-skip-link {
    position: fixed;
    top: -100px;
    left: 20px;
    background: var(--a11y-primary);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 1000001;
    font-weight: 700;
    box-shadow: 0 10px 25px rgba(67, 100, 247, 0.25);
    text-decoration: none;
    transition: top 0.2s ease;
}

.a11y-skip-link:focus {
    top: 20px;
}

/* Reading Mask overlays */
.a11y-reading-mask-top,
.a11y-reading-mask-bottom {
    position: fixed;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.7);
    pointer-events: none;
    z-index: 999998;
    transition: height 0.05s linear, top 0.05s linear;
}

.a11y-reading-mask-top {
    top: 0;
}

.a11y-reading-mask-bottom {
    bottom: 0;
}

/* Reading Line */
.a11y-reading-line {
    position: fixed;
    left: 0;
    right: 0;
    height: 4px;
    background: #ef4444;
    box-shadow: 0 0 10px #ef4444;
    pointer-events: none;
    z-index: 999998;
    transition: top 0.05s linear;
}

/* Dark Mode Widget Overrides (When client browser or contrast mode dark is active) */
@media (prefers-color-scheme: dark) {
    :root:not(.a11y-light-widget) {
        --a11y-bg: rgba(28, 28, 30, 0.85);
        --a11y-text: #f8fafc;
        --a11y-border: rgba(255, 255, 255, 0.08);
    }
    .a11y-control-card {
        background: rgba(255, 255, 255, 0.05);
    }
    .a11y-control-card:hover {
        background: rgba(255, 255, 255, 0.1);
    }
    .a11y-card-icon {
        background: rgba(255, 255, 255, 0.04);
    }
    .a11y-close:hover {
        background: rgba(255, 255, 255, 0.1);
    }
    .a11y-segmented {
        background: rgba(255, 255, 255, 0.06);
    }
    .a11y-segmented-btn.active {
        background: rgba(255, 255, 255, 0.15);
        color: #ffffff;
    }
    .a11y-btn-reset {
        background: rgba(255, 255, 255, 0.08);
        color: #ffffff;
    }
    .a11y-btn-reset:hover {
        background: rgba(255, 255, 255, 0.12);
    }
}
