/**
 * style.css — Connect Four Dark Mode Stylesheet
 * ==============================================
 * Implements a polished dark mode UI with:
 *   - Deep charcoal background with subtle gradients
 *   - Blue game board grid with circular holes
 *   - Yellow and red tokens with 3D gradient effects
 *   - Token drop animation (CSS keyframes)
 *   - Preview token above columns (semi-transparent)
 *   - Win cell pulsing animation
 *   - Responsive layout (works on desktop and tablet)
 *   - Smooth transitions and hover effects
 */

/* ─── CSS Custom Properties (Design Tokens) ──────────────────────────── */

:root {
  /* Dark mode palette */
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-card: #1C2333;
  --bg-hover: #252D3D;

  --text-primary: #E6EDF3;
  --text-secondary: #8B949E;
  --text-muted: #6E7681;

  --accent-blue: #1E6DF2;
  --accent-blue-hover: #388BFD;
  --accent-green: #2DA44E;

  --board-blue: #1E3A8A;
  --board-blue-dark: #1E40AF;
  --board-hole: #0D1117;

  --token-yellow: #FBBF24;
  --token-yellow-dark: #D97706;
  --token-red: #EF4444;
  --token-red-dark: #B91C1C;

  --border-subtle: #30363D;
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  /* Layout */
  --board-cell-size: 72px;
  --board-gap: 6px;
  --token-size: 56px;

  /* Typography */
  --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
}

/* ─── Reset & Global Styles ──────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(30, 58, 138, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(239, 68, 68, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 0%, rgba(251, 191, 36, 0.05) 0%, transparent 50%);
}

/* ─── Language Selector ──────────────────────────────────────────────── */

.lang-bar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
}

.lang-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.lang-select:hover {
  border-color: var(--accent-blue);
}

.lang-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(30, 109, 242, 0.3);
}

/* ─── Main Menu ──────────────────────────────────────────────────────── */

#main-menu {
  text-align: center;
  animation: fadeInUp 0.5s ease;
}

#main-menu.hidden {
  display: none;
}

.menu-title {
  font-size: 3rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--token-yellow), var(--token-red));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.menu-subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2.5rem;
}

.menu-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.menu-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.25rem 2rem;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  min-width: 200px;
}

.menu-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-blue);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(30, 109, 242, 0.2);
}

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

/* ─── Game Container ─────────────────────────────────────────────────── */

#game-container {
  text-align: center;
  animation: fadeInUp 0.4s ease;
}

#game-container.hidden {
  display: none;
}

.game-header {
  margin-bottom: 1.5rem;
}

.game-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
  width: 100%;
}

#game-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  flex-grow: 1;
}

.header-btn {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

#game-status {
  font-size: 1.15rem;
  font-weight: 600;
  min-height: 1.5em;
  transition: color var(--transition-normal);
  margin-bottom: 0.5rem;
}

/* Thinking animation (pulsing dots) */
#game-status.thinking::after {
  content: '';
  animation: thinkingDots 1.5s infinite;
}

@keyframes thinkingDots {
  0% { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
  100% { content: '.'; }
}

/* ─── Preview Row ──────────────────────────────────────────────────────── */

#preview-row {
  display: flex;
  gap: var(--board-gap);
  justify-content: center;
  margin-bottom: 6px;
  height: 40px;
}

.preview-slot {
  width: var(--board-cell-size);
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-token {
  width: var(--token-size);
  height: var(--token-size);
  border-radius: 50%;
  opacity: 0;
  transform: translateY(10px);
  transition: all var(--transition-normal);
}

.preview-yellow {
  background: linear-gradient(135deg, var(--token-yellow), var(--token-yellow-dark));
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3);
}

.preview-red {
  background: linear-gradient(135deg, var(--token-red), var(--token-red-dark));
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.preview-visible {
  opacity: 0.85;
  transform: translateY(0);
}

/* ─── Game Board ─────────────────────────────────────────────────────── */

.board-wrapper {
  display: inline-block;
  background: linear-gradient(180deg, var(--board-blue), var(--board-blue-dark));
  border-radius: 16px;
  padding: 12px;
  box-shadow:
    var(--shadow-lg),
    inset 0 2px 4px rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.08);
}

#game-board {
  display: grid;
  grid-template-columns: repeat(7, var(--board-cell-size));
  grid-template-rows: repeat(6, var(--board-cell-size));
  gap: var(--board-gap);
  cursor: pointer;
}

/* Board disabled state (during AI thinking) */
#game-board.board-disabled {
  cursor: not-allowed;
  opacity: 0.7;
  pointer-events: none;
}

/* ─── Individual Cells ───────────────────────────────────────────────── */

.cell {
  width: var(--board-cell-size);
  height: var(--board-cell-size);
  border-radius: 50%;
  background: var(--board-hole);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

/* Hover glow on empty cells */
.cell:hover .token-empty {
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.15);
}

/* ─── Tokens ─────────────────────────────────────────────────────────── */

.token {
  width: var(--token-size);
  height: var(--token-size);
  border-radius: 50%;
  transition: all var(--transition-fast);
}

/* Empty token slot */
.token-empty {
  background: transparent;
}

/* Player 1 — Yellow token */
.token-yellow {
  background: linear-gradient(135deg, var(--token-yellow), var(--token-yellow-dark));
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.2),
    inset 0 4px 6px rgba(255, 255, 255, 0.2),
    0 2px 8px rgba(251, 191, 36, 0.3);
}

/* Player 2 — Red token */
.token-red {
  background: linear-gradient(135deg, var(--token-red), var(--token-red-dark));
  box-shadow:
    inset 0 -4px 6px rgba(0, 0, 0, 0.2),
    inset 0 4px 6px rgba(255, 255, 255, 0.15),
    0 2px 8px rgba(239, 68, 68, 0.3);
}

/* ─── Drop Animation ─────────────────────────────────────────────────── */

.token-drop {
  animation: dropBounce 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes dropBounce {
  0% {
    transform: translateY(-400px);
    opacity: 0.3;
  }
  60% {
    transform: translateY(0);
    opacity: 1;
  }
  75% {
    transform: translateY(-8px);
  }
  85% {
    transform: translateY(0);
  }
  92% {
    transform: translateY(-3px);
  }
  100% {
    transform: translateY(0);
  }
}

/* ─── Winning Cell Animation ─────────────────────────────────────────── */

.cell-winning .token {
  animation: winPulse 0.8s ease-in-out infinite alternate;
}

@keyframes winPulse {
  0% {
    transform: scale(1);
    box-shadow:
      inset 0 -4px 6px rgba(0, 0, 0, 0.2),
      0 0 12px rgba(255, 255, 255, 0.5);
  }
  100% {
    transform: scale(1.12);
    box-shadow:
      inset 0 -4px 6px rgba(0, 0, 0, 0.2),
      0 0 24px rgba(255, 255, 255, 0.8),
      0 0 48px rgba(255, 255, 255, 0.3);
  }
}

/* ─── Result Overlay ─────────────────────────────────────────────────── */

#result-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#result-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 3rem 4rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.result-emoji {
  font-size: 4rem;
  margin-bottom: 1rem;
  display: block;
}

#result-text {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 2rem;
  color: var(--text-primary);
}

.result-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.result-btn {
  padding: 0.75rem 1.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.result-btn-primary {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}

.result-btn-primary:hover {
  background: var(--accent-blue-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(30, 109, 242, 0.3);
}

.result-btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.result-btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* ─── Readme Link ────────────────────────────────────────────────────── */

.readme-link {
  margin-top: 2rem;
}

.readme-link a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color var(--transition-fast);
}

.readme-link a:hover {
  color: var(--accent-blue);
  text-decoration: underline;
}

/* ─── Animations ─────────────────────────────────────────────────────── */

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

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ─── Responsive Design ──────────────────────────────────────────────── */

@media (max-width: 640px) {
  :root {
    --board-cell-size: 44px;
    --token-size: 34px;
    --board-gap: 3px;
  }

  .menu-title {
    font-size: 2rem;
  }

  .menu-buttons {
    flex-direction: column;
    align-items: center;
  }

  .menu-btn {
    width: 100%;
    max-width: 280px;
  }

  .result-card {
    padding: 2rem 1.5rem;
  }

  .result-emoji {
    font-size: 2.5rem;
  }

  .result-buttons {
    flex-direction: column;
  }

  #preview-row {
    gap: var(--board-gap);
    height: 30px;
  }

  .preview-slot {
    width: var(--board-cell-size);
    height: 30px;
  }
}

@media (max-width: 380px) {
  :root {
    --board-cell-size: 38px;
    --token-size: 30px;
  }
}
