/* =====================================================================
   Tic-Tac-Toe — styles propres au jeu (préfixe ttt-)
   La barre, le plein écran et les infobulles sont dans css/games.css.
   ===================================================================== */

/* Barre commune aux couleurs du jeu */
.ttt-jeu {
  --mg-jeu-largeur: 1204px; /* barre de 1180 px + marges de 12 px : ne pas changer */
  --mgb-fond:
    radial-gradient(
      120% 180% at 0% 0%,
      rgba(255, 79, 163, 0.32),
      transparent 55%
    ),
    radial-gradient(
      120% 180% at 100% 100%,
      rgba(62, 230, 255, 0.25),
      transparent 55%
    ),
    linear-gradient(120deg, #120f2e, #2a1d5e);
  --mgb-accent: #ff7ac0;
  --mgb-titre: linear-gradient(100deg, #ff7ac0, #ffffff 50%, #5cecff);
  --mg-stat-largeur: 4.2em;
  --mg-fs-fond: #0b0920;
  --mg-bulle-fond: #1b1540;

  --ttt-x: #ff4fa3;
  --ttt-o: #3ee6ff;
  --ttt-x-doux: rgba(255, 79, 163, 0.18);
  --ttt-o-doux: rgba(62, 230, 255, 0.16);
  --ttt-trait: rgba(196, 184, 255, 0.55);
  --ttt-fond: #0f0c28;
}

.ttt-jeu [hidden] {
  display: none !important;
}

.ttt-stat-x b {
  color: var(--ttt-x) !important;
}
.ttt-stat-o b {
  color: var(--ttt-o) !important;
}

.ttt-groupe {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Une couleur par groupe de réglages */
.ttt-g-mode {
  --mgb-accent: #ec4899;
}
.ttt-g-adv {
  --mgb-accent: #7c5cff;
}
.ttt-g-niveau {
  --mgb-accent: #0e9fb3;
}

/* Séparateurs bien visibles */
.ttt-commandes .mg-commandes-sep {
  width: 2px;
  height: 30px;
  margin: 0 6px;
  border-radius: 2px;
  background: rgba(60, 50, 120, 0.3);
}

/* ---------- Zone de jeu ---------- */
.ttt-zone {
  position: relative;
  box-sizing: border-box;
  align-self: center;
  width: min(var(--mg-barre-largeur, 1180px), calc(100vw - 24px));
  border-radius: 16px;
  overflow: hidden;
  background:
    radial-gradient(70% 90% at 50% 45%, #251c5c 0%, transparent 70%),
    radial-gradient(
        circle at 1px 1px,
        rgba(255, 255, 255, 0.07) 1px,
        transparent 1.5px
      )
      0 0 / 22px 22px,
    var(--ttt-fond);
  color: #ece8ff;
  font-family: "Outfit", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 14px 40px -18px rgba(15, 10, 50, 0.6);
}

.ttt-jeu.mg-fs .ttt-zone {
  align-self: stretch;
  width: auto;
  flex: 1;
  min-height: 0;
}

/* Halos colorés qui flottent */
.ttt-halo {
  position: absolute;
  width: 46%;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.32;
  pointer-events: none;
}
.ttt-halo-1 {
  background: var(--ttt-x);
  left: -12%;
  top: -18%;
  animation: ttt-flotte 18s ease-in-out infinite alternate;
}
.ttt-halo-2 {
  background: var(--ttt-o);
  right: -12%;
  bottom: -22%;
  animation: ttt-flotte 22s ease-in-out infinite alternate-reverse;
}
@keyframes ttt-flotte {
  to {
    transform: translate(18%, 14%) scale(1.15);
  }
}
.ttt-zone.tour-1 .ttt-halo-1,
.ttt-zone.tour-2 .ttt-halo-2 {
  opacity: 0.45;
}
.ttt-halo {
  transition: opacity 0.6s;
}

.ttt-scene {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-columns: var(--ttt-c, 210px) var(--ttt-s, 500px) var(
      --ttt-c,
      210px
    );
  grid-template-areas: "a p b";
  justify-content: center;
  align-content: center;
  align-items: center;
  gap: var(--ttt-gap, 28px);
}

/* ---------- Cartes des joueurs ---------- */
.ttt-carte {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 14px 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition:
    transform 0.35s cubic-bezier(0.3, 1.5, 0.5, 1),
    box-shadow 0.35s,
    border-color 0.35s,
    opacity 0.35s;
  opacity: 0.6;
  text-align: center;
}
.ttt-carte-1 {
  grid-area: a;
  --c: var(--ttt-x);
}
.ttt-carte-2 {
  grid-area: b;
  --c: var(--ttt-o);
}
.ttt-carte.actif {
  opacity: 1;
  transform: scale(1.04);
  border-color: color-mix(in srgb, var(--c) 70%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--c) 40%, transparent),
    0 0 34px -6px var(--c);
}
.ttt-avatar {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 35%,
    color-mix(in srgb, var(--c) 30%, transparent),
    transparent 70%
  );
}
.ttt-avatar svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.ttt-nom {
  font-family: "Madimi One", sans-serif;
  font-size: 1.35em;
  color: var(--c);
  text-shadow: 0 0 14px color-mix(in srgb, var(--c) 60%, transparent);
}
.ttt-etat {
  margin-top: 2px;
  min-height: 1.3em;
  font-size: 0.92em;
  color: #b9b2e6;
}
.ttt-carte.actif .ttt-etat {
  color: #fff;
}

/* Robot */
.ttt-robot .tete {
  fill: #1f1a48;
  stroke: var(--ttt-o);
  stroke-width: 3;
}
.ttt-robot .oeil {
  fill: #eafcff;
}
.ttt-robot .pupille {
  fill: #0f0c28;
  transition: transform 0.12s;
}
.ttt-robot .bouche {
  fill: none;
  stroke: var(--ttt-o);
  stroke-width: 3.5;
  stroke-linecap: round;
  transition: d 0.3s;
}
.ttt-robot .antenne {
  stroke: var(--ttt-o);
  stroke-width: 3;
}
.ttt-robot .ampoule {
  fill: var(--ttt-o);
  filter: drop-shadow(0 0 4px var(--ttt-o));
}
.ttt-robot .joue {
  fill: var(--ttt-x);
  opacity: 0;
  transition: opacity 0.3s;
}
.ttt-robot.content .joue {
  opacity: 0.5;
}
.ttt-robot.reflechit .ampoule {
  animation: ttt-clignote 0.5s steps(2) infinite;
}
.ttt-robot.reflechit .yeux {
  transform: translateY(-3px);
}
.ttt-robot .yeux {
  transition: transform 0.25s;
}
.ttt-robot .paupiere {
  fill: #1f1a48;
  transform-box: fill-box;
  transform-origin: center;
  transform: scaleY(0);
  animation: ttt-cligne 5s infinite;
}
@keyframes ttt-cligne {
  0%,
  94%,
  100% {
    transform: scaleY(0);
  }
  97% {
    transform: scaleY(1);
  }
}
@keyframes ttt-clignote {
  50% {
    opacity: 0.25;
  }
}
.ttt-robot.triste .tete {
  stroke: #8f88c8;
}
.ttt-robot.boude {
  animation: ttt-secoue 0.5s;
}
@keyframes ttt-secoue {
  25% {
    transform: rotate(-6deg);
  }
  75% {
    transform: rotate(6deg);
  }
}

/* Bulle du robot */
.ttt-bulle {
  position: absolute;
  top: calc(100% + 14px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 16px;
  background: #fff;
  color: #1b1540;
  font-weight: 600;
  font-size: 0.95em;
  line-height: 1.3;
  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.6);
  animation: ttt-bulle 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.ttt-bulle::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -8px;
  border: 8px solid transparent;
  border-bottom-color: #fff;
}
@keyframes ttt-bulle {
  from {
    transform: translateX(-50%) scale(0.6);
    opacity: 0;
  }
}

/* ---------- Plateau ---------- */
.ttt-cadre {
  grid-area: p;
  position: relative;
  width: var(--ttt-s, 500px);
  height: var(--ttt-s, 500px);
}
.ttt-plateau {
  position: absolute;
  inset: 0;
}
.ttt-grille {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.ttt-traits {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.ttt-traits path {
  fill: none;
  stroke: var(--ttt-trait);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  filter: drop-shadow(0 0 5px rgba(168, 145, 255, 0.8));
  animation: ttt-trace 0.5s ease-out forwards;
}
.ttt-traits path:nth-child(2) {
  animation-delay: 0.08s;
}
.ttt-traits path:nth-child(3) {
  animation-delay: 0.16s;
}
.ttt-traits path:nth-child(4) {
  animation-delay: 0.24s;
}
.ttt-traits.fin path {
  stroke-width: 2.2;
  stroke: rgba(196, 184, 255, 0.32);
  filter: none;
}
@keyframes ttt-trace {
  to {
    stroke-dashoffset: 0;
  }
}

.ttt-case {
  position: relative;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: default;
  border-radius: 12px;
  outline: none;
}
.ttt-case svg {
  position: absolute;
  inset: 14%;
  width: 72%;
  height: 72%;
  overflow: visible;
  pointer-events: none;
}
.ttt-case.jouable {
  cursor: pointer;
}
.ttt-case.jouable:hover,
.ttt-case.jouable:focus-visible {
  background: rgba(255, 255, 255, 0.05);
}
/* Aperçu du coup au survol */
.ttt-case.jouable::after {
  content: "";
  position: absolute;
  inset: 22%;
  opacity: 0;
  background: no-repeat center / contain;
  transition:
    opacity 0.15s,
    transform 0.15s;
  transform: scale(0.8);
}
.tour-1 .ttt-case.jouable::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M20 20L80 80M80 20L20 80' stroke='%23ff4fa3' stroke-width='12' stroke-linecap='round'/%3E%3C/svg%3E");
}
.tour-2 .ttt-case.jouable::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='32' fill='none' stroke='%233ee6ff' stroke-width='12'/%3E%3C/svg%3E");
}
.ttt-case.jouable:hover::after,
.ttt-case.jouable:focus-visible::after {
  opacity: 0.3;
  transform: scale(1);
}

/* Marques */
.ttt-m {
  fill: none;
  stroke-linecap: round;
  stroke-width: 12;
}
.ttt-m path,
.ttt-m circle {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: ttt-trace 0.28s cubic-bezier(0.5, 0, 0.3, 1) forwards;
}
.ttt-m path + path {
  animation-delay: 0.14s;
}
.ttt-m circle {
  animation-duration: 0.42s;
}
.ttt-m.j1 {
  stroke: var(--ttt-x);
  filter: drop-shadow(0 0 6px var(--ttt-x));
}
.ttt-m.j2 {
  stroke: var(--ttt-o);
  filter: drop-shadow(0 0 6px var(--ttt-o));
}
.ttt-m.statique path,
.ttt-m.statique circle {
  animation: none;
  stroke-dashoffset: 0;
}
.ttt-case.pose svg {
  animation: ttt-pose 0.4s cubic-bezier(0.3, 1.8, 0.5, 1);
}
@keyframes ttt-pose {
  from {
    transform: scale(0.6);
  }
}
.ttt-case.dernier::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
}
/* Évanescent : le pion qui va s'effacer */
.ttt-case.fragile svg {
  animation: ttt-fragile 1s ease-in-out infinite;
}
@keyframes ttt-fragile {
  50% {
    opacity: 0.25;
    transform: scale(0.88);
  }
}
.ttt-case.part svg {
  animation: ttt-part 0.45s ease-in forwards;
}
@keyframes ttt-part {
  to {
    opacity: 0;
    transform: scale(1.4) rotate(25deg);
    filter: blur(6px);
  }
}
/* Cases perdantes en fin de partie */
.ttt-plateau.termine .ttt-case:not(.gagnante) svg {
  opacity: 0.28;
  transition: opacity 0.5s;
}
.ttt-case.gagnante svg {
  animation: ttt-gagne 0.7s ease-in-out 2 alternate;
}
@keyframes ttt-gagne {
  to {
    transform: scale(1.12);
  }
}

/* Ligne gagnante */
.ttt-ligne {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 3;
}
.ttt-ligne line {
  stroke: #fff;
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: ttt-trace 0.45s 0.15s cubic-bezier(0.6, 0, 0.3, 1) forwards;
}

/* ---------- Ultime : 9 petites grilles ---------- */
.ttt-macro {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}
.ttt-sous {
  position: relative;
  margin: 7%;
  border-radius: 14px;
  transition:
    background 0.3s,
    box-shadow 0.3s;
}
.ttt-sous .ttt-traits path {
  stroke-width: 3;
  stroke: rgba(196, 184, 255, 0.38);
  filter: none;
}
.ttt-sous .ttt-case {
  border-radius: 8px;
}
.ttt-sous .ttt-case svg {
  inset: 18%;
  width: 64%;
  height: 64%;
}
.ttt-sous .ttt-m {
  stroke-width: 15;
  filter: none;
}
.ttt-sous.actif {
  background: color-mix(in srgb, var(--ttt-tour) 12%, transparent);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--ttt-tour) 70%, transparent),
    0 0 22px -4px var(--ttt-tour);
  animation: ttt-respire 1.6s ease-in-out infinite;
}
@keyframes ttt-respire {
  50% {
    box-shadow:
      0 0 0 2px color-mix(in srgb, var(--ttt-tour) 40%, transparent),
      0 0 10px -4px var(--ttt-tour);
  }
}
.tour-1 {
  --ttt-tour: var(--ttt-x);
}
.tour-2 {
  --ttt-tour: var(--ttt-o);
}
.ttt-sous.gagne-1 .ttt-grille,
.ttt-sous.gagne-2 .ttt-grille,
.ttt-sous.gagne-3 .ttt-grille {
  opacity: 0.2;
  transition: opacity 0.5s;
}
.ttt-sous .ttt-grand {
  position: absolute;
  inset: 6%;
  width: 88%;
  height: 88%;
  overflow: visible;
  pointer-events: none;
}
.ttt-grand.ttt-m {
  stroke-width: 11;
}
.ttt-grand.ttt-m.j1 {
  filter: drop-shadow(0 0 8px var(--ttt-x));
}
.ttt-grand.ttt-m.j2 {
  filter: drop-shadow(0 0 8px var(--ttt-o));
}
.ttt-grand-nul {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Madimi One", sans-serif;
  font-size: calc(var(--ttt-s, 500px) * 0.05);
  color: rgba(255, 255, 255, 0.45);
}
.ttt-plateau.termine .ttt-sous:not(.gagnante) .ttt-grand {
  opacity: 0.3;
  transition: opacity 0.5s;
}

/* ---------- Fin de partie ---------- */
.ttt-fin {
  position: absolute;
  inset: -8px;
  z-index: 5;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: rgba(11, 9, 32, 0.45);
  backdrop-filter: blur(1.5px);
  animation: ttt-apparait 0.4s ease-out;
}
@keyframes ttt-apparait {
  from {
    opacity: 0;
  }
}
.ttt-fin-carte {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 36px 24px;
  border-radius: 24px;
  background: linear-gradient(160deg, #2a2065, #171236);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    0 24px 60px -18px #000,
    0 0 40px -10px var(--ttt-fin, #a891ff);
  text-align: center;
  animation: ttt-rebond 0.55s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes ttt-rebond {
  from {
    transform: scale(0.5) translateY(30px);
    opacity: 0;
  }
}
.ttt-fin-titre {
  font-family: "Madimi One", sans-serif;
  font-size: 2.3em;
  line-height: 1.05;
  color: var(--ttt-fin, #fff);
  text-shadow: 0 0 20px
    color-mix(in srgb, var(--ttt-fin, #fff) 60%, transparent);
}
.ttt-fin-texte {
  color: #cfc8f5;
  margin-bottom: 6px;
}
.ttt-fin .mg-btn {
  background: var(--ttt-fin, var(--mgb-accent));
  color: #120f2e;
  padding: 0 26px;
}

.ttt-confettis {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
}

/* ---------- Écran étroit : cartes au-dessus du plateau ---------- */
.ttt-zone.etroit .ttt-scene {
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "a b" "p p";
  justify-items: center;
  align-content: center;
  gap: 10px;
  padding: 0 10px;
}
.ttt-zone.etroit .ttt-carte {
  width: 100%;
  box-sizing: border-box;
  flex-direction: row;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 16px;
  text-align: left;
}
.ttt-zone.etroit .ttt-carte.actif {
  transform: none;
}
.ttt-zone.etroit .ttt-avatar {
  width: 48px;
  height: 48px;
  flex: none;
}
.ttt-zone.etroit .ttt-nom {
  font-size: 1.05em;
}
.ttt-zone.etroit .ttt-etat {
  font-size: 0.8em;
}
.ttt-zone.etroit .ttt-bulle {
  display: none;
}
.ttt-zone.etroit .ttt-fin-titre {
  font-size: 1.7em;
}
.ttt-zone.etroit .ttt-fin-carte {
  padding: 18px 22px;
}

@media (prefers-reduced-motion: reduce) {
  .ttt-halo {
    animation: none;
  }
}
