/* ===========================================
   ULMEX Accessibility Widget
   WCAG 2.1 compliant accessibility toolbar
   =========================================== */

/* OpenDyslexic font for dyslexia mode */
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

/* ---- Toggle Button ---- */
.ulmex-a11y-toggle {
    position: fixed;
    left: 18px;
    bottom: 18px;
    z-index: 999999;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #1e293b;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,.25), 0 0 0 3px rgba(30,41,59,.15);
    transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}
.ulmex-a11y-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,.3), 0 0 0 4px rgba(30,41,59,.2);
    background: #334155;
}
.ulmex-a11y-toggle:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 3px;
}
.ulmex-a11y-toggle[aria-expanded="true"] {
    background: #dc2626;
}

/* ---- Panel ---- */
.ulmex-a11y-panel {
    position: fixed;
    left: 18px;
    bottom: 82px;
    z-index: 999998;
    width: 360px;
    max-width: calc(100vw - 36px);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.06);
    transform: translateY(12px) scale(.96);
    opacity: 0;
    visibility: hidden;
    transition: transform .25s cubic-bezier(.4,0,.2,1), opacity .25s ease, visibility .25s ease;
}
.ulmex-a11y-panel[hidden] {
    display: block !important; /* keep in DOM for transition */
}
.ulmex-a11y-panel.ulmex-a11y-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

/* Header */
.ulmex-a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 12px;
    border-bottom: 1px solid #f1f5f9;
}
.ulmex-a11y-panel-title {
    font-size: 17px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    line-height: 1.3;
}
.ulmex-a11y-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}
.ulmex-a11y-close:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.ulmex-a11y-close:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* ---- Option Grid ---- */
.ulmex-a11y-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 16px 16px 8px;
}
.ulmex-a11y-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 6px 12px;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    background: #fff;
    cursor: pointer;
    transition: border-color .15s, background .15s, box-shadow .15s, transform .1s;
    min-height: 90px;
}
.ulmex-a11y-option:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}
.ulmex-a11y-option:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 2px;
}
.ulmex-a11y-option[aria-pressed="true"] {
    border-color: #1e3a8a;
    background: #eff6ff;
    box-shadow: 0 0 0 1px #1e3a8a;
}
.ulmex-a11y-option:active {
    transform: scale(.97);
}

.ulmex-a11y-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: #334155;
}
.ulmex-a11y-option[aria-pressed="true"] .ulmex-a11y-icon {
    color: #1e3a8a;
}

.ulmex-a11y-label {
    font-size: 11.5px;
    font-weight: 500;
    color: #475569;
    text-align: center;
    line-height: 1.3;
    letter-spacing: -.01em;
}
.ulmex-a11y-option[aria-pressed="true"] .ulmex-a11y-label {
    color: #1e3a8a;
    font-weight: 600;
}

/* ---- Reset Button ---- */
.ulmex-a11y-reset-wrap {
    padding: 12px 16px 18px;
    text-align: center;
}
.ulmex-a11y-reset {
    display: inline-block;
    padding: 10px 28px;
    border-radius: 24px;
    border: none;
    background: #ca8a04;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.ulmex-a11y-reset:hover {
    background: #a16207;
}
.ulmex-a11y-reset:focus-visible {
    outline: 3px solid #ca8a04;
    outline-offset: 3px;
}
.ulmex-a11y-reset:active {
    transform: scale(.96);
}

/* ---- Page Structure Overlay ---- */
.ulmex-a11y-structure {
    position: fixed;
    left: 18px;
    bottom: 82px;
    z-index: 999997;
    width: 360px;
    max-width: calc(100vw - 36px);
    max-height: 60vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.18);
    overflow: hidden;
    transform: translateY(12px);
    opacity: 0;
    visibility: hidden;
    transition: transform .25s ease, opacity .25s ease, visibility .25s ease;
}
.ulmex-a11y-structure[hidden] {
    display: block !important;
}
.ulmex-a11y-structure.ulmex-a11y-open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}
.ulmex-a11y-structure-inner {
    display: flex;
    flex-direction: column;
    max-height: 60vh;
}
.ulmex-a11y-structure-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
}
.ulmex-a11y-structure-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}
.ulmex-a11y-structure-header button {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ulmex-a11y-structure-header button:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.ulmex-a11y-structure-content {
    padding: 12px 16px 16px;
    overflow-y: auto;
    flex: 1;
}
.ulmex-a11y-heading-item {
    display: block;
    padding: 6px 8px;
    margin: 2px 0;
    border-radius: 6px;
    font-size: 13px;
    color: #334155;
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background .1s;
}
.ulmex-a11y-heading-item:hover {
    background: #f1f5f9;
}
.ulmex-a11y-heading-item[data-level="1"] { font-weight: 700; font-size: 15px; padding-left: 8px; color: #0f172a; }
.ulmex-a11y-heading-item[data-level="2"] { font-weight: 600; font-size: 14px; padding-left: 20px; color: #1e293b; }
.ulmex-a11y-heading-item[data-level="3"] { padding-left: 36px; }
.ulmex-a11y-heading-item[data-level="4"] { padding-left: 52px; font-size: 12px; color: #64748b; }
.ulmex-a11y-heading-item[data-level="5"] { padding-left: 64px; font-size: 12px; color: #94a3b8; }
.ulmex-a11y-heading-item[data-level="6"] { padding-left: 76px; font-size: 11px; color: #94a3b8; }
.ulmex-a11y-heading-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    background: #e2e8f0;
    color: #64748b;
    margin-right: 6px;
    vertical-align: middle;
    text-transform: uppercase;
}

/* ---- Click-to-read highlight ---- */
.ulmex-a11y-reading-highlight {
    outline: 3px solid #2563eb !important;
    outline-offset: 2px !important;
    border-radius: 4px;
}

/* =============================
   ACCESSIBILITY MODE STYLES
   ============================= */

/* High Contrast */
body.ulmex-a11y-high-contrast,
body.ulmex-a11y-high-contrast * {
    background-color: #000 !important;
    color: #fff !important;
    border-color: #fff !important;
}
body.ulmex-a11y-high-contrast img {
    filter: grayscale(100%) contrast(1.2) !important;
}
body.ulmex-a11y-high-contrast a,
body.ulmex-a11y-high-contrast a * {
    color: #ffff00 !important;
    text-decoration: underline !important;
}
body.ulmex-a11y-high-contrast button,
body.ulmex-a11y-high-contrast input,
body.ulmex-a11y-high-contrast select,
body.ulmex-a11y-high-contrast textarea {
    border: 2px solid #fff !important;
}
/* Exclude the widget itself from high contrast */
body.ulmex-a11y-high-contrast #ulmex-a11y-widget,
body.ulmex-a11y-high-contrast #ulmex-a11y-widget * {
    background-color: revert !important;
    color: revert !important;
    border-color: revert !important;
    filter: none !important;
    text-decoration: revert !important;
}
body.ulmex-a11y-high-contrast .ulmex-a11y-panel {
    background: #fff !important;
}
body.ulmex-a11y-high-contrast .ulmex-a11y-panel *,
body.ulmex-a11y-high-contrast .ulmex-a11y-structure *,
body.ulmex-a11y-high-contrast .ulmex-a11y-structure {
    background-color: revert !important;
    color: revert !important;
    border-color: revert !important;
}

/* Highlight Links */
body.ulmex-a11y-highlight-links a {
    outline: 2px solid #2563eb !important;
    outline-offset: 2px !important;
    background: rgba(37, 99, 235, .08) !important;
    text-decoration: underline !important;
}
body.ulmex-a11y-highlight-links #ulmex-a11y-widget a {
    outline: none !important;
    background: transparent !important;
    text-decoration: none !important;
}

/* Large Text */
body.ulmex-a11y-large-text {
    font-size: 125% !important;
}
body.ulmex-a11y-large-text p,
body.ulmex-a11y-large-text li,
body.ulmex-a11y-large-text span,
body.ulmex-a11y-large-text td,
body.ulmex-a11y-large-text th,
body.ulmex-a11y-large-text label,
body.ulmex-a11y-large-text div {
    font-size: inherit !important;
}
body.ulmex-a11y-large-text #ulmex-a11y-widget {
    font-size: initial !important;
}
body.ulmex-a11y-large-text #ulmex-a11y-widget * {
    font-size: revert !important;
}

/* Text Spacing */
body.ulmex-a11y-text-spacing {
    letter-spacing: .12em !important;
    word-spacing: .16em !important;
}
body.ulmex-a11y-text-spacing p,
body.ulmex-a11y-text-spacing li,
body.ulmex-a11y-text-spacing td,
body.ulmex-a11y-text-spacing th,
body.ulmex-a11y-text-spacing span,
body.ulmex-a11y-text-spacing div {
    line-height: 1.8 !important;
}
body.ulmex-a11y-text-spacing #ulmex-a11y-widget,
body.ulmex-a11y-text-spacing #ulmex-a11y-widget * {
    letter-spacing: normal !important;
    word-spacing: normal !important;
    line-height: revert !important;
}

/* Stop Animations */
body.ulmex-a11y-stop-animations,
body.ulmex-a11y-stop-animations *,
body.ulmex-a11y-stop-animations *::before,
body.ulmex-a11y-stop-animations *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
}
/* Keep widget animations */
body.ulmex-a11y-stop-animations #ulmex-a11y-widget,
body.ulmex-a11y-stop-animations #ulmex-a11y-widget * {
    transition: all .15s ease !important;
}

/* Hide Images */
body.ulmex-a11y-hide-images img,
body.ulmex-a11y-hide-images svg:not(#ulmex-a11y-widget svg),
body.ulmex-a11y-hide-images video,
body.ulmex-a11y-hide-images picture,
body.ulmex-a11y-hide-images [style*="background-image"] {
    visibility: hidden !important;
}
body.ulmex-a11y-hide-images #ulmex-a11y-widget img,
body.ulmex-a11y-hide-images #ulmex-a11y-widget svg {
    visibility: visible !important;
}

/* Dyslexia-Friendly Font */
body.ulmex-a11y-dyslexia-font,
body.ulmex-a11y-dyslexia-font * {
    font-family: 'OpenDyslexic', Arial, sans-serif !important;
}
body.ulmex-a11y-dyslexia-font #ulmex-a11y-widget,
body.ulmex-a11y-dyslexia-font #ulmex-a11y-widget * {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}
body.ulmex-a11y-dyslexia-font .fas,
body.ulmex-a11y-dyslexia-font .far,
body.ulmex-a11y-dyslexia-font .fab,
body.ulmex-a11y-dyslexia-font .fa,
body.ulmex-a11y-dyslexia-font [class*="fa-"] {
    font-family: 'Font Awesome 5 Free', 'Font Awesome 5 Brands' !important;
}

/* Big Cursor */
body.ulmex-a11y-big-cursor,
body.ulmex-a11y-big-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Cpath d='M8 4l28 18-13 3 8 16-6 3-8-16-9 9V4z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 8 4, auto !important;
}
body.ulmex-a11y-big-cursor a,
body.ulmex-a11y-big-cursor button,
body.ulmex-a11y-big-cursor [role="button"],
body.ulmex-a11y-big-cursor input[type="submit"],
body.ulmex-a11y-big-cursor input[type="button"] {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Cpath d='M8 4l28 18-13 3 8 16-6 3-8-16-9 9V4z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 8 4, pointer !important;
}

/* ---- Reading indicator ---- */
.ulmex-a11y-reading-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: #2563eb;
    z-index: 9999999;
    transform-origin: left;
    transform: scaleX(0);
    transition: transform .3s ease;
}

/* ---- Mobile responsive ---- */
@media (max-width: 420px) {
    .ulmex-a11y-panel {
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        bottom: 78px;
    }
    .ulmex-a11y-structure {
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
    }
    .ulmex-a11y-toggle {
        left: 12px;
        bottom: 12px;
        width: 46px;
        height: 46px;
    }
    .ulmex-a11y-grid {
        gap: 8px;
        padding: 12px 12px 6px;
    }
    .ulmex-a11y-option {
        padding: 10px 4px;
        min-height: 80px;
    }
    .ulmex-a11y-label {
        font-size: 10.5px;
    }
}

/* ---- Reduced motion preference ---- */
@media (prefers-reduced-motion: reduce) {
    .ulmex-a11y-panel,
    .ulmex-a11y-structure,
    .ulmex-a11y-toggle {
        transition-duration: 0.01ms !important;
    }
}

/* ---- Print: hide widget ---- */
@media print {
    #ulmex-a11y-widget { display: none !important; }
}
