* {
  box-sizing: border-box;
}

:root {
  --board-size: min(92vw, 680px);
  --cell-size: calc(var(--board-size) / 15);
  --stone-size: 68%;
  --panel-bg: rgba(255, 255, 255, 0.86);
  --shadow-soft: 0 10px 25px rgba(0, 0, 0, 0.18);
  --shadow-strong: 0 14px 32px rgba(0, 0, 0, 0.22);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  color: #222;
  background-image: url("background.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.page-overlay {
  min-height: 100vh;
  padding: 18px 12px;
  background: rgba(255, 255, 255, 0.06);
}

.container {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 18px 24px;
  background: var(--panel-bg);
  border-radius: 22px;
  box-shadow: var(--shadow-strong);
  text-align: center;
  backdrop-filter: blur(7px);
}

.top-header {
  margin-bottom: 14px;
}

.logo {
  width: min(120px, 28vw);
  height: auto;
  display: block;
  margin: 8px auto 10px;
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
}

h1 {
  margin: 8px 0 6px;
  color: #333;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.2;
}

h2 {
  margin: 6px 0 18px;
  font-size: clamp(18px, 2.2vw, 28px);
  color: #111;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
}

.control-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 120px;
}

.control-group label {
  font-weight: 700;
  font-size: 14px;
  color: #333;
}

.hidden-label {
  visibility: hidden;
}

select,
input,
button {
  min-height: 42px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  font-size: 16px;
  font-family: inherit;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

select {
  background: white;
  color: #111;
}

input {
  background: white;
  color: #111;
}

button {
  background: linear-gradient(180deg, #1d62ff, #0047e6);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 71, 230, 0.28);
}

button:active {
  transform: translateY(0);
  opacity: 0.95;
}

.game-area {
  display: flex;
  justify-content: center;
  align-items: center;
}

#board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  justify-content: center;
  margin: 10px auto 0;
  background:
    linear-gradient(to right, rgba(70, 45, 20, 0.35) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(70, 45, 20, 0.35) 1px, transparent 1px),
    linear-gradient(180deg, #e4c996, #d8b87f);
  background-size: calc(100% / 15) calc(100% / 15), calc(100% / 15) calc(100% / 15), 100% 100%;
  border: 2px solid rgba(80, 52, 22, 0.35);
  border-radius: 10px;
  box-shadow: inset 0 2px 10px rgba(255, 255, 255, 0.2), 0 8px 20px rgba(0, 0, 0, 0.12);
  overflow: visible;
}

.cell {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
}

.cell::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: var(--stone-size);
  height: var(--stone-size);
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.cell.black::after {
  background: radial-gradient(circle at 30% 30%, #444, #000 68%);
  opacity: 1;
  animation: pop 0.2s ease-out;
}

.cell.white::after {
  background: radial-gradient(circle at 30% 30%, #ffffff, #ececec 68%);
  border: 1px solid rgba(0, 0, 0, 0.55);
  opacity: 1;
  animation: pop 0.2s ease-out;
}

.cell:hover::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: var(--stone-size);
  height: var(--stone-size);
  transform: translate(-50%, -50%) scale(var(--s, 1));
  border-radius: 50%;
  opacity: 0.28;
}

.cell:hover:not(.black):not(.white)::after {
  background: black;
}

body.white-turn .cell:hover:not(.black):not(.white)::after {
  background: white;
  border: 1px solid black;
}

.cell.placing::after {
  --s: 1;
  animation: pop 200ms ease-out;
}

.cell.last-move::after {
  box-shadow: 0 0 14px rgba(0, 150, 255, 0.75);
}

.cell.winner::after {
  animation: winnerGlow 0.8s ease-in-out infinite;
  z-index: 2;
}

@keyframes pop {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
  70% {
    transform: translate(-50%, -50%) scale(1.15);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

@keyframes winnerGlow {
  0% {
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0 0 6px gold, 0 0 10px rgba(255, 215, 0, 0.45);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.12);
    box-shadow: 0 0 14px gold, 0 0 22px rgba(255, 215, 0, 0.75);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0 0 6px gold, 0 0 10px rgba(255, 215, 0, 0.45);
  }
}

.online-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 20px 0;
}

.online-box {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 14px;
  backdrop-filter: blur(6px);
}

.online-box h3 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 18px;
}

#onlineInfo {
  margin-bottom: 10px;
  font-size: 14px;
  color: #444;
}

#onlinePlayers,
#publicMatches {
  text-align: left;
}

.player-row,
.match-row,
.public-match-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.player-row:last-child,
.match-row:last-child,
.public-match-row:last-child {
  border-bottom: none;
}

.player-row span,
.match-row span {
  font-size: 15px;
  color: #222;
}

.online-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.online-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.watch-btn {
  min-width: 92px;
}

.watch-btn.watching {
  background: #e74c3c !important;
  color: #fff !important;
  font-weight: 700;
  box-shadow: 0 0 14px rgba(231, 76, 60, 0.45);
}

.watch-btn.watching:disabled {
  opacity: 1;
  cursor: default;
}

body.watching-mode #board {
  transform: scale(0.9);
  transform-origin: top center;
  margin-top: 10px;
}

body.watching-mode #status {
  color: #1d4ed8;
  font-weight: 700;
}

body.watching-mode .container {
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.08), var(--shadow-strong);
}

.spectator-board {
  transform: scale(0.9);
  transform-origin: top center;
}

#board.game-locked {
  pointer-events: none;
  opacity: 0.98;
}

.play-again {
  background: #e53935 !important;
  color: white !important;
  transform: scale(1.05);
  box-shadow: 0 0 14px rgba(229, 57, 53, 0.55);
}

#scoreBoard {
  padding: 2px 5px;
  margin: 4px auto;
  max-width: 160px;
}

.score-title {
  font-size: 12px;
  margin-bottom: 2px;
}

#scoreText {
  font-size: 16px;
  font-weight: bold;
}

@media (max-width: 768px) {
  :root {
    --board-size: 96vw;
    --stone-size: 66%;
  }

  .buttons-row {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }

  .buttons-row button {
    width: auto !important;
    min-width: 120px;
  }

  .page-overlay {
    padding: 10px 8px;
  }

  .container {
    padding: 16px 10px 18px;
  }

  .logo {
    width: min(92px, 24vw);
  }

  .controls {
    gap: 10px;
    margin-bottom: 14px;
  }

  .control-group {
    min-width: 110px;
  }

  .control-group label {
    font-size: 13px;
  }

  select,
  input {
    width: 100%;
    min-height: 40px;
    font-size: 15px;
    padding: 8px 10px;
  }

  button {
    min-height: 40px;
    font-size: 15px;
    padding: 8px 10px;
  }

  .online-panel {
  grid-template-columns: 1fr;
  gap: 12px;
}

} /* fermeture de @media max-width: 768px */

@media (max-width: 520px) {
  :root {
    --board-size: 97vw;
    --stone-size: 64%;
  }

  .container {
    padding: 14px 8px 16px;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .control-group {
    min-width: 0;
    width: 100%;
  }

  .buttons-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 18px;
  }
}

#chatBadge {
  background: red;
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 12px;
  margin-left: 6px;

}

#shareMatchBtn {
  background: #2563eb;
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
}

.buttons-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap; /* permet retour ligne si écran petit */
}
.buttons-row button {
  width: auto !important;
}

.collapsible-box {
  text-align: left;
}

.collapse-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: transparent;
  color: #222;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.collapse-toggle:hover {
  transform: none;
  box-shadow: none;
}

.collapse-icon {
  font-size: 24px;
  font-weight: 700;
  color: #1d62ff;
  line-height: 1;
}

.panel-status {
  font-size: 14px;
  color: #555;
  margin-bottom: 8px;
  text-align: center;
}

.collapse-content {
  display: none;
  margin-top: 8px;
}

.collapsible-box.open .collapse-content {
  display: block;
}

.collapsible-box.open .collapse-icon {
  content: "-";
}

.collapsible-box.open .collapse-toggle .collapse-icon {
  transform: rotate(45deg);
}

/* 🔽 Réduire taille des boxes sans toucher au texte */

.online-box {
  padding: 8px 10px; /* réduit espace intérieur */
  min-height: auto;  /* enlève hauteur forcée */
}

.online-panel {
  margin: 10px 0; /* réduit espace autour */
  gap: 10px;      /* espace entre les deux boxes */
}

/* réduit espace entre les éléments à l'intérieur */
.online-box h3 {
  margin-bottom: 4px;
}

.panel-status {
  margin-bottom: 4px;
}

.collapse-toggle {
  margin-bottom: 4px;
}

/* réduit espace lignes joueurs */
.player-row,
.public-match-row {
  padding: 5px 0;
}

#installBtn {
  display: none;
  margin-top: 10px;
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  background: #2563eb;
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
}

#installBtn:hover {
  transform: translateY(-1px);
}

.ai-tool,
.online-tool {
  display: none !important;
}

body.mode-ai .ai-tool {
  display: flex !important;
}

body.mode-online .online-tool {
  display: flex !important;
}

body.mode-pvp .pvp-tool {
  display: inline-flex !important;
}

body.mode-online .online-panel {
  display: grid !important;
}

body:not(.mode-online) .online-panel {
  display: none !important;
}

body:not(.mode-online):not(.mode-tournament)
#chatContainer {
  display: none !important;
}

body.mode-online #chatContainer,
body.mode-tournament #chatContainer {
  display: block !important;
}

body.mode-tournament .controls {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

body.mode-tournament .buttons-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

body.mode-tournament .tournament-actions {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

body.mode-tournament #mode,
body.mode-tournament #shareSiteBtn,
body.mode-tournament #createTournamentBtn,
body.mode-tournament #joinTournamentBtn {
  height: 54px;
}

.players-arrow {
    color: #28a745;
    font-size: 26px;
    font-weight: bold;
    margin-left: 8px;
    transition: transform 0.2s ease;
}
.tournament-rules .collapse-toggle {
  width: auto !important;
  display: inline-flex !important;
  justify-content: flex-start !important;
  align-items: center !important;
  gap: 8px !important;
}

#tournamentTurnTimer {
  width: 95px;
  height: 95px;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  gap: 4px;

  text-align: center;
}

#tournamentTurnTimerLabel {
  font-size: 13px;
  font-weight: 600;
}

#tournamentTurnTimerValue {
  margin-left: 0;   /* supprimer l'ancien décalage horizontal */
  font-size: 28px;
  font-weight: 800;
}

#boardWrapper {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

#tournamentTrophyOverlay {
  position: absolute;
  inset: 0;
  z-index: 50;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 18px;

  background: rgba(17,24,39,0.18);

backdrop-filter: blur(1px);
-webkit-backdrop-filter: blur(1px);

  border-radius: 14px;
}

#tournamentTrophyOverlay[hidden] {
  display: none !important;
}

.trophy-card {
  width: min(320px, 80%);
  padding: 16px 14px;

  text-align: center;

  background: rgba(255,255,255,0.62);

backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(244,197,66,.85);
  border-radius: 22px;

  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.3),
    0 0 30px rgba(244, 197, 66, 0.5);

  animation: trophyAppear 0.7s ease-out;
}

.trophy-icon {
  font-size: 86px;
  line-height: 1;
  margin-bottom: 8px;

  animation: trophyBounce 1.3s ease-in-out infinite;
}

.trophy-card h2 {
  margin: 6px 0 18px;

  font-size: 20px;
  color: #111827;
}

.trophy-ranking {
  display: grid;
  gap: 9px;

  font-size: 18px;
  color: #374151;
}

/* Le timer n'apparaît qu'en mode Tournament */

body:not(.mode-tournament) #tournamentTurnTimer {
    display: none !important;
}

body.mode-tournament #tournamentTurnTimer {
    display: flex;
}

.trophy-ranking strong {
  color: #111827;
}

.trophy-congratulations {
  margin: 18px 0 12px;

  font-size: 21px;
  font-weight: 800;
  color: #b7791f;
}

.trophy-final-match {
  margin: 12px auto 18px;
  padding: 12px;

  background: #f3f4f6;
  border-radius: 8px;

  color: #111827;
}

#trophyFinalScore {
  margin-top: 5px;
  font-size: 20px;
  font-weight: 800;
}

#closeTournamentBtn {
  padding: 11px 18px;

  border: none;
  border-radius: 10px;

  background: #2563eb;
  color: white;

  font-size: 12px;
  font-weight: 700;

  cursor: pointer;
}

#closeTournamentBtn:hover {
  transform: translateY(-1px);
}

@keyframes trophyAppear {
  from {
    opacity: 0;
    transform: scale(0.65) translateY(25px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes trophyBounce {
  0%,
  100% {
    transform: translateY(0) rotate(-2deg);
  }

  50% {
    transform: translateY(-8px) rotate(2deg);
  }
}

@media (max-width: 600px) {
  .trophy-card {
    padding: 18px 14px;
  }

  .trophy-icon {
    font-size: 66px;
  }

  .trophy-card h2 {
    font-size: 22px;
  }

  .trophy-ranking {
    font-size: 15px;
  }
}

/* ==================================
   TOURNAMENT CONFETTI
================================== */

#tournamentConfetti {
  position: fixed;
  inset: 0;
  z-index: 10000;
  overflow: hidden;
  pointer-events: none;
}

.tournament-confetti-piece {
  position: absolute;
  top: -60px;
  display: block;

  animation-name: tournamentConfettiFall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;

  will-change: transform, opacity;
}

@keyframes tournamentConfettiFall {
  0% {
    transform:
      translateY(-60px)
      rotate(0deg);

    opacity: 1;
  }

  85% {
    opacity: 1;
  }

  100% {
    transform:
      translateY(110vh)
      rotate(720deg);

    opacity: 0;
  }
}

/* ==================================
   CHAT FERMÉ = PETITE BARRE
================================== */

#chatContainer {
  width: 220px !important;
  min-width: 0 !important;
  max-width: calc(100vw - 28px) !important;
}

/* Quand le contenu est fermé */
#chatContainer:has(#chatContent[style*="display: none"]),
#chatContainer:has(#chatContent:not([style])) {
  width: 105px !important;
  min-width: 105px !important;
}

/* Petite barre bleue quand fermé */
#chatContainer:has(#chatContent[style*="display: none"]) #chatHeader,
#chatContainer:has(#chatContent:not([style])) #chatHeader {
  border-radius: 12px !important;
  padding: 8px 10px !important;
  white-space: nowrap;
}

/* Quand le chat est ouvert */
#chatContainer:has(#chatContent[style*="display: block"]) {
  width: 220px !important;
  min-width: 220px !important;
}

/* Le contenu ouvert */
#chatContainer:has(#chatContent[style*="display: block"]) #chatContent {
  display: block !important;
}

#chatContainer.chat-collapsed {
  width: 105px !important;
  min-width: 105px !important;
  max-width: 105px !important;
}

#chatContainer.chat-collapsed #chatHeader {
  border-radius: 12px !important;
  white-space: nowrap;
}

#chatContainer.chat-open {
  width: 220px !important;
  min-width: 220px !important;
  max-width: 220px !important;
}

#chatContainer.chat-open #chatHeader {
  border-radius: 12px 12px 0 0 !important;
}

#chatInput {
  background: white !important;
  color: #111 !important;
  caret-color: #111 !important;
}

#chatInput::placeholder {
  color: #777;
  opacity: 1;
}

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

#chatInput {
  flex: 1;
  min-width: 0;
}

#chatSend {
  flex: 0 0 auto;
}

/* ==================================
   CHAT - POSITION ET APPARENCE
================================== */

#chatContainer {
  position: fixed !important;
  right: 18px !important;
  bottom: 22px !important;
  z-index: 9999 !important;

  width: 220px;
  background: white;
  border-radius: 12px;
  overflow: hidden;

  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
}

@media (max-width: 600px) {
  #chatContainer {
    right: 12px !important;
    bottom: 12px !important;
    max-width: calc(100vw - 24px) !important;
  }

  #chatContainer.chat-open {
    width: min(220px, calc(100vw - 24px)) !important;
  }
}

/* Barre bleue Chat */
#chatHeader {
  background: linear-gradient(180deg, #1d62ff, #0047e6) !important;
  color: white !important;

  padding: 10px 14px !important;
  font-size: 15px !important;
  font-weight: bold !important;

  cursor: pointer;
  text-align: center;

  border-radius: 12px;
}

/* Zone ouverte */
#chatContent {
  background: white;
  padding: 10px;
}

/* Messages */
#chatBox {
  min-height: 80px;
  max-height: 160px;
  overflow-y: auto;

  color: #222;
  background: white;

  text-align: left;
  font-size: 14px;

  padding: 6px;
}

/* Champ + bouton */
.chat-input-row {
  display: flex !important;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

#chatInput {
  flex: 1;
  min-width: 0;

  background: white !important;
  color: #111 !important;
  caret-color: black !important;

  border: 1px solid #aaa;
  border-radius: 8px;

  padding: 8px;
}

#chatSend {
  width: 42px;
  min-width: 42px;
  padding: 8px !important;
}

/* CHAT FERMÉ */
#chatContainer.chat-collapsed {
  width: 165px !important;
  min-width: 165px !important;
  max-width: 165px !important;
}

#chatContainer.chat-collapsed #chatContent {
  display: none !important;
}

#chatContainer.chat-collapsed #chatHeader {
  border-radius: 12px !important;
  white-space: nowrap !important;
  width: 100% !important;
}

/* CHAT OUVERT */
#chatContainer.chat-open {
  width: 220px !important;
}

#chatContainer.chat-open #chatContent {
  display: block !important;
}

#chatContainer.chat-open #chatHeader {
  border-radius: 12px 12px 0 0 !important;
}

/* ===== ONLINE INVITATION AU CENTRE ===== */

#inviteBox {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;

  transform: translate(-50%, -50%) !important;

  z-index: 20000 !important;

  background: white !important;
  padding: 18px 22px !important;
  border-radius: 14px !important;

  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.30) !important;

  text-align: center !important;
}

#inviteBox button:first-of-type {
  animation: inviteAcceptShake 0.8s infinite;
}

@keyframes inviteAcceptShake {
  0%, 100% {
    transform: rotate(0deg) scale(1);
  }

  25% {
    transform: rotate(-3deg) scale(1.05);
  }

  50% {
    transform: rotate(3deg) scale(1.05);
  }

  75% {
    transform: rotate(-3deg) scale(1.05);
  }
}

#homePage .home-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  display: block;
  margin: 0 auto 20px auto;
}

#homePage {
  min-height: 100vh;
  padding: 40px 20px;
  box-sizing: border-box;

  background:
    linear-gradient(rgba(255,255,255,0.88), rgba(255,255,255,0.88)),
    url("/images/home-bg.jpg") center/cover no-repeat fixed;
}

.home-page-content {
  max-width: 900px;
  margin: 0 auto;
  text-align: center;
}

#homePage .home-intro,
#homePage .home-section p {
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
  padding: 0 15px;
}

.status-row {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.home-icon-btn {
  position: absolute;
  left: 25px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 22px;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(0,0,0,0.18);
}

.home-icon-btn:hover {
  transform: scale(1.05);
}

/* ===== PRIVACY / LEGAL PAGE ===== */

.legal-page {
  min-height: 100vh;
  padding: 40px 20px;
  box-sizing: border-box;

  background:
    linear-gradient(rgba(255,255,255,0.94), rgba(255,255,255,0.94)),
    url("/images/home-bg.jpg") center/cover no-repeat fixed;
}

.legal-container {
  max-width: 850px;
  margin: 0 auto;
  padding: 40px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 20px;
  box-shadow: 0 6px 25px rgba(0,0,0,0.15);

  text-align: left;
}

.legal-logo {
  width: 90px;
  height: 90px;
  object-fit: contain;
  display: block;
  margin: 0 auto 20px auto;
}

.legal-container h1 {
  text-align: center;
}

.legal-container h2 {
  margin-top: 32px;
}

.legal-container h3 {
  margin-top: 22px;
}

.legal-container p,
.legal-container li {
  line-height: 1.7;
}

.legal-updated {
  text-align: center;
  opacity: 0.7;
}

.legal-home-link {
  display: inline-block;
  margin-bottom: 20px;
  text-decoration: none;
  font-weight: 600;
}

.legal-footer {
  margin-top: 45px;
  padding-top: 20px;
  border-top: 1px solid #ddd;
  text-align: center;
}

.header-left-tools {
  position: absolute;
  left: 25px;
  display: flex;
  gap: 10px;
}

.info-icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 22px;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(0,0,0,0.18);
}

.info-menu {
  display: none;
  position: absolute;
  top: 150px;
  left: 30px;
  width: 220px;
  padding: 15px;
  background: white;
  border-radius: 14px;
  box-shadow: 0 5px 20px rgba(0,0,0,0.18);
  z-index: 1000;
}

.info-menu a {
  display: block;
  padding: 10px;
  text-decoration: none;
  color: #333;
}

.info-menu a:hover {
  background: #f2f2f2;
  border-radius: 8px;
}

.header-left-tools .home-icon-btn,
.header-left-tools .info-icon-btn {
  position: static;
  left: auto;
}

.home-challenge-section {
  width: 100%;
  max-width: 760px;
  margin: 28px auto 10px auto;
  padding: 22px 20px;
  box-sizing: border-box;
  text-align: center;

  background: rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
}

.home-challenge-section h2 {
  margin: 0 0 12px 0;
  font-size: 28px;
}

.home-challenge-section p {
  max-width: 620px;
  margin: 0 auto 18px auto;
  line-height: 1.6;
  font-size: 16px;
}

.challenge-link-btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 12px;

  background: #146ef5;
  color: white;
  text-decoration: none;
  font-weight: 700;
  font-size: 17px;
}

.challenge-link-btn:hover {
  opacity: 0.9;
}

.game-area {
  display: block;
}

.info-icon-btn {
  background: #146ef5;
  color: white;
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}

.about-page {
  min-height: 100vh;
  margin: 0;
  padding: 40px 20px;
  box-sizing: border-box;

  background:
    linear-gradient(rgba(255,255,255,0.90), rgba(255,255,255,0.90)),
    url("/background.png") center/cover no-repeat fixed;

  font-family: Arial, sans-serif;
}

.about-container {
  max-width: 800px;
  margin: 40px auto;
  padding: 40px;
  background: rgba(255,255,255,0.92);
  border-radius: 22px;
  box-shadow: 0 10px 35px rgba(0,0,0,0.15);
  text-align: center;
}

.about-logo {
  width: 110px;
  height: 110px;
  object-fit: contain;
  margin-bottom: 20px;
}

.about-container h1 {
  font-size: 38px;
  margin-bottom: 25px;
}

.about-container p {
  max-width: 680px;
  margin: 0 auto 20px auto;
  line-height: 1.7;
  font-size: 18px;
}

.about-back-button {
  display: inline-block;
  margin-top: 20px;
  padding: 14px 22px;
  background: #1677ff;
  color: white;
  text-decoration: none;
  border-radius: 10px;
  font-weight: bold;
}

.contact-page {
  min-height: 100vh;
  margin: 0;
  padding: 40px 20px;
  box-sizing: border-box;

  background:
    linear-gradient(rgba(255,255,255,0.90), rgba(255,255,255,0.90)),
    url("/background.png") center/cover no-repeat fixed;

  font-family: Arial, sans-serif;
}

.contact-container {
  max-width: 760px;
  margin: 40px auto;
  padding: 40px;
  background: rgba(255,255,255,0.94);
  border-radius: 22px;
  box-shadow: 0 10px 35px rgba(0,0,0,0.15);
}

.contact-logo {
  width: 100px;
  height: 100px;
  object-fit: contain;
  display: block;
  margin: 0 auto 20px auto;
}

.contact-container h1 {
  text-align: center;
  font-size: 38px;
  margin-bottom: 15px;
}

.contact-intro {
  text-align: center;
  line-height: 1.6;
  margin-bottom: 30px;
}

#contactForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#contactForm label {
  font-weight: bold;
}

#contactForm input,
#contactForm textarea {
  width: 100%;
  padding: 14px;
  box-sizing: border-box;
  border: 1px solid #bbb;
  border-radius: 8px;
  font-size: 16px;
}

.contact-send-btn {
  margin-top: 10px;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: #1677ff;
  color: white;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
}

.contact-back-button {
  display: block;
  width: fit-content;
  margin: 25px auto 0 auto;
  text-decoration: none;
  font-weight: bold;
}

/* =====================================================
   PLAY VS AI + CHALLENGE INTEGRATED
   ===================================================== */

#aiChallengePanel {
  width: 100%;
  max-width: 950px;
  margin: 18px auto 22px;
  padding: 16px;
  box-sizing: border-box;

  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}


/* ---------- PLAYER SUMMARY ---------- */

#aiChallengePanel .challenge-profile-summary {
  grid-column: 1 / -1;

  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  padding: 16px 18px;

  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

#aiChallengePanel .challenge-player-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

#aiChallengePanel .avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;

  display: flex;
  align-items: center;
  justify-content: center;

  background: #2f3742;
  color: white;

  font-size: 22px;
  font-weight: 700;
}

#aiChallengePanel .player-name {
  font-size: 20px;
  font-weight: 700;
}

#aiChallengePanel .player-status {
  margin-top: 3px;
  font-size: 14px;
}

#aiChallengePanel .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
}

#aiChallengePanel .dot.green {
  background: #22c55e;
}

#aiChallengePanel .dot.red {
  background: #ef4444;
}


/* ---------- PROGRESS ---------- */

#aiChallengePanel .progress-wrap {
  margin-top: 14px;
}

#aiChallengePanel .progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;

  margin-bottom: 6px;
  font-size: 13px;
}

#aiChallengePanel .progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;

  background: #e5e7eb;
  overflow: hidden;
}

#aiChallengePanel .progress-fill {
  height: 100%;
  border-radius: 999px;

  background: #22c55e;
  transition: width 0.3s ease;
}


/* ---------- CARDS ---------- */

#aiChallengePanel .challenge-integrated-card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;

  padding: 16px;

  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

#aiChallengePanel .challenge-integrated-card h3 {
  margin: 0 0 14px;
  text-align: center;

  font-size: 18px;
}


/* ---------- PROFILE STATS ---------- */

#aiChallengePanel .stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

#aiChallengePanel .stat-box {
  padding: 10px 8px;

  background: #f7f7f7;
  border-radius: 12px;

  display: flex;
  flex-direction: column;
  align-items: center;

  text-align: center;
}

#aiChallengePanel .stat-box .label {
  font-size: 12px;
  opacity: 0.7;
}

#aiChallengePanel .stat-box .value {
  margin-top: 3px;

  font-size: 18px;
  font-weight: 700;
}


/* ---------- LEADERBOARD LEVEL BUTTONS ---------- */

#aiChallengePanel .leaderboard-level-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);

  gap: 8px;
  margin-bottom: 12px;
}

#aiChallengePanel .leaderboard-level-btn {
  border: none;
  border-radius: 10px;

  padding: 10px 6px;

  cursor: pointer;

  font-size: 14px;
  font-weight: 600;

  background: #e9eef8;
  color: #263238;
}

#aiChallengePanel .leaderboard-level-btn.active {
  background: #2563eb;
  color: white;
}


/* ---------- LEADERBOARD PLAYERS ---------- */

#aiChallengePanel .leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#aiChallengePanel .leaderboard-item {
  display: flex;
  justify-content: space-between;
  align-items: center;

  gap: 12px;

  padding: 10px;

  background: #f7f7f7;
  border-radius: 12px;
}

#aiChallengePanel .lb-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#aiChallengePanel .rank-badge {
  width: 34px;
  height: 34px;

  border-radius: 50%;

  display: flex;
  align-items: center;
  justify-content: center;

  background: #2f3742;
  color: white;

  font-weight: 700;
}

#aiChallengePanel .lb-name {
  font-weight: 700;
}

#aiChallengePanel .lb-sub {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

#aiChallengePanel .lb-points {
  font-weight: 700;
  white-space: nowrap;
}


/* ---------- HISTORY ---------- */

#aiChallengePanel .history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#aiChallengePanel .history-item {
  padding: 10px 12px;

  background: #f7f7f7;
  border-radius: 12px;

  display: flex;
  flex-direction: column;
  gap: 3px;
}

#aiChallengePanel .history-item strong {
  font-size: 14px;
}

#aiChallengePanel .history-item span {
  font-size: 13px;
  opacity: 0.75;
}


/* ---------- ACTION BUTTONS ---------- */

#aiChallengePanel .challenge-actions-row {
  grid-column: 1 / -1;

  display: flex;
  justify-content: center;
  align-items: center;

  gap: 12px;
  flex-wrap: wrap;

  padding-top: 2px;
}

#aiChallengePanel .challenge-actions-row button {
  min-width: 160px;

  padding: 11px 18px;

  border: none;
  border-radius: 12px;

  cursor: pointer;

  font-size: 15px;
  font-weight: 700;
}

#aiChallengePanel .danger-btn {
  background: #e9e9e9;
  color: #333;
}

#aiChallengePanel .share-btn {
  background: #22c55e;
  color: white;
}


/* ---------- EMPTY TEXT ---------- */

#aiChallengePanel .empty-text {
  padding: 12px;
  text-align: center;
  opacity: 0.65;
}


/* =====================================================
   MOBILE
   ===================================================== */

@media (max-width: 700px) {

  #aiChallengePanel {
    grid-template-columns: 1fr;

    padding: 10px;
    gap: 10px;
  }

  #aiChallengePanel .challenge-profile-summary,
  #aiChallengePanel .challenge-actions-row {
    grid-column: 1;
  }

  #aiChallengePanel .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  #aiChallengePanel .leaderboard-level-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  #aiChallengePanel .challenge-actions-row {
    flex-direction: column;
  }

  #aiChallengePanel .challenge-actions-row button {
    width: 100%;
  }
}

#aiChallengePanel .challenge-collapse-btn {
  width: 100%;
  border: none;
  background: transparent;
  padding: 10px 4px;

  display: flex;
  justify-content: space-between;
  align-items: center;

  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

#aiChallengePanel .challenge-actions-row {
  grid-column: 1 / -1;
  margin-top: 4px;
}

#aiChallengePanel .challenge-actions-row button {
  flex: 1;
  max-width: 240px;
}

/* ===== PLAY AGAIN AU CENTRE DE LA GRILLE ===== */

#boardWrapper {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

.play-again-center {
  position: absolute !important;

  top: 50% !important;
  left: 50% !important;

  transform: translate(-50%, -50%) !important;

  z-index: 100 !important;

  display: inline-flex !important;
  align-items: center;
  justify-content: center;

  margin: 0 !important;

  min-width: 160px;
  min-height: 54px;

  background: linear-gradient(
    180deg,
    #ef5350,
    #d32f2f
  ) !important;

  color: white !important;

  border: none !important;
  border-radius: 12px;

  padding: 12px 24px;

  font-size: 18px;
  font-weight: 700;

  cursor: pointer;

  box-shadow:
    0 8px 25px rgba(211, 47, 47, 0.45) !important;
}

.play-again {
  background: #e53935 !important;
  color: white !important;
  transform: scale(1.05);
  box-shadow: 0 0 14px rgba(229, 57, 53, 0.55);
}

/* =====================================
   CHALLENGE - NOUVELLE BARRE COMPACTE
===================================== */

body.mode-ai #aiChallengePanel {
  display: block !important;
}

#aiChallengePanel {
  width: 100%;
  max-width: 760px;
  margin: 10px auto 14px;
  padding: 0 8px;
  box-sizing: border-box;
}

/* Ligne des 5 icônes */
.challenge-toolbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.challenge-toolbar-left,
.challenge-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Petits boutons */
#aiChallengePanel .challenge-icon-btn {
  width: 48px !important;
  height: 48px !important;

  min-width: 48px !important;
  min-height: 48px !important;

  padding: 0 !important;
  margin: 0 !important;

  display: flex !important;
  align-items: center;
  justify-content: center;

  background: rgba(255, 255, 255, 0.94) !important;
  color: #222 !important;

  border: none !important;
  border-radius: 14px !important;

  font-size: 23px !important;
  line-height: 1 !important;

  box-shadow: 0 4px 12px rgba(0,0,0,0.13) !important;

  cursor: pointer;
}

/* Reset */
#aiChallengePanel .reset-icon-btn {
  background: #eeeeee !important;
}

/* Share */
#aiChallengePanel .share-icon-btn {
  background: #22c55e !important;
  color: white !important;
}

/* Contenu qui s'ouvre sous les icônes */
.challenge-mini-content {
  width: 100%;
  margin-top: 10px;
  padding: 14px;

  background: rgba(255,255,255,0.94);
  border-radius: 16px;

  box-shadow: 0 4px 14px rgba(0,0,0,0.10);
}

.challenge-mini-content h3 {
  margin: 0 0 14px;
  text-align: center;
}

/* Mobile */
@media (max-width: 520px) {

  #aiChallengePanel {
    padding: 0 4px;
    margin-top: 8px;
  }

  .challenge-toolbar {
    gap: 5px;
  }

  .challenge-toolbar-left,
  .challenge-toolbar-right {
    gap: 5px;
  }

  #aiChallengePanel .challenge-icon-btn {
    width: 44px !important;
    height: 44px !important;

    min-width: 44px !important;
    min-height: 44px !important;

    font-size: 21px !important;
    border-radius: 12px !important;
  }
}