/* Barre commune (css/games.css) aux couleurs du tapis */
.jeu421 {
  --mg-jeu-largeur: 1040px;
  --mgb-fond: radial-gradient(120% 160% at 0% 0%, rgba(184, 134, 11, 0.3), transparent 55%),
    linear-gradient(120deg, #0f3d2a, #1d6b45);
  --mgb-accent: #ffd54f;
  --mgb-titre: linear-gradient(100deg, #ffffff, #ffd54f);
  --mg-bulle-fond: #0f3d2a;
  --mg-fs-fond: radial-gradient(ellipse at 30% 40%, #fdfdff, #e4ece7);
}

.mg-stat b.pot-421 {
  color: #ffd54f;
}

/* Plateau à gauche, derniers coups à droite (en dessous sur un écran étroit) */
.q-table {
  display: grid;
  grid-template-columns: minmax(0, 620px) minmax(0, 380px);
  justify-content: center;
  gap: 20px;
  width: 100%;
  margin-bottom: 16px;
}
@media (max-width: 900px) {
  .q-table {
    grid-template-columns: minmax(0, 620px);
  }
}

#jeu-421 {
  position: relative;
  box-sizing: border-box;
  border: 2px solid #333;
  border-radius: 12px;
  background: #fafafa;
  padding: 26px 32px 24px;
  box-shadow: 0 2px 8px #0002;
}
.phase-421 {
  text-align: center;
  font-weight: bold;
  color: #1a5e9a;
  margin-bottom: 14px;
}

/* Piste et dés 3D : css/des-3d.css */
#jeu-421 .des {
  --taille-de: 66px;
  gap: 48px;
  min-height: 240px;
  margin: 6px -10px 34px; /* sous le plateau : son épaisseur et son ombre */
}
@media (max-width: 480px) {
  #jeu-421 .des {
    --taille-de: 52px;
    gap: 22px;
    min-height: 170px;
  }
}
.combinaison-421 {
  text-align: center;
  min-height: 1.4em;
  font-weight: bold;
  margin-bottom: 16px;
}
#jeu-421 .actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

/* Historique des coups */
/* Même hauteur que le plateau (sans l'agrandir) : la liste défile à l'intérieur */
#historique-container {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  height: 0;
  min-height: 100%;
  padding: 14px 12px 8px;
  border-radius: 12px;
  box-shadow: 0 2px 8px #0002;
  background: #fafafa;
}
.historique-defil {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.historique-421 thead th {
  position: sticky;
  top: 0;
  background: #fafafa;
}
@media (max-width: 900px) {
  #historique-container {
    height: auto;
    min-height: 0;
    max-height: 320px;
  }
}
#historique-container h3 {
  font-size: 1.1em;
  margin-bottom: 8px;
  text-align: center;
}
.historique-421 {
  width: 100%;
  table-layout: fixed; /* colonnes de largeur fixe, alignées d'une ligne à l'autre */
  border-collapse: separate;
  border-spacing: 0 4px;
  color: #333;
}
.historique-421 th {
  padding: 2px 8px;
  font-size: 0.8em;
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
  text-align: center;
}
.historique-421 td {
  padding: 5px 4px;
  background: #f3f3f3;
  text-align: center;
  vertical-align: middle;
}
.historique-421 td:first-child {
  border-radius: 6px 0 0 6px;
}
.historique-421 td:last-child {
  border-radius: 0 6px 6px 0;
}
.historique-421 td[colspan] {
  border-radius: 6px;
  background: #fff4d6;
  font-weight: bold;
}
.historique-421 td small {
  display: block;
  font-size: 0.8em;
  color: #666;
}
.historique-421 td.gagne {
  background: #e3f5e3;
}
.historique-421 td.gagne small {
  color: #1a7e1a;
  font-weight: bold;
}
@media (max-width: 420px) {
  .historique-421 td,
  .historique-421 th {
    padding: 4px 3px;
  }
}
/* Plein écran : plateau et dés agrandis */
.jeu421.mg-fs .q-table {
  grid-template-columns: minmax(0, 760px) minmax(0, 420px);
}
.jeu421.mg-fs #jeu-421 .des {
  --taille-de: clamp(60px, 8vh, 92px);
  min-height: clamp(220px, 42vh, 400px);
  margin-inline: 22px; /* le bas du plateau, plus haut, s'évase davantage */
}
/* Perspective plus douce : plateau plus haut sans déborder du cadre */
.jeu421.mg-fs #jeu-421 .des::before {
  transform: perspective(1000px) rotateX(30deg);
}

.historique-de {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 22px;
  height: 22px;
  margin: 0 1px;
  vertical-align: middle;
  border: 1px solid #888;
  border-radius: 4px;
  background: #fff;
}
.historique-de i {
  width: 5px;
  height: 5px;
  margin: auto;
  border-radius: 50%;
}
.historique-de i.pt {
  background: #222;
}

/* Règles */

.regles-421 {
  /* centrage forcé : la feuille du site remet les marges à zéro */
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(720px, calc(100vw - 32px));
  height: fit-content;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 0;
  border: none;
  border-radius: 14px;
  box-shadow: 0 10px 40px #0005;
  color: #222;
  background: #fff;
}
.regles-421::backdrop {
  background: #0008;
}
.regles-421[open] {
  animation: regles-apparait 0.2s ease-out;
}
@keyframes regles-apparait {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}
.regles-contenu {
  padding: 20px 24px;
  line-height: 1.45;
}
.regles-421 h2 {
  margin: 0 0 4px;
  font-size: 1.35em;
  color: #1a5e9a;
  text-align: center;
}
.regles-but {
  margin: 0 0 14px;
  text-align: center;
  font-style: italic;
  color: #555;
}
.regles-421 h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 6px;
  font-size: 1.05em;
  color: #1a5e9a;
}
.regles-421 h3 small {
  font-weight: normal;
  color: #777;
}
.regles-421 h3 .num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #1a5e9a;
  color: #fff;
  font-size: 0.8em;
}
.regles-421 p {
  margin: 0 0 8px;
}
.combis-421 {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
}
.combis-421 th {
  padding: 4px 8px;
  font-size: 0.8em;
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
  text-align: left;
  border-bottom: 2px solid #e2e2e2;
}
.combis-421 td {
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}
.combis-421 tbody tr:nth-child(odd) {
  background: #f7f9fc;
}
.combis-421 td small {
  display: block;
  font-size: 0.82em;
  color: #777;
}
.combis-421 td[data-des] {
  white-space: nowrap;
}
.combis-421 th:last-child,
.combis-421 .val {
  text-align: center;
}
.combis-421 .val {
  font-weight: bold;
  color: #b8860b;
}
.regles-note {
  margin-top: 10px !important;
  text-align: center;
  color: #555;
}
.regles-fermer {
  margin: 14px 0 0;
  text-align: center;
}
@media (max-width: 420px) {
  .regles-contenu {
    padding: 16px;
  }
  .combis-421 td,
  .combis-421 th {
    padding: 5px 4px;
  }
}

/* Fin de partie */
.popup-421 {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 24px #0003;
  padding: 32px 48px;
  font-size: 1.4em;
  font-weight: bold;
  text-align: center;
  z-index: 9999;
}
.popup-421.gagne {
  border: 2px solid #1cae4a;
  color: #1cae4a;
}
.popup-421.perdu {
  border: 2px solid #d32f2f;
  color: #d32f2f;
}
.popup-421 button {
  margin-top: 24px;
}
