/**
 * Accessibility Styles
 * WCAG AAA Compliance
 */

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

.skip-links {
  position: fixed;
  top: -200px;
  left: 8px;
  display: flex;
  gap: 4px;
  z-index: 1000000;
  padding: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.skip-links:focus-within { 
  top: 0;
  opacity: 1;
  pointer-events: auto;
}

.skip-link {
  position: relative;
  background: #0f172a;
  color: #fef08a;
  padding: 6px 10px;
  text-decoration: none;
  font-weight: 600;
  font-size: 12px;
  line-height: 1;
  border: 1px solid #334155;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  opacity: 1; /* container controls visibility */
  pointer-events: auto;
}
.skip-link:focus { outline: 2px solid #22c55e; outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .skip-links, .skip-links:focus-within { transition: transform .18s ease; }
}

/* ============================================
   FOCUS INDICATORS (WCAG AAA)
   ============================================ */

*:focus {
  outline: 3px solid #22c55e;
  outline-offset: 2px;
}

/* High contrast focus for buttons */
button:focus,
a:focus,
input:focus,
textarea:focus,
select:focus,
[role="button"]:focus,
[role="tab"]:focus,
[tabindex]:focus {
  outline: 3px solid #22c55e;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

/* Focus within for containers */
.quiz-card:focus-within,
.quest-card:focus-within,
.modal:focus-within {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

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

/* Enhanced focus-visible for keyboard navigation */
*:focus-visible {
  outline: 3px solid #22c55e;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.3);
}

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

.sr-only,
.visually-hidden {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ============================================
   IMPROVED COLOR CONTRAST (WCAG AAA 7:1)
   ============================================ */

/* Ensure text has sufficient contrast */
body {
  color: #f1f5f9; /* Improved from #e5e7eb */
}

/* Muted text with better contrast */
.muted,
.text-muted,
.secondary-text {
  color: #cbd5e1; /* Improved from #94a3b8 */
}

/* Links with better contrast */
a {
  color: #60a5fa;
  text-decoration: underline;
}

a:hover,
a:focus {
  color: #93c5fd;
  text-decoration: underline;
}

/* Buttons with better contrast */
button,
.btn {
  color: #ffffff;
  font-weight: 600;
}

button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Success/error colors with better contrast */
.success-text {
  color: #6ee7b7; /* WCAG AAA compliant green */
}

.error-text {
  color: #fca5a5; /* WCAG AAA compliant red */
}

.warning-text {
  color: #fcd34d; /* WCAG AAA compliant yellow */
}

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

/* Indicate keyboard navigation mode */
body.using-keyboard *:focus {
  outline: 3px solid #22c55e;
  outline-offset: 2px;
}

/* Enhanced hover states for better feedback */
button:hover:not(:disabled),
.clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

button:active:not(:disabled),
.clickable:active {
  transform: translateY(0);
}

/* ============================================
   QUIZ ANSWER ACCESSIBILITY
   ============================================ */

.answer-option {
  cursor: pointer;
  transition: all 0.2s ease;
}

.answer-option:hover {
  transform: scale(1.02);
}

.answer-option:focus {
  outline: 3px solid #22c55e;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.2);
}

.answer-option[aria-checked="true"] {
  outline: 3px solid #60a5fa;
  box-shadow: 0 0 0 5px rgba(96, 165, 250, 0.3);
}

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

[role="dialog"],
.modal {
  outline: none;
}

[role="dialog"]:focus,
.modal:focus {
  outline: none;
}

/* Modal overlay for context */
.modal-overlay {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

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

/* Enhanced form inputs */
input,
textarea,
select {
  border: 2px solid #475569;
  transition: border-color 0.2s;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #22c55e;
  outline: 3px solid #22c55e;
  outline-offset: 2px;
}

input:invalid,
textarea:invalid,
select:invalid {
  border-color: #ef4444;
}

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

/* Error messages */
.error-message,
[role="alert"] {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.1);
  border: 2px solid #ef4444;
  padding: 12px;
  border-radius: 6px;
  margin-top: 8px;
}

/* Required field indicator */
.required::after,
[aria-required="true"]::after {
  content: " *";
  color: #fca5a5;
}

/* ============================================
   TAB NAVIGATION (View Switcher)
   ============================================ */

[role="tab"] {
  cursor: pointer;
}

[role="tab"]:hover {
  background: rgba(96, 165, 250, 0.1);
}

[role="tab"][aria-selected="true"] {
  background: rgba(34, 197, 94, 0.15);
  border-bottom: 3px solid #22c55e;
}

[role="tab"]:focus {
  outline: 3px solid #22c55e;
  outline-offset: -2px;
  z-index: 10;
}

/* ============================================
   LOADING STATES
   ============================================ */

[aria-busy="true"] {
  opacity: 0.6;
  cursor: wait;
  pointer-events: none;
}

/* Loading spinner with accessible label */
.loading-spinner::after {
  content: "Loading...";
  position: absolute;
  left: -10000px;
}

/* ============================================
   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;
  }
  
  /* Preserve card flip animation — it's the core interaction, not decoration */
  .quest-card {
    transition-duration: 0.72s !important;
  }

  /* Keep essential focus animations */
  *:focus,
  *:focus-visible {
    transition: none;
  }
}

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

@media (prefers-contrast: high) {
  *:focus {
    outline-width: 4px;
    outline-color: currentColor;
  }
  
  button,
  .btn {
    border: 2px solid currentColor;
  }
  
  .answer-option {
    border: 2px solid currentColor;
  }
}

/* ============================================
   DARK MODE (forced-colors: active)
   ============================================ */

@media (forced-colors: active) {
  *:focus {
    outline: 3px solid Highlight;
  }
  
  button:disabled {
    opacity: 1;
    color: GrayText;
  }
}

/* ============================================
   TOUCH TARGET SIZE (minimum 44x44px)
   ============================================ */

button,
a,
input[type="checkbox"],
input[type="radio"],
select,
[role="button"],
[role="tab"],
.clickable {
  min-height: 44px;
  min-width: 44px;
  padding: 12px;
  touch-action: manipulation;
}

/* Exception for icon-only buttons - ensure hit area */
.icon-button,
.btn-icon {
  padding: 12px;
  min-width: 44px;
  min-height: 44px;
}

/* ============================================
   TEXT SPACING (user override support)
   ============================================ */

/* Allow text spacing customization */
* {
  line-height: 1.5 !important;
  letter-spacing: 0.05em;
  word-spacing: 0.1em;
}

p {
  margin-bottom: 1em;
}

/* ============================================
   TOOLTIPS AND HINTS
   ============================================ */

[aria-describedby] {
  position: relative;
}

.tooltip,
[role="tooltip"] {
  background: #1e293b;
  color: #f1f5f9;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.875rem;
  border: 1px solid #22c55e;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

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

[aria-live="polite"],
[aria-live="assertive"],
[role="status"],
[role="alert"] {
  /* Visible for debugging, hidden for production */
}

/* ============================================
   RESPONSIVE TEXT SIZE
   ============================================ */

/* Ensure text can be resized up to 200% */
html {
  font-size: 100%;
}

@media (min-width: 1200px) {
  html {
    font-size: 112.5%; /* 18px base */
  }
}

/* ============================================
   PRINT STYLES (Accessibility)
   ============================================ */

@media print {
  .skip-links,
  .no-print,
  [aria-hidden="true"] {
    display: none !important;
  }
  
  a::after {
    content: " (" attr(href) ")";
  }
  
  *:focus {
    outline: none;
  }
}

/* ============================================
   CUSTOM PROPERTIES FOR EASY THEMING
   ============================================ */

:root {
  --focus-color: #22c55e;
  --focus-outline-width: 3px;
  --focus-outline-offset: 2px;
  --text-color: #f1f5f9;
  --muted-color: #cbd5e1;
  --link-color: #60a5fa;
  --error-color: #fca5a5;
  --success-color: #6ee7b7;
  --warning-color: #fcd34d;
}
