/* AAA Text Spacing Requirements */
.aaa-text-spacing {
    /* Level AAA requires specific spacing */
    line-height: 1.5;
    letter-spacing: 0.12em;
    word-spacing: 0.16em;
    margin-block: 2em;
}

/* Text Justification Controls */
p {
    text-align: start; /* Avoid justified text for better readability */
    max-width: 80ch; /* Ensure optimal line length */
}

/* Font Size Controls */
.readable-text {
    font-size: clamp(1rem, 1.2vw, 1.25rem);
    font-weight: 400;
}

/* High Contrast Text */
.high-contrast-text {
    color: #000000;
    background-color: #ffffff;
    text-shadow: none;
}

/* Control Button Styles */
.media-controls button,
.language-selector button {
    padding: 0.5rem 1rem;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background-color: white;
    color: #212529;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.media-controls button:hover,
.language-selector button:hover {
    background-color: #f8f9fa;
    border-color: #adb5bd;
}

.media-controls button:focus,
.language-selector button:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Range Input Styling */
.media-controls input[type="range"] {
    width: 100%;
    padding: 0.5rem 0;
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem;
    border-bottom: 1px solid #dee2e6;
}

.control-group:last-child {
    border-bottom: none;
}

.control-group-label {
    font-weight: 500;
    color: #495057;
    margin-bottom: 0.25rem;
}

/* Text Size Controls */
.text-controls {
    width: 100%;
}

.text-controls .button-container {
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
}

.text-size-button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.text-size-button:hover {
    background-color: #f8f9fa;
    border-color: #adb5bd;
}

.text-size-button:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

.text-size-button .material-icons {
    font-size: 1.25rem;
}

/* Accessibility Panel - Collapsible Container */
.accessibility-panel {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    right: 1rem;
    z-index: 1050;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Mobile positioning - bottom right */
@media (max-width: 768px) {
    .accessibility-panel {
        top: auto;
        bottom: 1rem;
        right: 1rem;
        flex-direction: column-reverse; /* Reverse to make content appear above button */
        z-index: 1060; /* Higher z-index to appear above mobile menus */
    }
    
    /* Safe area adjustments for devices with notches/home indicators */
    .accessibility-panel {
        bottom: max(1rem, env(safe-area-inset-bottom));
        right: max(1rem, env(safe-area-inset-right));
    }
}

/* Accessibility Toggle Button */
.accessibility-toggle {
    background: white;
    border: 2px solid #0d6efd;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
    margin-bottom: 0.5rem;
}

.accessibility-toggle:hover {
    background-color: #f8f9fa;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.accessibility-toggle:focus {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
}

.accessibility-toggle .material-icons {
    font-size: 24px;
    color: #0d6efd;
}

/* Accessibility Content Container */
.accessibility-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 1rem;
    gap: 1rem;
    min-width: 280px;
    max-width: 320px;
    border: 1px solid #dee2e6;
    display: none; /* Hidden by default */
    flex-direction: column;
}

/* Show content when panel is open */
.accessibility-panel[aria-expanded="true"] .accessibility-content {
    display: flex;
}

/* Language Selector Styles - Updated for Panel */
.language-selector {
    width: 100%;
}

.language-selector select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 6px;
    border: 2px solid #dee2e6;
    background-color: white;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.language-selector select:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* Text Controls - Updated for Panel */
.text-controls {
    width: 100%;
}

.text-controls .button-container {
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
}

.text-size-button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 0.75rem;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 1rem;
    min-height: 48px; /* Ensure touch-friendly minimum size */
}

.text-size-button:hover {
    background-color: #f8f9fa;
    border-color: #0d6efd;
}

.text-size-button:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* Removed Audio Description and Sign Language toggles - no content available */

/* Reading Level Indicator */
.reading-level {
    display: inline-block;
    padding: 0.2em 0.5em;
    border-radius: 3px;
    font-size: 0.8em;
    margin-left: 0.5em;
    background: #f0f0f0;
}

/* Screen Reader Only Content */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    /* Ensure high contrast for accessibility tools */
    color: #000000 !important;
    background-color: #ffffff !important;
}

/* Fix contrast issues for any remaining elements */
.sr-live-region {
    /* Ensure proper contrast for screen reader live regions */
    color: #000000 !important;
    background-color: #ffffff !important;
    /* Override any inline styles that might cause contrast issues */
    opacity: 1 !important;
    /* Ensure the text is accessible when visible */
    padding: 0.25rem 0.5rem !important;
    border: 1px solid #dee2e6 !important;
    border-radius: 0.25rem !important;
}

/* More specific selector to override inline styles */
div[role="status"].sr-live-region,
div[role="alert"].sr-live-region {
    color: #000000 !important;
    background-color: #ffffff !important;
    /* Force override of any inline styles */
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .accessibility-panel {
        right: 0.75rem;
        bottom: 0.75rem;
        top: auto;
        flex-direction: column-reverse; /* Content above button */
    }
    
    .accessibility-content {
        min-width: 260px;
        max-width: calc(100vw - 2rem);
        margin-bottom: 0.5rem; /* Space between content and button */
        /* Ensure content doesn't overflow screen */
        max-height: calc(100vh - 120px); /* Leave space for button and margins */
        overflow-y: auto;
        /* Adjust positioning for mobile */
        align-self: flex-end;
    }
    
    .accessibility-toggle {
        width: 48px;
        height: 48px;
        margin-bottom: 0; /* Remove margin when at bottom */
        /* Ensure button is easily tappable */
        border-width: 2px;
    }
    
    .accessibility-toggle .material-icons {
        font-size: 20px;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .accessibility-panel {
        right: 0.5rem;
        bottom: 0.5rem;
    }
    
    .accessibility-content {
        min-width: 240px;
        max-width: calc(100vw - 1.5rem);
        padding: 0.75rem;
    }
}

/* Portrait mode specific adjustments */
@media screen and (orientation: portrait) and (max-width: 768px) {
    .accessibility-panel {
        bottom: 1rem;
        right: 1rem;
        /* Ensure content has enough space above in portrait */
        flex-direction: column-reverse;
    }
    
    .accessibility-content {
        /* Adjust max height for portrait mode - more vertical space available */
        max-height: calc(100vh - 150px);
        margin-bottom: 0.75rem;
        /* Ensure proper positioning in portrait */
        align-self: flex-end;
    }
}

/* Portrait mode for small devices */
@media screen and (orientation: portrait) and (max-width: 480px) {
    .accessibility-panel {
        bottom: 2.75rem;
        right: 0.5rem;
    }
    
    .accessibility-content {
        max-height: calc(100vh - 120px);
        min-width: 220px;
        max-width: calc(100vw - 1rem);
    }
}

/* Landscape mode specific adjustments - improved visibility */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .accessibility-panel {
        bottom: 0.75rem;
        right: 0.75rem;
        flex-direction: column-reverse; /* Content above button, button stays at bottom */
    }
    
    .accessibility-content {
        /* Less vertical space in landscape but keep content readable */
        max-height: calc(100vh - 100px);
        margin-bottom: 0.5rem; /* Space between content and button */
        /* Increase content width for better readability in landscape */
        min-width: 300px;
        max-width: 350px;
        /* Increase padding for better touch targets */
        padding: 1rem;
        /* Ensure content aligns to the right like button */
        align-self: flex-end;
    }
    
    .accessibility-toggle {
        /* Keep button size adequate for touch interaction */
        width: 50px;
        height: 50px;
    }
    
    .accessibility-toggle .material-icons {
        font-size: 22px;
    }
    
    /* Enhanced text size buttons for landscape mode */
    .text-size-button {
        padding: 1rem 0.875rem;
        font-size: 1.1rem;
        font-weight: 700;
        min-height: 52px; /* Larger touch target in landscape */
    }
    
    /* Better spacing for control groups */
    .control-group {
        margin-bottom: 1.25rem;
    }
    
    .control-group h4 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
}

/* Additional landscape adjustments for very small heights */
@media screen and (orientation: landscape) and (max-height: 400px) {
    .accessibility-content {
        /* More compact for very small landscape screens */
        padding: 0.75rem;
        min-width: 280px;
        max-width: 320px;
    }
    
    /* Ensure text controls are large enough */
    .text-size-button {
        padding: 0.75rem 0.75rem;
        min-height: 44px;
        font-size: 1rem;
        font-weight: 600;
    }
    
    .language-selector select {
        padding: 0.75rem;
        font-size: 1rem;
        min-height: 44px;
    }
}

/* Print Styles for Accessibility */
@media print {
    * {
        color: #000 !important;
        background: #fff !important;
    }
    
    a[href]::after {
        content: " (" attr(href) ")";
    }
    
    .accessibility-panel {
        display: none;
    }
}