/* La Citadelle — thème parchemin médiéval (direction artistique unique, assumée) */
:root {
  --parchemin: #f0e6d2;
  --parchemin-fonce: #e4d5b7;
  --encre: #3a2f1b;
  --encre-2: #6b5d40;
  --encre-3: #8d7d5c;
  --bois: #7a5230;
  --bois-fonce: #5c3d22;
  --or: #b8860b;
  --sceau: #8c2d2d;
  /* Statuts (palette validée — le score chiffré accompagne TOUJOURS la couleur) */
  --sante-bonne: #0ca30c;
  --sante-attention: #fab219;
  --sante-serieuse: #ec835a;
  --sante-critique: #d03b3b;
  /* Drapeaux de quartier (catégorielles, ordre fixe) */
  --groupe-quatuor: #2f6db3;
  --groupe-metaprojet: #7b4fa6;
  --groupe-compagnons: #2e8b74;
  --groupe-outils: #b06e2a;
  --groupe-aucun: #77706a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--parchemin);
  color: var(--encre);
  font: 15px/1.45 Georgia, 'Times New Roman', serif;
}

body {
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(184, 134, 11, 0.06), transparent 50%),
    radial-gradient(ellipse at 85% 90%, rgba(92, 61, 34, 0.08), transparent 55%);
}

/* ── Barre supérieure ── */
.barre {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: linear-gradient(180deg, var(--bois), var(--bois-fonce));
  color: var(--parchemin);
  border-bottom: 3px solid var(--or);
  flex-wrap: wrap;
}
.barre h1 { font-size: 20px; margin: 0; letter-spacing: 0.5px; }
.sous-titre { font-size: 13px; opacity: 0.75; font-style: italic; margin-left: 6px; }
.barre-centre { display: flex; align-items: center; gap: 12px; flex: 1; }
.garnison {
  font-size: 16px;
  font-weight: bold;
  background: rgba(0, 0, 0, 0.25);
  padding: 3px 12px;
  border-radius: 12px;
  border: 1px solid var(--or);
}
.garnison.pleine { border-color: var(--sante-critique); }
.federation-badge {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--encre-3);
}
.federation-badge.isole { border-color: var(--sante-critique); color: #ffd9d9; }
.barre-actions { display: flex; gap: 8px; }

/* ── HUD « état du Royaume » ── */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  padding: 8px 16px;
  background: var(--parchemin-fonce);
  border-bottom: 2px solid var(--bois);
}
.hud-bloc { display: flex; align-items: center; gap: 8px; }
.hud-titre { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--encre-2); }
.hud-moyenne { font-size: 20px; font-weight: bold; font-variant-numeric: tabular-nums; }
.hud-repartition { display: flex; gap: 8px; }
.pip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: bold; font-variant-numeric: tabular-nums; }
.pip .pastille { width: 10px; height: 10px; border-radius: 3px; display: inline-block; box-shadow: 0 0 0 1px rgba(0,0,0,0.12) inset; }
.hud-etats { gap: 8px; }
.hud-chip { font-size: 12px; color: var(--encre-2); background: rgba(255,255,255,0.4); border: 1px solid var(--encre-3); border-radius: 10px; padding: 1px 9px; }
.hud-garnison { margin-left: auto; }
.hud-garnison .creneaux { display: flex; gap: 3px; }
.hud-garnison .creneau {
  width: 20px; height: 22px; border-radius: 3px; font-size: 12px; line-height: 22px; text-align: center;
  border: 1px solid var(--bois-fonce);
}
.hud-garnison .creneau.occupe { color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,0.35); }
.hud-garnison .creneau.libre { color: var(--encre-3); background: rgba(255,255,255,0.35); border-style: dashed; }

.bouton {
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  background: var(--parchemin);
  color: var(--encre);
  border: 1px solid var(--bois-fonce);
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.bouton:hover:not(:disabled) { background: var(--parchemin-fonce); }
.bouton:disabled { opacity: 0.45; cursor: not-allowed; }
.bouton-primaire { background: var(--or); color: #fff; border-color: var(--bois-fonce); }
.bouton-danger { background: var(--sceau); color: #fff; }

/* ── Scène : carte + panneau ── */
.scene { flex: 1; display: flex; min-height: 0; }
.carte { flex: 1; min-width: 0; position: relative; }
.carte svg { width: 100%; height: 100%; display: block; cursor: grab; }
.carte svg:active { cursor: grabbing; }

/* Infobulle au survol d'un bâtiment */
.infobulle {
  position: absolute;
  z-index: 6;
  max-width: 260px;
  pointer-events: none;
  background: var(--parchemin);
  color: var(--encre);
  border: 1px solid var(--bois);
  border-left: 3px solid var(--or);
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 12.5px;
  line-height: 1.4;
  box-shadow: 0 6px 18px rgba(40, 28, 12, 0.35);
}
.infobulle .ib-titre { font-weight: bold; font-size: 13.5px; margin-bottom: 3px; }
.infobulle .ib-sante { margin: 2px 0; }
.infobulle .ib-score { font-weight: bold; font-variant-numeric: tabular-nums; }
.infobulle .ib-dirty { color: var(--sante-serieuse); }
.infobulle .ib-risque { color: var(--sceau); }
.infobulle .ib-brume { color: var(--encre-3); font-style: italic; }

/* Bâtiments */
.batiment { cursor: pointer; }
.batiment .corps { transition: filter 0.15s; }
.batiment:hover .corps { filter: brightness(1.12); }
.batiment.selectionne .socle { stroke: var(--or); stroke-width: 2.5; }
.batiment.pause .corps { opacity: 0.55; }
.batiment.absent .corps { filter: grayscale(0.9) opacity(0.5); }
.batiment.hors-filtre { opacity: 0.2; pointer-events: none; }
.legende-entree { cursor: pointer; }
.legende-entree:hover text { fill: var(--or) !important; }
.legende-entree.actif text { fill: var(--or) !important; font-weight: bold; }
.anneau-objectif { pointer-events: none; }
.batiment text {
  font: 11px Georgia, serif;
  fill: var(--encre);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--parchemin);
  stroke-width: 2.5px;
  pointer-events: none;
}
.batiment .score-sante { font-weight: bold; font-size: 10px; }

/* Territoires de quartier (derrière les bâtiments) */
.territoire { pointer-events: none; }
.territoire-nom {
  font: italic 700 15px Georgia, serif;
  text-anchor: start;
  opacity: 0.55;
  letter-spacing: 0.5px;
}

/* Alertes carte : bâtiment critique (santé basse) + front le plus chaud */
.halo-alerte { fill: none; stroke-width: 3; pointer-events: none; }
.halo-critique { stroke: var(--sante-critique); animation: pulse-halo 1.8s ease-in-out infinite; }
.halo-front { stroke: var(--or); animation: pulse-halo 2.2s ease-in-out infinite; }
.marqueur-alerte { pointer-events: none; animation: pulse-marqueur 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse-halo {
  0%, 100% { opacity: 0.15; stroke-width: 2; }
  50% { opacity: 0.7; stroke-width: 4; }
}
@keyframes pulse-marqueur {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Unités (agents alloués) : orbite lente autour du bâtiment */
.unites { animation: orbite 14s linear infinite; transform-box: fill-box; transform-origin: center; }
.batiment.pause .unites { animation-play-state: paused; opacity: 0.4; }
@keyframes orbite { to { transform: rotate(360deg); } }

/* Routes */
.route { fill: none; stroke: var(--encre-3); stroke-width: 1.5; opacity: 0.55; }
.route.fil-rouge {
  stroke: var(--sceau);
  stroke-width: 2.5;
  stroke-dasharray: 7 5;
  opacity: 0.8;
  animation: convoi 1.6s linear infinite;
}
@keyframes convoi { to { stroke-dashoffset: -12; } }

@media (prefers-reduced-motion: reduce) {
  .unites, .route.fil-rouge, .halo-alerte, .marqueur-alerte { animation: none; }
  .halo-critique { opacity: 0.55; }
  .halo-front { opacity: 0.5; }
}

/* ── Panneau latéral ── */
.panneau {
  width: 380px;
  max-width: 45vw;
  overflow-y: auto;
  background: var(--parchemin-fonce);
  border-left: 3px solid var(--bois);
  padding: 14px 16px;
}
.panneau h2 { margin: 0 0 2px; font-size: 19px; }
.panneau h3 {
  margin: 16px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--encre-2);
  border-bottom: 1px solid var(--encre-3);
  padding-bottom: 2px;
}
.panneau .fermer { float: right; }
.chip-groupe {
  display: inline-block;
  font-size: 11px;
  color: #fff;
  padding: 1px 8px;
  border-radius: 8px;
  vertical-align: middle;
}
.sante-ligne { display: flex; align-items: center; gap: 8px; margin: 8px 0 2px; }
.sante-barre { flex: 1; height: 10px; background: rgba(0, 0, 0, 0.12); border-radius: 5px; overflow: hidden; }
.sante-barre > div { height: 100%; border-radius: 5px; }
.sante-score { font-weight: bold; min-width: 52px; }
.penalites { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--encre-2); }
.meta-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.meta-table td { padding: 2px 4px; vertical-align: top; }
.meta-table td:first-child { color: var(--encre-2); white-space: nowrap; width: 1%; }
.tldr { font-size: 13px; font-style: italic; background: rgba(255, 255, 255, 0.35); padding: 8px; border-left: 3px solid var(--or); margin: 6px 0; }
.badge-dirty { color: var(--sante-serieuse); font-weight: bold; }
.badge-absent { color: var(--encre-3); font-style: italic; }

/* Sliders */
.slider-ligne { display: grid; grid-template-columns: 92px 1fr 42px; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.slider-ligne input[type="range"] { width: 100%; accent-color: var(--bois); }
.slider-ligne .valeur { text-align: right; font-weight: bold; font-variant-numeric: tabular-nums; }
.slider-ligne.energie input[type="range"] { accent-color: var(--or); }
.note-energie { font-size: 12px; color: var(--encre-2); margin: 2px 0 0; }

/* Objectifs */
.objectif { background: rgba(255, 255, 255, 0.35); border: 1px solid var(--encre-3); border-radius: 5px; padding: 7px 9px; margin: 6px 0; font-size: 13px; }
.objectif.fait { opacity: 0.55; }
.objectif .titre-obj { font-weight: bold; }
.objectif .sous-taches { margin: 4px 0 0; padding-left: 4px; list-style: none; }
.objectif .sous-taches li { margin: 2px 0; }
.objectif .actions-obj { margin-top: 5px; display: flex; gap: 6px; }
.objectif .actions-obj .bouton { font-size: 11.5px; padding: 2px 8px; }
.ajout-objectif { display: flex; gap: 6px; margin-top: 8px; }
.ajout-objectif input { flex: 1; font: inherit; font-size: 13px; padding: 4px 8px; border: 1px solid var(--encre-3); border-radius: 4px; background: #fffdf7; }

/* Actions RTS */
.actions-rts { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
.actions-rts .bouton { text-align: left; font-size: 12.5px; padding: 7px 9px; }
.no-touch-note { font-size: 12.5px; color: var(--sceau); font-style: italic; margin-top: 8px; }

/* ── Salle de guerre ── */
.war-room {
  max-height: 42vh;
  overflow-y: auto;
  background: var(--bois-fonce);
  color: var(--parchemin);
  border-top: 3px solid var(--or);
  padding: 10px 16px 16px;
}
.war-room h2 { font-size: 16px; margin: 4px 0 8px; }
.war-room table { width: 100%; border-collapse: collapse; font-size: 13px; }
.war-room th { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--or); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.8; }
.war-room td { padding: 5px 8px; border-bottom: 1px solid rgba(240, 230, 210, 0.15); vertical-align: middle; }
.war-room .bouton { font-size: 11.5px; padding: 2px 8px; }
.statut-chip { font-size: 11px; padding: 1px 8px; border-radius: 8px; white-space: nowrap; }
.statut-pending { background: var(--parchemin); color: var(--encre); }
.statut-claimed { background: var(--or); color: #fff; }
.statut-done { background: var(--sante-bonne); color: #fff; }
.statut-cancelled { background: var(--groupe-aucun); color: #fff; }
.attente-slot { font-size: 11px; color: var(--sante-attention); }
.vide { font-style: italic; opacity: 0.7; padding: 12px 0; }

/* ── Dialogues ── */
dialog {
  border: 3px solid var(--bois);
  border-radius: 6px;
  background: var(--parchemin);
  color: var(--encre);
  max-width: min(860px, 92vw);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
dialog::backdrop { background: rgba(40, 28, 12, 0.55); }
dialog h2 { margin-top: 0; }
#dialogue-prompt pre {
  max-height: 48vh;
  overflow: auto;
  background: #fffdf7;
  border: 1px solid var(--encre-3);
  padding: 12px;
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.dialogue-boutons { display: flex; gap: 8px; justify-content: flex-end; }
.aide { font-size: 13px; color: var(--encre-2); }
#champ-jeton { font: inherit; padding: 6px 10px; width: 100%; margin: 8px 0; border: 1px solid var(--encre-3); border-radius: 4px; }

/* ── Vue liste ── */
.liste-vue { flex: 1; overflow: auto; padding: 12px 16px; }
.liste-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.liste-table th {
  text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--bois);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--encre-2);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.liste-table th:hover { color: var(--or); }
.liste-table td { padding: 5px 8px; border-bottom: 1px solid var(--encre-3); vertical-align: middle; }
.liste-ligne { cursor: pointer; transition: background 0.1s; }
.liste-ligne:hover { background: rgba(184, 134, 11, 0.1); }
.liste-ligne.pause { opacity: 0.55; }
.liste-ligne.absent { opacity: 0.5; }
.liste-nom { font-weight: bold; display: flex; align-items: center; gap: 6px; }
.liste-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Petits écrans : panneau en surcouche */
@media (max-width: 820px) {
  .panneau { position: absolute; right: 0; top: 0; bottom: 0; max-width: 88vw; z-index: 5; box-shadow: -8px 0 24px rgba(0,0,0,0.3); }
  .scene { position: relative; }
}
