:root {
  --nuit: #0b0a08;
  --nuit-clair: #1a1712;
  --sable: #d9c08a;
  --accent: #e0a33a;
  --texte: #efe4cc;
  --texte-faible: #a2937a;
  --bord: #4a4237;
  --largeur-panneau: 260px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--nuit);
  color: var(--texte);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.partie {
  display: grid;
  grid-template-columns: 1fr var(--largeur-panneau);
  grid-template-rows: 1fr;
  height: 100vh;
}

.terrain {
  position: relative;
  grid-column: 1;
  grid-row: 1;
  overflow: hidden;
}

#carte {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* ---------------------------------------------------------- Panneau */

#panneau {
  grid-column: 2;
  grid-row: 1;
  /* Plaque visee : quatre coinets d'angle en accent, un leger degrade chaud en
     dessous. Les coinets sont des fonds, pas des pseudo-elements : ils restent
     ainsi epingles meme quand le panneau deroule (overflow-y: auto). */
  background-color: var(--nuit-clair);
  background-image:
    linear-gradient(rgba(224, 163, 58, 0.5), rgba(224, 163, 58, 0.5)),
    linear-gradient(rgba(224, 163, 58, 0.5), rgba(224, 163, 58, 0.5)),
    linear-gradient(rgba(224, 163, 58, 0.5), rgba(224, 163, 58, 0.5)),
    linear-gradient(rgba(224, 163, 58, 0.5), rgba(224, 163, 58, 0.5)),
    linear-gradient(180deg, rgba(255, 240, 210, 0.04), rgba(0, 0, 0, 0) 40%);
  background-repeat: no-repeat;
  background-position:
    left 5px top 5px,
    left 5px top 5px,
    right 5px bottom 5px,
    right 5px bottom 5px;
  background-size:
    1px 13px,
    13px 1px,
    13px 1px,
    1px 13px;
  border-left: 1px solid var(--bord);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
  overflow-y: auto;
}

#panneau h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent);
  /* Gravure : ombre sombre en bas, reflet pale en haut. */
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.8), 0 -1px 0 rgba(255, 240, 210, 0.12);
}

#panneau header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  align-items: center;
  column-gap: 0.6rem;
  row-gap: 0.3rem;
}

#panneau header h2 {
  grid-column: 1;
  grid-row: 1;
  font-size: 0.8rem;
}

/* Nom du joueur, a gauche juste sous le titre de la partie. */
#etat {
  grid-column: 1;
  grid-row: 2;
  margin: 0;
  align-self: start;
}

/* Les boutons (menu, son, aide, pause) forment un petit bloc 2 x 2. */
.actions-tete {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-columns: repeat(2, 2rem);
  gap: 0.3rem;
  align-content: start;
}

/* Vitesses directement dans le panneau, sous les boutons d'en-tete. */
.actions-vitesse {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}
.actions-vitesse[hidden] { display: none; }
.actions-vitesse .vitesses { display: flex; gap: 0.3rem; }
.actions-vitesse .bouton-tete {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

/* Boutons de l'en-tete (menu, aide, son, pause). */
.bouton-tete {
  width: 2rem;
  height: 2rem;
  padding: 0.2rem;
  background: transparent;
  border: 1px solid var(--bord);
  border-radius: 4px;
  color: var(--texte);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  line-height: 1;
}
.bouton-tete[hidden] { display: none; }

.bouton-tete:hover:not(:disabled) { border-color: var(--accent); }
.bouton-tete.actif { border-color: var(--accent); color: var(--accent); }

/* Le bouton Lobby est une icone (maison), comme le bouton du son. */
.bouton-lobby { line-height: 0; }

.bouton-lobby svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Le panneau d'aide est replie : le bouton « ? » de l'en-tete le deroule. */
.aides-voile { display: none; }
.aides-voile.ouvert { display: block; }

/* Icône de haut-parleur : le point .coupe s'affiche quand le son est coupé. */
.bouton-son { line-height: 0; }

.bouton-son svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bouton-son .haut-parleur { fill: currentColor; stroke: none; }
.bouton-son .coupe { display: none; }
.bouton-son.coupe .coupe { display: block; }
.bouton-son.coupe .voyants { display: none; }

.bouton-pause { line-height: 0; }

.bouton-pause svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bouton-pause .icone-reprendre { display: none; fill: currentColor; stroke: none; }
.bouton-pause.actif .icone-pause { display: none; }
.bouton-pause.actif .icone-reprendre { display: block; }

#panneau h3 {
  margin: 0 0 0.4rem;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--texte-faible);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}

.bloc {
  border-top: 1px solid var(--bord);
  padding-top: 0.8rem;
}

.etat { margin: 0.3rem 0 0; color: var(--texte-faible); font-size: 0.8rem; }

/* Epice et energie sur deux lignes, meme gabarit de texte. */
.ressources {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  border-top: 1px solid var(--bord);
  padding-top: 0.8rem;
}
.ressource {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0;
  gap: 0.6rem;
  font-size: 1rem;
}
.ressource span { color: var(--texte-faible); }
.ressource strong {
  display: inline-block;
  color: var(--texte);
  font-variant-numeric: tabular-nums;
  transform-origin: right center;
}
.ressource strong.deficit { color: #e05548; }
.ressource:first-child strong { color: var(--accent); }

/* Compteurs : pulsation verte quand la valeur monte, alerte clignotante quand
   l'energie passe en deficit. */
@keyframes pulse-hausse {
  0% { transform: scale(1); }
  35% { transform: scale(1.16); color: #9fe07a; }
  100% { transform: scale(1); }
}
.ressource strong.pulse { animation: pulse-hausse 0.5s ease; }

@keyframes alerte-deficit {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.ressource strong.deficit { animation: alerte-deficit 1s ease-in-out infinite; }

.aide { margin: 0; padding-left: 1.1rem; color: var(--texte-faible); font-size: 0.78rem; line-height: 1.7; }
.aide b { color: var(--texte); font-weight: 600; }

button {
  font: inherit;
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: linear-gradient(180deg, #eab24e 0%, var(--accent) 100%);
  color: #241f16;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 0 0 1px var(--accent), 0 0 14px rgba(224, 163, 58, 0.45);
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; }

/* -------------------------------------------------------- Minimap */

.minimap-bloc { margin-top: auto; padding-bottom: 0.2rem; }

#minimap {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--bord);
  border-radius: 4px;
  background: #000;
  cursor: pointer;
  image-rendering: pixelated;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Radar operationnel : liseré dore et lueur interne, en echo au balayage. */
#minimap.radar-actif {
  border-color: var(--accent);
  box-shadow:
    0 0 10px rgba(224, 163, 58, 0.5),
    inset 0 0 10px rgba(140, 227, 107, 0.25);
}

/* -------------------------------------------------------- Accueil */

.voile {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 10, 8, 0.92);
  z-index: 10;
  transition: opacity 0.4s ease;
}

.voile.cache { opacity: 0; pointer-events: none; }

.fenetre {
  width: min(340px, 90%);
  padding: 2rem;
  border: 1px solid var(--bord);
  border-radius: 6px;
  background: var(--nuit-clair);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.fenetre h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 0.3em;
  color: var(--accent);
  text-align: center;
}

.sous-titre {
  margin: 0 0 1rem;
  text-align: center;
  color: var(--texte-faible);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

label { color: var(--texte-faible); font-size: 0.78rem; margin-top: 0.4rem; }

input, select {
  font: inherit;
  padding: 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--bord);
  background: var(--nuit);
  color: var(--texte);
}

button#jouer { margin-top: 1.2rem; }

/* -------------------------------------------------------- Bandeau */

.bandeau {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%) translateY(calc(100% + 3rem));
  background: #7a2f24;
  color: #fff;
  padding: 0.7rem 1.2rem;
  border-radius: 4px;
  font-size: 0.85rem;
  transition: transform 0.3s ease;
  z-index: 20;
  pointer-events: none;
}

.bandeau.visible { transform: translateX(-50%) translateY(0); pointer-events: auto; }

/* Information neutre : ni rouge d'alerte, ni prefixe « Erreur ». */
.bandeau.info { background: #2f3a2a; }

/* --------------------------------------------------------- Panneau menu */

/* Le panneau de selection vit dans la barre laterale : il se remplit quand
   on choisit un batiment ou une unite, et reste vide autrement. */
.menu-flottant { display: none; }
.menu-flottant.visible { display: block; }
.menu-flottant h2 { margin: 0 0 0.6rem; font-size: 0.95rem; color: var(--accent); }
.menu-flottant .pv { margin-left: 0.5rem; font-size: 0.72rem; color: var(--texte-faible);
  letter-spacing: 0.05em; font-variant-numeric: tabular-nums; }
.menu-flottant h3 { margin: 0.6rem 0 0.2rem; font-size: 0.7rem;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--texte-faible); }

/* Reserve restante d'un champ de minerai, affichee au clic sur le minerai. */
.menu-flottant .reserve-champ { margin: 0; font-size: 0.85rem; color: var(--texte-faible); }
.menu-flottant .reserve-champ .valeur { color: var(--accent); font-weight: 600;
  font-variant-numeric: tabular-nums; }

/* Remplissage de la cuve d'un recolteur selectionne. */
.menu-flottant .cuve { margin: 0 0 0.15rem; }
.menu-flottant .cuve-texte {
  display: flex; justify-content: space-between; gap: 0.6rem;
  margin: 0.22rem 0 0; font-size: 0.72rem; color: var(--texte-faible);
  font-variant-numeric: tabular-nums;
}
.menu-flottant .cuve-pct { color: var(--accent); }

.liste-batiments, .liste-unites { display: flex; flex-direction: column; gap: 3px; }
/* Capacite de construction : n / plafond, qui grandit avec les bases. */
.menu-flottant .capacite-batiments {
  margin: 0 0 0.35rem; font-size: 0.72rem; color: var(--texte-faible);
  font-variant-numeric: tabular-nums;
}
.menu-flottant .capacite-batiments.plein { color: #d9534f; }

/* Embarquement / debarquement d'un avion de transport. */
.menu-flottant .zone-transport {
  margin: 0.5rem 0 0;
  padding-top: 0.5rem;
  border-top: 1px solid var(--bord);
}
.menu-flottant .bouton-transport {
  width: 100%; padding: 0.45rem; font-size: 0.85rem;
  background: var(--nuit-clair); border: 1px solid var(--bord);
  color: var(--texte); border-radius: 3px; cursor: pointer;
}
.menu-flottant .bouton-transport:hover { background: var(--nuit); border-color: var(--accent); }
.ligne-production-unite { display: flex; align-items: stretch; gap: 4px; }
.ligne-production-unite .ligne-unite { flex: 1 1 auto; min-width: 0; }
.case-repetition {
  flex: 0 0 3.5rem; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; padding: 0.2rem 0.25rem;
  background: var(--nuit); border: 1px solid var(--bord); border-radius: 3px;
  color: var(--texte-faible); font-size: 0.62rem; line-height: 1.1;
  text-align: center; cursor: pointer; user-select: none;
}
.case-repetition input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.case-repetition.actif { border-color: var(--accent); color: var(--accent); background: rgba(224,163,58,0.12); }
.ligne-batiment, .ligne-unite {
  display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 0.5rem;
  width: 100%; text-align: left; padding: 0.4rem 0.5rem;
  background: var(--nuit); border: 1px solid var(--bord);
  color: var(--texte); font-weight: 400; cursor: pointer;
}
.ligne-batiment .nom, .ligne-unite .nom { font-size: 0.85rem; }
.ligne-batiment .cout, .ligne-unite .cout { font-size: 0.8rem; color: var(--accent); }
.ligne-batiment .desc, .ligne-unite .desc {
  grid-column: 1 / -1; font-size: 0.7rem; color: var(--texte-faible);
}
/* La description d'un bâtiment reste repliée tant qu'il n'est pas choisi :
   la liste tient ainsi en huit lignes compactes. */
.ligne-batiment .desc { display: none; }
.ligne-batiment.actif .desc { display: block; }
.ligne-batiment.actif { border-color: var(--accent); background: rgba(224,163,58,0.18); }
/* Icone de reparation, posee a cote du pourcentage de vie dans l'entete.
   Toujours presente pour nos batiments : accentuee quand la reparation est en
   cours, estompee quand il n'y a rien a reparer. */
.bouton-reparer {
  margin-left: 0.5rem;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  background: transparent;
  border: 1px solid var(--bord);
  border-radius: 4px;
  color: var(--texte-faible);
  line-height: 0;
  cursor: pointer;
}
.bouton-reparer svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.bouton-reparer:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.bouton-reparer.actif { color: var(--accent); border-color: var(--accent); background: rgba(224,163,58,0.18); }
.bouton-reparer.inaccessible { opacity: 0.4; cursor: default; }
.ligne-unite.inaccessible, .ligne-batiment.inaccessible { opacity: 0.5; }

/* File de production (panneau flottant et panneau global) */

.production { display: flex; flex-direction: column; gap: 4px; }
.production .vide, .vide { margin: 0; color: var(--texte-faible); font-size: 0.76rem; }

.ligne-file, .ligne-production {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px;
  padding: 0.35rem 0.45rem; background: var(--nuit);
  border-left: 2px solid var(--accent); border-radius: 3px; margin-bottom: 1px;
}
.ligne-file .nom, .ligne-production .nom {
  flex: 1 1 auto; font-size: 0.82rem; color: var(--texte);
}
.ligne-file .origine, .ligne-production .origine {
  font-size: 0.68rem; color: var(--texte-faible); font-style: italic;
}
.ligne-file .attente, .ligne-production .attente {
  font-size: 0.72rem; color: var(--accent); font-variant-numeric: tabular-nums;
}
.ligne-file .annuler, .ligne-production .annuler {
  width: auto; padding: 0 0.35rem; margin: 0; background: transparent;
  border: none; color: var(--texte-faible); font-size: 0.95rem; line-height: 1.4;
}
.ligne-file .annuler:hover, .ligne-production .annuler:hover { color: #c0483c; }

.ligne-file .repetir, .ligne-production .repetir {
  width: auto; padding: 0 0.35rem; margin: 0 0 0 0.25rem; background: transparent;
  border: none; color: var(--texte-faible); font-size: 0.95rem; line-height: 1.4;
}
.ligne-file .repetir:hover, .ligne-production .repetir:hover { color: #5fb0e0; }
.ligne-file .repetir.actif, .ligne-production .repetir.actif { color: #5fb0e0; font-weight: bold; }

.jauge {
  flex-basis: 100%; height: 5px; border-radius: 3px; overflow: hidden;
  background: rgba(255, 255, 255, 0.10);
}
.jauge > span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #b9862f, #f0c060);
  transition: width 0.15s linear;
}

.ligne-production { border-left-color: var(--accent); }
.ligne-production .nom { color: var(--texte); }

/* ------------------------------------------------------ Ordres d'unité */

.section-ordres { margin-top: 0.6rem; }

.grille-ordres {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.bouton-ordre {
  padding: 0.45rem 0.3rem;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--nuit);
  color: var(--texte);
  border: 1px solid var(--bord);
}
.bouton-ordre:hover:not(:disabled) { border-color: var(--accent); }
.bouton-ordre.actif {
  border-color: var(--accent);
  background: rgba(224, 163, 58, 0.18);
  color: var(--accent);
}
/* Ordre en cours d'execution : la selection obeit deja a cet ordre. */
.bouton-ordre.en-cours {
  border-color: #8ce36b;
  background: rgba(140, 227, 107, 0.16);
  color: #8ce36b;
}
.bouton-ordre.en-cours::after {
  content: ' •';
  color: #8ce36b;
}
.bouton-ordre:disabled { opacity: 0.4; }

.indice-ordre {
  margin: 0.4rem 0 0;
  min-height: 1em;
  font-size: 0.72rem;
  color: var(--accent);
}


/* -------------------------------------------------------- Voile de pause */

.pause-voile {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  background: rgba(8, 10, 18, 0.55);
  backdrop-filter: blur(2px);
}
.pause-voile.cache { display: none; }
.pause-cadre {
  padding: 1.4rem 2.2rem;
  border: 1px solid var(--bord);
  border-radius: 6px;
  background: rgba(18, 20, 28, 0.92);
  text-align: center;
}
.pause-cadre h2 { margin: 0; letter-spacing: 0.12em; text-transform: uppercase; font-size: 1rem; }
.pause-cadre p { margin: 0.5rem 0 0; color: var(--texte-faible); font-size: 0.8rem; }

/* --------------------------------------------------- Centre de recherche */

.zone-recherche { display: flex; flex-direction: column; gap: 0.8rem; }

.recherche-en-cours {
  border: 1px solid var(--bord);
  border-radius: 6px;
  padding: 0.8rem;
  background: rgba(20, 24, 34, 0.6);
}
.recherche-titre {
  font-weight: bold;
  color: var(--texte);
  margin-bottom: 0.4rem;
}
.recherche-barre {
  height: 8px;
  background: rgba(40, 44, 58, 0.6);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}
.recherche-progression {
  height: 100%;
  background: #5fb0e0;
  width: 0%;
  transition: width 0.3s ease;
}
.recherche-compteur {
  color: var(--texte-faible);
  font-size: 0.8rem;
}

.liste-recherche {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 40vh;
  overflow-y: auto;
}
.ligne-recherche {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--bord);
  border-radius: 4px;
  background: rgba(20, 24, 34, 0.4);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.ligne-recherche:hover:not(.disabled):not(.terminee):not(.bloquee) {
  background: rgba(40, 44, 58, 0.7);
}
.ligne-recherche.actif {
  border-color: #5fb0e0;
  background: rgba(95, 176, 224, 0.15);
}
.ligne-recherche.actif .desc,
.ligne-recherche.actif .pre-requis {
  display: block;
}
.ligne-recherche .desc,
.ligne-recherche .pre-requis {
  display: none;
}
.ligne-recherche.terminee {
  color: #7fc26b;
  border-color: #7fc26b;
  background: rgba(127, 194, 107, 0.15);
  cursor: pointer;
}
.ligne-recherche.terminee:hover {
  background: rgba(127, 194, 107, 0.25);
  border-color: #9adf7c;
}
.ligne-recherche.en-cours {
  border-color: #5fb0e0;
  background: rgba(95, 176, 224, 0.05);
  color: var(--texte);
  cursor: default;
}
.ligne-recherche.en-cours .nom {
  color: #5fb0e0;
  font-weight: bold;
}
.ligne-recherche.bloquee {
  opacity: 0.5;
  cursor: not-allowed;
}

.recherche-ligne-principale {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 0.2rem;
}

.ligne-recherche .nom { color: var(--texte); font-size: 0.85rem; }
.ligne-recherche .cout {
  color: #e0a33a;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.ligne-recherche .desc {
  color: var(--texte-faible);
  font-size: 0.7rem;
  line-height: 1.4;
  margin-top: 0.2rem;
}
.ligne-recherche .pre-requis {
  font-size: 0.7rem;
  color: var(--texte-faible);
  font-style: italic;
  margin-top: 0.1rem;
}

.recherche-jauge-barre {
  width: 100%;
  height: 6px;
  background: rgba(40, 44, 58, 0.6);
  border-radius: 3px;
  overflow: hidden;
}
.recherche-jauge-remplissage {
  height: 100%;
  background: #5fb0e0;
  width: 0%;
  transition: width 0.3s ease;
}
.recherche-jauge-compteur {
  color: #5fb0e0;
  font-size: 0.75rem;
}

/* --------------------------------------------------- Compteur d'images */

.compteur-fps {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 10;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: rgba(10, 10, 14, 0.55);
  color: #9adf7c;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

#minerai {
  left: 6rem;
  color: #d4a017;
}
