/* ===============================
   Isolate – styles spécifiques
   =============================== */

.is-jeu {
  --is-violet: #7c5cff;
  --is-or: #ffd54a;
  --is-bleu: #8fcbff;
  --is-encre: #232a3a;
  /* côté du plateau ; une case = --s (--n cases par côté) */
  --plateau: min(540px, calc(100vw - 56px));
  --bord: calc(var(--plateau) * 0.03); /* bordure du cadre */
  /* Barre commune (css/games.css) : largeur du cadre, couleurs du jeu */
  --mg-jeu-largeur: calc(var(--plateau) + 2 * var(--bord) + 24px);
  --mgb-fond: radial-gradient(120% 160% at 0% 0%, rgba(124, 92, 255, 0.3), transparent 55%),
    linear-gradient(120deg, #1b2130, #33405c);
  --mgb-accent: var(--is-or);
  --mgb-titre: linear-gradient(100deg, var(--is-bleu), #ffffff 50%, var(--is-or));
  --mg-fs-fond: radial-gradient(circle at 50% 40%, #eef1f7, #d3d9e4);
  --mg-bulle-fond: var(--is-encre);
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Pion miniature (bandeau, statut, fin de partie) ---------- */

.is-mini {
  display: inline-block;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  line-height: 0;
}

.is-mini svg {
  width: 100%;
  height: 100%;
}

/* ---------- Bandeau et statut ---------- */

/* Duel, dans la barre commune */
.is-score {
  flex: 1;
  display: flex;
  gap: 6px;
  min-width: 0;
  container-type: inline-size;
}

.is-sb-joueur {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 10px;
  min-width: 0;
  transition:
    background 0.2s,
    box-shadow 0.2s;
}

#is-sb-2 {
  justify-content: flex-end;
}

.is-sb-joueur.actif {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 -3px 0 var(--is-or);
}

#is-sb-2.actif {
  box-shadow: inset 0 -3px 0 var(--is-bleu);
}

.is-sb-nom {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Niveau de l'ordinateur, fixé pour la partie */
.is-sb-niveau {
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 0.78em;
  white-space: nowrap;
}

.is-sb-niveau:empty {
  display: none;
}

/* Bandeau étroit : pions seulement */
@container (max-width: 300px) {
  .is-sb-nom {
    display: none;
  }
  .is-sb-joueur {
    padding: 7px 12px;
  }
}

.is-statut {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
  margin: 8px auto 10px auto;
  font-weight: bold;
  color: #2c3446;
  text-align: center;
}

.is-statut .is-mini {
  width: 22px;
  height: 22px;
}

.is-statut.victoire {
  color: #23955a;
}

.is-statut.alerte {
  color: #d32f2f;
}

/* ---------- Boutons-icônes au centre du bandeau ---------- */

/* ---------- Plateau : dalles de pierre au-dessus du vide ---------- */

.is-cadre {
  width: fit-content;
  margin: 0 auto;
  padding: var(--bord);
  border-radius: 16px;
  background: linear-gradient(160deg, #3a4357, #252c3b 60%, #1c2230);
  box-shadow:
    0 14px 30px -8px rgba(15, 20, 35, 0.55),
    0 3px 6px rgba(0, 0, 0, 0.25),
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    inset 0 -3px 0 rgba(0, 0, 0, 0.3);
}

.is-plateau {
  --n: 7;
  --s: calc(var(--plateau) / var(--n));
  position: relative;
  width: var(--plateau);
  height: var(--plateau);
  border-radius: 8px;
  /* le vide, sous les dalles */
  background:
    radial-gradient(circle at 50% 45%, rgba(70, 90, 140, 0.35), transparent 70%),
    radial-gradient(circle at 50% 50%, #161c2b, #090c14);
  box-shadow: inset 0 0 calc(var(--s) * 0.5) rgba(0, 0, 0, 0.7);
  touch-action: none; /* le doigt déplace le pion, pas la page */
}

.is-plateau.glisse,
.is-plateau.glisse .is-case {
  cursor: grabbing !important;
}

.is-cases {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  width: 100%;
  height: 100%;
}

.is-case {
  position: relative;
  padding: calc(var(--s) * 0.05);
}

.is-dalle {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: calc(var(--s) * 0.14);
  transition:
    transform 0.15s,
    filter 0.2s;
}

.is-case.claire .is-dalle {
  background:
    radial-gradient(circle at 22% 30%, rgba(255, 255, 255, 0.55), transparent 35%),
    radial-gradient(circle at 75% 80%, rgba(120, 130, 150, 0.18), transparent 40%),
    linear-gradient(145deg, #eef1f5, #cdd4de);
  box-shadow:
    0 calc(var(--s) * 0.06) 0 #9aa4b3,
    0 calc(var(--s) * 0.1) calc(var(--s) * 0.12) rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.is-case.foncee .is-dalle {
  background:
    radial-gradient(circle at 22% 30%, rgba(255, 255, 255, 0.28), transparent 35%),
    radial-gradient(circle at 75% 80%, rgba(20, 25, 40, 0.18), transparent 40%),
    linear-gradient(145deg, #a2acba, #7c8696);
  box-shadow:
    0 calc(var(--s) * 0.06) 0 #565f6e,
    0 calc(var(--s) * 0.1) calc(var(--s) * 0.12) rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

/* Dalle supprimée : elle tombe dans le vide et laisse son empreinte */
.is-case.trou .is-dalle {
  animation: is-chute 0.6s cubic-bezier(0.55, 0, 0.75, 0.4) forwards;
  pointer-events: none;
}

.is-case.trou::before {
  content: "";
  position: absolute;
  inset: calc(var(--s) * 0.08);
  border-radius: calc(var(--s) * 0.14);
  border: 1px dashed rgba(160, 180, 220, 0.12);
  box-shadow: inset 0 0 calc(var(--s) * 0.15) rgba(0, 0, 0, 0.6);
  animation: is-fondu 0.6s 0.3s both;
}

@keyframes is-chute {
  0% {
    transform: none;
  }
  15% {
    transform: translateY(calc(var(--s) * 0.04)) rotate(-3deg);
  }
  100% {
    transform: translateY(calc(var(--s) * 0.35)) scale(0.3) rotate(25deg);
    opacity: 0;
    filter: brightness(0.3);
  }
}

@keyframes is-fondu {
  from {
    opacity: 0;
  }
}

/* Choc sur une dalle renforcée */
.is-dalle.choc {
  animation: is-choc 0.4s ease-out;
}

@keyframes is-choc {
  20% {
    transform: translate(calc(var(--s) * -0.035), calc(var(--s) * 0.02)) rotate(-2deg);
  }
  40% {
    transform: translate(calc(var(--s) * 0.03), calc(var(--s) * -0.01)) rotate(1.5deg);
  }
  60% {
    transform: translate(calc(var(--s) * -0.02), 0) rotate(-1deg);
  }
  80% {
    transform: translate(calc(var(--s) * 0.01), 0);
  }
}

/* Dalle fissurée : un peu assombrie, fissure tracée en direct */
.is-case.fissuree .is-dalle {
  filter: brightness(0.93) saturate(0.9);
}

.is-fissure {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.is-fissure path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: is-trace 0.35s ease-out forwards;
}

.is-f-ombre path {
  stroke: rgba(28, 32, 42, 0.8);
}

.is-f-reflet path {
  stroke: rgba(255, 255, 255, 0.6);
  stroke-width: 1.1;
}

.is-f-ombre .is-f-rayon {
  stroke-width: 2.6;
}

.is-f-ombre .is-f-branche {
  stroke-width: 1.7;
}

.is-f-ombre .is-f-toile {
  stroke-width: 1.3;
}

.is-fissure .is-f-branche {
  animation-delay: 0.15s;
}

.is-fissure .is-f-toile {
  animation-delay: 0.25s;
}

.is-fissure .is-f-impact {
  fill: rgba(28, 32, 42, 0.65);
  stroke: none;
  stroke-dashoffset: 0;
  animation: is-fondu 0.2s ease-out;
}

@keyframes is-trace {
  to {
    stroke-dashoffset: 0;
  }
}

/* Révélation des cases renforcées jamais découvertes, en fin de partie */
.is-case.revelee .is-dalle::after {
  content: "";
  position: absolute;
  inset: 22%;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2024%2024'%3E%3Cpath%20d%3D'M12%202%20L20%205.5%20V11%20C20%2016.5%2016.8%2020.5%2012%2022.5%20C7.2%2020.5%204%2016.5%204%2011%20V5.5%20Z'%20fill%3D'rgba(109%2C152%2C183%2C0.4)'%20stroke%3D'rgba(49%2C83%2C107%2C0.9)'%20stroke-width%3D'1.6'%20stroke-linejoin%3D'round'%2F%3E%3Cpath%20d%3D'M9%2012%20L11%2014%20L15.5%209'%20fill%3D'none'%20stroke%3D'rgba(49%2C83%2C107%2C0.9)'%20stroke-width%3D'1.6'%20stroke-linecap%3D'round'%20stroke-linejoin%3D'round'%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  pointer-events: none;
  animation: is-revele 0.45s var(--mg-ressort, ease-out) both;
}

@keyframes is-revele {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
}

/* ---------- Aides de jeu ---------- */

/* Cases d'arrivée possibles du pion */
.is-case.cible {
  cursor: pointer;
}

.is-case.cible::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 40% 35%, #fff8d6, var(--is-or) 70%);
  box-shadow: 0 0 calc(var(--s) * 0.15) rgba(255, 213, 74, 0.8);
  opacity: 0.85;
  pointer-events: none;
  animation: is-apparait 0.25s var(--mg-ressort, ease-out);
  transition: transform 0.15s var(--mg-ressort, ease);
}

.is-case.cible:hover::after,
.is-case.cible.survolee::after {
  transform: translate(-50%, -50%) scale(1.4);
  opacity: 1;
}

.is-case.cible.survolee .is-dalle {
  box-shadow:
    0 0 0 3px rgba(255, 213, 74, 0.9),
    0 calc(var(--s) * 0.1) calc(var(--s) * 0.12) rgba(0, 0, 0, 0.5);
}

@keyframes is-apparait {
  from {
    transform: translate(-50%, -50%) scale(0);
  }
}

/* Case du pion, qu'on peut saisir */
.is-case.saisissable {
  cursor: grab;
}

/* Étape de suppression : la dalle visée rougit et s'enfonce un peu */
.is-case.supprimable {
  cursor: pointer;
}

.is-case.supprimable .is-dalle::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  background: rgba(229, 57, 53, 0.3);
  box-shadow: inset 0 0 0 calc(var(--s) * 0.04) rgba(229, 57, 53, 0.85);
  opacity: 0;
  transition: opacity 0.12s;
}

@media (hover: hover) {
  .is-case.supprimable:hover .is-dalle {
    transform: translateY(calc(var(--s) * 0.03));
  }
  .is-case.supprimable:hover .is-dalle::before {
    opacity: 1;
  }
}

/* Dernier déplacement de l'ordinateur */
.is-case.dernier-de .is-dalle::before,
.is-case.dernier .is-dalle::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 calc(var(--s) * 0.035) rgba(60, 140, 220, 0.55);
  background: rgba(143, 203, 255, 0.18);
}

.is-case.dernier-de .is-dalle::before {
  background: none;
  box-shadow: inset 0 0 0 calc(var(--s) * 0.03) rgba(60, 140, 220, 0.4);
}

/* ---------- Pions ---------- */

.is-pion {
  position: absolute;
  z-index: 3;
  left: calc(var(--c) * 100% / var(--n));
  top: calc(var(--l) * 100% / var(--n));
  width: calc(100% / var(--n));
  height: calc(100% / var(--n));
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition:
    left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    top 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.is-pion svg {
  width: 80%;
  height: 80%;
  transform: translateY(calc(var(--s) * -0.03));
  filter: drop-shadow(0 calc(var(--s) * 0.06) calc(var(--s) * 0.05) rgba(0, 0, 0, 0.45));
  transition:
    transform 0.18s var(--mg-ressort, ease),
    filter 0.3s;
}

/* Saut d'une case à l'autre */
.is-pion.saute svg {
  animation: is-saut 0.32s ease-out;
}

@keyframes is-saut {
  45% {
    transform: translateY(calc(var(--s) * -0.22)) scale(1.12);
    filter: drop-shadow(0 calc(var(--s) * 0.2) calc(var(--s) * 0.08) rgba(0, 0, 0, 0.3));
  }
}

/* Pion qui a la main : halo qui respire */
.is-pion.actif::before {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  box-shadow: 0 0 calc(var(--s) * 0.18) calc(var(--s) * 0.03) rgba(255, 213, 74, 0.7);
  animation: is-halo 1.4s ease-in-out infinite alternate;
}

.is-pion.j2.actif::before {
  box-shadow: 0 0 calc(var(--s) * 0.18) calc(var(--s) * 0.03) rgba(143, 203, 255, 0.75);
}

@keyframes is-halo {
  from {
    opacity: 0.35;
  }
}

/* Pion tenu en main : il suit le pointeur, agrandi et soulevé */
.is-pion.tenu {
  z-index: 10;
  transition: none;
}

.is-pion.tenu svg {
  transform: translateY(calc(var(--s) * -0.15)) scale(1.15);
  filter: drop-shadow(0 calc(var(--s) * 0.2) calc(var(--s) * 0.1) rgba(0, 0, 0, 0.4));
}

/* Pion isolé : la partie est perdue pour lui */
.is-pion.isole svg {
  filter: grayscale(0.75) brightness(0.85)
    drop-shadow(0 calc(var(--s) * 0.06) calc(var(--s) * 0.05) rgba(0, 0, 0, 0.45));
  animation: is-isole 0.6s ease-in-out;
}

@keyframes is-isole {
  20%,
  60% {
    transform: translateX(calc(var(--s) * -0.06)) rotate(-6deg);
  }
  40%,
  80% {
    transform: translateX(calc(var(--s) * 0.06)) rotate(6deg);
  }
}

/* ---------- Éclats de pierre ---------- */

.is-eclat {
  position: absolute;
  z-index: 4;
  left: calc(var(--c) * 100% / var(--n));
  top: calc(var(--l) * 100% / var(--n));
  width: calc(var(--s) * var(--taille));
  height: calc(var(--s) * var(--taille));
  clip-path: polygon(10% 0, 100% 25%, 80% 100%, 0 70%);
  pointer-events: none;
  animation: is-eclat 0.6s cubic-bezier(0.2, 0.7, 0.4, 1) forwards;
}

.is-eclat.claire {
  background: #c9d0da;
}

.is-eclat.foncee {
  background: #7a8494;
}

.is-eclat.chute {
  animation: is-eclat-chute 0.75s cubic-bezier(0.4, 0, 0.8, 0.6) forwards;
}

@keyframes is-eclat {
  to {
    transform: translate(calc(var(--dx) * var(--s)), calc(var(--dy) * var(--s))) rotate(var(--rot));
    opacity: 0;
  }
}

@keyframes is-eclat-chute {
  to {
    transform: translate(calc(var(--dx) * var(--s) * 0.6), calc(var(--dy) * var(--s) * 0.4 + var(--s) * 0.5))
      rotate(var(--rot)) scale(0.3);
    opacity: 0;
  }
}

/* ---------- Fenêtres ---------- */

/* La barre commune reste au-dessus du voile des fenêtres (configuration, confirmation) */
.is-jeu > .mg-barre {
  position: relative;
  z-index: 3001;
}

.is-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  background: rgba(15, 20, 35, 0.55);
  animation: is-fondu 0.25s ease-out;
}

.is-modal[hidden] {
  display: none;
}

.is-modal-box {
  background: #fff;
  border-radius: 20px;
  padding: 26px 28px 22px 28px;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-sizing: border-box;
  text-align: center;
  color: var(--mg-texte, #25233d);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  animation: is-pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes is-pop {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
}

.is-modal-titre {
  font-family: "Madimi One", sans-serif;
  font-size: 1.6em;
  line-height: 1.15;
  color: var(--is-encre);
}

.is-modal-titre.is-defaite {
  color: #d32f2f;
}

.is-modal-sous {
  margin-top: 8px;
  color: #5c6475;
  line-height: 1.45;
}

.is-modal-btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
}

.is-fin-pion .is-mini {
  width: 60px;
  height: 60px;
  margin-bottom: 10px;
  animation: is-bond 0.6s ease-out both;
}

@keyframes is-bond {
  0% {
    transform: translateY(-30px);
    opacity: 0;
  }
  60% {
    transform: translateY(0);
    opacity: 1;
  }
  80% {
    transform: translateY(-6px);
  }
}

/* Configuration de la partie */
.is-config-groupe {
  margin-top: 18px;
  text-align: left;
}

.is-config-label {
  font-weight: bold;
  margin-bottom: 8px;
}

.is-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.is-option {
  flex: 1;
  min-width: 70px;
  padding: 9px 12px;
  border: 2px solid #dcd8ec;
  border-radius: 12px;
  background: #fff;
  color: var(--mg-texte, #25233d);
  font-family: inherit;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s,
    transform 0.2s var(--mg-ressort, ease);
}

.is-option:hover {
  border-color: var(--is-violet);
}

.is-option.selected {
  background: var(--is-violet);
  border-color: var(--is-violet);
  color: #fff;
  box-shadow: 0 8px 18px -10px rgba(124, 92, 255, 0.9);
}

.is-option:active {
  transform: scale(0.96);
}

.is-option:focus-visible {
  outline: 3px solid var(--is-violet);
  outline-offset: 2px;
}

.is-config-interrupteur {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-weight: bold;
}

/* Règles */
.is-regles-texte {
  margin-top: 12px;
  text-align: left;
  line-height: 1.5;
}

.is-regles-texte p {
  margin: 0 0 10px 0;
}

.is-regles-note {
  padding: 8px 12px;
  border-radius: 10px;
  background: #f1f3f8;
  font-size: 0.92em;
  color: #4a5262;
}

/* ---------- Infobulle (attribut data-bulle) ---------- */

/* Pointe vers l'élément survolé */

/* ---------- Compteur de parties ---------- */

.is-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 12px auto 0 auto;
  font-size: 0.9em;
}

.is-modal-box .is-stats {
  margin-top: 14px;
}

.is-stat {
  padding: 4px 11px;
  border-radius: 999px;
  background: #e8ebf2;
  color: #4a5262;
  white-space: nowrap;
}

.is-stat b {
  font-family: "Madimi One", sans-serif;
  font-weight: normal;
}

.is-stat.victoires b {
  color: #23955a;
}

.is-stat.defaites b {
  color: #d32f2f;
}

.is-stat.taux b {
  color: var(--is-violet);
}

.is-stat.vide {
  background: none;
  color: #8a91a1;
}

/* ---------- Plein écran ---------- */

.is-jeu.mg-fs {
  justify-content: center;
  overflow: hidden;
}

/* La barre garde la largeur du cadre */
.is-jeu.mg-fs > .mg-barre {
  align-self: center;
  width: calc(var(--plateau) + 2 * var(--bord));
}

/* Aucun élément ne se tasse : c'est le plateau qui est redimensionné */
.is-jeu.mg-fs > * {
  flex-shrink: 0;
}

/* ---------- Petits écrans ---------- */

@media (max-width: 520px) {
  .is-jeu {
    --plateau: calc(100vw - 40px);
  }
  .is-cadre {
    border-radius: 10px;
  }
  
  .is-modal-box {
    padding: 22px 18px 18px 18px;
  }
}

/* ---------- Mouvements réduits ---------- */

@media (prefers-reduced-motion: reduce) {
  .is-pion,
  .is-pion svg,
  .is-dalle {
    transition: none;
  }
  .is-pion.saute svg,
  .is-pion.isole svg,
  .is-pion.actif::before,
  .is-dalle.choc {
    animation: none;
  }
}
