/* ===============================
   Box Factory – styles spécifiques
   =============================== */

.bf-jeu {
  --bf-j1: #ff8a1f;
  --bf-j1-fonce: #a8520a;
  --bf-j2: #2f8cff;
  --bf-j2-fonce: #164f99;
  --bf-violet: #7c5cff;
  --bf-jaune: #f5c518;
  --bf-encre: #232a3a;
  /* côté du plateau (carré) */
  --plateau: min(540px, calc(100vw - 56px));
  --bord: calc(var(--plateau) * 0.035); /* bande de sécurité autour du plateau */
  /* 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(255, 138, 31, 0.22), transparent 55%),
    radial-gradient(120% 160% at 100% 100%, rgba(47, 140, 255, 0.22), transparent 55%),
    linear-gradient(120deg, #1b2130, #33405c);
  --mgb-accent: var(--bf-jaune);
  --mgb-titre: linear-gradient(100deg, #ffc58f, #ffffff 50%, #a9d0ff);
  --mg-fs-fond: radial-gradient(circle at 50% 40%, #eef1f7, #d3d9e4);
  --mg-bulle-fond: var(--bf-encre);
  user-select: none;
  -webkit-user-select: none;
}

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

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

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

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

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

.bf-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;
}

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

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

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

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

/* Nombre de boîtes fermées */
.bf-sb-points {
  min-width: 1.6em;
  padding: 1px 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  font-family: "Madimi One", sans-serif;
  font-size: 1.15em;
  text-align: center;
}

#bf-sb-1 .bf-sb-points {
  color: #ffc58f;
}

#bf-sb-2 .bf-sb-points {
  color: #a9d0ff;
}

.bf-sb-points.bump {
  animation: bf-bump 0.45s var(--mg-ressort, ease-out);
}

@keyframes bf-bump {
  40% {
    transform: scale(1.45);
    background: rgba(255, 255, 255, 0.35);
  }
}

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

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

/* Bandeau moyen : pas la place pour le niveau à côté du nom */
@container (max-width: 400px) {
  .bf-sb-niveau {
    display: none;
  }
}

/* Bandeau étroit : cartons et scores seulement */
@container (max-width: 320px) {
  .bf-sb-nom,
  .bf-sb-niveau {
    display: none;
  }
  .bf-sb-joueur {
    padding: 7px 12px;
  }
}

.bf-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;
}

.bf-statut .bf-mini {
  width: 24px;
  height: 24px;
}

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

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

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

/* ---------- Plateau : tôle larmée dans un cadre à rayures de sécurité ---------- */

.bf-cadre {
  width: fit-content;
  margin: 0 auto;
  padding: var(--bord);
  border-radius: 14px;
  background: repeating-linear-gradient(-45deg, var(--bf-jaune) 0 14px, #2a2a2a 14px 28px);
  box-shadow:
    0 14px 30px -8px rgba(15, 20, 35, 0.5),
    0 3px 6px rgba(0, 0, 0, 0.25),
    inset 0 0 0 3px rgba(0, 0, 0, 0.35);
}

.bf-plateau {
  position: relative;
  width: var(--plateau);
  height: var(--plateau);
  border-radius: 6px;
  /* tôle d'acier larmée */
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.5), transparent 55%),
    repeating-linear-gradient(45deg, transparent 0 9px, rgba(255, 255, 255, 0.35) 9px 11px, transparent 11px 20px),
    repeating-linear-gradient(-45deg, transparent 0 9px, rgba(70, 80, 95, 0.12) 9px 11px, transparent 11px 20px),
    linear-gradient(160deg, #d9dee5, #b8c0cb);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.6),
    inset 0 0 18px rgba(30, 40, 55, 0.35);
  touch-action: none; /* le doigt pose une barre, il ne fait pas défiler la page */
}

.bf-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Emplacements des barres : rainures dans la tôle */
.bf-rainure {
  stroke: rgba(40, 50, 65, 0.16);
  stroke-width: 9;
  stroke-linecap: round;
}

/* Barre fantôme sous le pointeur */
.bf-apercu {
  stroke-width: 13;
  stroke-linecap: round;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
}

.bf-apercu.visible {
  opacity: 0.45;
}

.bf-apercu.j1 {
  stroke: var(--bf-j1);
}

.bf-apercu.j2 {
  stroke: var(--bf-j2);
}

.bf-plateau.jouable {
  cursor: pointer;
}

/* Barres posées : acier peint à la couleur du joueur */
.bf-barre line {
  stroke-linecap: round;
  fill: none;
}

.bf-barre-ombre {
  stroke: rgba(20, 25, 35, 0.3);
  stroke-width: 14;
}

.bf-barre-corps {
  stroke-width: 14;
}

.bf-barre-reflet {
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 3.5;
}

.bf-barre.j1 .bf-barre-corps {
  stroke: var(--bf-j1);
}

.bf-barre.j2 .bf-barre-corps {
  stroke: var(--bf-j2);
}

/* La barre se déroule d'un boulon à l'autre */
.bf-barre.pose line {
  stroke-dasharray: 1;
  animation: bf-trace 0.28s ease-out both;
}

@keyframes bf-trace {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

/* Barres posées par l'adversaire à son dernier tour */
.bf-barre.dernier .bf-barre-corps {
  animation: bf-dernier 1.2s ease-in-out infinite alternate;
}

.bf-barre.dernier.j1 {
  filter: drop-shadow(0 0 5px rgba(255, 138, 31, 0.85));
}

.bf-barre.dernier.j2 {
  filter: drop-shadow(0 0 5px rgba(47, 140, 255, 0.85));
}

.bf-barre.dernier .bf-barre-reflet {
  stroke: #fff;
}

@keyframes bf-dernier {
  to {
    stroke-width: 17;
  }
}

/* Boulons hexagonaux */
.bf-boulon polygon {
  stroke: #4b5563;
  stroke-width: 2;
  filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, 0.35));
}

.bf-boulon-centre {
  fill: #7d8796;
  stroke: #4b5563;
  stroke-width: 1.2;
}

/* Carton fermé : il tombe sur le plateau et rebondit */
.bf-carton {
  transform-box: fill-box;
  transform-origin: center;
  animation: bf-pose 0.5s cubic-bezier(0.3, 1.5, 0.5, 1) both;
  filter: drop-shadow(0 3px 3px rgba(40, 25, 10, 0.35));
}

@keyframes bf-pose {
  0% {
    transform: scale(1.6) rotate(-8deg);
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
}

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

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

.bf-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: bf-fondu 0.25s ease-out;
}

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

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

.bf-modal-box {
  background: #fff;
  border-radius: 20px;
  padding: 26px 28px 22px 28px;
  width: 100%;
  max-width: 440px;
  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: bf-pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

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

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

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

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

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

.bf-fin-icone {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.bf-fin-icone .bf-mini {
  width: 64px;
  height: 64px;
  margin-bottom: 10px;
  animation: bf-bond 0.6s ease-out both;
}

.bf-fin-icone .bf-mini + .bf-mini {
  animation-delay: 0.12s;
}

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

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

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

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

.bf-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);
}

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

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

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

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

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

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

.bf-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 ---------- */

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

.bf-stats[hidden] {
  display: none;
}

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

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

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

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

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

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

.bf-stat.vide {
  background: none;
  color: #8a91a1;
  white-space: normal;
}

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

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

/* La barre garde la largeur du cadre */
.bf-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é */
.bf-jeu.mg-fs > * {
  flex-shrink: 0;
}

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

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

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

@media (prefers-reduced-motion: reduce) {
  .bf-barre.pose line,
  .bf-barre.dernier .bf-barre-corps,
  .bf-carton,
  .bf-sb-points.bump {
    animation: none;
  }
}
