/**
 * Accessibility Enhancements for Aura Online
 * WCAG 2.1 AA Compliant Styling
 * Maintains existing fonts and visual design
 */

 #accessibility-shortcuts {
    position: absolute;
    bottom: 2em;
    left: 2em;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 16px;
    font-weight: bold;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid #ffffff;
    text-align: center;
    line-height: 1.5;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    cursor: default;
    font-family: var(--font-family-sans-serif);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-lg);
    color: var(--color-white);
    background: var(--color-black);
    border: 1px solid var(--color-white);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-4);
    margin: var(--spacing-4);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
 }

/* ===== FOCUS MANAGEMENT ===== */

/* Enhanced focus indicators */
*:focus {
    outline: 3px solid #4a9eff !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 1px rgba(74, 158, 255, 0.5) !important;
}

/* Focus visible for modern browsers */
*:focus-visible {
    outline: 3px solid #4a9eff !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 1px rgba(74, 158, 255, 0.5) !important;
}

/* Remove focus outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none !important;
    box-shadow: none !important;
}

/* High contrast focus for buttons and interactive elements */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus,
[role="button"]:focus,
[tabindex]:focus {
    outline: 3px solid #4a9eff !important;
    outline-offset: 2px !important;
    background-color: rgba(74, 158, 255, 0.1) !important;
    transition: all 0.2s ease !important;
}

/* ===== SKIP LINKS ===== */

.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000000;
    color: #ffffff;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: bold;
    font-size: 14px;
    z-index: 10000;
    transition: top 0.3s ease;
    border: 2px solid #4a9eff;
}

.skip-link:focus {
    top: 6px;
    outline: 3px solid #ffffff;
}

.skip-links {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
}

/* ===== SCREEN READER ENHANCEMENTS ===== */

/* Screen reader only text */
.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;
}

/* Screen reader only text that can be focused */
.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 8px 16px !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
    background: #000000 !important;
    color: #ffffff !important;
    border: 2px solid #4a9eff !important;
    border-radius: 4px !important;
    z-index: 10000 !important;
}

/* ===== HIGH CONTRAST SUPPORT ===== */

/* High contrast mode detection and support */
@media (prefers-contrast: high) {
    /* Enhance borders and outlines */
    button,
    input,
    select,
    textarea,
    .card,
    .nav-link,
    .quick-action-btn {
        border: 2px solid #ffffff !important;
    }
    
    /* Ensure text contrast */
    body,
    h1, h2, h3, h4, h5, h6,
    p, span, div,
    .nav-text,
    .character-name,
    .gold-count {
        color: #ffffff !important;
        text-shadow: 1px 1px 2px #000000 !important;
    }
    
    /* Background adjustments */
    .nav-menu,
    .card,
    .quick-action-btn {
        background: #000000 !important;
        border: 2px solid #ffffff !important;
    }
    
    /* Link styling */
    a {
        color: #00ffff !important;
        text-decoration: underline !important;
    }
    
    a:hover,
    a:focus {
        color: #ffffff !important;
        background: #0066cc !important;
    }
}

/* ===== REDUCED MOTION SUPPORT ===== */

@media (prefers-reduced-motion: reduce) {
    /* Disable animations and transitions */
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    /* Keep essential feedback transitions but make them instant */
    *:focus,
    *:hover {
        transition: none !important;
    }
    
    /* Disable parallax and transform animations */
    .fantasy-background,
    .menu-toggle,
    .nav-menu {
        transform: none !important;
    }
}

/* ===== COLOR CONTRAST ENHANCEMENTS ===== */

/* Ensure minimum contrast ratios */
.text-muted,
.nav-text-muted,
.version-text {
    color: #cccccc !important; /* Improved from #999999 */
}

.welcome-text,
.guest-text {
    color: #dddddd !important; /* Improved contrast */
}

/* Error and success states with better contrast */
.error,
.message.error {
    background: #cc0000 !important;
    color: #ffffff !important;
    border: 2px solid #ff4444 !important;
}

.success,
.message.success {
    background: #006600 !important;
    color: #ffffff !important;
    border: 2px solid #44ff44 !important;
}

.warning,
.message.warning {
    background: #cc6600 !important;
    color: #ffffff !important;
    border: 2px solid #ffaa44 !important;
}

/* ===== KEYBOARD NAVIGATION ENHANCEMENTS ===== */

/* Ensure all interactive elements are keyboard accessible */
[role="button"],
[onclick],
[onkeydown] {
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Add keyboard indicators for custom interactive elements */
[role="button"]:focus,
[onclick]:focus {
    outline: 3px solid #4a9eff !important;
    outline-offset: 2px !important;
}

/* Improve table navigation */
table {
    border-collapse: collapse;
}

th,
td {
    border: 1px solid #666666;
    padding: 8px 12px;
}

th:focus,
td:focus {
    background: rgba(74, 158, 255, 0.2) !important;
    outline: 2px solid #4a9eff !important;
}

/* ===== TOUCH TARGET IMPROVEMENTS ===== */

/* Ensure minimum 44px touch targets */
button,
a,
input,
select,
textarea,
[role="button"],
.nav-link,
.quick-action-btn,
.menu-toggle {
    min-height: 44px !important;
    min-width: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Exception for text links in paragraphs */
p a,
span a,
div a:not(.nav-link):not(.quick-action-btn) {
    min-height: auto !important;
    min-width: auto !important;
    display: inline !important;
    padding: 2px 4px !important;
}

/* ===== FORM ACCESSIBILITY ===== */

/* Enhanced form labels */
label {
    font-weight: bold;
    color: #ffffff;
    margin-bottom: 4px;
    display: block;
}

/* Required field indicators */
.required::after {
    content: " *";
    color: #ff4444;
    font-weight: bold;
    aria-label: "required";
}

/* Form validation styling */
.form-error {
    color: #ff4444 !important;
    font-weight: bold;
    font-size: 14px;
    margin-top: 4px;
    display: block;
}

input:invalid,
select:invalid,
textarea:invalid {
    border: 2px solid #ff4444 !important;
    background: rgba(255, 68, 68, 0.1) !important;
}

input:valid,
select:valid,
textarea:valid {
    border: 2px solid #44ff44 !important;
}

/* Fieldset and legend styling */
fieldset {
    border: 2px solid #666666;
    border-radius: 4px;
    padding: 16px;
    margin: 16px 0;
}

legend {
    font-weight: bold;
    color: #ffffff;
    padding: 0 8px;
    background: #000000;
}

/* ===== LOADING AND STATUS INDICATORS ===== */

/* Loading spinner accessibility */
.loading-spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #4a9eff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
    .loading-spinner {
        animation: none;
        border: 4px solid #4a9eff;
    }
    
    .loading-spinner::after {
        content: "Loading...";
        position: absolute;
        top: 50px;
        left: 50%;
        transform: translateX(-50%);
        color: #ffffff;
        font-weight: bold;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Status announcements for screen readers */
.status-announcement {
    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;
}

/* ===== MODAL AND DIALOG ACCESSIBILITY ===== */

/* Modal backdrop */
.modal-backdrop {
    background: rgba(0, 0, 0, 0.8) !important;
    backdrop-filter: blur(2px);
}

/* Modal focus trap */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a1a1a;
    border: 2px solid #4a9eff;
    border-radius: 8px;
    padding: 24px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 10000;
}

.modal:focus {
    outline: none;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #666666;
}

.modal-title {
    color: #ffffff;
    font-size: 20px;
    font-weight: bold;
    margin: 0;
}

.modal-close {
    background: none;
    border: 2px solid #666666;
    color: #ffffff;
    font-size: 24px;
    width: 44px;
    height: 44px;
    border-radius: 4px;
    cursor: pointer;
}

.modal-close:hover,
.modal-close:focus {
    background: #ff4444;
    border-color: #ff4444;
}

/* ===== RESPONSIVE TEXT SCALING ===== */

/* Support for user font size preferences */
@media (prefers-reduced-data: reduce) {
    /* Optimize for data-sensitive users */
    .game-logo,
    .gold-icon,
    img {
        loading: lazy;
    }
}

/* Large text support */
@media (min-resolution: 120dpi) and (max-resolution: 199dpi) {
    body {
        font-size: 16px;
        line-height: 1.5;
    }
}

@media (min-resolution: 200dpi) {
    body {
        font-size: 18px;
        line-height: 1.6;
    }
    
    .nav-link,
    .quick-action-btn {
        padding: 16px 20px;
    }
}

/* ===== PRINT ACCESSIBILITY ===== */

@media print {
    /* Ensure good contrast for printing */
    * {
        background: transparent !important;
        color: #000000 !important;
        text-shadow: none !important;
        box-shadow: none !important;
    }
    
    a,
    a:visited {
        text-decoration: underline;
        color: #000000 !important;
    }
    
    /* Show URLs for links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 12px;
        color: #666666;
    }
    
    /* Hide navigation and interactive elements */
    .nav-menu,
    .menu-toggle,
    .nav-overlay,
    .mobile-nav-helpers,
    button,
    .quick-action-btn {
        display: none !important;
    }
    
    /* Ensure headings are clear */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        font-weight: bold;
        margin-top: 24px;
        margin-bottom: 12px;
    }
    
    /* Prevent page breaks in important content */
    .character-info,
    .card,
    .important {
        page-break-inside: avoid;
    }
}

/* ===== LANGUAGE AND RTL SUPPORT ===== */

/* Right-to-left language support */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .nav-menu {
    left: auto;
    right: 0;
    transform: translateX(100%);
}

[dir="rtl"] .nav-menu.active {
    transform: translateX(0);
}

[dir="rtl"] .menu-toggle {
    order: 3;
}

[dir="rtl"] .game-title {
    order: 2;
}

[dir="rtl"] .user-info {
    order: 1;
}

/* ===== ERROR HANDLING AND FALLBACKS ===== */

/* Fallback fonts for accessibility (while maintaining design) */
.game-logo {
    alt: "Aura Online";
}

/* Image fallbacks */
img {
    max-width: 100%;
    height: auto;
}

img:not([alt]) {
    outline: 2px solid #ff4444;
}

img:not([alt])::after {
    content: "Missing alt text";
    color: #ff4444;
    font-weight: bold;
    display: block;
    text-align: center;
    padding: 8px;
    background: rgba(255, 68, 68, 0.1);
}

/* ===== ANIMATION SAFETY ===== */

/* Prevent seizure-inducing animations */
@media (prefers-reduced-motion: no-preference) {
    * {
        animation-duration: 0.3s;
        transition-duration: 0.3s;
    }
    
    /* Limit flashing/strobing effects */
    .blink,
    .flash,
    .strobe {
        animation: none !important;
    }
}

/* ===== UTILITY CLASSES ===== */

/* Accessibility utility classes */
.a11y-hidden {
    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;
}

.a11y-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 8px 16px !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
    background: #000000 !important;
    color: #ffffff !important;
    border: 2px solid #4a9eff !important;
    z-index: 10000 !important;
}

.a11y-high-contrast {
    border: 2px solid #ffffff !important;
    background: #000000 !important;
    color: #ffffff !important;
}

/* ===== DEBUGGING HELPERS (Development Only) ===== */

/*
.debug-a11y * {
    outline: 1px solid red !important;
}

.debug-a11y *:focus {
    outline: 3px solid lime !important;
}

.debug-a11y [tabindex] {
    outline: 2px solid blue !important;
}

.debug-a11y [role] {
    outline: 2px solid orange !important;
}
*/
