/* =========================================================================
   STYLE DE LA MACHINE DE NIM - APPRENTISSAGE PAR RENFORCEMENT
   Design moderne, réaliste et pédagogique (Arnaud DURAND / Mathix)
   ========================================================================= */

@charset "UTF-8";

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background-color: #f1f5f9;
  color: #1e293b;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* En-tête */
.app-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  color: #ffffff;
  padding: 1rem 1.5rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.header-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}

.header-title {
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge-pill {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  background: #f59e0b;
  color: #0f172a;
}

.header-subtitle {
  font-size: 0.78rem;
  color: #cbd5e1;
  margin-top: 0.15rem;
}

.header-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: #e2e8f0;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all 0.2s;
}

.header-link:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

/* Conteneur principal */
.main-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
  width: 100%;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Carte générique */
.card-section {
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  padding: 1.25rem;
}

/* =========================================================================
   BARRE DES STATISTIQUES
   ========================================================================= */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.stats-group {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.stat-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.stat-dot.blue { background: #2563eb; box-shadow: 0 0 8px rgba(37,99,235,0.4); }
.stat-dot.red { background: #dc2626; box-shadow: 0 0 8px rgba(220,38,38,0.4); }
.stat-dot.green { background: #16a34a; box-shadow: 0 0 8px rgba(22,163,74,0.4); }

.stat-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1.1;
}
.stat-value.blue { color: #2563eb; }
.stat-value.red { color: #dc2626; }
.stat-value.green { color: #16a34a; }

.stat-progress-container {
  flex: 1;
  max-width: 440px;
  min-width: 260px;
}

.stat-progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.stat-progress-bar {
  width: 100%;
  height: 14px;
  border-radius: 9999px;
  background: #ef4444;
  overflow: hidden;
  display: flex;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

.stat-progress-fill-blue {
  background: #2563eb;
  height: 100%;
  transition: width 0.35s ease;
  border-radius: 9999px 0 0 9999px;
}

/* =========================================================================
   DISPOSITION PLATEAU & JOURNAL LATÉRAL
   ========================================================================= */
.game-and-log-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 1.15rem;
  align-items: stretch;
  width: 100%;
}

.board-main-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.board-main-col #nim-table-root {
  display: flex;
  flex-direction: column;
}

/* =========================================================================
   PLATEAU DE JEU DE NIM (FEUTRINE & BOIS)
   ========================================================================= */
.game-table {
  background: radial-gradient(ellipse at center, #1b4d3e 0%, #12382c 70%, #0a2019 100%);
  border: 9px solid #5c3a1e;
  border-radius: 20px;
  box-shadow: 
    inset 0 0 35px rgba(0, 0, 0, 0.7),
    0 10px 25px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
  padding: 1.25rem 1.15rem;
  color: #ffffff;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-height: 590px;
}

.game-table::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: radial-gradient(rgba(255,255,255,0.06) 1.5px, transparent 0);
  background-size: 18px 18px;
  pointer-events: none;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 0.75rem;
  margin-bottom: 0.85rem;
  position: relative;
  z-index: 1;
}

.table-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.table-badge-tokens {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid rgba(16, 185, 129, 0.5);
  color: #6ee7b7;
  padding: 0.2rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 800;
}

.table-turn-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: 8px;
}
.table-turn-badge.machine { background: #2563eb; color: #ffffff; }
.table-turn-badge.opponent { background: #ea580c; color: #ffffff; }

/* Alignement vertical direct : Casiers juste au-dessus des pions */
.board-aligned-container {
  width: 100%;
  overflow-x: auto;
  margin: 0.35rem 0 0.85rem 0;
  padding: 0.35rem 0.15rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
  flex: 1;
  display: flex;
  align-items: center;
}

.board-aligned-container::-webkit-scrollbar {
  height: 6px;
}
.board-aligned-container::-webkit-scrollbar-track {
  background: transparent;
}
.board-aligned-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 9999px;
}

.board-aligned-grid {
  display: grid;
  grid-template-columns: repeat(var(--board-cols, 8), minmax(95px, 1fr));
  gap: 0.5rem;
  width: 100%;
}

.aligned-box-col {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: center;
  position: relative;
  overflow: visible;
  min-width: 0;
}

/* Zone d'attente au-dessus du casier (bille piochée) */
.box-holding-slot {
  width: 100%;
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  background: rgba(0, 0, 0, 0.28);
  border: 1.5px dashed rgba(255, 255, 255, 0.2);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.3s ease;
  overflow: visible;
  box-sizing: border-box;
}

.box-holding-slot.has-waiting {
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid rgba(251, 191, 36, 0.7);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.35);
}

.box-holding-slot.holding-rewarding {
  border-color: #22c55e;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.55);
}

.box-holding-slot.holding-penalizing {
  border-color: #ef4444;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.55);
}

.holding-empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

.holding-dash {
  font-size: 0.56rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.28);
}

.holding-active-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  animation: bead-extract-to-top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  z-index: 10;
}

.holding-beads-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  position: relative;
  z-index: 15;
}

.holding-bead-extracted {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: 
    inset -2px -2px 5px rgba(0, 0, 0, 0.6), 
    inset 2px 2px 5px rgba(255, 255, 255, 0.85), 
    0 3px 6px rgba(0,0,0,0.5);
  display: inline-block;
  flex-shrink: 0;
}

.holding-tag {
  font-size: 0.62rem;
  font-weight: 900;
  color: #fef08a;
  background: rgba(0, 0, 0, 0.5);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

/* Animations d'extraction, récompense et punition */
@keyframes bead-extract-to-top {
  0% {
    transform: translateY(35px) scale(0.6);
    opacity: 0;
  }
  70% {
    transform: translateY(-6px) scale(1.15);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes bead-bonus-pop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  60% {
    transform: scale(1.3);
    filter: drop-shadow(0 0 10px #4ade80);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.anim-bonus-bead-appear {
  animation: bead-bonus-pop 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes beads-dive-down {
  0% {
    transform: translateY(0) scale(1);
    filter: drop-shadow(0 0 10px #4ade80);
    opacity: 1;
  }
  30% {
    transform: translateY(-8px) scale(1.1);
    filter: drop-shadow(0 0 16px #22c55e) brightness(1.3);
    opacity: 1;
  }
  100% {
    transform: translateY(75px) scale(0.6);
    filter: drop-shadow(0 0 2px #22c55e);
    opacity: 0;
  }
}

.anim-dive-into-box {
  animation: beads-dive-down 0.85s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
}

@keyframes bead-fly-away-up {
  0% {
    transform: translateY(0) scale(1);
    filter: drop-shadow(0 0 8px #ef4444);
    opacity: 1;
  }
  25% {
    transform: translateY(-10px) scale(1.2);
    filter: drop-shadow(0 0 16px #dc2626) brightness(1.35);
    opacity: 1;
  }
  100% {
    transform: translateY(-90px) scale(0.2);
    filter: blur(3px) drop-shadow(0 0 0 transparent);
    opacity: 0;
  }
}

.anim-punish-fly-away {
  animation: bead-fly-away-up 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards !important;
}

@keyframes bead-shake-danger {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px) rotate(-8deg); filter: drop-shadow(0 0 8px #ef4444); }
  40%, 80% { transform: translateX(3px) rotate(8deg); filter: drop-shadow(0 0 8px #ef4444); }
}

.holding-bead-shake {
  animation: bead-shake-danger 0.35s ease infinite;
}

.aligned-pion-slot {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0;
  position: relative;
  min-height: 66px;
}

.pion-slot-label {
  font-size: 0.68rem;
  font-weight: 800;
  color: #a7f3d0;
  margin-top: 0.3rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.token-slot-empty {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.25);
  font-size: 0.72rem;
  font-weight: 700;
  user-select: none;
  transition: all 0.3s ease;
}

/* Ligne des joueurs sous les casiers et les pions */
.board-players-bar {
  display: grid;
  grid-template-columns: minmax(170px, 220px) 1fr minmax(170px, 220px);
  gap: 0.85rem;
  align-items: center;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  padding-top: 0.85rem;
  position: relative;
  z-index: 1;
}

@media (max-width: 960px) {
  .board-players-bar {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

.player-panel {
  background: rgba(15, 23, 42, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: all 0.3s;
}

.player-panel.active {
  border-color: #38bdf8;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.4);
  background: rgba(15, 23, 42, 0.75);
}

.player-panel.active-opponent {
  border-color: #34d399;
  box-shadow: 0 0 16px rgba(52, 211, 153, 0.4);
  background: rgba(15, 23, 42, 0.75);
}

.player-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 0.25rem;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
.player-avatar.machine { background: rgba(37, 99, 235, 0.35); border: 2px solid #60a5fa; }
.player-avatar.opponent { background: rgba(16, 185, 129, 0.35); border: 2px solid #34d399; }

.player-name {
  font-size: 0.92rem;
  font-weight: 800;
}
.player-name.machine { color: #93c5fd; }
.player-name.opponent { color: #a7f3d0; }

.player-sub {
  font-size: 0.68rem;
  color: #94a3b8;
  margin-bottom: 0.55rem;
}

/* Coupelle de jetons pris */
.tokens-captured-area {
  width: 100%;
}

.captured-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #cbd5e1;
  margin-bottom: 0.25rem;
}

.token-tray {
  background: radial-gradient(circle at 40% 40%, rgba(255,255,255,0.08), rgba(0,0,0,0.5));
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
  min-height: 44px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
}

.mini-token {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd700, #b38600);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.8);
  border: 1px solid #ffe87c;
  display: inline-block;
  animation: mini-token-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes mini-token-pop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Actions au centre */
.center-actions-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.5rem;
  text-align: center;
}

.center-turn-indicator {
  font-size: 0.82rem;
  font-weight: 700;
  color: #e2e8f0;
}

/* Jetons de Nim dorés 3D */
.nim-token {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe87c 0%, #e6b800 45%, #b38600 80%, #805e00 100%);
  box-shadow: 
    0 5px 10px rgba(0,0,0,0.45),
    inset 0 2px 4px rgba(255,255,255,0.8),
    inset 0 -3px 5px rgba(0,0,0,0.5);
  border: 2px dashed rgba(255, 235, 150, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s ease;
  user-select: none;
}

.nim-token::after {
  content: '';
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.5);
  background: radial-gradient(circle at 40% 40%, rgba(255,255,255,0.35), rgba(0,0,0,0.15));
}

.nim-token.human-selectable {
  cursor: pointer;
  animation: pulse-selectable 1.5s infinite;
}

.nim-token.human-selectable:hover {
  transform: translateY(-8px) scale(1.15);
  filter: brightness(1.2);
  box-shadow: 0 10px 20px rgba(255, 215, 0, 0.6), inset 0 2px 4px rgba(255,255,255,0.9);
}

@keyframes pulse-selectable {
  0%, 100% {
    box-shadow: 0 5px 10px rgba(0,0,0,0.45), 0 0 0 0 rgba(255, 215, 0, 0.5);
  }
  50% {
    box-shadow: 0 7px 14px rgba(0,0,0,0.55), 0 0 0 7px rgba(255, 215, 0, 0);
  }
}

/* Animation de prise des jetons vers la machine ou l'adversaire */
@keyframes token-fly-to-machine {
  0% { transform: scale(1) translateY(0); opacity: 1; }
  35% { transform: scale(1.25) translateY(-35px); filter: brightness(1.3); }
  100% { transform: scale(0.55) translate(-220px, 80px); opacity: 0.1; }
}

@keyframes token-fly-to-opponent {
  0% { transform: scale(1) translateY(0); opacity: 1; }
  35% { transform: scale(1.25) translateY(-35px); filter: brightness(1.3); }
  100% { transform: scale(0.55) translate(220px, 80px); opacity: 0.1; }
}

.token-taking-machine {
  animation: token-fly-to-machine 0.65s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.token-taking-opponent {
  animation: token-fly-to-opponent 0.65s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* Actions du joueur humain */
.human-actions-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.85rem;
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(251, 191, 36, 0.5);
  padding: 0.5rem 0.85rem;
  border-radius: 12px;
}

.btn-human-move {
  padding: 0.4rem 0.85rem;
  background: #f59e0b;
  color: #0f172a;
  font-weight: 800;
  font-size: 0.8rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: all 0.2s;
}

.btn-human-move:hover {
  background: #fbbf24;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.4);
}

/* Bannière élégante flottante de fin de manche (ne cache pas les casiers) */
.end-banner-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(8px);
  padding: 0.4rem 1.15rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  z-index: 25;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
  animation: banner-drop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes banner-drop {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.end-banner-bar.win {
  border-color: #22c55e;
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.4);
}

.end-banner-bar.loss {
  border-color: #ef4444;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
}

.banner-bar-title {
  font-size: 0.82rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.banner-bar-title.win { color: #4ade80; }
.banner-bar-title.loss { color: #f87171; }

.btn-banner-action {
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.76rem;
  font-weight: 800;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s;
}

.btn-banner-action.win {
  background: #16a34a;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.4);
}
.btn-banner-action.win:hover { background: #15803d; transform: scale(1.04); }

.btn-banner-action.loss {
  background: #dc2626;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4);
}
.btn-banner-action.loss:hover { background: #b91c1c; transform: scale(1.04); }

.btn-banner-action.replay {
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}
.btn-banner-action.replay:hover { background: #1d4ed8; transform: scale(1.04); }

/* =========================================================================
   BARRE DE CONTRÔLE PAS-À-PAS
   ========================================================================= */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.controls-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  padding: 0.65rem 1.25rem;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.88rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.45);
}

.btn-success {
  padding: 0.65rem 1.1rem;
  background: #16a34a;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(22, 163, 74, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.2s;
}

.btn-success:hover {
  background: #15803d;
  transform: translateY(-1px);
}

.btn-warning {
  padding: 0.65rem 1.1rem;
  background: #d97706;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.2s;
}

.btn-secondary {
  padding: 0.65rem 1rem;
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
  font-size: 0.82rem;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
}

.speed-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #64748b;
}

.btn-fast-train {
  padding: 0.5rem 0.75rem;
  background: #ede9fe;
  color: #6b21a8;
  font-weight: 700;
  font-size: 0.75rem;
  border-radius: 8px;
  border: 1px solid #c4b5fd;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s;
}

.btn-fast-train:hover {
  background: #ddd6fe;
}

.btn-continuous {
  padding: 0.55rem 0.95rem;
  background: #7c3aed;
  color: #ffffff;
  font-weight: 700;
  font-size: 0.78rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.3);
}

.btn-continuous:hover {
  background: #6d28d9;
}

/* =========================================================================
   JOURNAL PÉDAGOGIQUE (COMPACT, À DROITE DU PLATEAU À LA MÊME HAUTEUR)
   ========================================================================= */
.log-column-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.compact-log-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 0.85rem;
  background: #ffffff;
  border-radius: 20px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.compact-log-panel .log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 0.35rem;
  margin-bottom: 0.25rem;
}

.compact-log-panel .log-title {
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.compact-log-panel .log-subtitle {
  font-size: 0.65rem;
  color: #64748b;
  margin-bottom: 0.45rem;
  line-height: 1.25;
}

.btn-clear-logs {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  color: #475569;
}
.btn-clear-logs:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.compact-log-panel .log-list {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.compact-log-panel .log-message {
  padding: 0.38rem 0.55rem;
  border-radius: 6px;
  font-size: 0.71rem;
  line-height: 1.35;
  border-left: 3px solid #94a3b8;
  background: #f8fafc;
  color: #334155;
  animation: log-slide 0.2s ease-out;
  word-break: break-word;
}

@keyframes log-slide {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.compact-log-panel .log-message.neutral {
  border-left-color: #64748b;
  background: #f8fafc;
  color: #334155;
}

.compact-log-panel .log-message.machine {
  border-left-color: #2563eb;
  background: #eff6ff;
  color: #1e3a8a;
  font-weight: 500;
}

.compact-log-panel .log-message.opponent {
  border-left-color: #ea580c;
  background: #fff7ed;
  color: #9a3412;
  font-weight: 500;
}

.compact-log-panel .log-message.reward {
  border-left-color: #16a34a;
  background: #f0fdf4;
  color: #166534;
  font-weight: 700;
}

.compact-log-panel .log-message.penalty {
  border-left-color: #dc2626;
  background: #fef2f2;
  color: #991b1b;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .game-and-log-layout {
    grid-template-columns: 1fr;
  }
  .log-column-wrapper {
    position: static;
    height: auto;
  }
  .compact-log-panel {
    position: static;
    inset: auto;
    height: auto;
    max-height: 240px;
  }
  .compact-log-panel .log-list {
    max-height: 170px;
  }
}

/* =========================================================================
   LES CASIERS DE LA MACHINE (BOÎTES D'ALLUMETTES & BILLES)
   ========================================================================= */
.boxes-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.boxes-title-group h2 {
  font-size: 1.15rem;
  font-weight: 900;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.boxes-subtitle {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.15rem;
}

.boxes-legend {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: #ffffff;
  padding: 0.35rem 0.75rem;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: #334155;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* Grille des casiers (8 boîtes alignées sur grand écran) */
.matchboxes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
}

/* Boîte d'allumettes individuelle */
.matchbox-card {
  background: linear-gradient(145deg, #fbf7ee 0%, #ede3ce 100%);
  border: 2px solid #cbb592;
  border-radius: 12px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.9);
  padding: 0.45rem 0.4rem;
  position: relative;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
  height: 180px;
  min-height: 180px;
  max-height: 180px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.matchbox-card.active-box {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px #fef08a, 0 6px 18px rgba(245, 158, 11, 0.4);
  background: linear-gradient(145deg, #fffdf0 0%, #fef3c7 100%);
  z-index: 5;
}

.box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(180, 83, 9, 0.2);
  padding-bottom: 0.15rem;
  margin-bottom: 0.25rem;
  height: 20px;
  min-height: 20px;
  max-height: 20px;
  box-sizing: border-box;
  overflow: hidden;
}

.box-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
  overflow: hidden;
}

.box-number {
  font-weight: 900;
  font-size: 0.78rem;
  color: #78350f;
  white-space: nowrap;
}

.box-active-badge {
  font-size: 0.52rem;
  font-weight: 900;
  text-transform: uppercase;
  background: #f59e0b;
  color: #451a03;
  padding: 0.05rem 0.25rem;
  border-radius: 4px;
  white-space: nowrap;
  animation: pulse-active 1.2s infinite;
}

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

.box-total-balls {
  font-size: 0.65rem;
  font-weight: 800;
  color: #92400e;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Chambre intérieure du casier avec billes 3D */
.box-chamber {
  background: #fffdfa;
  border: 1px solid rgba(180, 83, 9, 0.18);
  border-radius: 8px;
  padding: 0.35rem 0.3rem;
  height: 70px;
  min-height: 70px;
  max-height: 70px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-content: flex-start;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
  box-sizing: border-box;
}

/* Bille 3D réaliste */
.bead-ball {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 
    inset -2px -2px 3px rgba(0,0,0,0.45),
    inset 2px 2px 3px rgba(255,255,255,0.7),
    0 1px 3px rgba(0,0,0,0.3);
  position: relative;
  flex-shrink: 0;
}

.bead-ball::before {
  content: '';
  position: absolute;
  top: 15%;
  left: 20%;
  width: 32%;
  height: 28%;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  transform: rotate(-25deg);
}

/* Barre de proportions */
.prob-bar-container {
  height: 6px;
  min-height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: #cbd5e1;
  display: flex;
  margin: 0.25rem 0;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
  box-sizing: border-box;
}

.prob-bar-segment {
  height: 100%;
  transition: width 0.35s ease;
}

/* Décompte chiffré par couleur */
.box-counts {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.15rem;
  margin-bottom: 0.25rem;
  height: 16px;
  min-height: 16px;
  max-height: 16px;
  box-sizing: border-box;
}

.count-item {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.65rem;
  font-weight: 800;
  color: #334155;
  white-space: nowrap;
}

.count-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Tiroir de coup retenu */
.drawer-slot {
  background: #231a14;
  border: 1px solid #453327;
  border-radius: 6px;
  height: 24px;
  min-height: 24px;
  max-height: 24px;
  padding: 0 0.35rem;
  font-size: 0.65rem;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
}
.drawer-slot.empty {
  color: #64748b;
}
.drawer-slot.filled {
  color: #fde68a;
  background: #2a1b12;
  border-color: #854d0e;
}

.drawer-move-label,
.drawer-empty-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
}

/* Animations de récompense / punition */
.matchbox-card.reward-pulse {
  animation: box-reward 0.8s ease-in-out infinite alternate;
  border-color: #22c55e;
}

.matchbox-card.penalty-pulse {
  animation: box-penalty 0.8s ease-in-out infinite alternate;
  border-color: #ef4444;
}

@keyframes box-reward {
  0% { box-shadow: 0 0 0 2px #86efac, 0 8px 16px rgba(34, 197, 94, 0.3); }
  100% { box-shadow: 0 0 0 6px #22c55e, 0 12px 28px rgba(34, 197, 94, 0.6); transform: scale(1.05); }
}

@keyframes box-penalty {
  0% { box-shadow: 0 0 0 2px #fca5a5, 0 8px 16px rgba(239, 68, 68, 0.3); }
  100% { box-shadow: 0 0 0 6px #ef4444, 0 12px 28px rgba(239, 68, 68, 0.6); transform: scale(1.05); }
}

.floating-badge {
  position: absolute;
  top: -14px;
  right: -8px;
  font-weight: 900;
  font-size: 0.78rem;
  padding: 0.2rem 0.65rem;
  border-radius: 9999px;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: float-badge 1.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  pointer-events: none;
  z-index: 25;
}

.floating-badge.reward {
  background: linear-gradient(135deg, #22c55e, #16a34a);
}

.floating-badge.penalty {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
}

@keyframes float-badge {
  0% { transform: translateY(8px) scale(0.6); opacity: 0; }
  30% { transform: translateY(-4px) scale(1.15); opacity: 1; }
  75% { transform: translateY(-12px) scale(1); opacity: 1; }
  100% { transform: translateY(-26px) scale(0.9); opacity: 0; }
}

/* =========================================================================
   SECTION DES PARAMÈTRES
   ========================================================================= */
.settings-details {
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 1rem 1.25rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.settings-summary {
  cursor: pointer;
  font-weight: 800;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
}
.settings-summary::-webkit-details-marker { display: none; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #f1f5f9;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #475569;
}

.form-control {
  width: 100%;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #1e293b;
  font-weight: 600;
}

.form-control:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.btn-reset-danger {
  width: 100%;
  padding: 0.5rem 0.85rem;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-reset-danger:hover {
  background: #fee2e2;
  color: #991b1b;
}

/* Pied de page */
.app-footer {
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  padding: 1rem 1.5rem;
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 1.5rem;
}

.footer-container {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.footer-container a {
  color: #2563eb;
  font-weight: 700;
  text-decoration: none;
}
.footer-container a:hover {
  text-decoration: underline;
}
