/* === RESET & BASE === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
  touch-action: pan-y;
  overflow-x: hidden;
}

/* === HEADER === */
/* === HEADER MODERNISÉ === */
header {
  background: transparent;
  padding: 1rem;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.header-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  max-width: 1400px;
  margin: 0 auto;
}

/* Box générique du header */
.header-box {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 0.8rem 1.2rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
}

.header-box:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  transform: translateY(-2px);
}

/* Titre */
.header-title {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem 2rem;
}

.header-title h1 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* Tour du joueur */
.header-turn {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 180px;
  text-align: center;
}

.header-label {
  font-size: 0.75rem;
  color: #636e72;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#turn-info {
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: bold;
  color: #2d3436;
  white-space: nowrap;
}

/* Boutons d'action */
.header-actions {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding: 0.5rem;
}

.header-btn {
  padding: 0.7rem 1.2rem;
  font-size: clamp(0.85rem, 1.8vw, 1rem);
  font-weight: 600;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.header-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
}

.header-btn:active:not(:disabled) {
  transform: translateY(0);
}

.header-btn:disabled {
  background: #95a5a6;
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

/* Niveau IA */
.header-ai {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 140px;
}

.header-select {
  padding: 0.6rem 1rem;
  font-size: clamp(0.85rem, 1.8vw, 1rem);
  font-weight: 600;
  background: white;
  color: #2d3436;
  border: 2px solid #667eea;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23667eea' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-right: 2.5rem;
}

.header-select:hover {
  border-color: #764ba2;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.header-select:focus {
  outline: none;
  border-color: #764ba2;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
}

/* Responsive Mobile */
@media (max-width: 768px) {
  .header-container {
    gap: 0.8rem;
    padding: 0.5rem;
  }
  
  .header-box {
    padding: 0.6rem 1rem;
  }
  
  .header-title {
    width: 100%;
    text-align: center;
    padding: 0.8rem 1rem;
  }
  
  .header-turn {
    min-width: auto;
    flex: 1;
  }
  
  .header-actions {
    width: 100%;
    justify-content: center;
    gap: 0.5rem;
  }
  
  .header-btn {
    flex: 1;
    min-width: 120px;
  }
  
  .header-ai {
    width: 100%;
  }
  
  .header-select {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .header-title h1 {
    font-size: 1.3rem;
  }
  
  .header-btn {
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
  }
}


#game-status {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

#turn-info {
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  font-weight: bold;
  transition: all 0.3s ease;
}

/* === GAME CONTAINER === */
main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}

#game-container {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  max-width: 900px;
  width: 100%;
}

/* === ZONES BARRIÈRES === */
.walls-zone {
  margin: 0.5rem 0;
  padding: 0.8rem;
  border-radius: 12px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.walls-zone-top {
  background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
}

.walls-zone-bottom {
  background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
}

.walls-label {
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  font-weight: bold;
  margin-bottom: 0.5rem;
  text-align: center;
  color: #2d3436;
}

.walls-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  min-height: 40px;
  padding: 0.5rem;
}

/* Barrière draggable */
.wall-piece {
  width: clamp(45px, 10vw, 60px);
  height: clamp(10px, 2vw, 12px);
  background: linear-gradient(135deg, #2d3436 0%, #636e72 100%);
  border-radius: 6px;
  cursor: grab;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  transition: all 0.2s ease;
  touch-action: none;
}

.wall-piece:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.wall-piece:active {
  cursor: grabbing;
}

/* === BOARD WRAPPER === */
#board-wrapper {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
  padding: 1rem;
  background: #dfe6e9;
  border-radius: 12px;
  overflow: hidden;
}

#board-container {
  position: relative;
  width: fit-content;
  touch-action: none;
}

/* === GRILLE PLATEAU === */
#board-grid {
  display: grid;
  background: #b2bec3;
  border: 3px solid #2d3436;
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.3);
  position: relative;
  z-index: 1;
  touch-action: none;
}

.board-cell {
  background: #ffffff;
  border: 2px solid #636e72;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.board-cell:hover {
  background: #e8f4f8;
  transform: scale(1.05);
}

/* Pions */
.board-cell.player-1::after,
.board-cell.player-2::after {
  content: '';
  width: 70%;
  height: 70%;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

.board-cell.player-1::after {
  background: radial-gradient(circle, #0984e3 0%, #0652dd 100%);
  box-shadow: 0 0 15px rgba(9, 132, 227, 0.8), inset 0 -3px 8px rgba(0,0,0,0.3);
}

.board-cell.player-2::after {
  background: radial-gradient(circle, #fdcb6e 0%, #e17055 100%);
  box-shadow: 0 0 15px rgba(253, 203, 110, 0.8), inset 0 -3px 8px rgba(0,0,0,0.3);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.board-cell.highlight-move {
  background: #55efc4 !important;
  box-shadow: inset 0 0 15px rgba(85, 239, 196, 0.8);
  animation: glow 1s infinite alternate;
}

@keyframes glow {
  from { box-shadow: inset 0 0 10px #00d4aa; }
  to { box-shadow: inset 0 0 20px #00b894; }
}

/* === SVG LAYER === */
#walls-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.wall-placed {
  fill: #2d3436;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

/* GHOST AMÉLIORÉ avec bordures pointillées */
.wall-preview {
  opacity: 0.9;
  transition: all 0.15s ease;
  animation: pulse-ghost 1.5s infinite;
}

@keyframes pulse-ghost {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.wall-preview.valid {
  fill: rgba(0, 184, 148, 0.4);
  stroke: #00b894;
  stroke-width: 3;
  stroke-dasharray: 6, 4;
  filter: drop-shadow(0 0 12px rgba(0, 184, 148, 0.8));
}

.wall-preview.invalid {
  fill: rgba(214, 48, 49, 0.3);
  stroke: #d63031;
  stroke-width: 3;
  stroke-dasharray: 6, 4;
  opacity: 0.6;
  filter: drop-shadow(0 0 12px rgba(214, 48, 49, 0.6));
}

/* === ZONES DE PLACEMENT === */
.wall-zone-horizontal,
.wall-zone-vertical {
  position: absolute;
  cursor: pointer;
  z-index: 15;
  border-radius: 4px;
  transition: all 0.2s ease;
  background: transparent;
  touch-action: none;
}

.wall-zone-horizontal:hover,
.wall-zone-vertical:hover {
  background: rgba(0, 184, 148, 0.25);
  box-shadow: 0 0 10px rgba(0, 184, 148, 0.5);
}

/* États drag/touch */
.wall-zone-horizontal.drop-active,
.wall-zone-vertical.drop-active {
  background: rgba(33, 150, 243, 0.4);
  z-index: 25;
}

.wall-zone-horizontal.drop-valid,
.wall-zone-vertical.drop-valid {
  background: rgba(0, 184, 148, 0.6) !important;
  box-shadow: 0 0 15px rgba(0, 184, 148, 0.8);
  animation: pulse-valid 1s infinite;
}

@keyframes pulse-valid {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.wall-zone-horizontal.drop-invalid,
.wall-zone-vertical.drop-invalid {
  background: rgba(214, 48, 49, 0.4) !important;
  box-shadow: 0 0 15px rgba(214, 48, 49, 0.6);
  cursor: not-allowed;
}

/* === POPUP VICTOIRE === */
#victory-popup {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  border-radius: 8px;
  animation: fadeIn 0.5s ease;
}

#victory-popup.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.victory-content {
  background: white;
  padding: 2rem 1.5rem;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  max-width: 90%;
  animation: slideUp 0.5s ease;
}

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

.victory-emoji {
  font-size: clamp(3rem, 10vw, 5rem);
  margin-bottom: 1rem;
  animation: bounce 1s ease infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

.victory-title {
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin-bottom: 0.5rem;
  color: #2d3436;
}

.victory-subtitle {
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  color: #636e72;
  margin-bottom: 1.5rem;
}

.victory-btn {
  padding: 0.8rem 1.5rem;
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: bold;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
}

.victory-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* === CONTROLS === */
#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
  align-items: center;
  margin-top: 1rem;
}

button:not(.victory-btn), select {
  padding: 0.6rem 1.2rem;
  font-size: clamp(0.85rem, 2vw, 1rem);
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

button:not(.victory-btn) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

button:not(.victory-btn):hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}

button:disabled {
  background: #95a5a6 !important;
  cursor: not-allowed;
  opacity: 0.6;
}

select {
  background: white;
  border: 2px solid #667eea;
  color: #333;
  cursor: pointer;
}

#ai-level {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}



/* === SECTION RÈGLES === */
#rules-section {
  background: transparent; /* Même couleur que le body */
  padding: 3rem 1.5rem;
  margin-top: 2rem;
}

.rules-container {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  align-items: start; /* IMPORTANT : Permet aux cards d'avoir des hauteurs différentes */
}

.rules-card {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  height: fit-content; /* AJOUT : La card s'adapte à son contenu */
}

.rules-card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  transform: translateY(-4px);
}

.rules-card h2 {
  color: #667eea;
  font-size: 1.5rem;
  margin-bottom: 1rem;
  border-bottom: 3px solid #667eea;
  padding-bottom: 0.5rem;
}

.rules-card h3 {
  color: #2d3436;
  font-size: 1.2rem;
  margin-top: 1.5rem;
  margin-bottom: 0.8rem;
}

.rules-card p {
  color: #2d3436;
  line-height: 1.8;
  margin-bottom: 1rem;
}

.rules-card ul {
  list-style: none;
  padding-left: 0;
  margin-bottom: 0; /* Pas d'espace vide en bas */
}

.rules-card ul li {
  color: #2d3436;
  line-height: 1.8;
  margin-bottom: 0.8rem;
  padding-left: 1.5rem;
  position: relative;
}

.rules-card ul li:last-child {
  margin-bottom: 0; /* Supprimer l'espace après le dernier item */
}

.rules-card ul li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: #667eea;
  font-weight: bold;
}

.rules-card ul ul {
  margin-top: 0.5rem;
  margin-left: 1rem;
}

.rules-card ul ul li::before {
  content: "◦";
  color: #764ba2;
}

.rules-card strong {
  color: #667eea;
  font-weight: 600;
}

/* === FOOTER === */
#game-footer {
  background: linear-gradient(135deg, #2d3436 0%, #000000 100%);
  color: white;
  padding: 2rem 1.5rem;
  text-align: center;
  border-top: 3px solid #667eea;
  margin-top: 3rem; /* Espace avant le footer */
}

.footer-content {
  max-width: 800px;
  margin: 0 auto;
}

.footer-credit {
  font-size: 1.2rem;
  margin-bottom: 0.8rem;
  font-weight: 500;
}

.heart {
  color: #e74c3c;
  animation: heartbeat 1.5s infinite;
  display: inline-block;
  font-size: 1.3rem;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  10%, 30% { transform: scale(1.1); }
  20%, 40% { transform: scale(1); }
}

.footer-link {
  color: #667eea;
  text-decoration: none;
  font-weight: 700;
  transition: all 0.3s ease;
  position: relative;
  padding-bottom: 2px;
}

.footer-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: #667eea;
  transition: width 0.3s ease;
}

.footer-link:hover {
  color: #764ba2;
}

.footer-link:hover::after {
  width: 100%;
}

.footer-info {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 0.5rem;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  #rules-section {
    padding: 2rem 1rem;
  }
  
  .rules-container {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  
  .rules-card {
    padding: 1.5rem;
  }
  
  .rules-card h2 {
    font-size: 1.3rem;
  }
  
  .rules-card h3 {
    font-size: 1.1rem;
  }
  
  #game-footer {
    padding: 1.5rem 1rem;
  }
  
  .footer-credit {
    font-size: 1rem;
  }
}



/* === RESPONSIVE MOBILE === */
@media (max-width: 600px) {
  #game-container {
    padding: 0.5rem;
  }
  
  .walls-zone {
    margin: 0.3rem 0;
    padding: 0.5rem;
  }
  
  #board-wrapper {
    padding: 0.5rem;
    margin: 0.5rem 0;
  }
  
  .wall-piece {
    min-width: 50px;
    min-height: 11px;
  }
  
  #controls {
    gap: 0.5rem;
    margin-top: 0.5rem;
  }
}

/* Amélioration tactile */
@media (hover: none) and (pointer: coarse) {
  .wall-zone-horizontal,
  .wall-zone-vertical {
    z-index: 20;
  }
  
  .board-cell:hover {
    transform: none;
  }
}
