/*  Variables globales  */
:root {
  --bg-from: #dce8ff;
  --bg-to: #f5f7fa;
  --surface: #ffffff;
  --border: #dde5f0;
  --shadow-sm: rgba(0, 0, 0, 0.06);
  --shadow-md: rgba(0, 0, 0, 0.1);
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.28);
  --x-color: #3b82f6;
  --o-color: #ef4444;
  --win-color: #d97706;
  --win-glow: rgba(217, 119, 6, 0.22);
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 18px;
  --cell-size: 110px;
}

/*  Reset de base  */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/*  Corps de page  */
body {
  font-family: "Poppins", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(145deg, var(--bg-from) 0%, var(--bg-to) 100%);
  min-height: 100vh;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 20px;
}

/*  En-tête  */
header {
  text-align: center;
  margin-bottom: 40px;
  animation: fade-down 0.5s ease both;
}

header h1 {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--x-color), var(--o-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 20px;
}

/*  Sélecteur de mode (PvP / PvE)  */
.modes {
  display: inline-flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 6px;
  box-shadow: 0 2px 10px var(--shadow-sm);
}

.modes button {
  padding: 10px 24px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.25s ease;
}

.modes button.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.modes button:hover:not(.active) {
  color: var(--text);
  background: #f1f5ff;
}

/*  Disposition principale en 3 colonnes  */
main {
  display: grid;
  grid-template-columns: 130px auto 130px;
  gap: 28px;
  align-items: center;
  justify-content: center;
  animation: fade-up 0.5s ease 0.1s both;
}

/*  Cartes de score  */
.score-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--shadow-sm);
  padding: 28px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border-top: 4px solid transparent;
}

/* Bordure colorée selon le joueur */
.score-card--x {
  border-top-color: var(--x-color);
}
.score-card--o {
  border-top-color: var(--o-color);
}

.score-symbol {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
}

.score-card--x .score-symbol {
  color: var(--x-color);
}
.score-card--o .score-symbol {
  color: var(--o-color);
}

.score-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-value {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

/*  Zone de jeu (centre)  */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

/*  Indicateur de tour / résultat  */
#status {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1.5px solid var(--border);
  padding: 10px 30px;
  border-radius: 50px;
  box-shadow: 0 2px 10px var(--shadow-sm);
  transition:
    color 0.3s,
    border-color 0.3s,
    box-shadow 0.3s;
  min-width: 230px;
  text-align: center;
}

#status.turn-x {
  color: var(--x-color);
  border-color: rgba(59, 130, 246, 0.4);
}
#status.turn-o {
  color: var(--o-color);
  border-color: rgba(239, 68, 68, 0.4);
}
#status.win {
  color: var(--win-color);
  border-color: rgba(217, 119, 6, 0.5);
  box-shadow: 0 0 20px var(--win-glow);
}
#status.draw {
  color: var(--text-muted);
  border-color: var(--border);
}

/*  Grille 3×3  */
.grid {
  display: grid;
  grid-template-columns: repeat(3, var(--cell-size));
  grid-template-rows: repeat(3, var(--cell-size));
  gap: 12px;
  padding: 16px;
  background: #edf2ff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 28px var(--shadow-md);
}

/*  Cellules  */
.cell {
  background: var(--surface);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 12px;
  box-shadow: 0 2px 6px var(--shadow-sm);
  transition:
    background 0.2s,
    border-color 0.2s,
    transform 0.15s;
  user-select: none;
}

.cell:hover:not(.taken) {
  background: #eef2ff;
  border-color: var(--primary);
  transform: scale(1.06);
}

.cell.taken {
  cursor: default;
}

/* Cellule gagnante */
.cell.win {
  background: #fffbeb;
  border-color: var(--win-color);
  animation: pulse-win 1.1s ease-in-out infinite alternate;
}

/*  Bouton Nouvelle partie  */
#reset-btn {
  padding: 13px 38px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  border: none;
  border-radius: 50px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 18px var(--primary-glow);
  transition:
    transform 0.25s,
    box-shadow 0.25s;
}

#reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 26px var(--primary-glow);
}
#reset-btn:active {
  transform: translateY(0);
}

/*  Animations  */
@keyframes pop {
  0% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  65% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes pulse-win {
  from {
    box-shadow: 0 0 6px var(--win-glow);
  }
  to {
    box-shadow: 0 0 22px var(--win-glow);
  }
}

@keyframes fade-down {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cell.pop {
  animation: pop 0.25s ease;
}

/*  Responsive  */
@media (max-width: 620px) {
  :root {
    --cell-size: 88px;
  }

  main {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  /* Scores côte à côte sous le jeu */
  .score-card {
    width: 100%;
    max-width: 340px;
    flex-direction: row;
    justify-content: space-around;
    padding: 18px 24px;
    border-top: none;
    border-left: 4px solid transparent;
  }

  .score-card--x {
    border-left-color: var(--x-color);
    order: 2;
  }
  .score-card--o {
    border-left-color: var(--o-color);
    order: 3;
  }
  .game-container {
    order: 1;
  }
}
