/**
 * NonVisionGames - Accessibility Stylesheet
 * 
 * WCAG 2.1 AAA Compliance
 * Optimized for screen readers, keyboard navigation, and assistive technologies
 */

/* ============================================================================
   SKIP LINKS (WCAG 2.4.1 - Bypass Blocks)
   ============================================================================ */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    z-index: 1000;
    padding: var(--space-3) var(--space-6);
    background-color: var(--color-primary);
    color: var(--color-light);
    text-decoration: none;
    font-weight: var(--font-weight-bold);
    border-radius: 0 0 var(--border-radius) 0;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: 0;
    outline: var(--focus-ring-width) solid var(--color-light);
    outline-offset: calc(var(--focus-ring-offset) * -1);
}

/* ============================================================================
   FOCUS INDICATORS (WCAG 2.4.7 - Focus Visible)
   ============================================================================ */

/* Enhanced focus styles for all interactive elements */
a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    /* Remove browser default */
    outline-style: solid;
}

/* Focus within for containers */
a:focus-within,
button:focus-within {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* Ensure focus is never hidden */
*:focus {
    scroll-margin-top: var(--space-8);
    scroll-margin-bottom: var(--space-8);
}

/* High visibility focus for critical actions */
.btn:focus,
.nav-link:focus {
    outline: var(--focus-ring-width) solid var(--color-accent);
    outline-offset: var(--focus-ring-offset);
    box-shadow: 0 0 0 calc(var(--focus-ring-width) + var(--focus-ring-offset)) rgba(255, 107, 0, 0.2);
}

/* ============================================================================
   SCREEN READER ONLY CONTENT (WCAG 1.3.1 - Info and Relationships)
   ============================================================================ */

/* Visually hidden but available to screen readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

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

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

/* Ensure keyboard users can see where they are */
*:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* Remove focus outline for mouse users (but keep for keyboard) */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Highlight interactive regions on keyboard focus */
nav:focus-within {
    background-color: rgba(0, 102, 204, 0.05);
}

/* ============================================================================
   REDUCED MOTION (WCAG 2.3.3 - Animation from Interactions)
   ============================================================================ */

@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 skip link transition for usability */
    .skip-link {
        transition: none;
    }
}

/* ============================================================================
   HIGH CONTRAST MODE (WCAG 1.4.6 - Contrast Enhanced)
   ============================================================================ */

@media (prefers-contrast: high) {
    :root {
        --color-text: #000000;
        --color-background: #FFFFFF;
        --color-primary: #0000CC;
        --color-border: #000000;
    }

    /* Ensure all borders are visible */
    .card,
    .btn,
    input,
    select,
    textarea {
        border: 2px solid var(--color-text);
    }

    /* Stronger focus indicators */
    *:focus {
        outline-width: 4px;
        outline-color: #000000;
    }

    /* Remove subtle shadows */
    .card,
    .btn,
    .site-header {
        box-shadow: none;
    }
}

/* ============================================================================
   LINK ACCESSIBILITY
   ============================================================================ */

/* External link indicator for screen readers */
a[href^="http"]:not([href*="nonvisiongames"])::after {
    content: " (external link)";
    font-size: 0;
    speak: always;
}

/* Download link indicator */
a[download]::before,
a[href$=".zip"]::before,
a[href$=".exe"]::before,
a[href$=".dmg"]::before {
    content: "Download: ";
    font-size: 0;
    speak: always;
}

/* Email link indicator */
a[href^="mailto:"]::before {
    content: "Email: ";
    font-size: 0;
    speak: always;
}

/* Ensure link text is never too small */
a {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
}

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

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

/* Ensure labels are always associated */
label {
    display: block;
    margin-bottom: var(--space-2);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

/* Required field indicator */
label.required::after,
label[aria-required="true"]::after {
    content: " *";
    color: var(--color-error);
    font-weight: var(--font-weight-bold);
    speak: literal-punctuation;
}

/* Screen reader announcement for required fields */
.required-indicator {
    color: var(--color-error);
}

/* Form inputs with proper sizing */
input,
textarea,
select {
    min-height: 44px;
    padding: var(--space-3);
    font-size: var(--font-size-base);
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius);
    background-color: var(--color-background);
    color: var(--color-text);
}

/* Focus state for form elements */
input:focus,
textarea:focus,
select:focus {
    border-color: var(--color-primary);
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: 0;
}

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

/* Error message styling */
.error-message {
    color: var(--color-error);
    font-size: var(--font-size-sm);
    margin-top: var(--space-2);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.error-message::before {
    content: "⚠";
    font-size: var(--font-size-lg);
    speak: literal-punctuation;
}

/* Help text */
.help-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-2);
}

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

table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: var(--space-6);
}

th {
    text-align: left;
    font-weight: var(--font-weight-bold);
    background-color: var(--color-surface);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
}

td {
    padding: var(--space-3);
    border: 1px solid var(--color-border);
}

/* Zebra striping for better readability */
tbody tr:nth-child(even) {
    background-color: var(--color-gray-100);
}

/* Highlight row on focus */
tbody tr:focus-within {
    background-color: rgba(0, 102, 204, 0.1);
    outline: 2px solid var(--color-primary);
}

/* ============================================================================
   HEADING ACCESSIBILITY
   ============================================================================ */

/* Ensure headings have proper spacing for screen reader navigation */
h1,
h2,
h3,
h4,
h5,
h6 {
    scroll-margin-top: var(--space-8);
}

/* Visual indicator for heading levels (development only) */
[data-debug-headings="true"] h1::before {
    content: "H1: ";
    color: red;
}

[data-debug-headings="true"] h2::before {
    content: "H2: ";
    color: orange;
}

[data-debug-headings="true"] h3::before {
    content: "H3: ";
    color: yellow;
}

[data-debug-headings="true"] h4::before {
    content: "H4: ";
    color: green;
}

[data-debug-headings="true"] h5::before {
    content: "H5: ";
    color: blue;
}

[data-debug-headings="true"] h6::before {
    content: "H6: ";
    color: purple;
}

/* ============================================================================
   LANDMARK REGIONS
   ============================================================================ */

/* Ensure landmarks are visually distinct (optional, for debugging) */
[data-debug-landmarks="true"] [role="banner"],
[data-debug-landmarks="true"] header {
    outline: 3px solid blue;
}

[data-debug-landmarks="true"] [role="navigation"],
[data-debug-landmarks="true"] nav {
    outline: 3px solid green;
}

[data-debug-landmarks="true"] [role="main"],
[data-debug-landmarks="true"] main {
    outline: 3px solid red;
}

[data-debug-landmarks="true"] [role="complementary"],
[data-debug-landmarks="true"] aside {
    outline: 3px solid purple;
}

[data-debug-landmarks="true"] [role="contentinfo"],
[data-debug-landmarks="true"] footer {
    outline: 3px solid orange;
}

/* ============================================================================
   TEXT SIZING & ZOOM (WCAG 1.4.4 - Resize Text)
   ============================================================================ */

/* Ensure text can scale up to 200% without breaking layout */
@media (min-width: 1px) {
    html {
        font-size: 100%;
    }
}

/* Support for user font size preferences */
@media (prefers-reduced-data: reduce) {

    /* Reduce non-essential visual elements */
    .card {
        box-shadow: none;
    }

    img {
        /* Placeholder for lazy loading */
    }
}

/* ============================================================================
   TOUCH TARGET SIZE (WCAG 2.5.5 - Target Size)
   ============================================================================ */

/* Ensure all interactive elements are at least 44x44px */
button,
.btn,
a.nav-link,
input[type="submit"],
input[type="button"],
input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    padding: var(--space-3) var(--space-4);
}

/* ============================================================================
   COLOR INDEPENDENCE (WCAG 1.4.1 - Use of Color)
   ============================================================================ */

/* Ensure information is not conveyed by color alone */
.success,
.error,
.warning,
.info {
    position: relative;
    padding-left: calc(var(--space-6) + var(--space-2));
}

.success::before {
    content: "✓";
    position: absolute;
    left: var(--space-3);
    font-weight: bold;
}

.error::before {
    content: "✗";
    position: absolute;
    left: var(--space-3);
    font-weight: bold;
}

.warning::before {
    content: "⚠";
    position: absolute;
    left: var(--space-3);
    font-weight: bold;
}

.info::before {
    content: "ℹ";
    position: absolute;
    left: var(--space-3);
    font-weight: bold;
}

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

@media print {

    /* Ensure focus indicators don't print */
    *:focus {
        outline: none;
    }

    /* Show skip link targets in print */
    .skip-link {
        position: static;
    }

    /* Expand abbreviations */
    abbr[title]::after {
        content: " (" attr(title) ")";
    }
}

/* ============================================================================
   BROWSER SPECIFIC FIXES
   ============================================================================ */

/* Firefox: Remove dotted outline */
::-moz-focus-inner {
    border: 0;
}

/* Safari: Ensure form elements are styled */
input[type="search"] {
    -webkit-appearance: textfield;
}

input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

/* ============================================================================
   LIVE REGIONS (ARIA)
   ============================================================================ */

/* Ensure live regions are properly announced */
[aria-live="polite"],
[aria-live="assertive"] {
    position: relative;
}

/* Status messages */
.status-message {
    padding: var(--space-4);
    border-radius: var(--border-radius);
    margin-bottom: var(--space-4);
    border-left: 4px solid;
}

.status-message.success {
    background-color: rgba(0, 170, 68, 0.1);
    border-color: var(--color-success);
    color: var(--color-success);
}

.status-message.error {
    background-color: rgba(204, 0, 0, 0.1);
    border-color: var(--color-error);
    color: var(--color-error);
}

.status-message.warning {
    background-color: rgba(255, 153, 0, 0.1);
    border-color: var(--color-warning);
    color: var(--color-warning);
}

.status-message.info {
    background-color: rgba(0, 102, 204, 0.1);
    border-color: var(--color-info);
    color: var(--color-info);
}