/* ============================================================
   FOURMILIÈRE — terrarium nocturne bioluminescent
   ============================================================ */

:root {
  --bg: #0a0d07;
  --panel: rgba(15, 20, 11, 0.78);
  --panel-2: rgba(9, 13, 6, 0.86);
  --ink: #e7f0da;
  --ink-dim: #8da183;
  --ink-faint: #5c6e54;
  --line: rgba(190, 255, 150, 0.09);
  --line-strong: rgba(190, 255, 150, 0.22);
  --accent: #a8e84c;
  --accent-soft: rgba(168, 232, 76, 0.14);
  --danger: #ff5d49;
  --r: 12px;
  --font-d: "Syne", sans-serif;
  --font-m: "IBM Plex Mono", monospace;

  /* ---- compacité du HUD (Jean : UI plus dense, sans rien retirer) ----
     --ui-scale = LEVIER MAÎTRE : zoom global du HUD (1 = taille d'origine,
     plus bas = plus compact). Règle la taille générale en UN point.
     Les tokens ci-dessous affinent l'AÉRATION (espacements) indépendamment
     du zoom, pour densifier sans tout rapetisser uniformément. */
  --ui-scale: 0.88;
  --pad: 9px;      /* padding standard des panneaux (était ~11-13) */
  --gap: 6px;      /* écart standard entre éléments empilés */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-m);
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}

#canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* ---------- HUD scaffolding ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; zoom: var(--ui-scale); }
#hud > * { pointer-events: auto; }
#topbar, .tb-group, .tb-actions, .tb-stats, #speedbox { min-width: 0; }

/* mode zen : l'UI s'efface quand la caméra reste immobile (les toasts restent) */
#hud > *:not(#toasts) { transition: opacity 0.22s ease; }
#hud.zen > *:not(#toasts) { opacity: 0; pointer-events: none; transition: opacity 1.1s ease; }

.panel {
  background: linear-gradient(165deg, rgba(20, 27, 13, 0.82), var(--panel-2));
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(220, 255, 180, 0.05);
}

.hidden { display: none !important; }

h3 {
  font-family: var(--font-d);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

button {
  font-family: var(--font-m);
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
}
button:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* ---------- Topbar ---------- */

#topbar {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 13px;
  animation: drop-in 0.6s cubic-bezier(0.2, 0.9, 0.25, 1) backwards;
}

#brand {
  font-family: var(--font-d);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.12em;
  color: var(--ink);
  white-space: nowrap;
}
#brand::first-letter { color: var(--accent); }
#brand span {
  display: block;
  font-family: var(--font-m);
  font-weight: 400;
  font-size: 8.5px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-top: 1px;
}

.tb-group { display: flex; align-items: center; gap: 7px; }
.tb-stats { margin-left: auto; gap: 12px; }
.tb-actions { gap: 5px; }

.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.stat label {
  font-size: 8px; letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--ink-faint);
}
.stat span { font-size: 13px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--accent);
  background: var(--accent-soft);
  transition: transform 0.12s, box-shadow 0.2s;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: 0 0 14px rgba(168, 232, 76, 0.25); }

#speeds { display: flex; gap: 2px; border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.spd {
  padding: 4px 9px;
  font-size: 11px;
  border-radius: 7px;
  color: var(--ink-dim);
  transition: background 0.15s, color 0.15s;
}
.spd:hover { color: var(--ink); }
.spd.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.txt-btn {
  padding: 6px 11px;
  font-size: 11px;
  letter-spacing: 0.06em;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink-dim);
  transition: all 0.15s;
}
.txt-btn:hover { color: var(--ink); border-color: var(--line-strong); background: rgba(190, 255, 150, 0.05); }
.txt-btn.warn:hover { color: var(--danger); border-color: rgba(255, 93, 73, 0.4); background: rgba(255, 93, 73, 0.07); }

/* ---------- Toolbar (éditeur) ---------- */

#toolbar {
  position: absolute;
  top: 70px; left: 10px;
  width: 164px;
  padding: 10px;
  animation: slide-r 0.55s 0.08s cubic-bezier(0.2, 0.9, 0.25, 1) backwards;
}
#toolbar h3 { margin-bottom: 8px; }

#tools { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 9px; }

.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px 5px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--ink-dim);
  transition: all 0.14s;
}
.tool-btn svg { width: 19px; height: 19px; }
.tool-btn span { font-size: 8.5px; letter-spacing: 0.12em; text-transform: uppercase; }
.tool-btn:hover { color: var(--ink); background: rgba(190, 255, 150, 0.04); }
.tool-btn.active {
  color: var(--accent);
  border-color: rgba(168, 232, 76, 0.35);
  background: var(--accent-soft);
  box-shadow: 0 0 16px rgba(168, 232, 76, 0.12), inset 0 0 12px rgba(168, 232, 76, 0.06);
}

.field { margin: 9px 0 2px; }
.field label {
  display: flex; justify-content: space-between;
  font-size: 9px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 5px;
}
.field label span { color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, rgba(168, 232, 76, 0.5), rgba(168, 232, 76, 0.12));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1a240e;
  box-shadow: 0 0 8px rgba(168, 232, 76, 0.5);
}
input[type="range"]::-moz-range-track {
  height: 3px; border-radius: 2px;
  background: rgba(168, 232, 76, 0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 9px; height: 9px; border: 2px solid #1a240e;
  border-radius: 50%; background: var(--accent);
}

#tool-params { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 4px; }
#tool-params .hint-text { font-size: 10px; color: var(--ink-faint); line-height: 1.5; padding: 6px 0; }
#tool-params .nest-preview { display: flex; align-items: center; gap: 7px; padding: 7px 0 3px; font-size: 10px; color: var(--ink-dim); }
#tool-params .nest-preview i {
  width: 12px; height: 12px; border-radius: 50%;
  box-shadow: 0 0 9px currentColor;
}

/* ---------- Colonies ---------- */

#colonies-panel {
  position: absolute;
  top: 70px; right: 10px;
  width: 224px;
  max-height: calc(100% - 132px);
  display: flex; flex-direction: column;
  pointer-events: none;
}
#colonies-panel h3 {
  pointer-events: auto;
  padding: 0 4px 7px;
  text-align: right;
  text-shadow: 0 2px 8px #000;
}
#colonies {
  pointer-events: auto;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex; flex-direction: column; gap: var(--gap);
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}
#colonies::-webkit-scrollbar { width: 4px; }
#colonies::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 2px; }

.colony-card {
  position: relative;
  background: linear-gradient(165deg, rgba(20, 27, 13, 0.84), var(--panel-2));
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c);
  border-radius: var(--r);
  padding: 8px 9px 6px;
  animation: slide-l 0.45s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}
.colony-card.dead { filter: saturate(0.25) brightness(0.75); }
.colony-card.dead::after {
  content: "EFFONDRÉE";
  position: absolute; top: 9px; right: 11px;
  font-size: 8.5px; letter-spacing: 0.25em;
  color: var(--danger);
}

/* carte de colonie sélectionnée (lien carte ↔ menu) */
.colony-card.selected {
  border-color: rgba(168, 232, 76, 0.55);
  box-shadow: 0 0 0 1px rgba(168, 232, 76, 0.4), 0 0 18px rgba(168, 232, 76, 0.18);
}
.colony-card.selected::before {
  content: "◉ sélectionnée";
  position: absolute; top: 9px; right: 11px;
  font-size: 8px; letter-spacing: 0.18em;
  color: var(--accent);
}

.empire-group {
  position: relative;
  border-left: 3px solid var(--c, #a8e84c);
  padding: 0 0 2px 6px;
  margin-bottom: 6px;
}
.empire-group::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--c, #a8e84c);
  opacity: 0.04;
  pointer-events: none;
}
.empire-hdr {
  padding: 4px 0 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c, #a8e84c);
  opacity: 0.8;
}
.cc-satellite { margin-left: 8px; }

.cc-head { display: flex; align-items: baseline; gap: 6px; margin-bottom: 5px; cursor: pointer; }
.cc-head:hover .cc-name { color: var(--accent); }
.cc-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 10px var(--c);
  align-self: center;
  flex: none;
}
.cc-name { font-family: var(--font-d); font-weight: 800; font-size: 13.5px; letter-spacing: 0.06em; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-pop { margin-left: auto; flex: none; font-size: 13px; font-weight: 600; color: var(--c); font-variant-numeric: tabular-nums; }
.cc-pop::after { content: " ●"; font-size: 7px; vertical-align: 2px; }

.cc-roles { display: flex; gap: 9px; font-size: 10px; color: var(--ink-dim); margin-bottom: 5px; }
.cc-roles b { color: var(--ink); font-weight: 500; }

.gauge { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.gauge label {
  width: 62px; flex: none;
  font-size: 8.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-faint);
}
.gauge .bar {
  flex: 1; height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}
.gauge .bar i {
  display: block; height: 100%;
  width: 0%;
  background: var(--c);
  border-radius: 2px;
  box-shadow: 0 0 6px var(--c);
  transition: width 0.4s ease;
}
.gauge .g-val { width: 38px; flex: none; text-align: right; font-size: 10px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

.cc-spark { width: 100%; height: 30px; margin: 6px 0 2px; display: block; opacity: 0.95; }

.cc-counters {
  display: flex; gap: 9px;
  font-size: 9px; color: var(--ink-faint);
  margin: 2px 0 4px;
  font-variant-numeric: tabular-nums;
}
.cc-counters b { color: var(--ink-dim); font-weight: 500; }

.cc-adv summary {
  cursor: pointer;
  list-style: none;
  font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink-faint);
  padding: 5px 0 2px;
  border-top: 1px dashed var(--line);
  transition: color 0.15s;
}
.cc-adv summary:hover { color: var(--accent); }
.cc-adv summary::before { content: "▸ "; }
.cc-adv[open] summary::before { content: "▾ "; }

.cc-adv .field { margin: 6px 0 0; }
.cc-adv .field label { margin-bottom: 2px; }

/* bloc « Détails de la colonie » (réutilise le style summary de cc-adv) */
.cc-det summary {
  cursor: pointer; list-style: none;
  font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink-faint);
  padding: 5px 0 2px;
  border-top: 1px dashed var(--line);
  transition: color 0.15s;
}
.cc-det summary:hover { color: var(--accent); }
.cc-det summary::before { content: "▸ "; }
.cc-det[open] summary::before { content: "▾ "; }
.cd-rows { display: grid; grid-template-columns: auto 1fr; gap: 1px 9px; margin: 4px 0 1px; font-size: 9.5px; }
.cd-rows dt { color: var(--ink-faint); white-space: nowrap; }
.cd-rows dd { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.cd-species { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; padding-top: 5px; border-top: 1px dashed var(--line); }
.cd-species span { font-size: 8.5px; color: var(--ink); padding: 1px 6px; border: 1px solid var(--line); border-radius: 10px; }
.cd-species em { color: var(--ink-faint); font-style: normal; }

.cc-rel { margin-top: 9px; }
.cc-rel > label {
  display: block;
  font-size: 8.5px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 5px;
}
.rel-row { display: flex; flex-wrap: wrap; gap: 4px; }
.rel-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  font-size: 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--ink-dim);
  transition: all 0.15s;
}
.rel-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--rc); box-shadow: 0 0 6px var(--rc); }
.rel-chip.hostile { border-color: rgba(255, 93, 73, 0.35); }
.rel-chip.allied { border-color: rgba(168, 232, 76, 0.4); color: var(--accent); }
.rel-chip:hover { transform: translateY(-1px); }

/* ---------- Layers ---------- */

#layers {
  position: absolute;
  bottom: 12px; right: 12px; left: auto;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px;
  animation: rise-plain 0.55s 0.15s cubic-bezier(0.2, 0.9, 0.25, 1) backwards;
}
#layers > label {
  font-size: 8.5px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 4px;
}
.txt-btn.on { color: var(--accent); border-color: rgba(168, 232, 76, 0.4); background: var(--accent-soft); }
.chip {
  padding: 5px 12px;
  font-size: 10.5px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--ink-faint);
  transition: all 0.15s;
}
.chip:hover { color: var(--ink-dim); }
.chip.on {
  color: var(--accent);
  border-color: rgba(168, 232, 76, 0.4);
  background: var(--accent-soft);
  box-shadow: 0 0 12px rgba(168, 232, 76, 0.12);
}

/* ---------- Écosystème (tableau de bord global) ---------- */

#ecopanel {
  position: absolute;
  top: 70px; left: 182px;
  width: 222px;
  max-height: calc(100% - 132px);
  display: flex; flex-direction: column;
  padding: 9px 4px 6px 10px;
  animation: slide-r 0.4s cubic-bezier(0.2, 0.9, 0.25, 1) backwards;
}
.eco-head { display: flex; align-items: center; gap: 7px; padding-right: 8px; margin-bottom: 6px; }
.eco-head h3 { margin: 0; }
.eco-head .in-close { margin-left: auto; }
#eco-body {
  overflow-y: auto; overflow-x: hidden;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}
#eco-body::-webkit-scrollbar { width: 4px; }
#eco-body::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 2px; }

.eco-sec {
  display: flex; align-items: baseline; justify-content: space-between;
  font-family: var(--font-d); font-weight: 800;
  font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent);
  margin: 8px 0 3px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--line);
}
.eco-sec:first-child { margin-top: 0; }
.eco-sec .eco-h { font-family: var(--font-m); font-weight: 400; font-size: 9px; letter-spacing: 0.04em; text-transform: none; color: var(--ink-faint); }

.eco-row {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 10px; padding: 1px 0;
}
.eco-row > span { color: var(--ink-dim); }
.eco-row > b { margin-left: auto; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.eco-row > em { color: var(--ink-faint); font-style: normal; font-size: 9px; }

.eco-brow {
  display: flex; align-items: center; gap: 6px;
  font-size: 9.5px; padding: 1px 0;
}
.eco-brow > span {
  flex: 0 0 78px; min-width: 0;
  display: flex; align-items: center; gap: 5px;
  color: var(--ink-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.eco-brow.dead > span { color: var(--ink-faint); text-decoration: line-through; }
.eco-brow .eco-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.eco-bar {
  flex: 1 1 auto; min-width: 18px; height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px; overflow: hidden;
}
.eco-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; box-shadow: 0 0 5px currentColor; transition: width 0.4s ease; }
.eco-brow > b { flex: 0 0 auto; min-width: 22px; text-align: right; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.eco-brow > b em { color: var(--ink-faint); font-style: normal; font-size: 8.5px; }
.eco-empty { font-size: 9px; color: var(--ink-faint); padding: 1px 0 3px; }
.eco-subt { font-size: 8px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--ink-faint); margin: 4px 0 1px; }

/* ---------- panneau Stats & équilibrage ---------- */
#statspanel {
  position: absolute;
  top: 64px; left: 182px;
  width: 388px;
  max-height: calc(100% - 116px);
  display: flex; flex-direction: column;
  padding: 9px 4px 8px 11px;
  animation: slide-r 0.4s cubic-bezier(0.2, 0.9, 0.25, 1) backwards;
}
.sp-head { display: flex; align-items: center; gap: 7px; padding-right: 8px; margin-bottom: 5px; }
.sp-head h3 { margin: 0; }
.sp-head #stats-reset { margin-left: auto; padding: 2px 7px; font-size: 9.5px; }
.sp-note {
  font-size: 9px; line-height: 1.4; color: var(--ink-faint);
  padding: 5px 8px 6px 0; margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.sp-note b { color: var(--ink-dim); font-weight: 600; }
#stats-body {
  overflow-y: auto; overflow-x: hidden;
  padding-right: 8px;
  scrollbar-width: thin; scrollbar-color: var(--ink-faint) transparent;
}
#stats-body::-webkit-scrollbar { width: 4px; }
#stats-body::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 2px; }
.sp-zone {
  display: flex; align-items: baseline; gap: 6px;
  font-family: var(--font-d); font-weight: 800;
  font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent);
  margin: 9px 0 4px; padding-bottom: 2px;
  border-bottom: 1px solid var(--line);
}
.sp-zone em { font-family: var(--font-m); font-weight: 400; font-size: 8.5px; letter-spacing: 0.03em; text-transform: none; color: var(--ink-faint); font-style: normal; }

/* cartes du tableau comparatif */
.st-card { margin-bottom: 7px; }
.st-card-h { display: flex; align-items: center; gap: 6px; font-size: 10px; margin-bottom: 2px; }
.st-card-h .st-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.st-card-h b { color: var(--ink); font-weight: 700; }
.st-card-h em { margin-left: auto; font-style: normal; font-size: 8.5px; color: var(--ink-faint); }

/* tables (comparatif + édition) */
.st-tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.st-tbl th {
  font-family: var(--font-m); font-weight: 500; font-size: 8px;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-faint);
  text-align: right; padding: 1px 3px; border-bottom: 1px solid var(--line);
}
.st-tbl th:first-child { text-align: left; }
.st-tbl td { font-size: 9.5px; color: var(--ink-dim); text-align: right; padding: 1px 3px; }
.st-tbl td.st-caste { text-align: left; color: var(--ink-dim); white-space: nowrap; }
.st-tbl tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.018); }
.st-tbl td.mod { color: var(--accent); font-weight: 700; }

/* champs numériques éditables */
.st-edit td { padding: 2px 2px; }
.st-in {
  width: 100%; min-width: 40px; box-sizing: border-box;
  font-family: var(--font-m); font-size: 9.5px; text-align: right;
  color: var(--ink); background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px;
  -moz-appearance: textfield;
}
.st-in:focus { outline: none; border-color: var(--accent); background: var(--accent-soft); }
.st-in.mod { border-color: rgba(168, 232, 76, 0.55); color: var(--accent); font-weight: 600; }

.sp-pick { margin: 5px 0 6px; }
.sp-pick button { flex: 1 1 30%; }
.sp-apply { display: flex; align-items: center; gap: 6px; font-size: 9.5px; color: var(--ink-dim); margin: 7px 0 2px; cursor: pointer; }
.sp-apply b { color: var(--ink); font-weight: 600; }
.sp-base { margin-top: 8px; }
.sp-base > summary { font-size: 9.5px; color: var(--ink-dim); cursor: pointer; padding: 3px 0; }
.sp-base > summary em { font-style: normal; color: var(--ink-faint); font-size: 8.5px; }

/* ---------- détail du dépérissement (inspecteur plante) ---------- */
.in-wither:not(:empty) {
  margin-top: 6px; padding-top: 5px;
  border-top: 1px dashed var(--line);
}
.iw-rows { display: grid; gap: 2px; }
.iw-rows > div { display: flex; align-items: baseline; gap: 8px; font-size: 9.5px; }
.iw-rows > div > span { color: var(--ink-faint); }
.iw-rows > div > b { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.iw-eta { margin-top: 5px; font-size: 9.5px; letter-spacing: 0.04em; }

/* ---------- profil d'espèce (inspecteur faune) ---------- */
.in-fap:not(:empty) { margin-top: 6px; padding-top: 5px; border-top: 1px dashed var(--line); }
.fap-title { font-size: 8.5px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 5px; }
.fap-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.fap-chips span {
  font-size: 9px; color: var(--ink);
  padding: 1px 6px;
  border: 1px solid var(--line); border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.fap-chips em { color: var(--ink-faint); font-style: normal; }

/* ---------- Inspecteur ---------- */

#inspector {
  position: absolute;
  top: 80px; right: 10px;
  width: 224px;
  padding: var(--pad) 10px;
  animation: rise-plain 0.3s cubic-bezier(0.2, 0.9, 0.25, 1) backwards;
}
.in-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.in-head .cc-dot { width: 8px; height: 8px; }
.in-title { font-family: var(--font-d); font-weight: 800; font-size: 12px; letter-spacing: 0.05em; }
.in-sub { font-size: 9.5px; color: var(--ink-faint); margin-left: 2px; }
.in-close { margin-left: auto; color: var(--ink-faint); font-size: 14px; padding: 2px 5px; }
.in-close:hover { color: var(--danger); }

.in-rows { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 10px; }
.in-rows dt { color: var(--ink-faint); }
.in-rows dd { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }

.in-hp { height: 4px; background: rgba(255,255,255,0.07); border-radius: 2px; margin: 5px 0 7px; overflow: hidden; }
.in-hp i { display: block; height: 100%; background: linear-gradient(90deg, var(--danger), var(--accent)); border-radius: 2px; transition: width 0.25s; }

.in-actions { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.in-actions label { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--ink-dim); cursor: pointer; }
.in-actions input[type="checkbox"] { accent-color: var(--accent); }
.in-actions .txt-btn { margin-left: auto; padding: 4px 9px; font-size: 10px; }

/* ---------- Toasts ---------- */

#toasts {
  position: absolute;
  bottom: 156px; left: 14px;
  display: flex; flex-direction: column-reverse; align-items: flex-start; gap: 6px;
  pointer-events: none;
}
/* Quand la bannière nuptiale est visible, on pousse la pile de toasts en
   dessous pour éviter tout chevauchement dans la bande haut-centre. */
#toasts.banner-on { bottom: 156px; }
.toast {
  background: var(--panel-2);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-left: 3px solid var(--tc, var(--accent));
  border-radius: 9px;
  padding: 7px 14px;
  font-size: 11px;
  color: var(--ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.35s cubic-bezier(0.2, 0.9, 0.25, 1) both;
  white-space: nowrap;
}
.toast.out { animation: toast-out 0.4s ease both; }

/* ---------- Hint ---------- */

#hint {
  position: absolute;
  top: 56px; right: 10px;
  max-width: 340px;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  font-size: 11px;
  color: var(--ink-dim);
  animation: drop-in 0.2s backwards;
}
#hint b { color: var(--accent); font-weight: 600; }
#hint p { line-height: 1.5; }

/* ---------- Animations ---------- */

@keyframes drop-in { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes slide-r { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
@keyframes slide-l { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
#inspector { animation-name: rise-plain; }
@keyframes rise-plain { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

/* ---------- vitesse (slider) ---------- */
#speedbox { display: flex; align-items: center; gap: 8px; padding: 0 4px; }
#speedbox input[type="range"] { width: 96px; }
#speed-val { font-size: 12px; font-weight: 600; color: var(--accent); min-width: 30px; font-variant-numeric: tabular-nums; }

#daynight span { font-size: 14px; }

/* ---------- pickers (types / espèces) ---------- */
.param-pick { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 2px; }
.param-pick button {
  flex: 1 1 44%;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 7px;
  font-size: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-dim);
  transition: all 0.14s;
}
.param-pick button i { width: 8px; height: 8px; border-radius: 2px; background: var(--pc, var(--accent)); flex: none; box-shadow: 0 0 6px var(--pc, var(--accent)); }
.param-pick button:hover { color: var(--ink); border-color: var(--line-strong); }
.param-pick button.sel { color: var(--ink); border-color: rgba(168,232,76,0.45); background: var(--accent-soft); }
.param-pick.species button { flex-basis: 100%; flex-direction: column; align-items: flex-start; gap: 1px; }
.param-pick.species .ps-latin { font-size: 8.5px; color: var(--ink-faint); font-style: italic; }

/* ---------- timeline (rewind) ---------- */
#timebar {
  position: absolute;
  bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  animation: rise 0.5s 0.2s backwards;
}
#timebar.rewinding { border-color: rgba(255,210,120,0.5); box-shadow: 0 0 18px rgba(255,200,100,0.18); }
#timeline { width: 150px; }
#time-label { font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); min-width: 54px; }
#timebar .icon-btn { width: 26px; height: 26px; font-size: 12px; }
#time-live { padding: 4px 8px; font-size: 10px; opacity: 0.5; pointer-events: none; }
#time-live.on { opacity: 1; pointer-events: auto; color: var(--accent); border-color: rgba(168,232,76,0.4); }

/* ---------- vue du nid (coupe) ---------- */
#nestpanel {
  position: absolute;
  top: 78px; right: 270px;
  width: 460px;
  padding: 10px 10px 6px;
  animation: rise-plain 0.3s backwards;
}
.np-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.np-head .cc-dot { width: 9px; height: 9px; }
#nest-title { font-family: var(--font-d); font-weight: 800; font-size: 14px; letter-spacing: 0.05em; }
#nest-sub { font-style: italic; }
.np-head .txt-btn { margin-left: auto; padding: 3px 7px; font-size: 11px; }
.np-head .in-close { margin-left: 0; }
#nestCanvas { width: 100%; height: auto; display: block; border-radius: 9px; background: #0a0d07; }

/* ---------- modale nouvelle carte ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: 12px;
  background: rgba(4, 7, 2, 0.62);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: fade 0.25s both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 20px 22px;
}
.modal-card h3 { margin-bottom: 16px; }
.modal-lbl { display: block; font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-faint); margin: 14px 0 7px; }
.pick-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pick-row button {
  flex: 1 1 0; min-width: 70px;
  padding: 9px 8px; font-size: 11px;
  border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink-dim); transition: all 0.15s; white-space: nowrap;
}
.pick-row button:hover { color: var(--ink); border-color: var(--line-strong); }
.pick-row button.sel { color: var(--accent); border-color: rgba(168,232,76,0.5); background: var(--accent-soft); }
.modal-check {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 0 2px;
  font-size: 11px; color: var(--ink-dim); cursor: pointer;
}
.modal-check input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }
.modal-check span { color: var(--ink-faint); font-size: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.modal-actions .go { color: var(--accent); border-color: rgba(168,232,76,0.5); background: var(--accent-soft); }
.modal-actions .go:hover { box-shadow: 0 0 14px rgba(168,232,76,0.25); }

/* ---------- bannière vol nuptial ---------- */
#nuptial-banner {
  position: absolute;
  top: 64px; left: 50%; transform: translateX(-50%);
  padding: 7px 16px;
  font-size: 12px; letter-spacing: 0.02em;
  color: #2a1c06;
  background: linear-gradient(100deg, #ffd9a0, #ffc46a);
  border: 1px solid rgba(255,220,150,0.8);
  border-radius: 20px;
  box-shadow: 0 6px 22px rgba(255,190,90,0.3), inset 0 1px 0 rgba(255,255,255,0.4);
  pointer-events: none;
  white-space: nowrap;
  animation: nuptial-pulse 2.4s ease-in-out infinite, banner-rise 0.45s backwards;
}
#nuptial-banner b { font-weight: 700; }
@keyframes nuptial-pulse {
  0%, 100% { box-shadow: 0 6px 22px rgba(255,190,90,0.25), inset 0 1px 0 rgba(255,255,255,0.4); }
  50% { box-shadow: 0 6px 30px rgba(255,205,110,0.55), inset 0 1px 0 rgba(255,255,255,0.5); }
}
@keyframes banner-rise {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- mini-carte ---------- */
#minimap {
  position: absolute;
  bottom: 12px; left: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #0a0d07;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  cursor: crosshair;
  image-rendering: pixelated;
  animation: rise-plain 0.5s 0.25s backwards;
}

@media (max-width: 1100px) {
  #nestpanel { right: 12px; top: auto; bottom: 120px; width: 380px; }
  #timebar { left: auto; right: 12px; bottom: 58px; transform: none; }
  #layers { left: 50%; right: auto; transform: translateX(-50%); }
  #minimap { display: none; }
  /* écran étroit : le tableau de bord éco chevaucherait la barre d'outils → masqué */
  #ecopanel, #statspanel { display: none !important; }
}

@media (max-width: 960px) {
  #topbar {
    height: auto;
    min-height: 52px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 12px;
  }

  #brand {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #topbar > .tb-group:first-of-type {
    justify-self: end;
  }

  .tb-stats {
    grid-column: 1 / -1;
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .tb-actions {
    grid-column: 1 / -1;
    width: 100%;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .tb-actions::-webkit-scrollbar { display: none; }
  .tb-actions .txt-btn { flex: 0 0 auto; }

  #toolbar,
  #colonies-panel {
    top: 138px;
  }

  #colonies-panel {
    max-height: calc(100% - 260px);
  }

  #hint {
    top: auto;
    bottom: 108px;
    max-width: calc(100vw - 24px);
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
  }

  #nuptial-banner,
  .toast {
    max-width: calc(100vw - 24px);
    white-space: normal;
    text-align: center;
  }
}

@media (max-width: 700px) {
  #topbar {
    top: 8px; left: 8px; right: 8px;
    padding: 8px 10px;
    gap: 7px 9px;
  }

  #brand {
    font-size: clamp(13px, 3.8vw, 15px);
    letter-spacing: 0.055em;
  }
  #brand span { display: none; }

  #speedbox {
    gap: 6px;
    padding: 0;
  }
  #speedbox input[type="range"] { width: min(54px, 16vw); }
  #speed-val { min-width: 25px; font-size: 11px; }

  .tb-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }
  .stat {
    align-items: center;
    min-width: 0;
    padding: 4px 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(190, 255, 150, 0.035);
  }
  .stat label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 7px;
    letter-spacing: 0.1em;
  }
  .stat span { font-size: 11px; }
  #daynight span { font-size: 12px; }

  .tb-actions {
    gap: 5px;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
  }
  .tb-actions .txt-btn {
    padding: 5px 9px;
    font-size: 10px;
  }

  #colonies-panel {
    top: 122px;
    left: 8px; right: 8px;
    width: auto;
    max-height: 30dvh;
  }
  #colonies-panel h3 {
    text-align: left;
    padding: 0 2px 6px;
  }
  #colonies {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 7px;
    scroll-snap-type: x proximity;
  }
  .colony-card {
    flex: 0 0 min(252px, calc(100vw - 44px));
    max-height: calc(30dvh - 26px);
    overflow: auto;
    scroll-snap-align: start;
    animation-name: rise-plain;
  }

  #toolbar {
    top: auto;
    left: 8px; right: 8px; bottom: 104px;
    width: auto;
    max-height: 204px;
    overflow: hidden;
    padding: 8px;
  }
  #toolbar h3 { display: none; }
  #tools {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 7px;
  }
  .tool-btn {
    min-height: 46px;
    padding: 6px 2px 5px;
    border-radius: 8px;
  }
  .tool-btn svg { width: 18px; height: 18px; }
  .tool-btn span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 7px;
    letter-spacing: 0.04em;
  }

  .field { margin: 7px 0 1px; }
  .field label {
    font-size: 8px;
    letter-spacing: 0.12em;
  }
  #tool-params {
    max-height: 54px;
    overflow: auto;
    margin-top: 7px;
  }
  #tool-params .hint-text {
    font-size: 9px;
    line-height: 1.35;
    padding: 4px 0;
  }
  .param-pick button {
    min-width: 0;
    padding: 5px;
    font-size: 9px;
  }

  #timebar {
    left: 8px; right: 8px; bottom: 56px;
    width: auto;
    gap: 6px;
    padding: 6px 8px;
  }
  #timeline {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
  }
  #time-label {
    min-width: 58px;
    text-align: center;
    font-size: 8px;
    letter-spacing: 0.08em;
  }
  #time-live {
    padding: 4px 7px;
    font-size: 9px;
  }

  #layers {
    left: 8px; right: 8px; bottom: 8px;
    transform: none;
    justify-content: center;
    gap: 5px;
    padding: 6px;
  }
  #layers > label { display: none; }
  .chip {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 4px;
    text-align: center;
    white-space: nowrap;
    font-size: 9.5px;
  }

  #hint {
    left: 8px; right: 8px; bottom: 318px;
    transform: none;
    max-width: none;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 8px 10px;
    text-align: left;
    font-size: 10px;
  }
  #hint p {
    min-width: 0;
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  #hint .txt-btn { flex: none; }

  #inspector {
    left: 8px; right: 8px; bottom: 318px;
    width: auto;
    max-height: 28dvh;
    overflow: auto;
  }

  #nestpanel {
    left: 8px; right: 8px; top: 122px; bottom: auto;
    width: auto;
    max-height: 42dvh;
    overflow: hidden;
  }
  #nest-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #nestCanvas {
    max-height: calc(42dvh - 42px);
    object-fit: contain;
  }

  .modal-card {
    width: calc(100vw - 20px);
    padding: 16px;
  }
  .pick-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .pick-row button {
    min-width: 0;
    white-space: normal;
  }

  #toasts,
  #toasts.banner-on {
    top: calc(122px + 30dvh + 8px);
    bottom: auto;
    left: 8px; right: 8px;
    transform: none;
    max-height: 112px;
    overflow: hidden;
  }
  .toast { width: max-content; }

  #nuptial-banner {
    top: calc(122px + 30dvh + 8px);
    left: 8px; right: 8px;
    transform: none;
    border-radius: 14px;
    white-space: normal;
    text-align: center;
    animation: nuptial-pulse 2.4s ease-in-out infinite, rise-plain 0.45s backwards;
  }
}

@media (max-width: 390px) {
  .tb-actions .txt-btn { padding-inline: 8px; }
  #tool-params { display: none; }
  #toolbar { max-height: 164px; }
  #hint,
  #inspector {
    top: auto;
    bottom: 278px;
  }
}

@media (max-width: 700px) and (max-height: 760px) {
  #colonies-panel { max-height: 25dvh; }
  .colony-card { max-height: calc(25dvh - 26px); }
  #toolbar { max-height: 170px; }
  #toasts,
  #toasts.banner-on,
  #nuptial-banner {
    top: calc(122px + 25dvh + 8px);
  }
  #toasts { max-height: 84px; bottom: auto; }
  #hint,
  #inspector {
    top: auto;
    bottom: 284px;
  }
}

#layers > #ver {
  margin-left: auto;
  align-self: center;
  padding-left: 4px;
  font-family: var(--font-m);
  font-size: 10px;
  letter-spacing: 0.4px;
  color: var(--ink-faint);
  opacity: 0.65;
  pointer-events: none;
  user-select: none;
}
