:root {
  color-scheme: dark;
  --fond: rgba(28, 26, 22, 0.86);
  --fond-2: rgba(44, 40, 34, 0.92);
  --bord: rgba(255, 240, 210, 0.14);
  --texte: #f4ecdc;
  --doux: #bfb29a;
  --accent: #e6b450;
  --vert: #6fbf73;
  --rouge: #e0604f;
  --bleu: #6aa8d8;
  --olive: #a3b061;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--texte);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d1a24; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Barre du haut ---------- */
#barre {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  padding: 8px 14px; background: linear-gradient(var(--fond), rgba(28, 26, 22, 0.7));
  border-bottom: 1px solid var(--bord); backdrop-filter: blur(6px);
}
.titre { display: flex; align-items: baseline; gap: 12px; }
.titre strong { font-size: 15px; letter-spacing: 0.3px; color: var(--accent); }
#horloge { font-variant-numeric: tabular-nums; font-size: 14px; }
.pastille { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: rgba(255,255,255,0.08); color: var(--doux); }
.pastille:empty { display: none; }
#vitesses { display: flex; gap: 2px; background: rgba(0,0,0,0.25); border-radius: 8px; padding: 2px; }
#vitesses button { border: 0; background: transparent; padding: 4px 9px; border-radius: 6px; font-size: 12px; }
#vitesses button.actif { background: var(--accent); color: #241c0c; font-weight: 600; }
#ressources { display: flex; flex-wrap: wrap; gap: 6px; }
.res { display: flex; align-items: center; gap: 5px; font-size: 12.5px; padding: 3px 8px; border-radius: 8px; background: rgba(255,255,255,0.06); font-variant-numeric: tabular-nums; }
.res .ico { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.res.alerte { background: rgba(224, 96, 79, 0.28); }
.res small { color: var(--doux); }
#jauges { display: flex; gap: 12px; margin-left: auto; font-size: 12px; }
.jauge { display: flex; align-items: center; gap: 6px; }
.jauge .barre { width: 70px; }

/* ---------- Barres ---------- */
.barre { height: 7px; background: rgba(255,255,255,0.1); border-radius: 4px; overflow: hidden; flex: 1; }
.barre > i { display: block; height: 100%; border-radius: 4px; background: var(--vert); transition: width 0.3s; }
.barre.moyen > i { background: var(--accent); }
.barre.bas > i { background: var(--rouge); }
.barre.neutre > i { background: var(--bleu); }

/* ---------- Panneau latéral ---------- */
#panneau {
  position: fixed; top: 58px; right: 10px; bottom: 10px; width: 370px; z-index: 4;
  display: flex; flex-direction: column; background: var(--fond); border: 1px solid var(--bord);
  border-radius: 12px; backdrop-filter: blur(6px); overflow: hidden;
}
#onglets { display: flex; border-bottom: 1px solid var(--bord); }
#onglets button { flex: 1; border: 0; background: transparent; padding: 9px 2px; font-size: 12px; white-space: nowrap; color: var(--doux); border-bottom: 2px solid transparent; }
#onglets button.actif { color: var(--texte); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 16px; padding: 0 4px; border-radius: 8px; background: var(--rouge); color: #fff; font-size: 10.5px; line-height: 16px; }
.badge:empty { display: none; }
#contenu { flex: 1; overflow-y: auto; padding: 12px 14px 20px; font-size: 13px; }
#contenu h3, #fiche h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--doux); margin: 16px 0 8px; font-weight: 600; }
#contenu h3:first-child { margin-top: 2px; }
.grille2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: rgba(255,255,255,0.05); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--doux); }
.ligne { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.ligne > label, .ligne > .lib { width: 118px; flex: none; color: var(--doux); font-size: 12px; }
.ligne .val { width: 30px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.boutons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.btn { border: 1px solid var(--bord); background: rgba(255,255,255,0.07); border-radius: 7px; padding: 6px 10px; font-size: 12.5px; }
.btn:hover:not(:disabled) { background: rgba(255,255,255,0.14); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.principal, button.principal { background: var(--accent); color: #241c0c; border-color: transparent; font-weight: 600; }
.btn.danger { border-color: rgba(224,96,79,0.5); }
select, input[type=search] { font: inherit; font-size: 12.5px; color: var(--texte); background: rgba(0,0,0,0.3); border: 1px solid var(--bord); border-radius: 7px; padding: 5px 8px; }
select option { background: #2c2822; }
.note { color: var(--doux); font-size: 12px; line-height: 1.45; }
.carte-bloc { background: rgba(255,255,255,0.05); border: 1px solid var(--bord); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }

/* liste des habitants */
.filtres { display: flex; gap: 6px; margin-bottom: 8px; }
.filtres input { flex: 1; min-width: 0; }
.liste-hab { display: flex; flex-direction: column; gap: 2px; }
.hab { display: grid; grid-template-columns: 10px 1fr 54px; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.hab:hover { background: rgba(255,255,255,0.07); }
.hab.sel { background: rgba(230,180,80,0.18); }
.hab .pt { width: 10px; height: 10px; border-radius: 50%; }
.hab .nom { font-size: 13px; }
.hab .etat { display: block; font-size: 11.5px; color: var(--doux); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hab .mini { height: 5px; }

/* conflits / assemblée / journal */
.conflit { border-left: 3px solid var(--rouge); }
.gravite { letter-spacing: 2px; color: var(--rouge); }
.option-vote { margin: 8px 0; }
.option-vote .tete { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.journal-e { padding: 6px 0 6px 10px; border-left: 2px solid var(--bord); margin-bottom: 4px; font-size: 12.5px; line-height: 1.4; }
.journal-e time { display: block; font-size: 11px; color: var(--doux); }
.journal-e.bien { border-color: var(--vert); }
.journal-e.mal { border-color: var(--rouge); }
.journal-e.conseil { border-color: var(--accent); }
.journal-e.evenement { border-color: var(--bleu); }
.journal-e[data-sujet] { cursor: pointer; }
.lien { color: var(--accent); cursor: pointer; text-decoration: underline dotted; }

/* ---------- Fiche habitant ---------- */
#fiche {
  position: fixed; left: 10px; bottom: 10px; z-index: 4; width: 400px; max-height: calc(100% - 78px);
  overflow-y: auto; background: var(--fond); border: 1px solid var(--bord); border-radius: 12px;
  padding: 12px 14px 14px; font-size: 13px; backdrop-filter: blur(6px);
}
#fiche .entete { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
#fiche h2 { margin: 0; font-size: 18px; }
#fiche .sous { color: var(--doux); font-size: 12.5px; margin-top: 2px; }
#fiche .fermer { border: 0; background: transparent; font-size: 18px; color: var(--doux); padding: 0 4px; }
.pensee { margin: 10px 0 4px; padding: 8px 10px; border-radius: 8px; background: rgba(230,180,80,0.1); font-style: italic; line-height: 1.4; }
.etat-actuel { font-size: 12.5px; color: var(--doux); }
.etat-actuel b { color: var(--texte); font-weight: 500; }
.souvenir { display: grid; grid-template-columns: 6px 1fr; gap: 8px; padding: 4px 0; font-size: 12.5px; line-height: 1.35; }
.souvenir i { width: 6px; border-radius: 3px; }
.souvenir small { color: var(--doux); display: block; font-size: 11px; }
.relation { display: flex; justify-content: space-between; gap: 6px; font-size: 12.5px; padding: 2px 0; }
.relation .aff { font-variant-numeric: tabular-nums; }
.pos { color: var(--vert); } .neg { color: var(--rouge); }
.metier-sel { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.souhait { font-size: 11.5px; color: var(--doux); }

/* étiquettes flottantes */
#etiquette, #infobulle {
  position: fixed; z-index: 3; pointer-events: none; transform: translate(-50%, -100%);
  background: rgba(20, 18, 14, 0.85); border: 1px solid var(--bord); border-radius: 6px;
  padding: 3px 8px; font-size: 12px; white-space: nowrap;
}
#infobulle { transform: translate(12px, 12px); }

/* notifications */
#toasts { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 8; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--fond-2); border: 1px solid var(--bord); border-left: 3px solid var(--accent); padding: 8px 14px; border-radius: 8px; font-size: 13px; max-width: 520px; animation: entree 0.25s ease-out; }
.toast.mal { border-left-color: var(--rouge); }
.toast.bien { border-left-color: var(--vert); }
@keyframes entree { from { opacity: 0; transform: translateY(-6px); } }

/* intro */
#intro { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(10, 14, 20, 0.55); padding: 16px; }
#intro .carte { max-width: 580px; background: var(--fond-2); border: 1px solid var(--bord); border-radius: 14px; padding: 26px 30px; line-height: 1.5; font-size: 14px; max-height: 100%; overflow-y: auto; }
#intro h1 { margin: 0; color: var(--accent); font-size: 26px; }
#intro .sous { margin-top: 4px; color: var(--doux); }
#intro ul { padding-left: 18px; }
#intro li { margin: 4px 0; }
#intro .petit { font-size: 12px; color: var(--doux); }
#intro button.principal { border: 0; padding: 10px 20px; border-radius: 9px; font-size: 15px; margin-top: 6px; }
#intro .avertissement { margin-top: 14px; }
#chargement { position: fixed; inset: 0; display: grid; place-items: center; z-index: 30; background: #0d1a24; color: var(--doux); font-size: 15px; }
#chargement.fini { display: none; }

@media (max-width: 900px) {
  #panneau { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 42%; }
  #fiche { left: 8px; right: 8px; width: auto; bottom: calc(42% + 16px); max-height: 38%; }
  #jauges { margin-left: 0; }
  #barre { padding: 6px 10px; gap: 6px 10px; }
  .titre strong { font-size: 13px; }
}

/* émergence : journée type */
.routine { display: flex; flex-direction: column; gap: 2px; }
.routine-ligne { display: grid; grid-template-columns: 82px repeat(24, 1fr); gap: 1px; align-items: center; font-size: 11px; color: var(--doux); }
.routine-ligne i { height: 12px; border-radius: 2px; background: var(--accent); }
.routine-ligne.heures b { font-weight: 400; font-size: 10px; }

/* dialogue */
.dialogue p { margin: 4px 0; font-size: 12.5px; line-height: 1.4; }
.dialogue p.moi { color: var(--doux); }
.dialogue p.lui b { color: var(--accent); }
.parole { display: flex; gap: 6px; margin-top: 6px; }
.parole input { flex: 1; min-width: 0; font: inherit; font-size: 12.5px; color: var(--texte); background: rgba(0,0,0,0.3); border: 1px solid var(--bord); border-radius: 7px; padding: 6px 8px; }
.pensee small { display: block; font-style: normal; font-size: 11px; color: var(--doux); margin-top: 3px; }
.journal-e.ancien { opacity: 0.6; }
#onglets button { font-size: 11.5px; }
#onglets { flex-wrap: wrap; }
#onglets button { flex: 1 1 30%; padding: 7px 2px; }
#onglets { flex-shrink: 0; }
#panneau { top: 80px; }
#fiche { max-height: calc(100% - 92px); }
@media (max-width: 900px) { #panneau { top: auto; } }

/* bandeau d'état de la pensée */
#bandeau { position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 9; max-width: min(640px, 92vw); background: var(--fond-2); border: 1px solid var(--bord); border-radius: 10px; padding: 8px 14px; font-size: 12.5px; line-height: 1.45; }
#bandeau.alerte { border-color: rgba(224,96,79,0.6); }
#bandeau code { background: rgba(255,255,255,0.1); padding: 1px 5px; border-radius: 4px; }
#bandeau a, #intro a { color: var(--accent); }
form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12.5px; }
form.inline input { width: 64px; font: inherit; color: var(--texte); background: rgba(0,0,0,0.3); border: 1px solid var(--bord); border-radius: 6px; padding: 4px 6px; }
.journal-e.pensee-e { opacity: 0.75; border-color: var(--doux); font-style: italic; }
#intro code { background: rgba(255,255,255,0.1); padding: 1px 5px; border-radius: 4px; }

#bandeau { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: center; text-align: center; }
#bandeau[hidden] { display: none !important; }
#bandeau.attente { border-color: var(--accent); }
#bandeau small { flex-basis: 100%; color: var(--doux); }
#bandeau .btn { font-size: 14px; padding: 8px 14px; }
@media (max-width: 900px) { #bandeau { top: auto; bottom: calc(42% + 18px); } }
#bandeau form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; text-align: left; }
#bandeau form b, #bandeau form small { flex-basis: 100%; }
#bandeau input { flex: 1; min-width: 0; font: inherit; color: var(--texte); background: rgba(0,0,0,0.3); border: 1px solid var(--bord); border-radius: 7px; padding: 8px; }

/* iPhone et Android zooment sur un champ dont le texte fait moins de 16px : on l'évite */
@media (max-width: 900px) { input, select, textarea { font-size: 16px !important; } }

/* ---------- Téléphone : une vue à la fois, barre de navigation en bas ---------- */
#nav-mobile { display: none; }
@media (max-width: 900px) {
  #nav-mobile {
    display: flex; gap: 2px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 12; overflow-x: auto;
    background: var(--fond-2); border-top: 1px solid var(--bord); backdrop-filter: blur(6px);
    padding: 4px max(4px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px));
  }
  #nav-mobile button { flex: 1 0 auto; border: 0; background: transparent; color: var(--doux); font-size: 13px; padding: 10px 8px; border-radius: 8px; white-space: nowrap; }
  #nav-mobile button.actif { color: var(--texte); background: rgba(255,255,255,0.1); }
  #nav-mobile button[hidden] { display: none; }
  #onglets { display: none; }
  #panneau, #fiche {
    top: auto !important; left: 0; right: 0; width: auto; height: auto; max-height: 58vh;
    bottom: calc(50px + env(safe-area-inset-bottom, 0px)); border-radius: 14px 14px 0 0; border-bottom: 0;
  }
  #panneau { height: 58vh; }
  body:not([data-vue="panneau"]) #panneau { display: none; }
  body:not([data-vue="fiche"]) #fiche { display: none; }
  #barre { gap: 4px 8px; padding: 6px max(10px, env(safe-area-inset-right, 0px)) 6px max(10px, env(safe-area-inset-left, 0px)); }
  #barre .titre strong, #jauges { display: none; }
  #ressources { flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; }
  #ressources .res { flex: none; }
  #vitesses button { padding: 6px 10px; }
  #bandeau { top: auto; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 24px); }
  body[data-vue="panneau"] #bandeau, body[data-vue="fiche"] #bandeau { bottom: calc(58vh + 58px + env(safe-area-inset-bottom, 0px)); }
  #toasts { top: auto; bottom: calc(120px + env(safe-area-inset-bottom, 0px)); width: calc(100vw - 24px); }
  .toast { max-width: 100%; }
}
