/**
 * Common Styles - Shared CSS for Game Collection
 * Provides accessibility-friendly base styles and utility classes
 */

/* ─── CSS VARIABLES ───────────────────────────────────────────────────────── */
:root {
  --primary-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --glass-bg: rgba(255, 255, 255, 0.15);
  --glass-border: rgba(255, 255, 255, 0.2);
  --glass-hover: rgba(255, 255, 255, 0.25);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.8);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
  --border-radius-sm: 12px;
  --border-radius-md: 20px;
  --border-radius-lg: 24px;
  --transition-fast: 0.2s ease;
  --transition-medium: 0.3s ease;
  --transition-slow: 0.5s ease;
  
  /* Accessible focus ring */
  --focus-ring-color: #FFD700;
  --focus-ring-width: 4px;
  --focus-ring-offset: 3px;
  
  /* Target sizes */
  --min-target-size: 44px;
  --min-target-size-large: 64px;
}

/* ─── RESET & BASE ────────────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
  background: var(--primary-bg);
  min-height: 100vh;
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Respect user's motion preferences */
@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;
  }
}

/* ─── ACCESSIBILITY ───────────────────────────────────────────────────────── */
/* 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;
}

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px 16px;
  z-index: 10000;
  transition: top 0.3s;
  text-decoration: none;
  font-weight: bold;
}

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

/* Focus styles for keyboard navigation */
.keyboard-navigation *:focus,
.keyboard-navigation button:focus,
.keyboard-navigation a:focus,
.keyboard-navigation [tabindex]:focus,
.keyboard-navigation input:focus,
.keyboard-navigation select:focus {
  outline: var(--focus-ring-width) solid var(--focus-ring-color) !important;
  outline-offset: var(--focus-ring-offset) !important;
}

/* ─── GAME CANVAS ─────────────────────────────────────────────────────────── */
.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: pointer;
}

.game-canvas:active {
  cursor: grabbing;
}

/* ─── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--border-radius-sm);
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: var(--transition-medium);
  min-height: var(--min-target-size);
  min-width: var(--min-target-size);
  text-decoration: none;
  color: inherit;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: white;
  color: #667eea;
}

.btn-primary:hover {
  background: #f0f0f0;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ─── GLASS PANELS ────────────────────────────────────────────────────────── */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid var(--glass-border);
  border-radius: var(--border-radius-md);
  padding: 20px;
}

.glass-panel:hover {
  background: var(--glass-hover);
}

/* ─── MODAL ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--primary-bg);
  padding: 30px;
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 90%;
  color: white;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 20px;
  text-align: center;
}

/* ─── BACK BUTTON ─────────────────────────────────────────────────────────── */
.back-btn {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  font-size: 24px;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: var(--transition-medium);
  cursor: pointer;
  min-height: var(--min-target-size);
  min-width: var(--min-target-size);
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateX(-5px);
}

.back-btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* ─── GAME CONTROLS ─────────────────────────────────────────────────────── */
.game-controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  z-index: 10;
  pointer-events: none;
}

.game-controls > * {
  pointer-events: auto;
}

.game-title {
  color: white;
  font-size: 20px;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

/* ─── SCORE DISPLAY ───────────────────────────────────────────────────────── */
.score-display {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 28px;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  z-index: 10;
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
}

/* ─── INSTRUCTIONS ────────────────────────────────────────────────────────── */
.instructions {
  position: absolute;
  top: 20px;
  right: 20px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 18px;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  z-index: 10;
  text-align: right;
  max-width: 200px;
}

/* ─── SETTINGS BUTTON ──────────────────────────────────────────────────────── */
.settings-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  z-index: 10;
  transition: var(--transition-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--min-target-size);
  min-width: var(--min-target-size);
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

/* ─── HIGH CONTRAST MODE ─────────────────────────────────────────────────── */
.high-contrast body {
  background: #000000 !important;
}

.high-contrast .glass-panel,
.high-contrast .modal-content {
  background: #000000 !important;
  border: 3px solid #ffffff !important;
  color: #ffffff !important;
}

.high-contrast .btn-primary {
  background: #ffffff !important;
  color: #000000 !important;
  border: 3px solid #000000 !important;
}

.high-contrast .btn-secondary {
  background: #000000 !important;
  color: #ffffff !important;
  border: 3px solid #ffffff !important;
}

.high-contrast .game-canvas {
  border: 2px solid #ffffff;
}

/* ─── MOTOR-FRIENDLY MODE ────────────────────────────────────────────────── */
.motor-friendly .btn,
.motor-friendly .back-btn,
.motor-friendly .settings-btn {
  min-height: var(--min-target-size-large) !important;
  min-width: var(--min-target-size-large) !important;
  font-size: 20px !important;
}

.motor-friendly .game-canvas {
  cursor: pointer;
}

.motor-friendly .modal-content {
  max-width: 90% !important;
  width: 90% !important;
}

.motor-friendly input[type="range"] {
  height: 24px !important;
}

.motor-friendly input[type="range"]::-webkit-slider-thumb {
  width: 36px !important;
  height: 36px !important;
}

.motor-friendly input[type="range"]::-moz-range-thumb {
  width: 36px !important;
  height: 36px !important;
}

/* ─── SCREEN READER MODE ────────────────────────────────────────────────── */
.screen-reader-mode .sr-announce {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ─── REDUCED MOTION ──────────────────────────────────────────────────────── */
.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ─── RESPONSIVE DESIGN ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --min-target-size: 48px;
  }
  
  .modal-content {
    max-width: 95%;
    padding: 20px;
  }
  
  .game-title {
    font-size: 16px;
  }
  
  .score-display {
    font-size: 22px;
  }
  
  .instructions {
    font-size: 14px;
    max-width: 150px;
  }
}

@media (max-width: 480px) {
  .game-controls {
    padding: 8px 12px;
  }
  
  .modal-content {
    padding: 15px;
  }
  
  .modal-header {
    font-size: 20px;
  }
}

/* ─── PRINT STYLES ────────────────────────────────────────────────────────── */
@media print {
  body {
    background: white !important;
    color: black !important;
  }
  
  .game-canvas,
  .modal-overlay,
  .settings-btn {
    display: none !important;
  }
}

/* ─── UTILITY CLASSES ─────────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }

.p-sm { padding: 8px; }
.p-md { padding: 16px; }
.p-lg { padding: 24px; }

.m-sm { margin: 8px; }
.m-md { margin: 16px; }
.m-lg { margin: 24px; }

.hidden { display: none !important; }
.invisible { visibility: hidden !important; }
.sr-only {
  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;
}
