/* ===============================
   Puissance 4 – styles spécifiques
   =============================== */

:root {
  --p4-bleu: #1f5fbf;
  --p4-bleu-fonce: #174a96;
}

/* ---------- Jeton (plateau, pastilles, score) ----------
   --t : diamètre du jeton, pour que le relief reste proportionné */
.p4-token {
  --t: 40px;
  position: relative;
  border-radius: 50%;
  background:
    radial-gradient(
      circle at 34% 28%,
      rgba(255, 255, 255, 0.38),
      rgba(255, 255, 255, 0) 42%
    ),
    var(--c, #999);
  box-shadow:
    inset 0 0 0 calc(var(--t) * 0.045) rgba(0, 0, 0, 0.16),
    inset 0 calc(var(--t) * -0.06) calc(var(--t) * 0.05) rgba(0, 0, 0, 0.22);
}

/* Anneau en creux au centre, comme sur les vrais jetons */
.p4-token::before {
  content: "";
  position: absolute;
  inset: 21%;
  border-radius: 50%;
  box-shadow:
    inset 0 calc(var(--t) * 0.035) calc(var(--t) * 0.03) rgba(0, 0, 0, 0.3),
    0 calc(var(--t) * 0.02) 0 rgba(255, 255, 255, 0.35);
}

/* ---------- Configuration ---------- */

.p4-panel {
  max-width: 600px;
  margin: 14px auto 36px auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  padding: 8px 32px 30px 32px;
  box-sizing: border-box;
}

.p4-section {
  padding: 14px 0 0 0;
}

.p4-row {
  margin-bottom: 18px;
}

.p4-label {
  font-weight: bold;
  font-size: 0.95em;
  margin-bottom: 10px;
  color: #3a4250;
}

.p4-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.p4-chips button {
  border: 2px solid #d3dae2;
  background: #f5f7fa;
  color: #333;
  border-radius: 22px;
  padding: 9px 20px;
  font-size: 0.95em;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.p4-chips button:hover {
  border-color: #8fb1dc;
}

.p4-chips button.sel {
  background: var(--p4-bleu);
  border-color: var(--p4-bleu);
  color: #fff;
}

.p4-colors {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 4px 0 2px 4px;
}

.p4-colors button {
  --t: 44px;
  width: 44px;
  height: 44px;
  border: none;
  padding: 0;
  cursor: pointer;
  transition:
    transform 0.15s,
    opacity 0.15s;
}

.p4-colors button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.p4-colors button.sel {
  outline: 3px solid var(--p4-bleu);
  outline-offset: 4px;
}

/* Couleur déjà prise par l'autre joueur */
.p4-colors button:disabled {
  opacity: 0.18;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.p4-start-row {
  text-align: center;
  padding-top: 22px;
}

.p4-start-row .p4-play {
  font-size: 1.1em;
  padding: 8px 34px;
}

/* Bouton principal (Jouer, Rejouer…) */
.p4-play {
  font-family: "Madimi One", sans-serif;
  font-size: 1.3em;
  letter-spacing: 0.5px;
  color: #fff;
  background: var(--p4-bleu);
  border: none;
  border-radius: 30px;
  padding: 12px 54px;
  cursor: pointer;
  box-shadow:
    0 4px 0 var(--p4-bleu-fonce),
    0 6px 14px rgba(31, 95, 191, 0.35);
  transition:
    transform 0.1s,
    box-shadow 0.1s,
    background 0.15s;
}

.p4-play:hover {
  background: #2a6fd6;
}

.p4-play:active {
  transform: translateY(3px);
  box-shadow:
    0 1px 0 var(--p4-bleu-fonce),
    0 2px 6px rgba(31, 95, 191, 0.3);
}

/* Boutons secondaires */
.p4-btn {
  font-size: 0.95em;
  color: var(--p4-bleu);
  background: #fff;
  border: 2px solid #c9d6e8;
  border-radius: 22px;
  padding: 8px 18px;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.p4-btn:hover {
  background: #eef4fc;
  border-color: var(--p4-bleu);
}

.p4-btn-danger {
  color: #c62828;
  border-color: #ecc4c4;
}

.p4-btn-danger:hover {
  background: #fdeeee;
  border-color: #c62828;
}

/* ---------- Écran de jeu ---------- */

/* Barre commune (css/games.css) aux couleurs du jeu */
.p4-jeu {
  --mg-jeu-largeur: 860px;
  --mgb-fond: radial-gradient(120% 160% at 0% 0%, rgba(255, 213, 79, 0.2), transparent 55%),
    radial-gradient(120% 160% at 100% 100%, rgba(229, 57, 53, 0.22), transparent 55%),
    linear-gradient(120deg, #14305f, var(--p4-bleu));
  --mgb-accent: #ffd54f;
  --mgb-titre: linear-gradient(100deg, #ff6b6b, #ffd54f);
  --mg-fs-fond: #eef2f7;
  --mg-bulle-fond: #14305f;
}

.p4-jeu .p4-panel {
  width: 100%;
  margin: 0 auto 26px auto;
}

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

#p4-game {
  --s: 60px; /* taille d'une case, ajustée en JS */
}

/* Score de la série, dans la barre commune */
.p4-score {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

.p4-sb-player {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 12px;
  border-radius: 10px;
  min-width: 0;
  transition: background 0.2s;
}

#p4-sb-1 {
  justify-content: flex-end;
}

.p4-sb-player.actif {
  background: rgba(255, 255, 255, 0.14);
}

.p4-sb-disc {
  --t: 22px;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
}

.p4-sb-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.95em;
}

.p4-sb-wins {
  font-family: "Madimi One", sans-serif;
  font-size: 1.6em;
  line-height: 1;
}

.p4-sb-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  font-size: 0.8em;
  color: var(--mgb-doux);
}

#p4-sb-draws {
  font-family: "Madimi One", sans-serif;
  font-size: 1.3em;
  color: #fff;
}

.p4-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
  margin: 8px auto 0 auto;
  font-weight: bold;
  color: #333;
  text-align: center;
}

.p4-status .p4-sb-disc {
  --t: 18px;
  width: 18px;
  height: 18px;
}

.p4-wrap {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* Plateau : fond clair (trous vides), jetons, puis cadre bleu percé par-dessus.
   Les jetons (0,9 case) sont plus grands que les trous (0,8 case) :
   leur bord passe sous le cadre et la case paraît entièrement remplie. */
.p4-board {
  position: relative;
  width: calc(var(--s) * 7.36);
  height: calc(var(--s) * 6.36);
  margin-top: var(--s); /* place pour le jeton en attente */
  margin-bottom: calc(var(--s) * 0.2);
  background: #e9f1fb;
  border-radius: calc(var(--s) * 0.25);
  cursor: pointer;
}

.p4-preview,
.p4-discs {
  position: absolute;
  left: calc(var(--s) * 0.18);
  width: calc(var(--s) * 7);
}

.p4-preview {
  top: calc(var(--s) * -1);
  height: var(--s);
}

.p4-discs {
  top: calc(var(--s) * 0.18);
  height: calc(var(--s) * 6);
}

.p4-frame {
  position: absolute;
  inset: 0;
  border: calc(var(--s) * 0.18) solid var(--p4-bleu);
  border-radius: calc(var(--s) * 0.25);
  background-image: radial-gradient(
    circle at 50% 50%,
    transparent calc(var(--s) * 0.4),
    var(--p4-bleu-fonce) calc(var(--s) * 0.4 + 0.6px),
    var(--p4-bleu) calc(var(--s) * 0.45)
  );
  background-size: var(--s) var(--s);
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.p4-disc {
  --t: calc(var(--s) * 0.9);
  position: absolute;
  width: calc(100% / 7 * 0.9);
  will-change: transform;
}

.p4-discs .p4-disc {
  height: calc(100% / 6 * 0.9);
}

/* Dernier coup joué */
.p4-disc.dernier::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14%;
  height: 14%;
  margin: -7% 0 0 -7%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
}

/* Alignement gagnant */
.p4-disc.gagnant {
  animation: p4-pulse 0.8s ease-in-out infinite alternate;
}

.p4-disc.gagnant::before {
  box-shadow:
    0 0 0 calc(var(--t) * 0.06) rgba(255, 255, 255, 0.95),
    inset 0 calc(var(--t) * 0.035) calc(var(--t) * 0.03) rgba(0, 0, 0, 0.3);
}

.p4-disc.perdant {
  filter: saturate(0.35) brightness(0.75);
}

@keyframes p4-pulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.35);
  }
}

.p4-ghost {
  top: 5%;
  height: 90%;
  opacity: 0.9;
  transition: left 0.08s ease-out;
  pointer-events: none;
}

.p4-ghost[hidden] {
  display: none;
}

/* ---------- Barre d'outils ---------- */

/* ---------- Fenêtres (fin de partie, confirmation) ---------- */

.p4-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, 25, 45, 0.55);
  animation: p4-fade 0.25s ease-out;
  overflow: hidden;
}

.p4-modal-box {
  position: relative;
  background: #fff;
  border-radius: 20px;
  padding: 26px 28px 24px 28px;
  width: 100%;
  max-width: 400px;
  box-sizing: border-box;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  animation: p4-pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.p4-modal-btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.p4-modal-btns .p4-play {
  font-size: 1.15em;
  padding: 10px 36px;
}

#p4-end .p4-modal-btns .p4-play {
  padding: 11px 64px;
}

.p4-modal-btns2 {
  margin-top: 14px;
}

.p4-end-tokens {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 12px;
}

.p4-end-tokens .p4-token {
  --t: 40px;
  width: 40px;
  height: 40px;
  animation: p4-hop 0.6s ease-out both;
}

.p4-end-title {
  font-family: "Madimi One", sans-serif;
  font-size: 2.2em;
  line-height: 1.1;
  color: #2a2f38;
}

.p4-end-sub {
  margin-top: 6px;
  color: #555;
}

.p4-end-score {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 6px 16px;
  border-radius: 20px;
  background: #f1f4f8;
  font-family: "Madimi One", sans-serif;
  font-size: 1.2em;
  color: #333;
}

.p4-end-score .p4-token {
  --t: 18px;
  width: 18px;
  height: 18px;
}

.p4-confirm-txt {
  font-weight: bold;
  font-size: 1.05em;
  color: #333;
}

@keyframes p4-fade {
  from {
    opacity: 0;
  }
}

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

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

/* Confettis en forme de jetons (victoire) */
.p4-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.p4-confetti span {
  position: absolute;
  top: -30px;
  border-radius: 50%;
  animation: p4-confetti linear forwards;
}

@keyframes p4-confetti {
  to {
    transform: translate(var(--dx), 110vh) rotate(var(--rot));
  }
}

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

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

@media (max-width: 520px) {
  .p4-panel {
    padding: 4px 18px 24px 18px;
  }
  .p4-chips button {
    padding: 8px 15px;
  }
  .p4-colors {
    gap: 11px;
  }
  .p4-colors button {
    --t: 38px;
    width: 38px;
    height: 38px;
  }
  .p4-sb-player {
    padding: 7px 9px;
    gap: 6px;
  }
  .p4-sb-name {
    font-size: 0.85em;
  }
  .p4-modal-box {
    padding: 22px 16px 20px 16px;
  }
}
