/* ===============================
   Tours de Hanoï – styles spécifiques
   =============================== */

:root {
  --th-bleu: #1f5fbf;
  --th-bleu-fonce: #174a96;
  --th-bois: #b77b45;
  --th-bois-clair: #d9a36c;
  --th-bois-fonce: #7c4b22;
}

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

.th-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: 22px 32px 30px 32px;
  box-sizing: border-box;
}

.th-intro {
  color: #555;
  line-height: 1.5;
  margin-bottom: 20px;
}

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

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

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

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

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

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

.th-goal {
  margin-top: 6px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #f1f4f8;
  color: #3a4250;
  text-align: center;
  line-height: 1.5;
}

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

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

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

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

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

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

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

.th-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.th-btn.actif {
  background: var(--th-bleu);
  border-color: var(--th-bleu);
  color: #fff;
}

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

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

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

/* Barre commune (css/games.css) aux couleurs du bois */
.th-jeu {
  --mg-jeu-largeur: 924px;
  --mgb-fond: radial-gradient(120% 160% at 0% 0%, rgba(217, 163, 108, 0.3), transparent 55%),
    linear-gradient(120deg, #3b2412, var(--th-bois-fonce));
  --mgb-accent: var(--th-bois-clair);
  --mgb-titre: linear-gradient(100deg, #ffe9cf, var(--th-bois-clair));
  --mg-fs-fond: #eef2f7;
  --mg-bulle-fond: #3b2412;
}

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

#th-game {
  padding: 0 8px;
}

.th-jeu.mg-fs {
  justify-content: center;
}

/* Dans la colonne flexible du plein écran, les marges automatiques réduiraient
   le plateau à la largeur de son contenu */
.th-jeu.mg-fs .th-wrap {
  width: 100%;
}

.mg-stat b.th-stat-rec {
  color: #ffd54f;
}

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

.th-status.erreur {
  color: #c62828;
}

.th-status.aide {
  color: #b26a00;
}

.th-wrap {
  position: relative;
  max-width: 880px;
  margin: 4px auto 0 auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.th-board {
  position: relative;
  margin: 0 auto;
  cursor: pointer;
}

/* Colonne cliquable (une par tige) */
.th-col {
  position: absolute;
  top: 0;
  border-radius: 14px;
  transition:
    background 0.15s,
    box-shadow 0.15s;
}

.th-col.arrivee {
  background: rgba(46, 160, 67, 0.07);
  box-shadow: inset 0 0 0 2px rgba(46, 160, 67, 0.25);
}

.th-col.ok {
  background: rgba(46, 160, 67, 0.16);
}

.th-col.ko {
  background: rgba(198, 40, 40, 0.09);
}

.th-col.survol.ok {
  background: rgba(46, 160, 67, 0.28);
}

.th-col.indice-src,
.th-col.indice-dst {
  animation: th-indice 0.5s ease-in-out 3 alternate;
}

.th-col.indice-src {
  background: rgba(31, 95, 191, 0.14);
}

.th-col.indice-dst {
  background: rgba(255, 170, 0, 0.22);
}

@keyframes th-indice {
  to {
    background: transparent;
  }
}

/* Numéro / repère sous chaque tige */
.th-tag {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.8em;
  color: #6b7482;
  white-space: nowrap;
  pointer-events: none;
}

.th-tag b {
  display: inline-block;
  min-width: 18px;
  padding: 1px 4px;
  margin-right: 4px;
  border: 1px solid #c9d0da;
  border-radius: 5px;
  background: #fff;
  color: #333;
  font-size: 0.95em;
}

.th-tag.arrivee {
  color: #2e7d32;
  font-weight: bold;
}

/* Tige et socle en bois */
.th-rod {
  position: absolute;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(
    90deg,
    var(--th-bois-fonce),
    var(--th-bois-clair) 40%,
    var(--th-bois) 70%,
    var(--th-bois-fonce)
  );
  pointer-events: none;
}

.th-base {
  position: absolute;
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      92deg,
      rgba(0, 0, 0, 0) 0 22px,
      rgba(0, 0, 0, 0.05) 22px 24px,
      rgba(0, 0, 0, 0) 24px 51px
    ),
    linear-gradient(180deg, var(--th-bois-clair), var(--th-bois) 45%, var(--th-bois-fonce));
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* Disques */
.th-disk {
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  border-radius: 999px;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.5),
      rgba(255, 255, 255, 0.08) 45%,
      rgba(0, 0, 0, 0.2)
    ),
    var(--c, #888);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.18),
    0 2px 3px rgba(0, 0, 0, 0.2);
  will-change: transform;
  pointer-events: none;
  transition: filter 0.15s, box-shadow 0.15s;
}

/* Trou central, traversé par la tige */
.th-disk::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 18%;
  bottom: 18%;
  width: var(--trou, 6px);
  transform: translateX(-50%);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.22);
}

.th-disk.leve {
  z-index: 5;
  filter: brightness(1.12);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.18),
    0 0 0 3px rgba(255, 255, 255, 0.9),
    0 8px 16px rgba(0, 0, 0, 0.3);
}

.th-disk.anime {
  z-index: 6;
}

.th-board.fini .th-disk {
  animation: th-brille 0.7s ease-in-out 2 alternate;
}

@keyframes th-brille {
  to {
    filter: brightness(1.35);
  }
}

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

.th-keys {
  text-align: center;
  font-size: 0.8em;
  color: #888;
  margin: 0 auto 14px auto;
}

.th-keys b {
  color: #555;
}

@media (hover: none) {
  .th-keys {
    display: none;
  }
}

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

.th-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: th-fade 0.25s ease-out;
  overflow: hidden;
}

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

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

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

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

.th-stars {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}

.th-stars svg {
  width: 42px;
  height: 42px;
  animation: th-hop 0.6s ease-out both;
}

.th-stars .on {
  fill: #ffc107;
  stroke: #e0a100;
}

.th-stars .off {
  fill: #e4e8ee;
  stroke: #cfd5de;
}

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

.th-end-sub {
  margin-top: 6px;
  color: #555;
  line-height: 1.45;
}

.th-end-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.th-end-stats span {
  padding: 6px 14px;
  border-radius: 20px;
  background: #f1f4f8;
  font-family: "Madimi One", sans-serif;
  font-size: 1.1em;
  color: #333;
}

.th-end-rec {
  margin-top: 12px;
  font-weight: bold;
  color: #2e7d32;
}

.th-end-rec:empty {
  display: none;
}

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

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

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

@keyframes th-hop {
  0% {
    transform: translateY(-30px) scale(0.6);
    opacity: 0;
  }
  60% {
    transform: translateY(0) scale(1.1);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

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

.th-confetti span {
  position: absolute;
  top: -30px;
  border-radius: 999px;
  animation: th-confetti linear forwards;
}

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

@media (max-width: 520px) {
  .th-panel {
    padding: 16px 18px 24px 18px;
  }
  .th-btn {
    padding: 7px 12px;
    font-size: 0.9em;
  }
  .th-end-title {
    font-size: 1.8em;
  }
}

/* ---------- Thèmes de couleur des disques (bois, métal, arc-en-ciel) ---------- */
.th-chips-theme button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
/* Aperçu : petite pile de 4 disques */
.th-apercu {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  width: 30px;
  height: 22px;
}
.th-apercu i {
  display: block;
  height: 4px;
  border-radius: 3px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(0, 0, 0, 0.2)),
    var(--c);
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.25);
}

/* Bois : veinage sur les disques */
.th-board[data-theme="bois"] .th-disk,
.th-apercu[data-theme="bois"] i {
  background:
    repeating-linear-gradient(
      100deg,
      rgba(0, 0, 0, 0) 0 9px,
      rgba(60, 30, 10, 0.16) 9px 11px,
      rgba(0, 0, 0, 0) 11px 17px,
      rgba(255, 235, 200, 0.12) 17px 18px
    ),
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.05) 45%, rgba(0, 0, 0, 0.25)),
    var(--c, #b77b45);
}

/* Métal : reflets brossés, tiges et socle en acier */
.th-board[data-theme="metal"] .th-disk,
.th-apercu[data-theme="metal"] i {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0) 0 2px, rgba(255, 255, 255, 0.07) 2px 3px),
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.75) 0%,
      rgba(255, 255, 255, 0.15) 30%,
      rgba(0, 0, 0, 0.12) 55%,
      rgba(255, 255, 255, 0.25) 75%,
      rgba(0, 0, 0, 0.3) 100%
    ),
    var(--c, #9aa3ad);
}
.th-board[data-theme="metal"] {
  --th-bois: #8e969f;
  --th-bois-clair: #d3d8de;
  --th-bois-fonce: #4f565e;
}

/* Plein écran : le plateau peut s'élargir (taille calculée par game.js) */
.th-jeu.mg-fs .th-wrap {
  max-width: none;
}
