/* Messages des visiteurs, en direct (src/chat.js) : le fil monte en bas à droite, au-dessus de la scène ;
   on remonte dans les anciens messages à la molette ou au doigt. */
#chat {
  position: fixed; right: 16px; bottom: 16px; z-index: 7; width: min(340px, calc(100vw - 32px));
  display: none; flex-direction: column; gap: 8px; pointer-events: none;
}
body.walking #chat:not([hidden]), body.touring #chat:not([hidden]) { display: flex; }
body.focus #chat, body:has(#pause.visible) #chat, body:has(#livre-panel:not([hidden])) #chat { display: none !important; }
/* téléphone : en bas à droite, à côté du joystick (qui occupe le bas à gauche) */
body.touch #chat { left: 160px; right: 160px; bottom: 24px; width: auto; }
body.touring #chat .ch-form { display: none; } /* visite guidée : lecture seule */
#chat > * { pointer-events: auto; }
#chat .ch-fil {
  list-style: none; margin: 0; padding: 0 2px 0 0; max-height: 32vh; overflow-y: auto; overscroll-behavior: contain;
  touch-action: pan-y; scrollbar-width: none; /* on fait défiler à la molette ou au doigt, sans barre */
  display: flex; flex-direction: column; gap: 6px;
}
/* fondu en haut seulement quand des messages plus anciens sont cachés au-dessus (main.js : .ch-fil.deborde) */
#chat .ch-fil.deborde { -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 36px); mask-image: linear-gradient(to bottom, transparent 0, #000 36px); }
#chat .ch-fil::-webkit-scrollbar { display: none; }
body.touch #chat .ch-fil { max-height: 30vh; }
body.touch:has(#atelier-barre:not([hidden])) #chat .ch-fil { max-height: 16vh; }
#chat .ch-fil > li:first-child { margin-top: auto; } /* peu de messages : collés en bas */
#chat .ch-nouveaux {
  align-self: flex-end; font: inherit; font-size: 0.78rem; color: #1a120a; background: var(--accent); border: 0;
  border-radius: 999px; padding: 4px 12px; cursor: pointer; margin-top: -4px;
}
#chat .ch-nouveaux[hidden] { display: none; }
#chat .ch-fil li {
  align-self: flex-end; max-width: 100%; overflow-wrap: anywhere; flex-shrink: 0;
  background: rgba(15, 12, 9, 0.58); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  border-radius: 14px; padding: 6px 12px; font-size: 0.88rem; line-height: 1.35; color: #f3ede2;
  animation: ch-entre 0.35s ease-out; transition: opacity 1s;
}
#chat .ch-fil b { color: var(--c, var(--accent)); font-weight: 600; margin-right: 6px; }
#chat .ch-fil .ch-salle { display: block; color: rgba(255, 255, 255, 0.5); font-size: 0.72rem; }
@keyframes ch-entre { from { opacity: 0; transform: translateY(12px); } }
#chat .ch-form { display: flex; gap: 6px; }
#chat .ch-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 0.9rem; color: var(--ink); background: rgba(15, 12, 9, 0.62);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px;
}
#chat .ch-form input[hidden] { display: none; }
#chat .ch-form input:focus { outline: none; border-color: var(--accent); }
#chat .ch-envoyer { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: #1a120a; font-size: 1rem; cursor: pointer; }
#chat .ch-info { align-self: flex-end; margin: 0; font-size: 0.78rem; color: var(--accent); background: rgba(15, 12, 9, 0.6); border-radius: 999px; padding: 4px 12px; }
#chat .ch-info[hidden] { display: none; }
body:not(.chat-actif) .pause-aide .hb-chat { display: none; }
/* miniature de l'avatar de l'auteur, devant son pseudo */
#chat .ch-fil li.ch-avec-avatar { display: grid; grid-template-columns: 34px minmax(0, 1fr); column-gap: 9px; align-items: center; padding-left: 7px; }
#chat .ch-fil .ch-avatar { grid-row: 1 / span 2; width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); object-fit: cover; }
#chat .ch-fil li.ch-avec-avatar .ch-salle { grid-column: 2; text-align: right; }
/* fenêtre « Votre pseudo », demandée à l'envoi du premier message */
#chat-pseudo { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(8, 6, 4, 0.72); padding: 16px; }
#chat-pseudo[hidden] { display: none; }
#chat-pseudo .cp-carte { width: min(400px, 100%); background: #17120d; border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; color: var(--ink); }
#chat-pseudo h2 { margin: 0 0 8px; font: 600 1.5rem var(--serif); }
#chat-pseudo p { margin: 0 0 12px; font-size: 0.86rem; color: var(--ink-soft); }
#chat-pseudo input { width: 100%; box-sizing: border-box; font: inherit; color: var(--ink); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 999px; padding: 9px 15px; margin-bottom: 12px; }
#chat-pseudo input:focus { outline: none; border-color: var(--accent); }
#chat-pseudo .cp-erreur { color: #f0a070; }
#chat-pseudo .cp-erreur[hidden] { display: none; }
#chat-pseudo .cp-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#chat-pseudo .cp-actions button { font: inherit; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
#chat-pseudo .cp-ok { background: var(--accent) !important; border-color: var(--accent) !important; color: #1a120a !important; font-weight: 500; }
/* le fil défile : Chrome le rend « focusable » et l'entoure d'un cadre bleu après un clic ; pas de cadre */
#chat .ch-fil:focus, #chat .ch-fil:focus-visible { outline: none; }
/* invitation reçue à venir s'asseoir */
#invit-siege { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100vw - 32px); background: rgba(23, 18, 13, 0.92); border: 1px solid var(--accent); border-radius: 14px; padding: 10px 14px; color: var(--ink); font-size: 0.9rem; }
#invit-siege[hidden] { display: none; }
#invit-siege button { font: inherit; font-size: 0.85rem; padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
#invit-siege .iv-oui { background: var(--accent); border-color: var(--accent); color: #1a120a; font-weight: 500; }
/* assis dans un groupe de places : inviter quelqu'un à rejoindre (main.js : majBoutonRejoindre) */
#btn-rejoindre { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 20; font: inherit; font-size: 0.9rem; padding: 9px 18px; border-radius: 999px;
  border: 1px solid var(--accent); background: rgba(23, 18, 13, 0.85); color: var(--ink); cursor: pointer; }
#btn-rejoindre[hidden] { display: none; }
body.appareil #btn-rejoindre { display: none; }
/* Messages et visiteurs dans une fenêtre (main.js : #social) ; en gros plan, deux boutons ronds en haut à gauche */
#social-barre { position: fixed; top: 14px; left: 14px; z-index: 13; display: none; gap: 10px; }
body.puzzle-gros-plan #social-barre, body.mur-gros-plan #social-barre { display: flex; }
/* (incognito : ni messages ni visiteurs, seulement « Inviter » ; un bouton caché le reste) */
body:not(.social-actif) #social-barre :is(.sb-chat, .sb-visiteurs), #social-barre button[hidden] { display: none; }
body:has(#puzzle-panneau:not([hidden])) #social-barre, body:has(#invitation:not([hidden])) #social-barre, body:has(#atelier-photo:not([hidden])) #social-barre { display: none !important; }
body:has(#pause.visible) #social-barre, body.appareil #social-barre, body.cadrage #social-barre, body:has(#social:not([hidden])) #social-barre { display: none !important; }
#social-barre button { position: relative; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--accent); background: rgba(23, 18, 13, 0.92);
  color: var(--ink); font-size: 1.3rem; display: grid; place-items: center; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,0.4); padding: 0; }
#social-barre .sb-badge, #social-barre .sb-n:not(:empty) { position: absolute; top: -5px; right: -5px; min-width: 20px; height: 20px; padding: 0 5px; box-sizing: border-box;
  border-radius: 999px; font: 600 0.72rem/20px var(--sans, inherit); text-align: center; }
#social-barre .sb-badge { background: #d94b3b; color: #fff; }
#social-barre .sb-badge[hidden] { display: none; }
#social-barre .sb-n:not(:empty) { background: var(--accent); color: #1a120a; }
#social { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; background: rgba(8, 6, 4, 0.6); padding: 16px; }
#social[hidden] { display: none; }
#social .so-carte { width: min(440px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: #17120d;
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 16px; color: var(--ink); box-sizing: border-box; }
#social .so-tete { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
#social .so-onglets { display: flex; gap: 6px; flex: 1; }
#social .so-onglets button, #social .so-inviter { font: inherit; font-size: 0.88rem; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
#social .so-onglets button { display: inline-flex; align-items: center; gap: 6px; }
#social .so-onglets button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #1a120a; font-weight: 500; }
#social .so-fermer { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--ink); font-size: 1rem; cursor: pointer; }
#social .so-corps { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
#social .so-vide { color: var(--ink-soft); font-size: 0.88rem; margin: 6px 0 12px; }
#social .so-liste { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#social .so-liste li { display: flex; align-items: center; gap: 10px; }
#social .so-liste img { width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); object-fit: cover; flex: none; }
#social .so-liste b { display: block; color: var(--c, var(--accent)); font-weight: 600; }
#social .so-liste small { color: var(--ink-soft); font-size: 0.78rem; }
#social .so-inviter { align-self: flex-start; }
/* le fil du chat, dans la fenêtre : à sa place dans la carte */
#social #chat.dans-social { display: flex !important; position: static; width: auto; left: auto; right: auto; bottom: auto; pointer-events: auto; }
#social #chat.dans-social .ch-fil { max-height: none !important; height: min(46vh, 380px); -webkit-mask-image: none; mask-image: none; }
#social #chat.dans-social .ch-fil li { align-self: stretch; background: rgba(255, 255, 255, 0.06); }
/* téléphone en paysage : un chat plus compact, à côté du joystick, qui laisse le bas de l'écran libre */
@media (max-height: 500px) and (orientation: landscape) {
  body.touch #chat { right: auto; width: min(300px, 38vw); bottom: 12px; gap: 6px; }
  body.touch #chat .ch-fil, body.touch:has(#atelier-barre:not([hidden])) #chat .ch-fil { max-height: 28vh; }
  #chat .ch-fil li { font-size: 0.8rem; padding: 4px 10px; }
  #chat .ch-form input { font-size: 0.84rem; padding: 6px 12px; }
  #chat .ch-envoyer { width: 34px; height: 34px; }
  /* « 🔍 Ce mur » / « 🔍 Puzzle » : en bas à droite, à gauche de la colonne de l'atelier, plus devant le chat */
  body:not(.puzzle-gros-plan):not(.mur-gros-plan) #puzzle-focus { left: auto; right: 84px; transform: none; bottom: 14px; }
}

@media (max-width: 600px), (max-height: 500px) { body.touch #chat { left: 124px; right: 124px; bottom: 18px; } }

/* bouton du mode compact, au début de la ligne de saisie */
#chat .ch-mode { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: rgba(15, 12, 9, 0.85); color: var(--ink); font-size: 0.95rem; cursor: pointer; padding: 0; }
/* mode compact : plus de saisie ni d'anciens messages ; ceux qui arrivent passent en notification 6 s */
#chat.compact .ch-form > :not(.ch-mode), #chat.compact .ch-nouveaux, #chat.compact .ch-info { display: none !important; }
#chat.compact .ch-form { justify-content: flex-end; }
#chat.compact .ch-fil { -webkit-mask-image: none; mask-image: none; overflow: hidden; }
#chat.compact .ch-fil li:not(.recent) { display: none; }
#chat.compact .ch-fil li.recent { animation: ch-toast 6s ease forwards; }
@keyframes ch-toast { 0% { opacity: 0; transform: translateY(8px); } 6% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
@media (max-width: 600px) { #chat .ch-mode { width: 34px; height: 34px; } }
/* téléphone en hauteur : plus de joystick de droite (on glisse sur l'écran pour regarder) ; le chat occupe le bas,
   à droite du joystick de marche */
@media (max-width: 600px) and (orientation: portrait) {
  body.touch #chat { left: 156px; right: 12px; bottom: 18px; }
  body.touch #chat:not(.compact) .ch-fil { max-height: 30vh; }
}

/* message de la modération (« 🛡️ Surveillant », src/chat.js marquerMod) : bulle dorée, à part */
#chat .ch-fil li.ch-mod { background: rgba(70, 52, 18, 0.85); border: 1px solid rgba(232, 184, 92, 0.75); }
#chat .ch-fil li.ch-mod b { color: #f2c76b; }
