/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

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

/* Better focus indicators */
.btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
.tab-btn:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(135, 56, 234, 0.2);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --purple: #6B21A8;
    --blue: #1E40AF;
    --red: #B91C1C;
    --yellow: #D97706;
    --green: #059669;
    --gray-light: #E5E7EB;
    --gray-dark: #111827;
  }
  
  .btn {
    border: 2px solid currentColor;
  }
}

/* Reduced motion support */
@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;
  }
  
  .timer-warning {
    animation: none;
    background-color: var(--red) !important;
    color: var(--white) !important;
    font-weight: bold;
  }
}

/* Color-blind friendly timer warning */
.timer-warning {
  animation: pulse-red 1s infinite;
  position: relative;
}

.timer-warning::after {
  content: "⚠️";
  position: absolute;
  right: -1.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
}

/* ===== PERFORMANCE IMPROVEMENTS ===== */

/* Loading spinner */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  min-height: 100px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-light);
  border-top: 4px solid var(--purple);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

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

/* Error toast notifications */
.error-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--red);
  color: var(--white);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  max-width: 300px;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Connection status indicator */
.status-offline {
  background: var(--red);
  color: var(--white);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.9rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
}

.status-online {
  display: none;
}

/* ===== ENHANCED VISUAL FEEDBACK ===== */

/* Success animation for correct answers */
@keyframes correctPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); background-color: var(--green); }
  100% { transform: scale(1); }
}

.feedback.correct {
  animation: correctPulse 0.6s ease-in-out;
}

/* Shake animation for incorrect answers */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.feedback.incorrect {
  animation: shake 0.5s ease-in-out;
}

/* Button press feedback */
.btn:active:not(:disabled) {
  transform: scale(0.98);
  transition: transform 0.1s ease-in-out;
}

/* ===== IMPROVED RESPONSIVE DESIGN ===== */

/* Better mobile spacing */
@media (max-width: 480px) {
  .app-main {
    padding: 0.5rem;
  }
  
  .scoreboard {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    font-size: 0.9rem;
  }
  
  .scoreboard-item {
    padding: 0.3rem 0.5rem;
  }
  
  #clue-container {
    font-size: 1.5rem;
    padding: 0.75rem;
    min-height: 50px;
  }
  
  .btn {
    padding: 0.6rem;
    font-size: 0.9rem;
  }
  
  .btn.large {
    padding: 0.8rem 1rem;
    font-size: 1rem;
  }
}

/* Tablet optimizations */
@media (min-width: 481px) and (max-width: 768px) {
  .difficulty-buttons {
    justify-content: center;
  }
  
  .difficulty-buttons .btn {
    min-width: 120px;
    max-width: 150px;
  }
  
  #answer-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
}

/* Large screen optimizations */
@media (min-width: 1200px) {
  .app-main {
    max-width: 900px;
  }
  
  #clue-container {
    font-size: 1.75rem;
    padding: 1.5rem;
    min-height: 80px;
  }
  
  .scoreboard {
    justify-content: center;
    gap: 2rem;
  }
  
  .scoreboard-item {
    min-width: 120px;
    text-align: center;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .app-header,
  .app-footer,
  .controls,
  .ad-container,
  #challenge-section {
    display: none;
  }
  
  body {
    background: white;
    color: black;
  }
  
  .btn {
    border: 1px solid black;
    background: white;
    color: black;
  }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --white: #1F2937;
    --gray-light: #374151;
    --gray-dark: #F9FAFB;
  }
  
  body {
    background: var(--white);
    color: var(--gray-dark);
  }
  
  .app-header {
    background: var(--gray-light);
    border-bottom-color: #4B5563;
  }
  
  #clue-container {
    background: var(--gray-light);
    color: var(--gray-dark);
  }
  
  #challenge-link {
    background: var(--gray-light);
    color: var(--gray-dark);
    border-color: #6B7280;
  }
  
  .tab-btn {
    background: var(--gray-light);
    color: var(--gray-dark);
  }
  
  #answer-history-list li {
    background: var(--gray-light);
  }
}

/* ===== ENHANCED ANIMATIONS ===== */

/* Smooth screen transitions */
.screen {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

.screen.active {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered animation for answer options */
#answer-container .btn {
  opacity: 0;
  animation: fadeInUp 0.3s ease-out forwards;
}

#answer-container .btn:nth-child(1) { animation-delay: 0.1s; }
#answer-container .btn:nth-child(2) { animation-delay: 0.2s; }
#answer-container .btn:nth-child(3) { animation-delay: 0.3s; }
#answer-container .btn:nth-child(4) { animation-delay: 0.4s; }

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Pulse animation for new history items */
#answer-history-list li:last-child {
  animation: newItemPulse 0.5s ease-out;
}

@keyframes newItemPulse {
  0% {
    background-color: var(--purple);
    color: var(--white);
    transform: scale(1.02);
  }
  100% {
    background-color: transparent;
    color: inherit;
    transform: scale(1);
  }
}

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

/* Spacing utilities */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }

/* Text utilities */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-bold { font-weight: bold; }
.font-normal { font-weight: normal; }

/* Display utilities */
.hidden { display: none; }
.block { display: block; }
.flex { display: flex; }
.grid { display: grid; }

/* Accessibility utilities */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--purple);
  color: var(--white);
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
}

.skip-link:focus {
  top: 6px;
}
