:root {
  --parchment: #f1e4c3;
  --parchment-dark: #d9c59a;
  --ink: #2b1d0e;
  --wood: #5a3a1c;
  --gold: #c9a227;
  --danger: #a3261f;
  --good: #2f6b2a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #345c82;
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden { display: none !important; }

.panel {
  position: fixed;
  background: var(--parchment);
  border: 3px solid var(--wood);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  padding: 6px 12px;
  font-size: 14px;
}

#topbar {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  align-items: center;
  white-space: nowrap;
}

#side {
  top: 8px;
  right: 8px;
  width: 280px;
}
#side h3 {
  margin: 0 0 4px;
  font-family: Cinzel, Georgia, serif;
  text-align: center;
}
#lb {
  margin: 0;
  padding-left: 22px;
}
#lb li { margin: 2px 0; white-space: nowrap; }
#lb li.me { font-weight: bold; }
#lb li.ally .nm { color: var(--good); font-weight: bold; }
/* Royaume qui nous attaque : son nom clignote en rouge (la classe « on » est ajoutée une fois sur deux) */
#lb li.attacker { cursor: pointer; }
#lb li.attacker .nm { color: var(--danger); font-weight: bold; }
#lb li.attacker.on .nm { color: #fff; background: var(--danger); border-radius: 3px; }
#lb .allies { display: inline-block; width: 30px; }
#lb .allies i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 2px;
  border: 1px solid var(--ink);
}

#lb .pct { display: inline-block; width: 42px; text-align: right; }
#lb .faithB { display: inline-block; width: 16px; text-align: center; }
#lb .faithB.good { color: #2f8a2a; }
#lb .faithB.bad { color: #b8322a; }
/* Un pacte : ses membres regroupés dans un cadre, avec la part des terres du pacte entier */
#lb li.pactGroup {
  border: 2px solid var(--wood);
  border-radius: 6px;
  padding: 1px 4px 2px;
  margin: 4px 0 4px -4px;
  background: rgba(120, 90, 40, 0.08);
}
#lb li.pactGroup.mine { border-color: var(--good); }
#lb .pactHead { display: flex; justify-content: space-between; font-size: 12px; font-weight: bold; font-style: italic; }
#lb .pactHead .pct { margin-right: 2px; }
#lb .pactHead span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#lb li.pactGroup ul { list-style: none; margin: 0; padding: 0; }
#lb li.pactGroup .allies { visibility: hidden; } /* (les alliés sont déjà dans le cadre) */
#lb button { padding: 0 4px; margin-left: 4px; font-size: 13px; line-height: 18px; }
#lb li > * { vertical-align: middle; }
.lbb { height: 22px; vertical-align: middle; margin-right: 4px; }
.msg .bn, .attack .bn { height: 22px; vertical-align: middle; margin-right: 4px; }
#kBanner { height: 26px; vertical-align: middle; }
#kName { text-shadow: 0 0 2px #000, 0 0 1px #000; } /* lisible même avec une bannière claire */
.pickTitle { text-align: left; margin: 10px 0 4px; }
#bannerPick { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 6px 0 4px; }
#bannerPick button { padding: 2px; background: transparent; border: 2px solid transparent; }
#bannerPick button:hover { background: var(--parchment-dark); }
#bannerPick button.active { border-color: var(--wood); background: var(--gold); }
#bannerPick img { height: 92px; display: block; }
.nm {
  display: inline-block;
  width: 105px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#bottomwrap {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#bottomwrap .panel { position: static; }

/* Jauge des soldats */
#troopGauge {
  width: min(420px, calc(100vw - 32px));
  padding: 4px 10px 6px;
  text-align: center;
  font-size: 13px;
}
#troopRate { margin-bottom: 3px; }
#troopGauge .gauge {
  position: relative;
  height: 20px;
  background: #d8c8a2;
  border: 2px solid var(--wood);
  border-radius: 10px;
  overflow: hidden;
}
#troopFill {
  height: 100%;
  width: 0;
  transition: width 0.2s linear, background 0.3s;
}
#troopText {
  position: absolute;
  inset: 0;
  line-height: 16px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 2px #000;
}

#attacks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.attack {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 4px 10px;
}
.attack button { padding: 2px 8px; font-size: 13px; }
.attack button:hover { background: #e9b5a8; }
.attack.incoming { border-color: var(--danger); color: var(--danger); padding-right: 10px; }
/* petite croix dans le coin d'une barre : retraite */
#bottomwrap .attack.panel, .attack { position: relative; padding-right: 22px; }
.attack button.x {
  position: absolute; top: -8px; right: -8px;
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  font-size: 15px; line-height: 16px; font-weight: bold;
  color: #fff; background: var(--danger); border: 2px solid var(--wood);
}
.attack button.x:hover { background: #a3261f; }
.attack .goto { cursor: pointer; }

#bottombar {
  display: flex;
  gap: 16px;
  align-items: center;
}
.slider { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.slider input { width: 130px; accent-color: var(--wood); }
#ratioVal { min-width: 90px; }

#builds { display: flex; gap: 6px; }
button {
  font-family: inherit;
  cursor: pointer;
  background: var(--parchment-dark);
  border: 2px solid var(--wood);
  border-radius: 6px;
  color: var(--ink);
  padding: 4px 8px;
}
button:hover { background: #e8d6a8; }
.build {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 70px;
  font-size: 12px;
}
.build .key {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 10px;
  font-weight: bold;
  color: var(--wood);
}
.build .icon { font-size: 20px; }
/* petit compteur en haut à droite (châteaux construits / maximum) */
.build .count {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
  font-weight: bold;
  color: var(--wood);
}
.build .count.full { color: var(--danger); }
.build.active { background: var(--gold); box-shadow: 0 0 0 2px var(--ink) inset; }
.build.poor .cost { color: var(--danger); }
/* bouton « Croisade » (avec une cathédrale) : un peu doré pour le distinguer des constructions */
.build.crusade { border-color: var(--gold); }
.build.crusade:disabled { opacity: 0.7; cursor: default; }

#hint {
  bottom: 8px;
  left: 8px;
  max-width: 340px;
  font-size: 13px;
  pointer-events: none;
}
#hint:empty { display: none; }

#log {
  position: fixed;
  top: 60px;
  left: 8px;
  width: 340px;
  max-height: calc(100vh - 140px);
  overflow: hidden;
  pointer-events: none;
}
.msg {
  background: rgba(241, 228, 195, 0.95);
  border-left: 5px solid var(--wood);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: opacity 1s;
}
.msg.warn { border-left-color: var(--danger); }
.msg.good { border-left-color: var(--good); }
.msg.fade { opacity: 0; }
.msg.request {
  pointer-events: auto;
  border-left-color: var(--gold);
  font-size: 14px;
}
.msg.request .choices { display: flex; gap: 6px; margin-top: 6px; }
.msg.request button:first-child { background: #b9d7a4; }
.msg.request button:last-child { background: #e9b5a8; }
.msg.betray { border-left-color: var(--danger); }
.msg.betray button:first-child { background: #e9b5a8; }
.msg.betray button:last-child { background: var(--parchment-dark); }
#traitor { color: var(--danger); font-weight: bold; }
.msg.upgrade img { display: block; width: 120px; margin: 4px auto; }
.msg.request.upgrade button[data-del] { background: #e9b5a8; }
.msg.request.upgrade button[data-no] { background: var(--parchment-dark); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 12, 4, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.card {
  background: var(--parchment);
  border: 4px double var(--wood);
  border-radius: 10px;
  padding: 24px 28px;
  max-width: 640px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.card h1 {
  font-family: Cinzel, Georgia, serif;
  margin: 0 0 6px;
  font-size: 28px;
}
.card .sub { margin-top: 0; font-style: italic; }
.card label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0;
  gap: 12px;
  text-align: left;
}
.card input, .card select {
  font-family: inherit;
  font-size: 15px;
  padding: 4px 6px;
  border: 2px solid var(--wood);
  border-radius: 4px;
  background: #fffaf0;
}
.card select { max-width: 62%; }
.big {
  font-family: Cinzel, Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  padding: 10px 20px;
  margin-top: 10px;
  background: var(--gold);
}
.rules {
  text-align: left;
  font-size: 13px;
  padding-left: 18px;
  margin: 6px 0 0;
}
/* Règles repliées : on clique sur le titre pour les dérouler */
.rulesBox { margin-top: 14px; text-align: left; border-top: 1px solid var(--parchment-dark); padding-top: 8px; }
.rulesBox summary { cursor: pointer; font-weight: bold; font-family: Cinzel, Georgia, serif; }
.rulesBox summary small { font-weight: normal; font-family: Georgia, serif; opacity: 0.7; }
.rules li { margin: 4px 0; }

@media (max-width: 760px) {
  #bannerPick img { height: 60px; }
  .panel { font-size: 12px; padding: 4px 8px; }
  #topbar { gap: 8px; left: 8px; right: 8px; transform: none; flex-wrap: wrap; justify-content: center; white-space: normal; }
  #side { top: auto; bottom: 120px; width: 170px; font-size: 11px; }
  .nm { width: 80px; }
  #bottomwrap { left: 8px; right: 8px; transform: none; }
  #bottombar { flex-wrap: wrap; justify-content: center; }
  /* (boutons plus étroits : les 5 constructions et la croisade tiennent sur un téléphone) */
  #builds { flex-wrap: wrap; justify-content: center; gap: 4px; }
  .build { min-width: 56px; padding: 4px; }
  #hint { display: none; }
  #log { top: 80px; width: calc(100% - 16px); }
}

/* Menu d'actions (clic droit sur la carte) */
.actionMenu {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  min-width: 200px;
  max-width: 250px;
}
.actionMenu button { text-align: left; }
.actionMenu.quickMenu { flex-direction: row; min-width: 0; padding: 4px; }
.quickMenu button { width: 34px; height: 34px; padding: 0; font-size: 17px; text-align: center; font-weight: bold; }
.quickMenu button.danger { color: #c0392b; }
.quickMenu button.up { color: var(--wood); }
.quickMenu button svg { display: block; margin: auto; width: 20px; height: 20px; }
/* icônes dessinées dans les menus et les boutons (voir ICONS dans main.js) */
.ico { width: 1.2em; height: 1.2em; vertical-align: -0.25em; }
.icotext { white-space: normal; }
button:disabled .ico { opacity: 0.6; }
.actionMenu button:disabled { opacity: 0.5; cursor: not-allowed; }
.actionMenu small { color: var(--danger); font-size: 11px; margin: -2px 4px 2px; }

/* Barre de résumé d'un royaume survolé (fixe, juste sous la barre du haut) */
.kTip {
  pointer-events: none;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 13px;
  padding: 3px 10px;
  z-index: 30;
}
.kTip .bn { height: 20px; vertical-align: middle; margin-right: 4px; }
.kTip span { white-space: nowrap; }

/* Prototype à deux : lien sélectionnable et état visible même pendant la reconnexion. */
#multiSalon { margin-top: 14px; font-size: 14px; }
#multiSalon input { width: 100%; min-width: 0; box-sizing: border-box; }
#multiSalon a { color: #755020; }
#multiJoueurs { font-weight: bold; }
#multiBandeau { position: fixed; top: 62px; left: 50%; transform: translateX(-50%); z-index: 100;
  max-width: min(650px, 90vw); padding: 10px 16px; color: #fff4d0; background: #45371b;
  border: 2px solid #c6a86c; border-radius: 6px; text-align: center; pointer-events: none; }
#multiBandeau.erreur { background: #9b1717; color: white; border-color: #ffb0a0; }
#bannerPick button:disabled { opacity: .25; cursor: not-allowed; }

#multiEtat.erreur { color: #9b1717; font-weight: bold; }
#startBtn:disabled { opacity: .55; cursor: wait; }
