/**
 * ACCESSIBILITY ENHANCEMENTS
 * WCAG 2.1 AAA Compliance
 * Version 2.0.0
 *
 * Comprehensive accessibility improvements including:
 * - Skip links
 * - Focus management
 * - Screen reader utilities
 * - Keyboard navigation
 * - Touch target sizing
 * - Color contrast
 * - Reduced motion support
 */

/* ========================================
   SKIP TO CONTENT LINK
   ======================================== */

.skip-to-main,
.skip-to-content,
.skip-link {
    position: fixed;
    top: -100%;
    left: var(--space-4);
    z-index: var(--z-top);
    padding: var(--space-3) var(--space-6);
    background-color: var(--brand-gold-900);
    color: var(--brand-navy-900);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-base);
    text-decoration: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    transition: top var(--duration-base) var(--ease-out);
}

.skip-to-main:focus,
.skip-to-content:focus,
.skip-link:focus {
    top: var(--space-4);
    outline: var(--focus-ring-width) solid var(--brand-navy-900);
    outline-offset: var(--focus-ring-offset);
}

/* ========================================
   SCREEN READER ONLY CONTENT
   ======================================== */

.sr-only,
.visually-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;
}

/* Allow screen reader only content to be focusable */
.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ========================================
   FOCUS STYLES - Enhanced Visibility
   ======================================== */

/* Remove default focus outline (we'll add custom ones) */
*:focus {
    outline: none;
}

/* Custom focus styles for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible,
[role="tab"]:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    position: relative;
    z-index: 10;
}

/* Enhanced focus for navigation links */
.nav-link:focus-visible,
.site-header a:focus-visible {
    outline: var(--focus-ring-width) solid var(--brand-gold-900);
    outline-offset: 4px;
    border-radius: var(--radius-sm);
}

/* Focus for cards and interactive containers */
.card:focus-visible,
.news-card:focus-visible,
.video-card:focus-visible,
.game-card:focus-visible {
    outline: var(--focus-ring-width) solid var(--brand-gold-900);
    outline-offset: 2px;
    box-shadow: var(--shadow-gold-lg);
}

/* ========================================
   KEYBOARD NAVIGATION IMPROVEMENTS
   ======================================== */

/* Make all clickable elements keyboard accessible */
[onclick],
[role="button"],
.clickable {
    cursor: pointer;
}

/* Ensure proper tab order */
[tabindex="-1"]:focus {
    outline: none;
}

/* Visual indicator for keyboard users */
body.using-keyboard *:focus {
    outline: 3px solid var(--brand-gold-900);
    outline-offset: 2px;
}

/* Detect keyboard usage */
body:not(.using-keyboard) *:focus {
    outline: none;
}

body:not(.using-keyboard) *:focus-visible {
    outline: 3px solid var(--brand-gold-900);
    outline-offset: 2px;
}

/* ========================================
   TOUCH TARGET SIZING (WCAG 2.5.5)
   ======================================== */

/* Minimum touch target size of 44x44px */
button,
a,
input[type="checkbox"],
input[type="radio"],
select,
[role="button"],
[role="link"],
.btn,
.nav-link,
.touch-target {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Exceptions for text links in paragraphs */
p a,
li a {
    min-width: auto;
    min-height: auto;
    display: inline;
}

/* Mobile touch targets should be even larger */
@media (max-width: 768px) {
    button,
    .btn,
    .nav-toggle,
    input[type="submit"],
    input[type="button"],
    [role="button"] {
        min-height: var(--touch-target-comfortable);
        padding: var(--space-3) var(--space-6);
    }
}

/* ========================================
   COLOR CONTRAST IMPROVEMENTS (WCAG AAA)
   ======================================== */

/* Ensure all text meets WCAG AAA (7:1 contrast ratio) */
body {
    color: var(--neutral-900);
    background-color: var(--neutral-white);
}

/* High contrast text */
h1, h2, h3, h4, h5, h6,
.heading,
.title,
strong,
b {
    color: var(--brand-navy-900);
}

/* Secondary text with sufficient contrast */
.text-muted,
.meta,
.caption,
small {
    color: var(--neutral-700); /* Ensures 7:1 contrast on white */
}

/* Link contrast */
a {
    color: var(--brand-navy-900);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
}

a:hover,
a:focus {
    color: var(--brand-navy-800);
    text-decoration-thickness: 3px;
}

/* Button contrast */
.btn,
button:not(.unstyled) {
    background-color: var(--brand-gold-900);
    color: var(--brand-navy-900);
    font-weight: var(--font-weight-bold);
}

.btn:hover,
.btn:focus {
    background-color: var(--brand-gold-800);
}

/* ========================================
   ARIA LIVE REGIONS
   ======================================== */

.status-message,
.alert,
.notification,
[role="status"],
[role="alert"],
[aria-live] {
    position: relative;
}

/* Ensure announcements are visible */
[role="status"]:not(:empty),
[role="alert"]:not(:empty) {
    padding: var(--space-4);
    margin: var(--space-4) 0;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--info-500);
}

[role="alert"]:not(:empty) {
    border-left-color: var(--error-500);
}

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

/* Labels must be visible */
label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: var(--font-weight-semibold);
    color: var(--neutral-900);
}

/* Required field indicators */
label .required,
label.required::after {
    content: " *";
    color: var(--error-600);
    font-weight: var(--font-weight-bold);
}

/* Form error messages */
.error-message,
.field-error,
[role="alert"].form-error {
    display: block;
    margin-top: var(--space-2);
    color: var(--error-700);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
}

/* Invalid input styling */
input:invalid,
textarea:invalid,
select:invalid,
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
    border-color: var(--error-600);
    border-width: 2px;
}

input:invalid:focus,
textarea:invalid:focus,
select:invalid:focus {
    outline-color: var(--error-600);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* Valid input confirmation */
input:valid.validated,
textarea:valid.validated,
select:valid.validated,
input[aria-invalid="false"],
textarea[aria-invalid="false"],
select[aria-invalid="false"] {
    border-color: var(--success-600);
}

/* Help text for inputs */
.help-text,
.field-description,
[id$="-description"] {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--neutral-700);
}

/* ========================================
   TABLE ACCESSIBILITY
   ======================================== */

/* Ensure table headers are properly styled */
table th {
    text-align: left;
    font-weight: var(--font-weight-bold);
    background-color: var(--neutral-100);
}

/* Caption styling */
caption {
    padding: var(--space-4);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-lg);
    text-align: left;
    color: var(--brand-navy-900);
}

/* ========================================
   HEADING HIERARCHY
   ======================================== */

/* Ensure proper heading levels */
h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-md); }
h6 { font-size: var(--font-size-base); }

/* Visually hidden headings for screen readers */
.heading-hidden {
    composes: sr-only;
}

/* ========================================
   LOADING & DISABLED STATES
   ======================================== */

/* Disabled elements should be clearly indicated */
:disabled,
[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Loading states */
[aria-busy="true"] {
    position: relative;
    pointer-events: none;
}

[aria-busy="true"]::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--neutral-300);
    border-top-color: var(--brand-gold-900);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   MODAL & DIALOG ACCESSIBILITY
   ======================================== */

/* Trap focus in modal */
.modal[aria-modal="true"],
.dialog[role="dialog"] {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-modal);
}

/* Backdrop */
.modal-backdrop,
.dialog-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: var(--z-modal-backdrop);
}

/* Prevent body scroll when modal is open */
body.modal-open,
body.dialog-open {
    overflow: hidden;
}

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

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Keep opacity transitions for accessibility */
    .fade,
    [data-animate="fade"] {
        transition: opacity 0.2s ease !important;
    }
}

/* ========================================
   HIGH CONTRAST MODE
   ======================================== */

@media (prefers-contrast: high) {
    /* Increase border visibility */
    button,
    input,
    select,
    textarea,
    .card,
    .btn {
        border-width: 2px;
    }

    /* Enhance focus indicators */
    *:focus-visible {
        outline-width: 4px;
    }

    /* Remove subtle backgrounds */
    .card,
    .sidebar-card,
    .schedule-game-card {
        background-color: var(--neutral-white);
    }
}

/* ========================================
   TEXT SPACING (WCAG 1.4.12)
   ======================================== */

/* Allow user text spacing overrides */
* {
    line-height: var(--line-height-normal) !important;
}

p,
li,
dd {
    margin-bottom: calc(var(--space-4) * 1.5);
}

/* ========================================
   KEYBOARD NAVIGATION HELPER
   ======================================== */

/* Add keyboard navigation detection script */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* ========================================
   CONTENT REFLOW (WCAG 1.4.10)
   ======================================== */

/* Ensure content doesn't require horizontal scrolling at 320px width */
@media (max-width: 320px) {
    * {
        max-width: 100%;
        overflow-wrap: break-word;
        word-wrap: break-word;
    }

    img {
        max-width: 100%;
        height: auto;
    }
}

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

@media print {
    /* Ensure links are visible in print */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 80%;
    }

    /* Show skip links in print */
    .skip-to-main,
    .skip-link {
        position: static;
    }

    /* Hide non-essential elements */
    nav,
    .nav-toggle,
    .mobile-menu-backdrop,
    button:not(.print-show) {
        display: none;
    }
}

/* ========================================
   CUSTOM FOCUS INDICATORS
   ======================================== */

/* Navigation focus */
.site-header .nav-link:focus-visible {
    outline: 3px solid var(--brand-gold-900);
    outline-offset: 4px;
    background-color: rgba(255, 184, 28, 0.15);
}

/* Card focus */
.card:focus-within,
.news-card:focus-within,
.video-card:focus-within {
    box-shadow: 0 0 0 3px var(--brand-gold-900);
}

/* Button focus */
.btn:focus-visible,
button:focus-visible {
    outline: 3px solid var(--brand-navy-900);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(255, 184, 28, 0.3);
}
