/* 
   Connect Four - Modern CSS Styling
   ===================================
   
   Features:
   - Responsive design that scales from mobile to desktop
   - Smooth animations for disc drops and hover effects
   - Accessible color scheme with high contrast
   - Modern card-based layout with subtle shadows
   - CSS Grid for perfect board alignment
   - Custom properties for easy theme customization
*/

/* CSS Custom Properties (CSS Variables) for easy theme management */
:root {
  /* Color Palette */
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-player1: #dc2626; /* Red */
  --color-player1-light: #f87171;
  --color-player2: #fbbf24; /* Yellow */
  --color-player2-light: #fde047;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-hover: #f1f5f9;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-shadow: rgba(0, 0, 0, 0.1);
  --color-shadow-strong: rgba(0, 0, 0, 0.15);
  
  /* Board Colors */
  --color-board: #1e40af;
  --color-board-dark: #1e3a8a;
  --color-cell-empty: #f8fafc;
  --color-cell-border: #cbd5e1;
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-full: 50%;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 var(--color-shadow);
  --shadow-md: 0 4px 6px -1px var(--color-shadow);
  --shadow-lg: 0 10px 15px -3px var(--color-shadow);
  
  /* Board Dimensions */
  --board-max-width: 560px;
  --cell-size: 4rem;
  --cell-gap: 0.25rem;
}

/* Reset and Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--color-bg) 0%, #e0e7ff 100%);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  padding: var(--spacing-md);
}

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

/* Main Game Container */
.game-container {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
}

/* Game Header */
.game-header {
  text-align: center;
  background: var(--color-surface);
  padding: var(--spacing-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.game-title {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--spacing-md);
  text-shadow: 0 2px 4px var(--color-shadow);
}

.game-info {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: var(--spacing-xl);
}

/* Turn Indicator */
.turn-indicator {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-weight: 600;
}

.turn-disc {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  border: 3px solid var(--color-border);
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

.turn-disc[data-player="1"] {
  background: var(--color-player1);
  border-color: var(--color-player1);
}

.turn-disc[data-player="2"] {
  background: var(--color-player2);
  border-color: var(--color-player2);
}

/* Score Display */
.score-display {
  display: flex;
  gap: var(--spacing-lg);
  flex-wrap: wrap;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-xs);
}

.score-label {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

.score-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

/* Game Controls */
.game-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: var(--spacing-md);
  background: var(--color-surface);
  padding: var(--spacing-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  align-items: center;
}

.control-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.control-select {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.control-select:hover {
  border-color: var(--color-primary);
}

.control-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.control-btn {
  padding: var(--spacing-sm) var(--spacing-lg);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.875rem;
  min-width: 120px;
}

.control-btn.primary {
  background: var(--color-primary);
  color: white;
}

.control-btn.primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.control-btn.secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-border);
}

.control-btn.secondary:hover:not(:disabled) {
  background: var(--color-surface-hover);
  border-color: var(--color-primary);
}

.control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.control-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* Board Container */
.board-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--color-surface);
  padding: var(--spacing-xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: var(--board-max-width);
  margin: 0 auto;
}

/* Preview Row */
.preview-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--cell-gap);
  margin-bottom: var(--spacing-md);
  width: 100%;
  max-width: calc(7 * var(--cell-size) + 6 * var(--cell-gap));
}

.preview-disc {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--radius-full);
  border: 3px solid transparent;
  opacity: 0;
  transition: all var(--transition-normal);
  pointer-events: none;
}

.preview-disc.visible {
  opacity: 0.7;
  transform: translateY(-10px);
}

.preview-disc.player1 {
  background: var(--color-player1-light);
  border-color: var(--color-player1);
}

.preview-disc.player2 {
  background: var(--color-player2-light);
  border-color: var(--color-player2);
}

/* Game Board */
.game-board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: var(--cell-gap);
  background: var(--color-board);
  padding: var(--spacing-md);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: calc(7 * var(--cell-size) + 6 * var(--cell-gap) + 2 * var(--spacing-md));
  position: relative;
}

/* Board Cells */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--color-cell-empty);
  border-radius: var(--radius-full);
  border: 2px solid var(--color-cell-border);
  position: relative;
  transition: all var(--transition-normal);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.cell.player1 {
  background: var(--color-player1);
  border-color: var(--color-player1);
  animation: dropIn 0.5s ease-out;
}

.cell.player2 {
  background: var(--color-player2);
  border-color: var(--color-player2);
  animation: dropIn 0.5s ease-out;
}

.cell.winning {
  animation: winPulse 1s ease-in-out infinite alternate;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
}

/* Column Overlay for Click Handling */
.column-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  z-index: 10;
  pointer-events: none;
}

.column-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  pointer-events: all;
  border-radius: var(--radius-md);
}

.column-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.column-btn:focus {
  outline: none;
}

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

/* Game Instructions */
.game-instructions {
  background: var(--color-surface);
  padding: var(--spacing-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.game-instructions h2 {
  color: var(--color-primary);
  margin-bottom: var(--spacing-md);
  font-size: 1.5rem;
}

.game-instructions p {
  margin-bottom: var(--spacing-sm);
  color: var(--color-text-muted);
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--color-surface);
  padding: var(--spacing-2xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: modalSlideIn 0.3s ease-out;
}

.modal-title {
  color: var(--color-primary);
  margin-bottom: var(--spacing-md);
  font-size: 1.75rem;
}

.modal-message {
  font-size: 1.125rem;
  margin-bottom: var(--spacing-xl);
  color: var(--color-text);
}

.modal-actions {
  display: flex;
  gap: var(--spacing-md);
  justify-content: center;
  flex-wrap: wrap;
}

/* Confetti Canvas */
.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* Animations */
@keyframes dropIn {
  0% {
    transform: translateY(-300px) scale(0.8);
    opacity: 0;
  }
  50% {
    transform: translateY(10px) scale(1.1);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes winPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  }
  100% {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(255, 255, 255, 1);
  }
}

@keyframes modalSlideIn {
  0% {
    transform: translateY(-50px) scale(0.9);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Responsive Design */
@media (max-width: 640px) {
  :root {
    --cell-size: 3rem;
    --spacing-lg: 1rem;
    --spacing-xl: 1.25rem;
  }
  
  .game-title {
    font-size: 2rem;
  }
  
  .game-info {
    flex-direction: column;
    gap: var(--spacing-md);
  }
  
  .score-display {
    justify-content: center;
  }
  
  .game-controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .control-group {
    flex-direction: row;
    justify-content: space-between;
  }
  
  .control-btn {
    min-width: auto;
    flex: 1;
  }
  
  .board-container {
    padding: var(--spacing-md);
  }
  
  .modal-content {
    padding: var(--spacing-lg);
  }
}

@media (max-width: 480px) {
  :root {
    --cell-size: 2.5rem;
  }
  
  body {
    padding: var(--spacing-sm);
  }
  
  .game-container {
    gap: var(--spacing-md);
  }
  
  .game-title {
    font-size: 1.75rem;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --color-border: #000000;
    --color-cell-border: #000000;
  }
  
  .cell {
    border-width: 3px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus styles for keyboard navigation */
.column-btn:focus-visible {
  outline: none;
}

/* Print styles */
@media print {
  .game-controls,
  .modal-overlay,
  .confetti-canvas {
    display: none !important;
  }
  
  .game-container {
    max-width: 100%;
  }
}
