/* Dames : styles communs aux pages de jeu (solo, a deux, multijoueur, defi du
   jour, relecture d'une partie). Les classes du damier sont posees par
   js/damier.js ; la taille du damier par dames-damier.js. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
  color: #e0e0e0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}
#app {
  position: relative; z-index: 1;
  background: rgba(20, 20, 35, 0.55);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 24px;
  padding: 30px 24px 24px;
  max-width: 800px;
  width: 100%;
  margin-top: 60px;
  text-align: center;
}
h1 {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--color-light), var(--color-mid), var(--color-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}
.sous-titre { color: #94a3b8; font-size: 0.9rem; margin: -2px 0 12px; }

/* ---------- Barre d'infos, compteurs, indicateur de tour ---------- */
.info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: #94a3b8;
}
.info-bar label { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; cursor: pointer; }
.info-bar input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--color-mid); }
.score-display { display: flex; gap: 16px; justify-content: center; margin-bottom: 12px; }
.score-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1.1rem;
}
.score-noir { background: rgba(30,30,30,0.8); color: #fff; border: 2px solid #555; }
.score-blanc { background: rgba(255,255,255,0.85); color: #1a1a1a; border: 2px solid #ccc; }
.score-box.actif { border-color: var(--color-mid); box-shadow: 0 0 12px color-mix(in srgb, var(--color-mid) 50%, transparent); }
/* Pastille dessinee comme un pion (l'emoji « cercle blanc » sortait en lavande) */
.pastille { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.pastille.blanc { background: radial-gradient(circle at 35% 35%, #fff, #ccc); box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
.pastille.noir { background: radial-gradient(circle at 35% 35%, #555, #1a1a1a); box-shadow: 0 0 0 1px rgba(255,255,255,0.25); }
.turn-indicator {
  font-size: 0.85rem;
  color: var(--color-accent);
  margin-bottom: 10px;
  min-height: 1.2em;
}
.turn-indicator.alerte { color: #fca5a5; font-weight: 600; }
.turn-indicator.bravo { color: #86efac; font-weight: 600; }

/* ---------- Damier ---------- */
.board-container { display: flex; justify-content: center; margin-bottom: 16px; }
.board-wrap { position: relative; width: 100%; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--n, 10), 1fr);
  background: #5c3a1e;
  border: 4px solid #3e2310;
  border-radius: 8px;
  padding: 2px;
  width: 100%;
  aspect-ratio: 1;
  /* Tailles internes (symbole de dame) relatives au damier */
  container-type: inline-size;
}
.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  position: relative;
  aspect-ratio: 1;
  transition: background 0.15s;
}
.cell.light { background: #f0d9b5; }
.cell.dark { background: #b58863; }
.cell.dark:hover { background: #c99b6d; }
.cell.valid-move::after {
  content: '';
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  position: absolute;
  z-index: 2;
}
.cell.valid-capture::after {
  content: '';
  width: 50%;
  height: 50%;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.45);
  position: absolute;
  z-index: 2;
}
/* Trace du dernier coup, teinte FROIDE : le dore se noie dans le brun des cases,
   et le bleu ne se confond avec aucune aide au coup en cours. */
.cell.trajet::before {
  content: '';
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: #2f6690;
  box-shadow: 0 0 0 1.5px rgba(255,255,255,0.65);
  z-index: 0;
}
.cell.trajet-depart::before { background: transparent; box-shadow: inset 0 0 0 2px #2f6690, 0 0 0 1.5px rgba(255,255,255,0.5); }
.cell.trajet-arrivee { box-shadow: inset 0 0 0 2px #2f6690; }
.cell.trajet-prise::before {
  inset: 34%;
  border-radius: 0;
  background:
    linear-gradient(45deg, transparent 44%, #c0392b 44%, #c0392b 56%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, #c0392b 44%, #c0392b 56%, transparent 56%);
  box-shadow: none;
  filter: drop-shadow(0 0 1px rgba(255,255,255,0.8));
}
.cell.selected { box-shadow: inset 0 0 0 3px #fbbf24; }
.cell.jouable .pion { outline: 2px solid rgba(251,191,36,0.9); outline-offset: 1px; }
.cell.gaffe { box-shadow: inset 0 0 0 3px #ef4444; }
.cell.cliquable { cursor: pointer; }
.pion {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  position: absolute;
  z-index: 1;
  transition: transform 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
}
.pion.noir {
  background: radial-gradient(circle at 35% 35%, #555, #1a1a1a);
  box-shadow: 0 2px 4px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.15);
}
.pion.blanc {
  background: radial-gradient(circle at 35% 35%, #fff, #ccc);
  box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 2px rgba(255,255,255,0.5);
}
.pion.dame { border: 2px solid #ffd700; box-shadow: 0 2px 6px rgba(0,0,0,0.4), 0 0 8px rgba(255,215,0,0.3); }
.pion.dame::after {
  content: '\265B';
  position: absolute;
  font-size: calc(42cqw / var(--n, 10));
  line-height: 1;
  z-index: 3;
}
.pion.blanc.dame::after { color: #b8860b; text-shadow: 0 0 4px rgba(184,134,11,0.6); }
.pion.noir.dame::after { color: #ffd700; text-shadow: 0 0 4px rgba(255,215,0,0.6); }
/* Damier retourne quand le joueur a les Noirs : ses pions restent en bas. */
.board.flip { transform: rotate(180deg); }
.board.flip .pion { transform: rotate(180deg); }

/* ---------- Ecran de depart pose sur le damier ---------- */
.setup {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(15, 12, 41, 0.82);
  backdrop-filter: blur(3px);
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.setup.visible { display: flex; }
/* Sur un petit ecran, les reglages peuvent depasser du damier : on fait defiler. */
.setup { overflow-y: auto; align-items: safe center; }
.setup-box { text-align: center; width: 100%; }
.setup-reglage { margin-bottom: 12px; }
.setup-label { font-size: 0.8rem; font-weight: 700; color: #cbd5e1; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.choix { display: inline-flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.choix button {
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: #e0e0e0;
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.choix button.active { background: color-mix(in srgb, var(--color-mid) 40%, transparent); border-color: var(--color-mid); color: #fff; }
.setup-box > p:not(.setup-label) { font-size: 1rem; font-weight: 700; margin-bottom: 14px; color: #e0e0e0; }
.setup-choices { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.setup-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 108px;
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #e0e0e0;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.setup-btn:hover { background: rgba(255,255,255,0.16); transform: translateY(-2px); }
.setup-btn small { font-size: 0.7rem; font-weight: 400; color: #94a3b8; }
.setup-pion { width: 26px; height: 26px; border-radius: 50%; }
.setup-pion.blanc { background: radial-gradient(circle at 35% 35%, #fff, #ccc); }
.setup-pion.noir { background: radial-gradient(circle at 35% 35%, #555, #1a1a1a); }
.setup-de { font-size: 1.4rem; line-height: 26px; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; line-height: 1; padding: 10px 24px; border: none; border-radius: 10px; font-family: 'Inter', sans-serif; font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.2s; text-decoration: none; }
/* .btn impose un display : sans cette regle, l'attribut hidden serait sans effet. */
.btn[hidden] { display: none; }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--color-btn1), var(--color-btn2)); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
.btn-secondary { background: rgba(255,255,255,0.1); color: #e0e0e0; border: 1px solid rgba(255,255,255,0.2); }
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.15); }
.btn-petit { padding: 7px 14px; font-size: 0.8rem; }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Historique des coups (notation officielle) ---------- */
.historique {
  margin: 0 auto 14px;
  max-width: 560px;
  text-align: left;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 8px 12px;
}
.historique summary { cursor: pointer; font-size: 0.85rem; color: #cbd5e1; font-weight: 600; }
.historique-liste {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-top: 8px;
  max-height: 140px;
  overflow-y: auto;
  position: relative;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: #cbd5e1;
}
.historique-liste .tour-num { color: #64748b; }
.historique-liste .coup { padding: 1px 4px; border-radius: 4px; }
.historique-liste .coup.actuel { background: color-mix(in srgb, var(--color-mid) 35%, transparent); color: #fff; }
.historique-liste .coup.gaffe { color: #fca5a5; text-decoration: underline wavy #ef4444; }
.historique-liste button.coup { background: none; border: none; color: inherit; font: inherit; cursor: pointer; }
.historique-vide { color: #64748b; font-size: 0.8rem; margin-top: 6px; }

/* ---------- Regles de la variante jouee ---------- */
.regles-variante {
  margin: 0 auto 14px;
  max-width: 560px;
  text-align: left;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 10px 14px;
}
.regles-variante summary { cursor: pointer; font-size: 0.85rem; color: #cbd5e1; font-weight: 600; }
.regles-variante ul { margin: 8px 0 0; padding-left: 18px; font-size: 0.85rem; line-height: 1.5; color: #e0e0e0; }
.regles-variante li { margin-bottom: 4px; }
.regles-variante p { margin-top: 8px; font-size: 0.8rem; }
.regles-variante a { color: var(--color-mid); }

/* ---------- Ecran de fin ---------- */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  justify-content: center;
  align-items: center;
}
.overlay.visible { display: flex; }
.overlay-card {
  background: rgba(30,30,50,0.95);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 40px 32px;
  max-width: 420px;
  width: 90%;
  text-align: center;
}
.overlay-card h2 { font-size: 1.8rem; font-weight: 800; margin-bottom: 12px; }
.overlay-card .result-score { font-size: 1.2rem; color: #94a3b8; margin-bottom: 8px; }
.overlay-card .result-raison { font-size: 0.9rem; color: #cbd5e1; margin-bottom: 16px; }
.overlay-card .result-enregistrement { font-size: 0.8rem; color: #94a3b8; margin-top: 12px; min-height: 1em; }
.overlay-card .actions { margin-top: 16px; }
.win-text { background: linear-gradient(90deg, var(--color-light), var(--color-mid)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.lose-text { background: linear-gradient(90deg, #f87171, #ef4444); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.draw-text { background: linear-gradient(90deg, #fbbf24, #f59e0b); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

/* ---------- Relecture d'une partie ---------- */
.relecture-controles { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.relecture-controles .btn { min-width: 44px; }
.relecture-compteur { color: #94a3b8; font-size: 0.85rem; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.relecture-curseur { width: 100%; max-width: 560px; accent-color: var(--color-mid); margin-bottom: 10px; }
.analyse-etat { color: #94a3b8; font-size: 0.8rem; margin-bottom: 8px; min-height: 1em; }
.relecture-entete { color: #cbd5e1; font-size: 0.9rem; margin-bottom: 12px; }

/* ---------- Defi du jour ---------- */
.defi-consigne { font-weight: 700; margin-bottom: 6px; }
.etat-defi { color: #cbd5e1; margin: 10px 0; }
.defi-avertissement { color: #94a3b8; font-size: 0.8rem; margin-top: 8px; }
.classement-section {
  margin: 22px auto 0;
  max-width: 800px;
  background: rgba(148, 163, 184, 0.09);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  padding: 16px;
  text-align: left;
}
.classement-titre { font-size: 1.1rem; margin-bottom: 10px; text-align: center; }
.classement-cta-compte { text-align: center; color: #c4b5fd; font-size: 0.85rem; margin-top: 10px; }
.lien-classement { display: block; text-align: center; margin-top: 10px; color: var(--color-accent); font-size: 0.85rem; }
.defi-compte { margin: 12px auto; max-width: 520px; }
.defi-compte p { color: #cbd5e1; margin-bottom: 10px; }
.defi-compte-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Multijoueur ---------- */
.code-display { font-size: 2rem; font-weight: 800; letter-spacing: 0.3em; color: var(--color-accent); margin: 12px 0; }
.waiting-msg { color: #94a3b8; margin-bottom: 16px; font-size: 0.95rem; }
.players-list { display: flex; gap: 12px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.player-tag { padding: 8px 18px; border-radius: 10px; font-weight: 600; font-size: 0.9rem; }
.player-blanc { background: rgba(255,255,255,0.85); color: #1a1a1a; border: 2px solid #ccc; }
.player-noir { background: rgba(30,30,30,0.8); color: #fff; border: 2px solid #555; }
.player-tag.actif { border-color: var(--color-mid); box-shadow: 0 0 12px color-mix(in srgb, var(--color-mid) 50%, transparent); }
.partie-classee { color: #fcd34d; font-size: 0.8rem; margin: -8px 0 10px; }
.variante-partie { color: #cbd5e1; font-size: 0.85rem; margin: -6px 0 12px; }
.variante-partie a { color: var(--color-mid); }
.share-link { display: flex; align-items: center; gap: 8px; justify-content: center; margin-bottom: 16px; }
.share-link input {
  font-family: 'Inter', sans-serif; font-size: 0.8rem; padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 8px;
  background: rgba(255,255,255,0.08); color: #e0e0e0; width: 260px; max-width: 60vw;
}
.share-link button {
  font-family: 'Inter', sans-serif; font-size: 0.8rem; padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; background: rgba(255,255,255,0.1);
  color: #e0e0e0; cursor: pointer;
}
.rejoindre-ligne { display: flex; gap: 8px; margin-bottom: 12px; }
.rejoindre-ligne input {
  flex: 1; min-width: 0; font-family: 'Inter', sans-serif; font-size: 0.9rem; padding: 10px 14px;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 10px; background: rgba(255,255,255,0.08); color: #e2e8f0; outline: none;
}
.erreur-rejoindre { color: #f87171; font-size: 0.82rem; min-height: 1.2rem; }
.rejoindre-titre { color: var(--color-accent); margin-bottom: 12px; }
.info-bar.centre { justify-content: center; }
.nulle-zone { margin-top: 14px; margin-bottom: 10px; }
.nulle-message { font-size: 0.85rem; color: var(--color-accent); margin-bottom: 8px; }
.erreur-partie { color: #fca5a5; margin: 16px 0; }
.overlay-elo { color: #fcd34d; font-weight: 600; margin-bottom: 8px; }

/* ---------- Absence de l'adversaire (multijoueur) ---------- */
.absence {
  font-size: 0.85rem;
  color: #fcd34d;
  background: rgba(251,191,36,0.1);
  border: 1px solid rgba(251,191,36,0.3);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 0 auto 10px;
  max-width: 460px;
}
.absence .btn { margin-top: 8px; }

footer { text-align: center; font-size: 0.78rem; color: #64748b; margin-top: 16px; }
footer a { color: #818cf8; text-decoration: none; }
footer a:hover { color: #a78bfa; }
.hidden { display: none !important; }

@media (max-width: 480px) {
  /* Largeur regagnee sur les marges pour agrandir les cases. Le banner sort de
     -24 px par defaut : on l'aligne sur le padding reduit de #app (#app dans le
     selecteur, banner.css etant charge apres). */
  body { padding: 16px 4px; }
  #app { padding: 20px 10px 16px; }
  #app .jeu-banner { margin-left: -10px; margin-right: -10px; }
  h1 { font-size: 1.3rem; }
  .board { border-width: 3px; }
  .setup-choices { flex-direction: column; align-items: stretch; gap: 8px; }
  .setup-btn { flex-direction: row; justify-content: center; gap: 8px; min-width: 0; padding: 10px; }
  .setup-btn small { display: none; }
}
