/* =========================================================================
 * Carcassonne en ligne — thème médiéval (parchemin & bois sombre)
 * ========================================================================= */

:root {
  --parchment: #f3ead2;
  --parchment-dark: #e7d9b4;
  --ink: #3b2a16;
  --ink-soft: #7a6136;
  --gold: #d9a441;
  --gold-bright: #ffd24a;
  --crimson: #8c1d1d;
  --crimson-dark: #6d1414;
  --wood: #221709;
  --wood-panel: #2d1f10;
  --wood-light: #3d2c17;
  --board-bg: #26331e;
  --serif: 'Crimson Pro', Georgia, 'Times New Roman', serif;
  --display: 'Cinzel', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--serif);
  font-size: 17px;
  background: var(--wood);
  color: #efe6cf;
  overflow: hidden;

  /* Sur mobile, un appui un peu long ou un glissé qui part de travers déclenche
   * la sélection de texte du navigateur : une bande bleue recouvre la moitié de
   * l'interface et ne s'en va qu'en tapant à côté, au risque de jouer un coup.
   * Rien ici ne se recopie à la main — le code de partie se copie d'un clic —
   * hormis les champs de saisie, rétablis juste en dessous. */
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;              /* ni menu « Copier / Partager » iOS */
  -webkit-tap-highlight-color: transparent; /* ni flash gris à chaque tape */
}

input, textarea, [contenteditable] {
  user-select: text; -webkit-user-select: text;
}

.hidden { display: none !important; }
.screen { height: 100%; }
.center { text-align: center; }

/* ------------------------------- Lobby -------------------------------- */

#lobby {
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255, 210, 74, .10), transparent 55%),
    radial-gradient(ellipse at center, #35502c 0%, #1b2a12 60%, #10190a 100%);
}

.lobby-card {
  position: relative;
  background:
    linear-gradient(160deg, rgba(255,255,255,.35), transparent 40%),
    var(--parchment);
  color: var(--ink);
  border-radius: 6px;
  border: 1px solid #b49b62;
  outline: 6px solid var(--wood-panel);
  box-shadow:
    0 0 0 8px #4a3417,
    0 24px 60px rgba(0, 0, 0, .65);
  padding: 26px 36px 30px;
  width: min(500px, 94vw);
  max-height: 92vh; overflow-y: auto;
}

.tile-banner {
  display: flex; justify-content: center; gap: 8px;
  margin: -4px 0 10px;
}
.tile-banner img {
  width: 52px; height: 52px;
  border-radius: 5px;
  border: 2px solid #8a6f3c;
  box-shadow: 0 3px 8px rgba(0,0,0,.35);
  transform: rotate(-4deg);
}
.tile-banner img:nth-child(2n) { transform: rotate(3deg); }
.tile-banner img:nth-child(3)  { transform: rotate(-1deg) scale(1.12); z-index: 1; }

.lobby-card h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 2.3em;
  letter-spacing: 2px;
  text-align: center;
  margin: 0;
  color: var(--crimson);
  text-shadow: 0 1px 0 #fff8, 0 2px 3px rgba(0,0,0,.15);
}
.subtitle {
  text-align: center;
  margin: 2px 0 20px;
  color: var(--ink-soft);
  font-style: italic;
}

.lobby-card h2 {
  font-family: var(--display);
  font-size: .95em;
  letter-spacing: .5px;
  margin: 0 0 12px;
  color: var(--ink);
}

.lobby-card label { display: block; margin-bottom: 16px; font-weight: 600; }
.lobby-card label.check { font-weight: 400; margin-bottom: 12px; }
.lobby-card label.check input { accent-color: var(--crimson); }

.lobby-card input[type=text], .lobby-card input:not([type=checkbox]) {
  display: block; width: 100%; margin-top: 5px;
  padding: 10px 12px; font-size: 1em; font-family: inherit;
  border: 1.5px solid #b49b62; border-radius: 6px;
  background: #fffdf6; color: var(--ink);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.07);
}
.lobby-card input:focus {
  outline: none;
  border-color: var(--crimson);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.07), 0 0 0 3px rgba(140,29,29,.15);
}

input.code {
  text-transform: uppercase; letter-spacing: 6px; font-weight: 700;
  text-align: center; font-size: 1.15em !important;
}

.lobby-cols { display: flex; gap: 16px; margin-top: 4px; }
.lobby-col {
  flex: 1;
  background: var(--parchment-dark);
  border: 1px solid #c6ad74;
  border-radius: 8px;
  padding: 14px 16px;
}

button {
  font: inherit; cursor: pointer;
  border: 0; border-radius: 6px; padding: 10px 14px;
  background: #d8c9a0; color: var(--ink);
  border: 1px solid #b49b62;
  box-shadow: 0 2px 0 #a08850;
  transition: transform .06s, box-shadow .06s, filter .1s;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(2px); box-shadow: 0 0 0 #a08850; }

button.primary {
  background: linear-gradient(180deg, #a52a2a, var(--crimson) 45%, var(--crimson-dark));
  color: #ffefd0;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 1px;
  border: 1px solid #5a1010;
  box-shadow: 0 3px 0 #4a0d0d, 0 4px 10px rgba(0,0,0,.25);
  width: 100%; margin-top: 10px;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
button.primary:active { transform: translateY(3px); box-shadow: 0 0 0 #4a0d0d; }
button.linklike {
  background: none; border: none; box-shadow: none;
  text-decoration: underline; color: var(--ink-soft); padding: 4px;
}
button:disabled { opacity: .45; cursor: default; transform: none; }

.room-code {
  display: inline-block;
  font-family: var(--display);
  font-size: 2em; font-weight: 800; letter-spacing: 10px;
  color: var(--crimson);
  background: #fffdf6;
  border: 2px dashed #c6ad74;
  border-radius: 8px;
  padding: 6px 10px 6px 20px;
}
.room-code:active { transform: scale(.97); }

.hint { color: var(--ink-soft); font-size: .88em; }

.room-code { cursor: pointer; }
.room-code:hover { background: #fff3d6; }
.copy-feedback {
  display: block;
  height: 1.3em;             /* hauteur réservée : aucun décalage */
  margin-top: 4px;
  color: #2a7a2a; font-weight: 700; font-size: .9em;
  opacity: 0; transition: opacity .25s;
}
.copy-feedback.show { opacity: 1; }

.color-choose { margin: 18px 0; }
.color-choose p { margin: 0 0 10px; }

#bot-controls { display: flex; gap: 10px; margin: 0 0 14px; }
#bot-controls select {
  flex: 0 0 auto;
  font: inherit; padding: 8px 10px;
  border: 1.5px solid #b49b62; border-radius: 6px;
  background: #fffdf6; color: var(--ink);
}
#bot-controls button { flex: 1; }
#lobby-players .bot-remove {
  margin-left: auto;
  background: none; border: none; box-shadow: none;
  color: #a01020; font-weight: 800; font-size: 1.1em;
  padding: 0 6px; cursor: pointer;
}
#lobby-players .badge { margin-left: auto; }
#lobby-players li .badge + .bot-remove { margin-left: 8px; }

#color-picker {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
  margin: 0;
}
.swatch {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(0,0,0,.25);
  cursor: pointer;
  transition: box-shadow .1s, opacity .1s;
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.swatch:hover { box-shadow: 0 0 0 3px rgba(0,0,0,.15); }
.swatch.mine {
  border-color: #fffdf6;
  box-shadow: 0 0 0 3px var(--crimson);
  cursor: default;
}
.swatch.mine::after {
  content: '✓';
  color: #fff; font-weight: 800; font-size: 17px;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.swatch.taken { cursor: default; opacity: .35; }
.swatch.taken:hover, .swatch.mine:hover { box-shadow: 0 0 0 3px transparent; }
.swatch.mine:hover { box-shadow: 0 0 0 3px var(--crimson); }
.error { color: #a01020; min-height: 1.3em; font-weight: 700; }

#lobby-players { list-style: none; padding: 0; margin: 14px 0; }
#lobby-players li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; margin: 6px 0;
  background: var(--parchment-dark);
  border: 1px solid #c6ad74;
  border-radius: 8px; font-weight: 600;
}
#lobby-players .pl-dot {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.35);
  flex: none;
}
#lobby-players .badge {
  margin-left: auto;
  font-size: .75em; letter-spacing: 1px;
  color: #fffdf6; background: var(--gold);
  border-radius: 20px; padding: 2px 10px;
  font-family: var(--display);
}

/* ------------------------------- Partie -------------------------------- */

#game { position: relative; }

#board {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background: var(--board-bg);
  cursor: grab; touch-action: none;
}
#board.dragging { cursor: grabbing; }

/* Bannière « à vous de jouer » */
#turn-banner {
  position: absolute;
  top: 14px; left: 50%; transform: translateX(-50%);
  margin-left: -130px;             /* compense la barre latérale */
  z-index: 5;
  font-family: var(--display);
  font-weight: 700; letter-spacing: 1px;
  color: #ffefd0;
  background: linear-gradient(180deg, #a52a2a, var(--crimson-dark));
  border: 1px solid #5a1010;
  border-radius: 30px;
  padding: 9px 26px;
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
  animation: banner-in .35s ease-out, banner-pulse 2.2s ease-in-out .4s infinite;
  pointer-events: none;
  white-space: nowrap;
}
@keyframes banner-in { from { transform: translate(-50%, -30px); opacity: 0; } }
@keyframes banner-pulse { 50% { box-shadow: 0 6px 26px rgba(255,210,74,.35); } }

/* --------- Barre latérale --------- */

#sidebar {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 260px; padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), transparent 120px),
    var(--wood-panel);
  border-left: 4px solid #14100a;
  box-shadow: -8px 0 24px rgba(0,0,0,.45);
  overflow-y: auto;
}

.side-title {
  font-family: var(--display);
  font-weight: 800; letter-spacing: 3px;
  text-align: center;
  color: var(--gold);
  font-size: 1.05em;
  border-bottom: 1px solid #4a3417;
  padding-bottom: 8px;
}

.side-heading {
  font-family: var(--display);
  font-size: .78em; letter-spacing: 2px;
  color: #b99b5e;
  margin-bottom: -6px;
}

#players { display: flex; flex-direction: column; gap: 6px; }
.player {
  display: flex; align-items: center; gap: 9px;
  background: var(--wood-light);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1.5px solid #14100a;
  transition: border-color .2s, background .2s;
}
.player.current {
  border-color: var(--gold-bright);
  background: #4a3a1c;
  box-shadow: 0 0 12px rgba(255, 210, 74, .18) inset;
}
.player.current .pname::after {
  content: ' ⚑';
  color: var(--gold-bright);
}
.player .dot {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  border: 2px solid rgba(255,255,255,.65);
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.player .pname {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 600;
}
.player .pmeeples { font-size: .82em; opacity: .8; letter-spacing: 1px; }
.player .pscore {
  font-family: var(--display);
  font-weight: 800; font-size: 1.15em;
  color: var(--gold-bright);
  min-width: 28px; text-align: right;
}

#turn-box {
  background: var(--wood-light);
  border: 1.5px solid #14100a;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
#turn-label {
  font-weight: 600;
  margin-bottom: 10px;
  min-height: 2.5em;
  line-height: 1.3;
}
#turn-row {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
}
#turn-actions-col { width: 100%; }
.preview-frame {
  display: inline-block;
  background: #171008;
  border: 1px solid #4a3417;
  border-radius: 8px;
  padding: 7px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.6);
}
#tile-preview { display: block; border-radius: 4px; }
#tile-actions { display: flex; gap: 8px; margin-top: 10px; }
#tile-actions button { flex: 1; padding: 9px 4px; }
#tile-actions button.primary { margin-top: 0; width: auto; }
#btn-rotate { background: #4a3a1c; color: #efe6cf; border-color: #14100a; box-shadow: 0 2px 0 #14100a; }
#btn-no-meeple {
  width: 100%; margin-top: 10px;
  background: #4a4434; color: #efe6cf;
  border-color: #14100a; box-shadow: 0 2px 0 #14100a;
}
#btn-recall {
  width: 100%; margin-top: 8px;
  background: #443055; color: #efe6cf;
  border-color: #14100a; box-shadow: 0 2px 0 #14100a;
}
.player .pabbot { font-size: .9em; }
.player .pabbot.off { opacity: .25; filter: grayscale(1); }
.mini-fig { height: 14px; vertical-align: -2px; }
.mini-fig.tall { height: 17px; vertical-align: -3px; }
/* --- Marchands et Bâtisseurs : la ligne joueur passe sur deux niveaux ---
 * Quatre figurines plus trois marchandises ne tiennent pas à côté du nom :
 * nom et score restent en haut, la réserve se replie en dessous. */
.player.tb {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  column-gap: 9px; row-gap: 5px;
  align-items: center;
}
.player.tb .pfigs {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 4px 9px;
}
.player .pgoods { display: inline-flex; gap: 5px; font-size: .78em; }
.player .pgoods > span { display: inline-flex; align-items: center; gap: 1px; }
.player .pgoods > span.off { opacity: .3; filter: grayscale(1); }
.mini-goods { height: 15px; vertical-align: -3px; }
#tiles-left {
  margin-top: 10px; font-size: .85em; color: #b99b5e;
  font-style: italic;
}

#log {
  flex: 1; min-height: 90px; overflow-y: auto;
  background: #1c1409;
  border: 1.5px solid #14100a;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: .84em; line-height: 1.5;
  color: #cbbfa4;
}
#log div { border-bottom: 1px solid rgba(255,255,255,.05); padding: 3px 0; }
#log div:last-child { border-bottom: 0; color: #efe6cf; }

#zoom-controls { display: flex; gap: 8px; }
#zoom-controls button {
  flex: 1; font-size: 1.15em; padding: 7px;
  background: var(--wood-light); color: #efe6cf;
  border-color: #14100a; box-shadow: 0 2px 0 #14100a;
}

/* Barres de défilement du panneau */
#sidebar ::-webkit-scrollbar, #sidebar::-webkit-scrollbar { width: 8px; }
#sidebar ::-webkit-scrollbar-thumb, #sidebar::-webkit-scrollbar-thumb {
  background: #4a3417; border-radius: 4px;
}

/* ---------------------------- Fin de partie ---------------------------- */

#final-overlay {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(10, 6, 2, .72);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.final-card {
  background: var(--parchment);
  color: var(--ink);
  border-radius: 6px;
  border: 1px solid #b49b62;
  outline: 6px solid var(--wood-panel);
  box-shadow: 0 0 0 8px #4a3417, 0 24px 60px rgba(0,0,0,.7);
  padding: 28px 36px;
  width: min(460px, 92vw); max-height: 85vh; overflow-y: auto;
  animation: banner-in .4s ease-out;
}
.final-card h2 {
  font-family: var(--display);
  margin-top: 0; text-align: center;
  color: var(--crimson);
}
#btn-show-board { width: 100%; margin-bottom: 8px; }
#btn-show-final {
  position: absolute; top: 14px; left: 14px; z-index: 6;
  background: linear-gradient(180deg, #a52a2a, var(--crimson-dark));
  color: #ffefd0;
  font-family: var(--display); font-weight: 700;
  border: 1px solid #5a1010; border-radius: 30px;
  padding: 9px 20px;
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
}

#final-ranking { padding-left: 28px; }
#final-ranking li {
  font-weight: 700; font-size: 1.15em; margin: 6px 0;
  font-family: var(--display);
}
#final-ranking li:first-child { color: var(--crimson); font-size: 1.3em; }
.final-card details { margin: 14px 0; }
.final-card summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); }
#final-detail { font-size: .9em; }

/* ------- Choix de la figurine, après avoir désigné un emplacement -------
 * Des libellés explicites remplacent les pastilles multiples : sur certaines
 * tuiles, deux variantes se retrouvaient à quelques pixels l'une de l'autre. */
#fig-chooser {
  position: absolute;
  bottom: 18px; left: 50%; transform: translateX(-50%);
  margin-left: -130px;             /* compense la barre latérale */
  z-index: 14;
  pointer-events: none;
}
.chooser-card {
  pointer-events: auto;
  background: var(--parchment);
  color: var(--ink);
  border-radius: 8px;
  border: 1px solid #b49b62;
  outline: 3px solid var(--wood-panel);
  box-shadow: 0 8px 28px rgba(0,0,0,.55);
  padding: 12px 16px;
  width: min(330px, 90vw);
  text-align: center;
  animation: pig-in .2s ease-out;
}
#fig-title {
  font-family: var(--display); font-weight: 700;
  color: var(--crimson); margin-bottom: 9px;
}
#fig-actions { display: flex; flex-direction: column; gap: 7px; }
#fig-actions button {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%;
}
#fig-cancel { margin-top: 8px; }

/* --------- Choix « reprendre son paysan ? » (cochon, T&B) ---------------
 * Panneau flottant, sans voile ni flou : le plateau doit rester lisible et
 * manipulable pour décider. Le conteneur laisse passer les clics, seule la
 * carte les intercepte. */
#pig-overlay {
  position: absolute;
  bottom: 18px; left: 50%; transform: translateX(-50%);
  margin-left: -130px;             /* compense la barre latérale */
  z-index: 12;
  pointer-events: none;
}
.pig-card {
  pointer-events: auto;
  background: var(--parchment);
  color: var(--ink);
  border-radius: 8px;
  border: 1px solid #b49b62;
  outline: 3px solid var(--wood-panel);
  box-shadow: 0 8px 28px rgba(0,0,0,.55);
  padding: 12px 16px;
  width: min(360px, 90vw);
  text-align: center;
  /* animation propre : banner-in suppose un translate(-50%) porté par
   * l'élément lui-même, or ici c'est le conteneur qui est centré. */
  animation: pig-in .25s ease-out;
}
@keyframes pig-in { from { transform: translateY(14px); opacity: 0; } }
.pig-card p { margin: 5px 0; font-size: .92em; }
.pig-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px;
  font-family: var(--display); font-weight: 700;
  color: var(--crimson);
  border-bottom: 1px solid rgba(120, 90, 40, .35);
  padding-bottom: 5px; margin-bottom: 6px;
}
#pig-timer { font-size: 1.15em; font-variant-numeric: tabular-nums; }
#pig-actions { display: flex; gap: 8px; margin: 9px 0 4px; }
#pig-actions button { flex: 1; }
#pig-field:empty, #pig-wait:empty { display: none; }
#pig-wait { font-size: .82em; }

/* ------------------------------ Mobile --------------------------------- */

button, .swatch { touch-action: manipulation; }

@media (max-width: 700px) {
  html { font-size: 15px; }
  /* éviter le zoom automatique iOS au focus des champs */
  .lobby-card input:not([type=checkbox]) { font-size: 16px; }
  .lobby-cols { flex-direction: column; }
  .tile-banner img { width: 42px; height: 42px; }
  .lobby-card { padding: 20px 18px 22px; }

  /* Le panneau latéral devient un volet en bas de l'écran */
  #sidebar {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 46vh;
    padding: 8px;
    gap: 8px;
    border-left: none;
    border-top: 3px solid #14100a;
    box-shadow: 0 -8px 24px rgba(0,0,0,.45);
  }
  .side-title { display: none; }

  /* Joueurs : rangée de puces compactes */
  #players { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .player { flex: 1 1 45%; min-width: 140px; padding: 4px 8px; gap: 6px; }
  .player .pscore { font-size: 1em; min-width: 20px; }
  .player .pmeeples { font-size: .78em; }
  /* cartes joueur étroites : on resserre la seconde ligne de l'extension */
  .player.tb { column-gap: 6px; row-gap: 3px; }
  .player.tb .pfigs { gap: 3px 6px; }
  .player.tb .pgoods { gap: 4px; font-size: .72em; }
  /* panneaux flottants : plus de barre latérale à compenser */
  #pig-overlay, #fig-chooser { margin-left: 0; bottom: 10px; }

  /* Tour de jeu : aperçu à gauche, actions à droite */
  #turn-box { padding: 7px 8px; }
  /* « À vous : placez la tuile. » fait doublon avec la bannière du plateau :
     on le masque pour gagner une ligne (le joueur courant reste surligné). */
  #turn-label { display: none; }
  #turn-row { flex-direction: row; gap: 9px; }
  .preview-frame { padding: 3px; flex: none; }
  #tile-preview { width: 58px; height: 58px; }
  #turn-actions-col { flex: 1; }
  #tile-actions { margin-top: 0; }
  #tile-actions button, #btn-no-meeple, #btn-recall {
    padding: 11px 6px;               /* cibles tactiles >= 44px */
  }
  #btn-no-meeple, #btn-recall { margin-top: 6px; }
  #tiles-left { margin-top: 4px; font-size: .78em; }

  /* Chronique repliée par défaut (touchez le titre pour l'ouvrir) */
  #log-heading { cursor: pointer; margin-bottom: -4px; }
  #log-heading::after { content: ' ▸'; }
  #log-heading.open::after { content: ' ▾'; }
  #log { display: none; }
  #log.open { display: block; flex: none; max-height: 18vh; min-height: 0; }

  /* Zoom sorti du volet : petit cluster flottant en haut-gauche du plateau
     (zone libre pendant le jeu). Libère une rangée entière dans le volet. */
  #zoom-controls {
    position: fixed;
    left: 8px; top: 8px;
    flex-direction: column;
    gap: 6px;
    z-index: 6;
  }
  #zoom-controls button {
    width: 42px; height: 42px; padding: 0; flex: none;
    opacity: .92;
  }

  /* Bannière plus discrète, centrée sur toute la largeur */
  #turn-banner {
    margin-left: 0;
    top: 8px;
    padding: 6px 16px;
    font-size: .78em;
    letter-spacing: .5px;
    line-height: 1.15;               /* interligne serré si 2 lignes */
    max-width: 78vw;                 /* laisse la place au zoom à gauche */
    white-space: normal;
    text-align: center;
  }

  /* Résultats : centré (le coin haut-gauche est pris par le zoom flottant) */
  #btn-show-final {
    left: 50%; transform: translateX(-50%);
    top: 8px;
  }

  .final-card { padding: 20px 22px; }
}
