/* La vitrine (T1.6). Reference : ARCHITECTURE.md 9.1, 9.2, 9.6.
 *
 * Le fond etoile est en CSS pur, pas en WebGL. Motif : le bundle UMD de
 * 3d-force-graph n'expose pas three (c'est ce qui garantit une seule instance,
 * regle 9.1), donc un ciel en THREE.Points demanderait une seconde instance.
 * Trois couches de degrades radiaux coutent zero image, zero requete et zero
 * milliseconde de simulation.
 */

:root {
  --fond: #05070d;
  --encre: #e8ecf5;
  --sourdine: #7d8aa3;
  --trait: #1c2436;
  --accent: #5eead4;
  --alerte: #f97362;
  --tiede: #fbbf24;

  /* Couleur par type de fait (9.2). Les six types d'ENTITE sont chauds et
   * lumineux : ce sont les hubs, ils doivent se voir. Les huit types
   * d'assertion sont froids. */
  --personne: #f472b6;
  --organisation: #fb923c;
  --projet: #facc15;
  --systeme: #22d3ee;
  --objet: #a78bfa;
  --lieu: #4ade80;

  --etat: #60a5fa;
  --evenement: #818cf8;
  --engagement: #34d399;
  --preference: #f0abfc;
  --decision: #fcd34d;
  --procedure: #94a3b8;
  --question: #fb7185;
  --synthese: #2dd4bf;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--fond);
  color: var(--encre);
  font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* --- Le ciel ------------------------------------------------------------ */

#ciel {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(1px 1px at 12% 22%, #fff 99%, transparent),
    radial-gradient(1px 1px at 78% 14%, #cfe 99%, transparent),
    radial-gradient(1px 1px at 33% 68%, #fff 99%, transparent),
    radial-gradient(2px 2px at 61% 45%, #bde 99%, transparent),
    radial-gradient(1px 1px at 89% 77%, #fff 99%, transparent),
    radial-gradient(1px 1px at 45% 88%, #eef 99%, transparent),
    radial-gradient(1px 1px at 7% 55%, #fff 99%, transparent),
    radial-gradient(1200px 700px at 70% 20%, #101a33 0%, transparent 70%),
    radial-gradient(900px 600px at 20% 80%, #0c1526 0%, transparent 70%),
    var(--fond);
  background-repeat: repeat;
  background-size: 340px 340px, 420px 420px, 280px 280px, 560px 560px,
                   380px 380px, 460px 460px, 300px 300px, 100% 100%, 100% 100%,
                   100% 100%;
  animation: derive 240s linear infinite;
}

@keyframes derive {
  to { background-position: 340px 340px, -420px 420px, 280px -280px,
                            -560px 560px, 380px 380px, 460px -460px,
                            -300px 300px, 0 0, 0 0, 0 0; }
}

#graphe { position: fixed; inset: 0; z-index: 1; }

/* --- Habillage commun --------------------------------------------------- */

.panneau {
  position: fixed;
  z-index: 3;
  background: rgba(8, 12, 22, 0.82);
  border: 1px solid var(--trait);
  border-radius: 10px;
  backdrop-filter: blur(10px);
}

.etiquette {
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--sourdine);
}

/* --- Le HUD des compteurs ----------------------------------------------- */

#hud { top: 16px; left: 16px; padding: 14px 16px; min-width: 250px; }

#titre { font-size: 15px; font-weight: 600; letter-spacing: 0.16em; }
#titre small {
  display: block;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--sourdine);
  margin-top: 2px;
}

#compteurs { margin-top: 12px; display: grid; gap: 3px; }

.compteur {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 2px 0;
  cursor: help;
  border-bottom: 1px solid transparent;
}
.compteur:hover { border-bottom-color: var(--trait); }
.compteur .valeur {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}
/* Une mesure impossible s'affiche "-" et se grise. JAMAIS zero. */
.compteur.absente .valeur { color: var(--sourdine); font-weight: 400; }

/* La preuve, au survol : la requete exacte qui a produit le nombre. */
.preuve {
  grid-column: 1 / -1;
  display: none;
  font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--sourdine);
  word-break: break-all;
  padding: 3px 0 5px;
}
.compteur:hover .preuve { display: block; }

/* Fraicheur : au-dela du seuil, tout se grise. Une vitrine figee ment en
 * silence (9.3 point 4). */
body.perimee #compteurs { opacity: 0.35; filter: grayscale(1); }

/* --- L'orbe a etats ------------------------------------------------------ */

#orbe {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block; margin-right: 7px; vertical-align: middle;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  transition: background 0.3s, box-shadow 0.3s;
}
#orbe.semis { background: var(--tiede); box-shadow: 0 0 14px var(--tiede);
              animation: pulse 1.1s ease-in-out infinite; }
#orbe.hors-ligne { background: var(--alerte); box-shadow: 0 0 10px var(--alerte); }
@keyframes pulse { 50% { transform: scale(1.7); opacity: 0.55; } }

#etat-ligne { margin-top: 12px; font-size: 11px; color: var(--sourdine); }

/* --- Le bandeau d'activite ---------------------------------------------- */

#bandeau {
  bottom: 16px; left: 16px; right: 16px;
  max-height: 132px; overflow: hidden;
  padding: 9px 14px;
  font: 11px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#bandeau .ligne { color: var(--sourdine); white-space: nowrap;
                  overflow: hidden; text-overflow: ellipsis; }
#bandeau .ligne .quand { color: #4a5670; margin-right: 9px; }
#bandeau .ligne.fort { color: var(--accent); }

/* --- Le panneau du fait, au clic ---------------------------------------- */

#fiche {
  top: 16px; right: 16px; width: 330px; max-height: calc(100vh - 190px);
  overflow: auto; padding: 15px 17px; display: none;
}
#fiche.ouverte { display: block; }
#fiche h2 { margin: 6px 0 10px; font-size: 14px; line-height: 1.4; }
#fiche dl { margin: 0; display: grid; grid-template-columns: 78px 1fr;
            gap: 4px 10px; font-size: 11px; }
#fiche dt { color: var(--sourdine); }
#fiche dd { margin: 0; word-break: break-word; }
#fiche .sources li { font: 10px/1.5 ui-monospace, Menlo, monospace;
                     color: var(--sourdine); word-break: break-all; }
#fiche ul { margin: 4px 0 0; padding-left: 15px; }
#fermer { float: right; cursor: pointer; color: var(--sourdine);
          font-size: 15px; line-height: 1; }
#fermer:hover { color: var(--encre); }

.puce-type {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 10px; letter-spacing: 0.05em;
  border: 1px solid currentColor;
}

/* --- Les commandes ------------------------------------------------------- */

#commandes { bottom: 164px; left: 16px; padding: 9px 13px; display: flex;
             gap: 14px; align-items: center; flex-wrap: wrap; }
#commandes label { display: flex; align-items: center; gap: 6px;
                   cursor: pointer; font-size: 11px; }
#commandes input[type="range"] { width: 92px; }

/* --- La porte du jeton --------------------------------------------------- */

#porte {
  position: fixed; inset: 0; z-index: 9;
  display: grid; place-items: center;
  background: rgba(3, 5, 10, 0.94);
}
#porte.fermee { display: none; }
#porte .boite { width: min(430px, 90vw); padding: 26px 28px;
                background: rgba(10, 14, 26, 0.96);
                border: 1px solid var(--trait); border-radius: 12px; }
#porte h1 { margin: 0 0 6px; font-size: 17px; letter-spacing: 0.18em; }
#porte p { color: var(--sourdine); font-size: 12px; margin: 0 0 16px; }
#porte input {
  width: 100%; padding: 9px 11px; background: #060911; color: var(--encre);
  border: 1px solid var(--trait); border-radius: 7px;
  font: 12px ui-monospace, Menlo, monospace;
}
#porte button {
  margin-top: 11px; width: 100%; padding: 9px; cursor: pointer;
  background: var(--accent); color: #041210;
  border: 0; border-radius: 7px; font-weight: 600; font-size: 12px;
}
#porte .erreur { color: var(--alerte); font-size: 11px; margin-top: 9px;
                 min-height: 15px; }

/* Le survol d'un noeud : 3d-force-graph pose son propre conteneur. */
.graph-tooltip {
  font: 12px ui-sans-serif, system-ui, sans-serif !important;
  background: rgba(8, 12, 22, 0.92) !important;
  border: 1px solid var(--trait); border-radius: 7px; padding: 6px 9px !important;
  max-width: 330px;
}


/* --- Le visage et son statut (T1.7, D29) -------------------------------- */

#visage { position: fixed; inset: 0; z-index: 2; pointer-events: none; }

/* Le statut est ecrit en toutes lettres, comme dans la reference. La
   difference tient en un mot : il ne peut afficher QUE les trois etats
   mesures. Pas de "LISTENING" quand rien n'ecoute. */
#statut {
  position: fixed; z-index: 3; right: 26px; top: 50%;
  transform: translateY(-50%); text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  pointer-events: none;
}
#statut-nom {
  display: block; font-size: 11px; letter-spacing: 0.28em;
  color: var(--accent); text-shadow: 0 0 14px currentColor;
}
#statut em {
  display: block; margin-top: 6px; font-style: normal;
  font-size: 9.5px; letter-spacing: 0.06em; color: var(--sourdine);
  max-width: 230px;
}
body.en-semis #statut-nom { color: var(--tiede); }
body.en-hors-ligne #statut-nom { color: var(--alerte); }
