:root {
  --bg: #12140f;
  --panel: rgba(22, 24, 18, 0.92);
  --line: #3a3b2c;
  --text: #e8e2cf;
  --muted: #a39d86;
  --gold: #c9a24d;
  --gold-dark: #8c6d2a;
  --danger: #e07a6a;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }

button {
  font: inherit; cursor: pointer; border: 1px solid var(--gold-dark);
  background: linear-gradient(#d4ae5a, #a8822f); color: #1c1608;
  padding: 8px 16px; border-radius: 6px; font-weight: 600;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
button:disabled { opacity: .55; cursor: default; }

/* --- Carte --- */
#viewport { position: fixed; inset: 0; overflow: hidden; cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
/* rien de la carte ne se sélectionne ni ne se « tire » comme une image (V0.1.20) */
#viewport * { user-select: none; -webkit-user-select: none; -webkit-user-drag: none; }
#viewport.dragging { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#tiles, #grid, #castles, #marches, #hover, #selected { position: absolute; inset: 0; }
#tiles img { position: absolute; display: block; user-select: none; -webkit-user-drag: none; pointer-events: none; }
#tiles img.apercu { left: 0; top: 0; width: 100%; height: 100%; }
#tiles img.fondu { opacity: 0; transition: opacity .3s; }
#tiles img.fondu.ok { opacity: 1; }
#grid {
  pointer-events: none; display: none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,.22) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.22) 1px, transparent 1px);
}
#viewport.show-grid #grid { display: block; }
#hover, #selected { pointer-events: none; display: none; box-sizing: border-box; inset: auto; }
#hover { border: 2px solid rgba(255,255,255,.45); background: rgba(255,255,255,.06); }
#selected { border: 3px solid var(--gold); box-shadow: 0 0 18px rgba(201,162,77,.6) inset; }

/* V0.1.23 : cases du domaine (bordure à la couleur du joueur) et image du stade sur tout le carré */
.dcase { position: absolute; box-sizing: border-box; border-style: solid; pointer-events: none; }
.castle { position: absolute; pointer-events: none; }
.castle img { display: block; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(0,0,0,.45)); }
.castle .tag {
  position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%); font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap;   /* cases de 104,5 px (V0.1.21) */
  background: rgba(0,0,0,.55); padding: 1px 6px; border-radius: 4px;
}
.castle.mine .tag { background: rgba(140,109,42,.9); }
.castle:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* --- Barre du haut --- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; gap: 16px; z-index: 15;   /* au-dessus du panneau et de la ville, pour le menu du pseudo (V0.1.37) */
  padding: 0 16px; background: linear-gradient(rgba(10,11,8,.92), rgba(10,11,8,.75)); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .3em; color: var(--gold); }
#hint { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#royaume { color: var(--text); font-weight: 600; font-size: 14px; padding: 3px 10px; border: 1px solid var(--gold-dark); border-radius: 999px; white-space: nowrap; }
#royaume:empty { display: none; }
#topbar .right { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-shrink: 0; }
.brand, #resbar { flex-shrink: 0; }
/* Boutons de la barre (V0.1.37) : icône + nom ; sous 1500 px, icône seule (nom au survol), le nombre reste */
.bouton-barre { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.bouton-barre[hidden] { display: none; }
.bouton-barre .bnb { font-variant-numeric: tabular-nums; }
@media (max-width: 1500px) {
  #topbar .btxt { display: none; }
  .bouton-barre { padding-left: 10px; padding-right: 10px; gap: 4px; }
  .bouton-barre .bico { font-size: 16px; }
}
/* Menu du pseudo (V0.1.37) */
#menuCompte { position: relative; }
#who { white-space: nowrap; }
#menuListe {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; z-index: 60; padding: 6px;
  display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--gold-dark);
  border-radius: 8px; box-shadow: 0 12px 30px rgba(0,0,0,.6);
}
#menuListe[hidden] { display: none; }
#menuListe > button, #menuListe > a {
  display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 6px; border: none;
  background: none; color: var(--text); text-decoration: none; font: inherit; font-weight: 500; cursor: pointer;
}
#menuListe > :is(button, a)[hidden] { display: none; }
#menuListe > button:hover, #menuListe > a:hover, #menuListe > :focus-visible { background: rgba(201,162,77,.15); color: var(--gold); filter: none; }
#logoutBtn { border-top: 1px solid var(--line) !important; border-radius: 0 0 6px 6px !important; margin-top: 4px; }
.toggle { display: flex; gap: 6px; align-items: center; color: var(--muted); cursor: pointer; }
#who { color: var(--gold); font-weight: 600; }
.ghost-link { color: var(--text); text-decoration: none; border: 1px solid var(--line); padding: 7px 14px; border-radius: 6px; }
.ghost-link:hover { border-color: var(--gold-dark); }

/* --- Panneau --- */
#panel {
  position: fixed; right: 16px; top: 68px; width: 300px; padding: 18px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
#panel h2 { margin: 0 0 6px; font-size: 18px; color: var(--gold); }
#panel p { margin: 0 0 12px; color: var(--muted); line-height: 1.4; }
#panel .close { position: absolute; top: 8px; right: 10px; background: none; border: none; color: var(--muted); font-size: 22px; padding: 0 4px; }

/* --- Connexion --- */
#authOverlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.35), rgba(0,0,0,.8));
}
#authOverlay[hidden], #panel[hidden] { display: none; }
.card {
  width: min(400px, 94vw); padding: 28px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.6);
}
.card h1 { margin: 0; text-align: center; letter-spacing: .35em; color: var(--gold); }
/* Logo à trois calques superposés (V0.1.26), ratio 1536 × 1024 ; déborde un peu sur les marges de la carte */
.logo { position: relative; aspect-ratio: 1536 / 1024; margin: -18px -24px -6px; user-select: none; }
.logo > img, .logo > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.card .sub:empty { display: none; }
.card .sub { margin: -6px 0 4px; text-align: center; color: var(--muted); font-size: 14px; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; background: transparent; color: var(--muted); border-color: var(--line); font-weight: 500; }
.tab.active { color: var(--text); border-color: var(--gold-dark); background: rgba(201,162,77,.12); }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.card input {
  font: inherit; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: #0d0e0a; color: var(--text);
}
.card input:focus { outline: 2px solid var(--gold-dark); border-color: transparent; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 0; }
.card .info { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text); }
.card .info:empty { display: none; }
.card .info.bon { padding: 10px 12px; border: 1px solid var(--gold-dark); border-radius: 6px; background: rgba(201,162,77,.1); }
.card [hidden] { display: none !important; }
.card .links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; margin: -4px 0 0; font-size: 13px; }
.card .links a { color: var(--muted); }
.card .links a:hover { color: var(--gold); }
#turnstileBox { min-height: 65px; display: flex; justify-content: center; }

/* ===== Jeu : barre de ressources, ville, fenêtres ===== */
#resbar { display: flex; gap: 14px; font-size: 14px; white-space: nowrap; }
#resbar .res { color: var(--text); font-variant-numeric: tabular-nums; }
#resbar .res.plein { color: #e6b450; }
button.alerte { border-color: #c0573f; color: #ffd2c4; }
#panelExtra { display: flex; flex-direction: column; gap: 8px; }
#panelExtra:empty { display: none; }
.small { font-size: 13px; } .muted { color: var(--muted); }

#ville { position: fixed; inset: 52px 0 0 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; background: var(--bg); z-index: 5; }
#ville[hidden] { display: none; }
#villeCarte { position: relative; overflow: hidden; display: grid; place-items: center; padding: 24px; min-height: 0; }
#villeCarte { height: 100%; box-sizing: border-box; }
/* Carte de la ville (V0.1.35) : image du propriétaire (2244 × 2804), la même pour tout le monde.
   L'aperçu léger s'affiche tout de suite, l'image complète se pose par-dessus dès qu'elle est chargée. */
#villeZone {
  position: relative; aspect-ratio: 2244 / 2804;
  height: min(100%, calc((100vw - 380px - 48px) * 2804 / 2244)); max-width: 100%;
  background: url("/img/ville/carte-ville.webp") center / cover no-repeat, url("/img/ville/carte-ville-apercu.webp") center / cover no-repeat, #2c3519;
  border-radius: 10px; box-shadow: 0 0 0 3px #4a3720, 0 0 0 5px #2b1f12, 0 30px 60px rgba(0,0,0,.6);
  user-select: none; -webkit-user-select: none;
}
/* Bâtiments de la ville (V0.1.36) : image détourée du propriétaire, étiquette dessous ; largeur et place dans EMPLACEMENTS (public/jeu.js) */
.emplacement {
  position: absolute; transform: translate(-50%, -50%); padding: 0; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; color: var(--text); font-weight: 500;
}
.emplacement:hover, .emplacement:focus-visible { background: none; filter: none; outline: none; }
.emplacement .bat-img { width: 100%; height: auto; display: block; pointer-events: none; filter: drop-shadow(0 6px 6px rgba(0,0,0,.55)); transition: filter .15s, transform .15s; }
.emplacement:hover .bat-img { filter: drop-shadow(0 0 10px rgba(255,220,140,.55)) drop-shadow(0 6px 6px rgba(0,0,0,.55)); transform: translateY(-2px); }
.emplacement.choisi .bat-img { filter: drop-shadow(0 0 8px rgba(201,162,77,.95)) drop-shadow(0 0 18px rgba(201,162,77,.6)); }
.emplacement.vide .bat-img { filter: grayscale(.85) brightness(.75) drop-shadow(0 6px 6px rgba(0,0,0,.55)); opacity: .6; }
.emplacement.vide.choisi .bat-img { filter: grayscale(.6) brightness(.85) drop-shadow(0 0 8px rgba(201,162,77,.95)); opacity: .85; }
.emplacement .etiquette {
  position: absolute; top: 100%; left: 50%; transform: translate(-50%, -40%); white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; padding: 2px 8px; border-radius: 8px; line-height: 1.2;
  background: rgba(14, 16, 10, .78); border: 1px solid rgba(201,162,77,.35); pointer-events: none;
}
.emplacement.choisi .etiquette { border-color: var(--gold); }
.emplacement.vide .etiquette { border-style: dashed; }
.emplacement .nom { font-size: 12px; }
.emplacement .niv { font-size: 11px; color: var(--gold); }
.emplacement .chantier { position: absolute; top: -6px; right: 4px; font-size: 22px; animation: tape 1s infinite; }
@keyframes tape { 50% { transform: rotate(-25deg); } }
#villeFiche { border-left: 1px solid var(--line); background: var(--panel); padding: 20px; overflow: auto; }
#villeFiche h2 { margin: 0; color: var(--gold); }
#villeFiche .sous { color: var(--muted); margin: 2px 0 8px; }
#villeFiche p { color: var(--text); opacity: .85; line-height: 1.45; }
#villeRetour { position: absolute; left: 16px; top: 14px; background: rgba(10,11,8,.8); }
.effet { margin: 4px 0; }
.bloc { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.cout { display: flex; flex-wrap: wrap; gap: 10px; font-variant-numeric: tabular-nums; }
.cout .ok { color: var(--text); } .cout .manque { color: var(--danger); }
.raison { color: var(--danger); font-size: 13px; }
.encours { margin-top: 12px; padding: 10px; border-radius: 8px; background: rgba(201,162,77,.12); border: 1px solid var(--gold-dark); }
.troupes { display: flex; flex-wrap: wrap; gap: 10px; }
.unite { padding: 10px; border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 6px; }
.unite.bloquee { opacity: .55; }
.uhaut { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.uform { display: flex; gap: 8px; align-items: center; }
.uform input, .rligne input { width: 80px; font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: #0d0e0a; color: var(--text); }

#fenetre { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0,0,0,.6); }
#fenetre[hidden] { display: none; }
.fen { position: relative; width: min(560px, 94vw); max-height: 86vh; overflow: auto; padding: 22px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.6); }
.fen h2 { margin: 0 0 4px; color: var(--gold); } .fen h3 { margin: 8px 0 0; font-size: 15px; }
.fen .close { position: absolute; top: 8px; right: 10px; background: none; border: none; color: var(--muted); font-size: 22px; }
.rligne { display: grid; grid-template-columns: 1fr 90px auto; gap: 8px; align-items: center; }
button.small { padding: 4px 10px; font-size: 13px; }
.raidinfos { padding: 10px; border-radius: 8px; background: rgba(255,255,255,.04); display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.marche { padding: 10px; border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 4px; }
.marche.alerte { border-color: #c0573f; background: rgba(192,87,63,.12); }
.rapport { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.rapport summary { cursor: pointer; }
.rapport.bon { border-left: 4px solid #6bbf6e; } .rapport.mauvais { border-left: 4px solid #c0573f; }
.rapport.nonlu summary b::after { content: " •"; color: var(--gold); }
.rapport > div { margin-top: 6px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; transition: .2s; z-index: 30;
  background: #3a1d17; color: #ffd9d2; border: 1px solid #c0573f; padding: 10px 16px; border-radius: 8px; }
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.bon { background: #1f2e1a; color: #d9f2cf; border-color: #6bbf6e; }

/* Page « Mon compte » et double authentification */
.cligne { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.cligne b { text-align: right; overflow-wrap: anywhere; }
.cetat { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.04); }
.cetat.bon { border-color: #6bbf6e; background: rgba(107,191,110,.1); }
.cboutons { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cform { display: flex; flex-direction: column; gap: 10px; }
.cchamp { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.cchamp input { font: inherit; padding: 9px 10px; border-radius: 6px; border: 1px solid var(--line); background: #0d0e0a; color: var(--text); }
.cchamp input:focus { outline: 2px solid var(--gold-dark); border-color: transparent; }
.cetapes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.cetapes li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; }
.cetapes li > div { display: flex; flex-direction: column; gap: 8px; }
.pastille { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-dark); color: #fff6e3; font-weight: bold; font-size: 14px; }
.cqr img { display: block; background: #fff; padding: 6px; border-radius: 8px; width: 200px; height: 200px; }
.ccle { display: inline-block; margin-top: 4px; font-size: 15px; letter-spacing: .08em; color: var(--gold); user-select: all; }
.cavert { padding: 10px 12px; border: 1px solid #c9a24d; border-radius: 8px; background: rgba(201,162,77,.12); font-size: 14px; line-height: 1.5; }
.ccodes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; padding: 12px; border-radius: 8px; background: #0d0e0a; border: 1px solid var(--line); }
.ccodes code { font-size: 16px; letter-spacing: .1em; text-align: center; user-select: all; }
.ccoche { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.fen .error:empty { display: none; }
#who { font-weight: 600; }
.fen a { color: #e8c37a; }

@media (max-width: 900px) {
  #ville { grid-template-columns: 1fr; grid-template-rows: 55vh auto; overflow: auto; }
  #villeFiche { border-left: none; border-top: 1px solid var(--line); }
  #resbar { gap: 8px; font-size: 12px; }
  .emplacement .etiquette { padding: 1px 5px; } .emplacement .nom { font-size: 11px; }
}
.bloc.alerte { border-color: #c0573f; background: rgba(192,87,63,.10); }

/* --- Monde de test (V0.1.24) --- */
#bandeTest { position: fixed; top: 0; left: 0; right: 0; height: 30px; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: #b3261e; color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .04em; text-align: center; padding: 0 8px; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
#bandeTest[hidden], #outilsTest[hidden] { display: none; }
body.test #topbar { top: 30px; }
body.test #panel { top: 98px; }
#outilsTest { position: fixed; left: 16px; bottom: 16px; width: 260px; padding: 14px; border-radius: 10px; display: flex; flex-direction: column; gap: 8px;
  background: var(--panel); border: 2px solid #b3261e; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
#outilsTest select { margin-left: 6px; }
#outilsTest button.actif { border-color: #e0b54a; color: #e0b54a; }
#outilsTest p { margin: 0; }

/* --- Armées en marche (V0.1.25) --- */
#marches { pointer-events: none; }
#traces { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; }
#traces line { stroke: #e0b54a; stroke-width: 3; stroke-dasharray: 10 8; opacity: .8; }
.pion { position: absolute; pointer-events: none; will-change: transform; }
.pion img { display: block; width: 100%; height: auto; filter: drop-shadow(0 5px 4px rgba(0,0,0,.55)); }
.pion .tag { position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); font-size: 10px; font-weight: 700; color: #fff;
  white-space: nowrap; background: rgba(0,0,0,.6); padding: 0 5px; border-radius: 4px; }
.pion.mien .tag { background: rgba(140,109,42,.9); }
.pion.pose img { filter: drop-shadow(0 0 6px #e0b54a) drop-shadow(0 5px 4px rgba(0,0,0,.55)); }

/* --- Téléphone (V0.1.50, audit F8) : la barre du haut tient sur l'écran ; les ressources défilent sur le côté,
   le menu du pseudo (Mon compte, Déconnexion) reste toujours visible à droite. --- */
@media (max-width: 700px) {
  #topbar { gap: 8px; padding: 0 8px; }
  .brand { letter-spacing: .12em; font-size: 13px; }
  #royaume { font-size: 12px; padding: 2px 7px; }
  #hint, #topbar .toggle { display: none; }
  #resbar { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  #resbar::-webkit-scrollbar { display: none; }
  #topbar .right { gap: 4px; }
  .bouton-barre { padding-left: 7px; padding-right: 7px; }
  #who { max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 420px) { .brand { display: none; } }
