/* ==========================================================================
   Accessibility Widget Styles (BRAC JPGSPH)
   ========================================================================== */

/* ---- Floating Launcher Button ---- */
.a11y-widget-wrap {
    position: relative;
    z-index: 1060;
    font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.a11y-trigger {
    position: fixed;
    left: 24px;
    bottom: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #1c2b4a;
    color: #ffffff;
    border: 2px solid #2e9591;
    box-shadow: 0 4px 18px rgba(28, 43, 74, 0.35);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 1060;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, box-shadow 0.25s ease;
}

.a11y-trigger:hover {
    background: #15223c;
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(28, 43, 74, 0.45);
}

.a11y-trigger:focus-visible {
    outline: 3px solid #f47920;
    outline-offset: 3px;
}

.a11y-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.a11y-trigger-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #f47920;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ---- Dialog Popup ---- */
.a11y-dialog {
    position: fixed;
    left: 24px;
    bottom: 84px;
    z-index: 1060;
    width: 360px;
    max-width: calc(100vw - 32px);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
    transform-origin: bottom left;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s ease;
    pointer-events: none;
}

.a11y-dialog.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.a11y-dialog-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(28, 43, 74, 0.18), 0 2px 10px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 120px);
}

/* Header */
.a11y-dialog-header {
    background: #1c2b4a;
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.a11y-dialog-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.a11y-header-icon {
    display: flex;
    color: #2e9591;
}

.a11y-dialog-title {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    line-height: 1.2;
}

.a11y-dialog-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.a11y-reset-btn {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 6px;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 9px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.a11y-reset-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.a11y-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.75);
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.a11y-close-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
}

.a11y-close-btn:focus-visible,
.a11y-reset-btn:focus-visible {
    outline: 2px solid #f47920;
    outline-offset: 2px;
}

/* Body */
.a11y-dialog-body {
    padding: 16px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overscroll-behavior: contain;
}

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

.a11y-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
    margin: 0;
}

/* Font scale row */
.a11y-font-scale-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px 12px;
}

.a11y-row-label {
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
}

.a11y-font-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.a11y-step-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #1c2b4a;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.a11y-step-btn:hover {
    background: #1c2b4a;
    color: #ffffff;
    border-color: #1c2b4a;
}

.a11y-font-value {
    font-size: 13px;
    font-weight: 700;
    color: #1c2b4a;
    min-width: 44px;
    text-align: center;
}

/* Grid layout for buttons */
.a11y-grid {
    display: grid;
    gap: 8px;
}

.a11y-grid-2 {
    grid-template-columns: 1fr 1fr;
}

.a11y-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

/* Feature Tiles */
.a11y-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px 8px;
    background: #f9fafb;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    color: #374151;
    gap: 6px;
    transition: all 0.15s ease;
    min-height: 76px;
    user-select: none;
}

.a11y-tile:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.a11y-tile:focus-visible {
    outline: 2px solid #1c2b4a;
    outline-offset: 2px;
}

.a11y-tile-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1c2b4a;
    height: 22px;
}

.a11y-tile-label {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    color: #1f2937;
}

.a11y-tile-status {
    font-size: 10px;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Active Tile State */
.a11y-tile.is-active {
    background: #e6f6f5;
    border-color: #2e9591;
    color: #0d4e4c;
    box-shadow: 0 2px 8px rgba(46, 149, 145, 0.2);
}

.a11y-tile.is-active .a11y-tile-icon {
    color: #2e9591;
}

.a11y-tile.is-active .a11y-tile-label {
    color: #0d4e4c;
}

.a11y-tile.is-active .a11y-tile-status {
    color: #2e9591;
    font-weight: 800;
}

/* Footer note */
.a11y-dialog-footer {
    background: #f9fafb;
    border-top: 1px solid #f3f4f6;
    padding: 10px 16px;
    text-align: center;
}

.a11y-footer-note {
    font-size: 11px;
    color: #6b7280;
}

/* Mobile Responsiveness */
@media (max-width: 575px) {
    .a11y-trigger {
        left: 16px;
        bottom: 16px;
        width: 44px;
        height: 44px;
    }

    .a11y-dialog {
        left: 16px;
        right: 16px;
        bottom: 72px;
        width: auto;
        max-width: none;
    }

    .a11y-dialog-card {
        max-height: calc(100vh - 100px);
    }
}

/* ---- Reading Guide (Horizontal Tracking Ruler) ---- */
.a11y-reading-ruler {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    height: 42px;
    background: rgba(244, 121, 32, 0.12);
    border-top: 2px solid #f47920;
    border-bottom: 2px solid #f47920;
    pointer-events: none;
    z-index: 99998;
    box-shadow: 0 0 16px rgba(244, 121, 32, 0.2);
}

body.a11y-guide-active .a11y-reading-ruler {
    display: block;
}

/* ==========================================================================
   Global Functional Overrides (Applied when toggled)
   ========================================================================== */

/* 0. Font Size Scaling (Scales all pixel and rem styled content proportionally) */
html[data-a11y-size="90"] body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler):not(.scroll-to-top) {
    zoom: 0.9;
}

html[data-a11y-size="110"] body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler):not(.scroll-to-top) {
    zoom: 1.12;
}

html[data-a11y-size="120"] body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler):not(.scroll-to-top) {
    zoom: 1.25;
}

html[data-a11y-size="130"] body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler):not(.scroll-to-top) {
    zoom: 1.38;
}

/* 1. Line & Letter Spacing (WCAG 1.4.12 Text Spacing) */
html.a11y-spacing-active body :not(.a11y-widget-wrap, .a11y-widget-wrap *),
body.a11y-spacing-active :not(.a11y-widget-wrap, .a11y-widget-wrap *) {
    line-height: 2.2 !important;
    letter-spacing: 0.1em !important;
    word-spacing: 0.2em !important;
}

html.a11y-spacing-active body p:not(.a11y-widget-wrap *),
body.a11y-spacing-active p:not(.a11y-widget-wrap *) {
    margin-bottom: 1.6em !important;
}

/* 2. Dyslexia Friendly Font */
html.a11y-dyslexic-active body :not(.a11y-widget-wrap, .a11y-widget-wrap *),
body.a11y-dyslexic-active :not(.a11y-widget-wrap, .a11y-widget-wrap *) {
    font-family: "Comic Sans MS", "Comic Sans", "Chalkboard SE", "OpenDyslexic", "Segoe UI", sans-serif !important;
}

/* 3. High Contrast Mode */
html.a11y-contrast-active,
body.a11y-contrast-active {
    background-color: #000000 !important;
    color: #ffffff !important;
}

html.a11y-contrast-active *:not(.a11y-widget-wrap, .a11y-widget-wrap *),
body.a11y-contrast-active *:not(.a11y-widget-wrap, .a11y-widget-wrap *) {
    background-color: #121212 !important;
    color: #ffffff !important;
    border-color: #ffd700 !important;
}

html.a11y-contrast-active a:not(.a11y-widget-wrap *),
body.a11y-contrast-active a:not(.a11y-widget-wrap *) {
    color: #ffd700 !important;
    text-decoration: underline !important;
}

/* 4. Grayscale (Monochromatic) */
html.a11y-grayscale-active body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler),
body.a11y-grayscale-active > :not(.a11y-widget-wrap):not(.a11y-reading-ruler) {
    filter: grayscale(100%) !important;
}

/* 5. Invert Colors */
html.a11y-invert-active body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler),
body.a11y-invert-active > :not(.a11y-widget-wrap):not(.a11y-reading-ruler) {
    filter: invert(100%) hue-rotate(180deg) !important;
}

html.a11y-invert-active body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler) img,
html.a11y-invert-active body > :not(.a11y-widget-wrap):not(.a11y-reading-ruler) video,
body.a11y-invert-active > :not(.a11y-widget-wrap):not(.a11y-reading-ruler) img,
body.a11y-invert-active > :not(.a11y-widget-wrap):not(.a11y-reading-ruler) video {
    filter: invert(100%) hue-rotate(180deg) !important;
}

/* 6. Highlight Links */
html.a11y-links-active a:not(.a11y-widget-wrap *),
body.a11y-links-active a:not(.a11y-widget-wrap *) {
    text-decoration: underline 2.5px #f47920 !important;
    outline: 2px dashed #f47920 !important;
    outline-offset: 2px !important;
    background-color: rgba(244, 121, 32, 0.15) !important;
    color: #000000 !important;
    font-weight: 700 !important;
}

/* 7. Big Cursor */
html.a11y-cursor-active,
html.a11y-cursor-active *,
body.a11y-cursor-active,
body.a11y-cursor-active * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='36' viewBox='0 0 24 24' fill='%231c2b4a' stroke='%23ffffff' stroke-width='1.5'%3E%3Cpath d='M4 4l7 17 2.5-6.5L20 12 4 4z'/%3E%3C/svg%3E") 4 4, auto !important;
}

/* 8. Pause Animations & Transitions */
html.a11y-motion-active *,
html.a11y-motion-active *::before,
html.a11y-motion-active *::after,
body.a11y-motion-active *,
body.a11y-motion-active *::before,
body.a11y-motion-active *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}
