/**
 * ============================================================================
 * BLAZE SPORTS INTEL - ACCESSIBILITY ENHANCEMENTS
 * ============================================================================
 * Version: 3.0.0
 * Description: Comprehensive WCAG 2.1 Level AAA compliance
 * Dependencies: blaze-design-system-enhanced.css
 * Last Updated: 2025-01-20
 * ============================================================================
 */

/**
 * ============================================================================
 * 1. KEYBOARD NAVIGATION ENHANCEMENTS
 * ============================================================================
 * Tab order, focus management, and keyboard shortcuts
 */

/* Focus visible for all interactive elements */
*:focus-visible {
  outline: 3px solid var(--color-brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-md);
  transition: outline-offset var(--duration-fast) var(--ease-smooth);
}

/* Enhanced focus for high-visibility elements */
.btn:focus-visible,
.game-card:focus-visible,
.quick-action-link:focus-visible {
  outline-width: 4px;
  outline-offset: 4px;
  box-shadow:
    0 0 0 4px var(--color-background-primary),
    0 0 0 8px var(--color-brand-primary);
}

/* Focus trap container */
.focus-trap {
  position: relative;
}

.focus-trap:focus-within {
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 4px;
}

/* Skip navigation link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--color-brand-primary);
  color: white;
  padding: 12px 24px;
  text-decoration: none;
  font-weight: 700;
  border-radius: 0 0 var(--radius-md) 0;
  z-index: 10000;
  transition: top var(--duration-fast) var(--ease-smooth);
  box-shadow: 0 4px 12px rgba(217, 98, 0, 0.5);
}

.skip-link:focus {
  top: 0;
  outline: none;
}

/* Keyboard shortcut hints */
.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--glass-surface-medium);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  margin-left: var(--rhythm-xs);
}

/**
 * ============================================================================
 * 2. ARIA LIVE REGIONS
 * ============================================================================
 * Screen reader announcements for dynamic content
 */

/* Polite live region (non-urgent updates) */
.sr-live-polite {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Assertive live region (urgent updates like scores) */
.sr-live-assertive {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Status announcements */
.sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/**
 * ============================================================================
 * 3. SCREEN READER ONLY UTILITIES
 * ============================================================================
 * Content visible only to assistive technologies
 */

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

/* Screen reader only but focusable */
.sr-only-focusable:not(:focus):not(:focus-within) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Screen reader only on mobile (visible on desktop) */
@media (max-width: 767px) {
  .sr-only-mobile {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }
}

/**
 * ============================================================================
 * 4. HIGH CONTRAST MODE SUPPORT
 * ============================================================================
 * Enhanced visibility for Windows High Contrast Mode
 */

@media (prefers-contrast: high) {
  /* Increase border visibility */
  .game-card,
  .btn,
  .card-branded {
    border-width: 3px !important;
  }

  /* Ensure text has solid backgrounds in high contrast */
  .live-badge,
  .btn-primary,
  .btn-secondary {
    border: 3px solid currentColor;
  }

  /* Remove glass morphism effects */
  * {
    backdrop-filter: none !important;
  }

  /* Solid backgrounds */
  .glass-surface-light,
  .glass-surface-medium,
  .glass-surface-heavy {
    background: var(--color-background-primary) !important;
  }
}

/**
 * ============================================================================
 * 5. REDUCED MOTION SUPPORT
 * ============================================================================
 * Respect user preference for reduced animation
 */

@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;
  }

  /* Disable pulse animations */
  .live-badge--pulse,
  .live-dot,
  .game-card--live {
    animation: none !important;
  }

  /* Disable hover transforms */
  .game-card:hover,
  .btn:hover {
    transform: none !important;
  }

  /* Disable particle effects */
  .particle-container,
  .overlay-heat-shimmer::after,
  .shine-metallic::before {
    display: none !important;
  }

  /* Disable skeleton shimmer */
  .skeleton {
    animation: none !important;
    opacity: 0.5;
  }

  /* Keep essential loading indicators visible */
  .loading-spinner {
    animation: spin 1s linear infinite !important;
  }
}

/**
 * ============================================================================
 * 6. TOUCH TARGET SIZING
 * ============================================================================
 * Minimum 44x44px touch targets for mobile
 */

/* Ensure interactive elements meet touch target minimum */
.btn,
.quick-action-link,
.nav-link,
button,
a[href],
input,
select,
textarea {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Exception for inline text links */
a:not([class]) {
  min-height: unset;
  min-width: unset;
  display: inline;
}

/* Touch target expansion for small icons */
.icon-button {
  position: relative;
  padding: 8px;
}

.icon-button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

/**
 * ============================================================================
 * 7. FORM ACCESSIBILITY
 * ============================================================================
 * Labels, error states, and validation feedback
 */

/* Required field indicator */
.form-label-required::after {
  content: ' *';
  color: var(--color-danger);
  font-weight: 700;
}

/* Error state */
.form-input-error {
  border-color: var(--color-danger) !important;
  background-color: rgba(255, 53, 71, 0.1);
}

.form-input-error:focus-visible {
  outline-color: var(--color-danger);
  box-shadow: 0 0 0 4px rgba(255, 53, 71, 0.2);
}

/* Error message */
.form-error-message {
  display: flex;
  align-items: center;
  gap: var(--rhythm-xs);
  padding: var(--rhythm-xs) var(--rhythm-sm);
  margin-top: var(--rhythm-xs);
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  background: rgba(255, 53, 71, 0.1);
  border-left: 3px solid var(--color-danger);
  border-radius: var(--radius-sm);
}

/* Success state */
.form-input-success {
  border-color: var(--color-success) !important;
}

.form-success-message {
  display: flex;
  align-items: center;
  gap: var(--rhythm-xs);
  padding: var(--rhythm-xs) var(--rhythm-sm);
  margin-top: var(--rhythm-xs);
  color: var(--color-success);
  font-size: var(--font-size-sm);
  background: rgba(0, 200, 81, 0.1);
  border-left: 3px solid var(--color-success);
  border-radius: var(--radius-sm);
}

/**
 * ============================================================================
 * 8. MODAL & DIALOG ACCESSIBILITY
 * ============================================================================
 * Focus management and keyboard trapping
 */

/* Modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--rhythm-md);
}

/* Modal container */
.modal-container {
  position: relative;
  background: var(--color-slate-900);
  border: 2px solid var(--glass-border);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

/* Modal close button (accessible) */
.modal-close {
  position: absolute;
  top: var(--rhythm-sm);
  right: var(--rhythm-sm);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-surface-medium);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-smooth);
}

.modal-close:hover,
.modal-close:focus-visible {
  background: var(--glass-surface-heavy);
  border-color: var(--color-brand-primary);
  color: var(--color-brand-primary);
}

/**
 * ============================================================================
 * 9. TABLE ACCESSIBILITY
 * ============================================================================
 * Responsive tables with proper semantics
 */

/* Accessible table wrapper */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--rhythm-md) 0;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
}

/* Table caption (visible or sr-only) */
.table-caption {
  padding: var(--rhythm-sm);
  font-weight: 600;
  text-align: left;
  background: var(--glass-surface-light);
  border-bottom: 1px solid var(--glass-border);
}

/* Sortable column headers */
.table-th-sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 2rem !important;
}

.table-th-sortable::after {
  content: '↕';
  position: absolute;
  right: var(--rhythm-sm);
  opacity: 0.5;
}

.table-th-sortable[aria-sort="ascending"]::after {
  content: '↑';
  opacity: 1;
}

.table-th-sortable[aria-sort="descending"]::after {
  content: '↓';
  opacity: 1;
}

/* Mobile responsive table */
@media (max-width: 767px) {
  .table-responsive {
    display: block;
  }

  .table-responsive thead {
    display: none;
  }

  .table-responsive tr {
    display: block;
    margin-bottom: var(--rhythm-md);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: var(--rhythm-sm);
    background: var(--glass-surface-light);
  }

  .table-responsive td {
    display: flex;
    justify-content: space-between;
    padding: var(--rhythm-xs) 0;
    border-bottom: 1px solid var(--glass-border);
  }

  .table-responsive td:last-child {
    border-bottom: none;
  }

  .table-responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-secondary);
  }
}

/**
 * ============================================================================
 * 10. COLOR BLIND MODE SUPPORT
 * ============================================================================
 * Alternative color schemes for deuteranopia and protanopia
 */

[data-colorblind-mode="deuteranopia"],
[data-colorblind-mode="protanopia"] {
  /* Replace green with blue */
  --color-win-high: #0088FF;
  --color-success: #0088FF;

  /* Replace red with amber */
  --color-live-primary: #FFB800;
  --color-danger: #FFB800;

  /* Adjust gradient */
  --gradient-live: linear-gradient(135deg, #FFB800 0%, #FFA500 100%);
}

/* Color blind mode toggle button */
.colorblind-toggle {
  position: fixed;
  bottom: var(--rhythm-md);
  right: var(--rhythm-md);
  width: 56px;
  height: 56px;
  background: var(--glass-surface-heavy);
  backdrop-filter: blur(var(--glass-blur-md));
  border: 2px solid var(--glass-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  transition: all var(--duration-fast) var(--ease-smooth);
}

.colorblind-toggle:hover,
.colorblind-toggle:focus-visible {
  transform: scale(1.1);
  border-color: var(--color-brand-primary);
  box-shadow: 0 8px 20px rgba(217, 98, 0, 0.4);
}

/**
 * ============================================================================
 * 11. LANDMARKS & SEMANTIC STRUCTURE
 * ============================================================================
 * Proper HTML5 semantic elements
 */

/* Ensure landmarks have proper roles when needed */
[role="banner"],
[role="navigation"],
[role="main"],
[role="complementary"],
[role="contentinfo"] {
  position: relative;
}

/* Landmark labels for screen readers */
nav[aria-label]::before,
section[aria-label]::before,
aside[aria-label]::before {
  content: attr(aria-label);
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/**
 * ============================================================================
 * 12. TEXT RESIZING SUPPORT
 * ============================================================================
 * Ensure layout doesn't break at 200% zoom
 */

/* Prevent horizontal scroll at high zoom */
@media (min-width: 768px) {
  html {
    overflow-x: hidden;
  }

  body {
    max-width: 100vw;
    overflow-x: hidden;
  }
}

/* Responsive images at high zoom */
img {
  max-width: 100%;
  height: auto;
}

/* Flexible containers */
.container,
.section,
.main-content {
  max-width: min(1400px, 100%);
  padding-left: clamp(1rem, 5vw, 2rem);
  padding-right: clamp(1rem, 5vw, 2rem);
}

/**
 * ============================================================================
 * 13. PRINT ACCESSIBILITY
 * ============================================================================
 * Ensure content is accessible when printed
 */

@media print {
  /* Show URLs for links */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }

  /* Don't show URLs for internal navigation */
  a[href^="#"]::after,
  a[href^="javascript:"]::after {
    content: "";
  }

  /* Hide interactive elements */
  .btn,
  .quick-action-link,
  .live-badge,
  .modal-overlay,
  .skip-link {
    display: none !important;
  }

  /* Ensure page breaks don't split important content */
  .game-card,
  .card-branded,
  article {
    page-break-inside: avoid;
  }

  /* High contrast for print */
  body {
    background: white !important;
    color: black !important;
  }

  .game-card,
  .card-branded {
    border: 2px solid black !important;
  }
}

/**
 * ============================================================================
 * END ACCESSIBILITY ENHANCEMENTS
 * ============================================================================
 */
