* { box-sizing: border-box; }

:root {
  --cell-size: 30px;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #eef2f7;
  color: #1a2330;
}

#app {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  padding: 16px;
  min-height: 100vh;
}

#boardPanel h1 {
  margin: 0 0 10px;
}

#boardWrap {
  overflow: auto;
  border: 2px solid #1f2a38;
  background: #d7dde6;
  padding: 6px;
  max-height: calc(100vh - 70px);
}

#board {
  display: grid;
  width: max-content;
  gap: 0;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  padding: 0;
  margin: 0;
  border: 1px solid #aab4c2;
  background: #f7f9fc;
  font-size: 19px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.vide {
  background: #f5f7fb;
  color: transparent;
}

.cell.j1 {
  background: #d72a2a;
  color: #fff;
  border: 2px solid #fff;
}

.cell.j2 {
  background: #29b14f;
  color: #111;
  border: 2px solid #111;
}

.cell.bloquee {
  background: #090909;
  border-color: #000;
  color: #090909;
  cursor: not-allowed;
}

.cell.selected-claim {
  outline: 3px solid #ffd200;
  outline-offset: -3px;
}

#inspector {
  background: #fff;
  border: 1px solid #c6d1df;
  border-radius: 8px;
  padding: 12px;
  height: fit-content;
}

#inspector h2 {
  margin: 0 0 12px;
}

.row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 14px;
}

.buttons {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.buttons button {
  padding: 8px 10px;
  font-weight: 600;
  cursor: pointer;
}

.buttons button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#message {
  min-height: 42px;
  margin-top: 12px;
  padding: 8px;
  background: #f2f6fc;
  border: 1px solid #d4deeb;
  border-radius: 6px;
  font-size: 13px;
}

#boardWrap { position: relative; }

.ai-thinking {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-weight: 600;
  pointer-events: auto;
  z-index: 5;
}

.ai-thinking.hidden { display: none; }

.ai-thinking .spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: morplus-spin .8s linear infinite;
}

@keyframes morplus-spin {
  to { transform: rotate(360deg); }
}

.cell.ai-blink {
  box-shadow: inset 0 0 0 2px #ffd54f, 0 0 10px rgba(255, 213, 79, 0.9);
  animation: ai-blink 0.66s ease-in-out 3; /* 3 fois ≈ 2s */
}

@keyframes ai-blink {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.9); }
}

body {
  background:
    radial-gradient(1200px 700px at 10% -10%, #2a3b70 0%, transparent 60%),
    radial-gradient(1000px 800px at 110% 10%, #4d1f54 0%, transparent 55%),
    #0c1224;
  color: #edf2ff;
}

#boardPanel h1 {
  background: linear-gradient(90deg, #fff, #b8e1ff, #ffd6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#boardWrap {
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 14px;
  background: rgba(9, 14, 30, 0.75);
  box-shadow: 0 20px 50px rgba(0,0,0,.45), inset 0 0 25px rgba(122,252,255,.08);
}

#board { border-radius: 10px; overflow: hidden; background: #1a233d; }

.cell {
  border: 1px solid rgba(255,255,255,.07);
  background: #202a46;
  transition: transform .12s ease, filter .2s ease, box-shadow .2s ease;
}
.cell:hover { transform: scale(1.05); z-index: 1; }

.cell.j1 {
  background: radial-gradient(circle at 30% 30%, #ff94a8 0%, #ff4d6d 55%, #b01637 100%);
  color: #fff;
  text-shadow: 0 0 8px rgba(255,255,255,.7);
  box-shadow: inset 0 0 10px rgba(255,255,255,.35), 0 0 12px rgba(255,77,109,.45);
}
.cell.j2 {
  background: radial-gradient(circle at 30% 30%, #b3ffc8 0%, #22c55e 55%, #0c7a38 100%);
  color: #0e1a12;
  text-shadow: 0 0 8px rgba(255,255,255,.45);
  box-shadow: inset 0 0 10px rgba(255,255,255,.3), 0 0 12px rgba(34,197,94,.45);
}

.cell.selected-claim {
  animation: claimPulse .8s ease-in-out infinite;
}
@keyframes claimPulse {
  0%,100% { box-shadow: inset 0 0 0 0 rgba(255,224,102,.2); }
  50% { box-shadow: inset 0 0 0 3px rgba(255,224,102,.45), 0 0 14px rgba(255,224,102,.6); }
}

.cell.pawn-pop { animation: pawnPop .38s cubic-bezier(.2,.8,.2,1); }
@keyframes pawnPop {
  0% { transform: scale(.15); filter: brightness(2.2); }
  70% { transform: scale(1.16); }
  100% { transform: scale(1); filter: brightness(1); }
}

.cell.lock-pop { animation: lockPop .55s ease; }
@keyframes lockPop {
  0% { transform: scale(1.18); filter: saturate(1.8); }
  100% { transform: scale(1); filter: saturate(1); }
}

#board.pre-win-active { animation: boardThrob .9s ease-in-out infinite; }
@keyframes boardThrob {
  0%,100% { box-shadow: 0 0 0 rgba(255,255,255,0); }
  50% { box-shadow: 0 0 24px rgba(255,214,102,.35); }
}

.cell.pre-win-line {
  animation: preWinBlink .55s ease-in-out infinite;
  box-shadow: inset 0 0 0 2px #ffe066, 0 0 16px rgba(255,224,102,.9);
}
@keyframes preWinBlink {
  0%,100% { filter: brightness(1); transform: scale(1); }
  50% { filter: brightness(1.8); transform: scale(1.08); }
}

.cell.win-line {
  animation: winPulse .85s ease-in-out infinite;
  box-shadow: inset 0 0 0 2px #fff, 0 0 18px rgba(122,252,255,.95);
}
@keyframes winPulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

#inspector {
  background: rgba(14, 22, 44, 0.85);
  border: 1px solid rgba(255,255,255,.2);
  color: #edf2ff;
  backdrop-filter: blur(6px);
}
.row span { color: #b8c5e6; }

.buttons button {
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(180deg, #4b6fff, #2c45c4);
  box-shadow: 0 8px 18px rgba(44,69,196,.45);
}

.victory-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(5, 10, 24, 0.78);
}
.victory-overlay.hidden { display: none; }

#confettiLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
#confettiLayer .confetti {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: confettiFall 2.8s cubic-bezier(.15,.7,.25,1) forwards;
}
@keyframes confettiFall {
  to { transform: translate3d(var(--dx), 110vh, 0) rotate(var(--rot)); }
}

.victory-card {
  position: relative;
  z-index: 2;
  min-width: 300px;
  text-align: center;
  border-radius: 18px;
  padding: 22px 24px;
  background: linear-gradient(180deg, rgba(36,55,112,.95), rgba(19,30,64,.95));
  border: 1px solid rgba(255,255,255,.28);
  box-shadow: 0 24px 60px rgba(0,0,0,.45), inset 0 0 20px rgba(122,252,255,.18);
}

.cell {
  border: 1px solid transparent; /* par défaut: pas de grille */
}

/* mode débutant */
#board.grid-help .cell {
  border-color: rgba(255, 255, 255, 0.10);
}

/* Grille "light" mais visible */
#board.grid-help .cell.vide {
  border-color: rgba(95, 110, 135, 0.55) !important;
}

/* Évite le gros contraste des pions (optionnel) */
#board.grid-help .cell.j1,
#board.grid-help .cell.j2,
#board.grid-help .cell.bloquee {
  border-width: 1px !important;
}

/* Layer FX */
.fx-layer{
  position:absolute; inset:0; pointer-events:none; z-index:9; overflow:hidden;
}

/* Texte combo */
.fx-word{
  position:absolute;
  left:50%; top:42%;
  transform:translate(-50%,-50%) scale(.55);
  font-weight:900;
  font-size:38px;
  letter-spacing:1px;
  color:#fff;
  text-shadow:0 0 12px rgba(255,255,255,.7), 0 10px 24px rgba(0,0,0,.5);
  animation:fxWord .9s ease forwards;
}
.fx-word.gold{ color:#ffe066; }
.fx-word.rainbow{
  background:linear-gradient(90deg,#ff6b6b,#ffd166,#7afcff,#80ed99,#c77dff);
  -webkit-background-clip:text; background-clip:text; color:transparent;
}
@keyframes fxWord{
  0%{ opacity:0; transform:translate(-50%,-50%) scale(.3) rotate(-5deg); }
  20%{ opacity:1; transform:translate(-50%,-50%) scale(1.08) rotate(0); }
  100%{ opacity:0; transform:translate(-50%,-90%) scale(.95); }
}

/* Shake board (triade) */
#boardWrap.shake{ animation:boardShake .34s linear; }
@keyframes boardShake{
  0%,100%{ transform:translateX(0); }
  20%{ transform:translateX(-6px); }
  40%{ transform:translateX(6px); }
  60%{ transform:translateX(-4px); }
  80%{ transform:translateX(4px); }
}

/* Étincelles */
.spark{
  position:absolute;
  width:7px; height:7px;
  border-radius:50%;
  box-shadow:0 0 10px currentColor;
  animation:sparkFly .62s ease-out forwards;
}
@keyframes sparkFly{
  to{ transform:translate(var(--dx), var(--dy)) scale(0); opacity:0; }
}

.rules-box{
  margin-top:12px;
  border:1px solid rgba(255,255,255,.2);
  border-radius:10px;
  background:rgba(10,16,34,.7);
}
.rules-box > summary{
  cursor:pointer;
  user-select:none;
  padding:9px 10px;
  font-weight:700;
  list-style:none;
  border-radius:10px;
  background:linear-gradient(180deg,#4968f2,#2d46bf);
  color:#fff;
}
.rules-box > summary::-webkit-details-marker{ display:none; }

.rules-box[open] > summary{
  border-bottom-left-radius:0;
  border-bottom-right-radius:0;
}

.rules-content{
  padding:10px 12px;
  max-height:320px;
  overflow:auto;
  font-size:12.5px;
  line-height:1.45;
  color:#dbe6ff;
}
.rules-content h4{
  margin:8px 0 6px;
  font-size:13px;
  color:#fff;
}
.rules-content ul, .rules-content ol{
  margin:0 0 8px 18px;
  padding:0;
}
.rules-tip{
  margin:6px 0 0;
  padding:8px;
  border-radius:8px;
  background:rgba(122,252,255,.1);
  border:1px solid rgba(122,252,255,.35);
}

#aiLevel:disabled { opacity: .55; cursor: not-allowed; }