/* UX4G Accessibility Widget – Local Layout, Icons & Effects
   This file is standalone: no external icon fonts or images needed.
   Optimized for all browser zoom levels (67%-150%).
*/

/* ===== LOCAL FONT (optional, safe fallback) ===== */
@font-face {
    font-family: 'NotoSansLocal';
    src: url('../fonts/NotoSans-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* ===== CUSTOM DYSLEXIA FONT ===== */
@font-face {
    font-family: 'OpenDyslexic3';
    src: url('../fonts/OpenDyslexic3-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* ===== RESET & BASE ===== */
* {
    box-sizing: border-box;
}

/* ===== MAIN PANEL ===== */
#uw-main {
    position: fixed;
    right: -33vw; /* Viewport width for better zoom scaling */
    bottom: clamp(4rem, 8vh, 8rem); /* Responsive bottom position */
    width: min(360px, 90vw); /* Flexible width with max limit */
    max-height: 80vh;
    background: #fdf5e6;
    color: #111827;
    border-radius: 16px 0 0 16px;
    box-shadow: 0 20px 50px rgba(15,23,42,0.45);
    z-index: 99998;
    overflow: hidden;
    font-family: 'NotoSansLocal', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: right center; /* Better scaling origin */
}

/* When panel is open */
#uw-main[style*="right: 0"] {
    right: 0 !important;
}

#uw-main .uwaw-body {
    padding: clamp(0.5rem, 1vh, 0.8rem) clamp(0.4rem, 0.8vw, 0.6rem);
}

#uw-main .second-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(0.5rem, 0.8vh, 0.7rem) clamp(0.7rem, 1.2vw, 1rem);
    background: #f9e0d5;
}

#uw-main h2#uw-heading {
    font-size: clamp(0.95rem, 1.1em, 1.2rem);
    font-weight: 700;
    margin: 0;
}

#uw-main .inner-short-key {
    font-size: clamp(0.7rem, 0.8em, 0.85rem);
    font-weight: 500;
    margin-left: 0.35rem;
    color: #7c2d12;
}

/* Close button (X) */
.uwaw-close {
    border: none;
    background: transparent;
    width: clamp(24px, 1.8em, 32px);
    height: clamp(24px, 1.8em, 32px);
    border-radius: 999px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

.uwaw-close::before,
.uwaw-close::after {
    content: '';
    position: absolute;
    inset: 50%;
    width: clamp(12px, 0.9em, 16px);
    height: clamp(1.5px, 0.12em, 2.5px);
    background: #111827;
    transform-origin: center;
}

.uwaw-close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.uwaw-close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.uwaw-close:hover::before,
.uwaw-close:hover::after {
    background: #7c2d12;
}

.h-scroll {
    overflow-x: hidden;
}

/* Grid of feature tiles */
.uwaw-features {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(0.4rem, 0.6vw, 0.6rem);
}

.uwaw-features__item {
    margin: 0;
}

/* ===== FEATURE CARD ===== */
.uwaw-features__item__i {
    width: 100%;
    border-radius: clamp(0.5rem, 0.7em, 0.8rem);
    border: none;
    padding: clamp(0.5rem, 0.8vh, 0.7rem) clamp(0.4rem, 0.6vw, 0.55rem);
    text-align: left;
    background: #dc1456;           /* main pink */
    color: #ffffff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: clamp(0.2rem, 0.3em, 0.4rem);
    min-height: clamp(60px, 4.5rem, 80px); /* Flexible height */
    position: relative;
    box-shadow: 0 4px 10px rgba(220, 20, 86, 0.4);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.uwaw-features__item__i:hover,
.uwaw-features__item__i:focus-visible {
    outline: none;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(220, 20, 86, 0.55);
    background: #b51247;
}

.uwaw-features__item__name {
    font-size: clamp(0.7rem, 0.85em, 0.85rem);
    font-weight: 600;
    line-height: 1.2;
}

/* ===== ICONS (NO EXTERNAL FONT) ===== */
.uwaw-features__item__icon {
    font-size: clamp(0.75rem, 0.9em, 1rem);
    opacity: 0.9;
}

/* Generic icon wrapper */
.ux4g-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: clamp(18px, 1.4em, 24px);
    height: clamp(18px, 1.4em, 24px);
    font-size: clamp(10px, 0.9em, 14px);
    font-weight: 700;
}

/* Each icon uses a Unicode glyph so no font file is required */
.ux4g-icon::before {
    display: inline-block;
    line-height: 1;
}

/* Bigger Text – A with up arrow */
.ux4g-icon.icon-bigger-text::before {
    content: "A↑";
}

/* Smaller Text – A with down arrow */
.ux4g-icon.icon-smaller-text::before {
    content: "A↓";
}

/* Text Spacing – three underlines */
.ux4g-icon.icon-text-spacing::before {
    content: "≋";
}

/* Line Height – double arrow up/down */
.ux4g-icon.icon-line-hight::before {
    content: "↕";
}

/* Dyslexia Friendly – DF monogram */
.ux4g-icon.icon-dyslexia-font::before {
    content: "Df";
}

/* ADHD Mode – focus target */
.ux4g-icon.icon-adhd-friendly::before {
    content: "◎";
}

/* Saturation base icon */
.ux4g-icon.icon-saturate::before {
    content: "◐";
}

.ux4g-icon.icon-lowsaturate::before {
    content: "◑";
}

.ux4g-icon.icon-highsaturate::before {
    content: "◉";
}

.ux4g-icon.icon-desaturate::before {
    content: "◌";
}

/* Moon & Sun inside toggle */
.ux4g-icon.icon-moon::before {
    content: "☾";
}

.ux4g-icon.icon-sun::before {
    content: "☀";
}

/* Invert Colors */
.ux4g-icon.icon-invert::before {
    content: "⇄";
}

/* Highlight Links */
.ux4g-icon.icon-highlight-links::before {
    content: "🔗";
}

/* Text to Speech */
.ux4g-icon.icon-speaker::before {
    content: "🔊";
}

/* Cursor */
.ux4g-icon.icon-cursor::before {
    content: "▴";
}

/* Pause Animation */
.ux4g-icon.icon-animation-pause::before {
    content: "❚❚";
}

/* Hide Images */
.ux4g-icon.icon-hide-images::before {
    content: "🖼";
}

/* ===== STEPPER BARS ===== */
.uwaw-features__item__steps {
    display: flex;
    gap: clamp(2px, 0.15em, 4px);
    margin-top: clamp(0.1rem, 0.15em, 0.2rem);
}

.uwaw-features__step {
    flex: 1;
    height: clamp(3px, 0.3em, 5px);
    border-radius: 999px;
    background: rgba(255,255,255,0.35);
}

/* Only the JS-activated steps become white */
.uwaw-features__step.ux4g-accessibility-active {
    background: #ffffff !important;
}

/* ===== ACTIVE TICK ===== */
.tick-active {
    position: absolute;
    top: clamp(0.3rem, 0.5em, 0.5rem);
    right: clamp(0.3rem, 0.5em, 0.5rem);
    width: clamp(14px, 1.1em, 18px);
    height: clamp(14px, 1.1em, 18px);
    border-radius: 999px;
    border: clamp(1.5px, 0.15em, 2.5px) solid rgba(255,255,255,0.8);
    background: transparent;
    display: none;
    align-items: center;
    justify-content: center;
}

/* Show tick when JS adds ux4g-accessibility-feature-active */
.ux4g-accessibility-feature-active .tick-active,
.ux4g-accessibility-feature-active .uwaw-features__item__enabled {
    display: inline-flex;
}

/* ===== RESET PANEL & BUTTON ===== */
.reset-panel {
    border-top: 1px solid rgba(15,23,42,0.08);
    padding: clamp(0.35rem, 0.5em, 0.5rem) clamp(0.5rem, 0.8em, 0.75rem) clamp(0.45rem, 0.6em, 0.6rem);
    background: #fef2f2;
}

.btn-reset-all {
    width: 100%;
    border-radius: 999px;
    border: none;
    padding: clamp(0.4rem, 0.6em, 0.5rem) clamp(0.6rem, 0.8em, 0.8rem);
    font-size: clamp(0.75rem, 0.85em, 0.85rem);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    cursor: pointer;
    background: #ef4444;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: clamp(0.3rem, 0.4em, 0.5rem);
    transition: background 0.2s ease, transform 0.2s ease;
}

.btn-reset-all:hover,
.btn-reset-all:focus-visible {
    outline: none;
    background: #b91c1c;
    transform: translateY(-1px);
}

.btn-reset-all:active {
    transform: translateY(0);
}

/* Reset icon inside button */
.reset-icon {
    width: clamp(14px, 1em, 18px);
    height: clamp(14px, 1em, 18px);
    background-color: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z'/%3E%3C/svg%3E") no-repeat center;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z'/%3E%3C/svg%3E") no-repeat center;
}

.reset-btn-text {
    font-size: clamp(0.75rem, 0.85em, 0.85rem);
}

/* ===== FLOATING TRIGGER BUTTON (ROUND, ICON + Ctrl+F2) ===== */
.uw-widget-custom-trigger {
    /* Position - use viewport units for better scaling */
    position: fixed;
    right: clamp(1rem, 3vw, 2rem);
    bottom: clamp(2rem, 5vh, 3rem);
    z-index: 99999;

    /* Size - scale with viewport */
    width: clamp(56px, 4.5rem, 70px);
    height: clamp(56px, 4.5rem, 70px);
    border-radius: 50%;
    padding: 0;
    border: none;

    /* Visuals */
    background: #111827;
    color: #ffffff;
    box-shadow: 0 10px 30px rgba(15,23,42,0.6);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;

    /* Layout */
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    gap: clamp(2px, 0.2em, 4px);
}

.uw-widget-custom-trigger:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 40px rgba(15,23,42,0.7);
}

.uw-widget-custom-trigger:active {
    transform: scale(0.98);
}

/* Icon inside trigger - scale proportionally */
.uw-widget-custom-trigger img {
    width: 55% !important; /* Percentage-based scaling */
    height: auto !important;
    max-width: 28px;
    max-height: 28px;
    min-width: 18px;
    min-height: 18px;
    margin: 0 !important;
    display: block;
    transition: all 0.2s ease;
}

/* Ctrl+F2 label inside circle */
.uw-widget-custom-trigger .short-key {
    font-size: clamp(9px, 0.7em, 11px) !important;
    line-height: 1;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: lowercase;
    margin: 0;
    opacity: 1;
    font-family: system-ui, sans-serif;
    cursor: pointer;
}

/* Hide long text "Accessibility Options" for compact circle */
.uw-widget-custom-trigger span:not(.short-key) {
    display: none;
}

/* ===== OVERLAY SKIP LINK ===== */
#accessibility-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99997;
    background: rgba(0, 0, 0, 0.5);
}

#accessibility-overlay .skip-link {
    border-radius: 999px;
    border: none;
    padding: clamp(0.5rem, 1vh, 0.7rem) clamp(0.8rem, 2vw, 1.2rem);
    background: #111827;
    color: #ffffff;
    font-size: clamp(0.8rem, 0.9em, 1rem);
    display: inline-flex;
    align-items: center;
    gap: clamp(0.4rem, 0.6em, 0.8rem);
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

#accessibility-overlay .skip-link:hover {
    background: #1f2937;
    transform: translateY(-2px);
}

#accessibility-overlay .icon-open-accessibile img {
    width: clamp(18px, 1.5em, 24px);
    height: clamp(18px, 1.5em, 24px);
}

#accessibility-overlay .icon-enter {
    font-size: clamp(0.7rem, 0.8em, 0.9rem);
    opacity: 0.8;
}

/* Prevent external theme leaking into widget */
.uwaw,
.uwaw * {
    box-sizing: border-box;
}

/* ===== ACCESSIBILITY EFFECT CLASSES (wired to JS prefix ux4g-accessibility-) ===== */

/* Highlight links */
body.ux4g-accessibility-highlight-links a,
body.ux4g-accessibility-highlight-links button,
body.ux4g-accessibility-highlight-links [role="button"] {
    outline: 2px solid #f97316 !important;
    outline-offset: 2px;
    background-color: rgba(250, 250, 210, 0.8);
    border-radius: 2px;
}

/* Dyslexia-friendly mode */
body.ux4g-accessibility-dyslexia-mode * {
    font-family: 'OpenDyslexic3', 'NotoSansLocal', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
    letter-spacing: 0.06em;
    line-height: 1.6 !important;
}

/* Hide images */
body.ux4g-accessibility-hide-images img,
body.ux4g-accessibility-hide-images picture,
body.ux4g-accessibility-hide-images figure,
body.ux4g-accessibility-hide-images svg,
body.ux4g-accessibility-hide-images canvas,
body.ux4g-accessibility-hide-images video,
body.ux4g-accessibility-hide-images iframe {
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Dark mode */
body.ux4g-accessibility-dark-mode {
    background-color: #020617 !important;
    color: #e5e7eb !important;
}

body.ux4g-accessibility-dark-mode * {
    background-color: transparent;
    color: inherit;
}

/* Widget should maintain its own colors in dark mode */
body.ux4g-accessibility-dark-mode #uw-main {
    background: #1f2937;
    color: #e5e7eb;
}

body.ux4g-accessibility-dark-mode .second-panel {
    background: #374151;
}

/* Invert colors */
html.ux4g-accessibility-invert-colors {
    filter: invert(1) hue-rotate(180deg);
}

/* Preserve widget appearance when invert is on */
html.ux4g-accessibility-invert-colors #uw-main,
html.ux4g-accessibility-invert-colors .uw-widget-custom-trigger {
    filter: invert(1) hue-rotate(180deg);
}

/* Saturation variants */
html.ux4g-accessibility-saturate-low {
    filter: saturate(0.6);
}

html.ux4g-accessibility-saturate-high {
    filter: saturate(1.5);
}

html.ux4g-accessibility-saturate-desaturate {
    filter: grayscale(1);
}

/* ADHD reading mask (spotlight bar) */
.reading-mask-horizontal {
    position: fixed;
    left: 0;
    width: 100%;
    height: clamp(120px, 15vh, 160px);
    top: calc(var(--y) * 1px) !important; /* Ensure proper pixel calculation from JS */
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 99996;

    background: rgba(255, 255, 255, 0.05);
    border-top: 2px solid rgba(255, 255, 255, 0.9);
    border-bottom: 2px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.85);
    mix-blend-mode: normal;
    clip-path: none;
    transition: opacity 0.2s ease;
}

.reading-mask-horizontal.mask-visible {
    opacity: 1;
}

.reading-mask-horizontal.mask-hidden {
    opacity: 0;
}

/* Pause all CSS animations when class added by JS */
body.ux4g-accessibility-animation-pause * {
    animation-play-state: paused !important;
    transition-duration: 0s !important;
}

/* ===== BIG ARROW CURSOR ===== */
body.ux4g-accessibility-custom-cursor,
body.ux4g-accessibility-custom-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath fill='%23000000' stroke='%23ffffff' stroke-width='1.5' stroke-linejoin='round' d='M3 3l7.5 18.5 2.9-7.2 7.6 1-18-12.3z'/%3E%3C/svg%3E") 0 0, auto !important;
}

/* Light-Dark toggle switch */
.light_dark_icon {
    position: relative;
    width: clamp(40px, 3em, 50px);
    height: clamp(20px, 1.5em, 25px);
    margin: 0 auto clamp(0.3rem, 0.4em, 0.5rem);
}

#checkbox {
    display: none;
}

.checkbox-label {
    display: block;
    width: 100%;
    height: 100%;
    background: #374151;
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s ease;
}

.checkbox-label .fas {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: clamp(10px, 0.8em, 12px);
    transition: opacity 0.3s ease;
}

.checkbox-label .fa-moon-stars {
    left: clamp(5px, 0.5em, 8px);
    color: #fbbf24;
}

.checkbox-label .fa-sun {
    right: clamp(5px, 0.5em, 8px);
    color: #f59e0b;
}

.ball {
    position: absolute;
    top: 50%;
    left: clamp(2px, 0.2em, 3px);
    transform: translateY(-50%);
    width: clamp(16px, 1.2em, 20px);
    height: clamp(16px, 1.2em, 20px);
    background: #ffffff;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

#checkbox:checked + .checkbox-label {
    background: #3b82f6;
}

#checkbox:checked + .checkbox-label .ball {
    transform: translate(calc(100% + clamp(2px, 0.2em, 3px)), -50%);
}

#checkbox:checked + .checkbox-label .fa-moon-stars {
    opacity: 0.5;
}

#checkbox:not(:checked) + .checkbox-label .fa-sun {
    opacity: 0.5;
}

/* ===== BRANDING SECTION ===== */
.accessibility-branding {
    margin-top: clamp(0.5rem, 0.7em, 0.8rem);
    padding-top: clamp(0.3rem, 0.5em, 0.6rem);
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    text-align: center;
    line-height: 1.3;
}

.branding-label {
    display: block;
    font-size: clamp(9px, 0.8em, 11px);
    font-weight: 600;
    color: #6b7280;
    opacity: 1;
    letter-spacing: 0.04em;
    text-transform: capitalize;
    margin-bottom: 2px;
}

.branding-name {
    display: block;
    font-size: clamp(9px, 0.8em, 11px);
    font-weight: 400;
    color: #111827;
}

/* Dark mode branding */
body.ux4g-accessibility-dark-mode .branding-label {
    color: #9ca3af;
}

body.ux4g-accessibility-dark-mode .branding-name {
    color: #e5e7eb;
}

/* ===== MOBILE ADJUSTMENTS ===== */
@media (max-width: 768px) {
    #uw-main {
        right: -100vw;
        width: 100vw;
        max-width: 100%;
        border-radius: 0;
        bottom: 0;
        max-height: 85vh;
    }

    #uw-main[style*="right: 0"] {
        right: 0 !important;
    }

    #uw-main[style*="right: -33vw"] {
        right: -100vw !important;
    }

    .uwaw-features {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: clamp(0.3rem, 0.5vw, 0.5rem);
    }

    .uw-widget-custom-trigger {
        right: clamp(0.8rem, 2vw, 1.2rem);
        bottom: clamp(1.5rem, 4vh, 2.5rem);
        width: clamp(52px, 4rem, 60px);
        height: clamp(52px, 4rem, 60px);
    }

    .uw-widget-custom-trigger .short-key {
        font-size: clamp(8px, 0.65em, 10px) !important;
    }

    #uw-main .uwaw-body {
        padding: clamp(0.4rem, 0.8vh, 0.6rem) clamp(0.3rem, 0.6vw, 0.5rem);
    }
}

@media (max-width: 480px) {
    .uwaw-features {
        grid-template-columns: 1fr;
    }

    #uw-main {
        max-height: 90vh;
    }

    .uw-widget-custom-trigger {
        width: clamp(48px, 3.5rem, 56px);
        height: clamp(48px, 3.5rem, 56px);
    }
}

/* ===== TABLET ADJUSTMENTS ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    #uw-main {
        width: min(340px, 85vw);
    }

    .uw-widget-custom-trigger {
        right: clamp(1.2rem, 2.5vw, 1.8rem);
        bottom: clamp(2rem, 4vh, 2.8rem);
    }
}

/* ===== FIX FOR HIGH ZOOM LEVELS (125%+) ===== */
@media screen and (min-resolution: 120dpi) {
    #uw-main {
        width: min(340px, 85vw);
    }

    .uw-widget-custom-trigger {
        transform: scale(0.95);
    }

    .uw-widget-custom-trigger:hover {
        transform: scale(1);
    }

    .uwaw-features__item__i {
        min-height: clamp(65px, 4.8rem, 85px);
    }
}

/* ===== FIX FOR LOW ZOOM LEVELS (67%-80%) ===== */
@media screen and (max-resolution: 96dpi) {
    #uw-main {
        width: min(380px, 92vw);
    }

    .uw-widget-custom-trigger {
        transform: scale(1.05);
    }

    .uw-widget-custom-trigger:hover {
        transform: scale(1.1);
    }
}

/* ===== ENSURE VISIBILITY AT ALL ZOOM LEVELS ===== */
@media (min-width: 1200px) {
    #uw-main {
        width: min(360px, 30vw);
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    #uw-main,
    .uw-widget-custom-trigger,
    #accessibility-overlay,
    .reading-mask-horizontal {
        display: none !important;
    }
}

/* ===== ACCESSIBILITY: HIGH CONTRAST MODE SUPPORT ===== */
@media (prefers-contrast: high) {
    .uwaw-features__item__i {
        border: 2px solid #000000;
    }

    .tick-active {
        border: 2px solid #000000;
        background: #ffffff;
    }
}

/* ===== ACCESSIBILITY: REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    #uw-main,
    .uw-widget-custom-trigger,
    .uwaw-features__item__i,
    .btn-reset-all,
    .checkbox-label,
    .reading-mask-horizontal {
        transition: none !important;
    }

    .uw-widget-custom-trigger:hover {
        transform: none;
    }
}
