/* Boitajeux — discussion du salon. Les couleurs suivent le thème du jeu (jetons --surface, --fg, --accent…). */

/* Bouton dans la barre du haut */
.chat-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 38px; --chat-dots: var(--surface); }
.chat-btn svg { width: 18px; height: 18px; display: block; }
.tb-bar .chat-btn { width: 38px; padding: 5px 0 !important; }
.chat-btn.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; --chat-dots: var(--accent); }
.chat-btn.on:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.chat-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--hot); color: #fff; font: 800 11px/18px var(--f-body); text-align: center; box-shadow: 0 0 0 2px var(--bg); animation: chat-pop .3s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes chat-pop { from { transform: scale(.3); } }

/* Panneau : carte à droite sur ordinateur, tiroir du bas sur téléphone */
.chat { position: fixed; z-index: 22; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 340px; height: min(540px, calc(100dvh - 90px)); display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); color: var(--fg); font-family: var(--f-body); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 50px -12px rgba(0, 0, 0, .7), 0 0 0 1px rgba(0, 0, 0, .2); animation: chat-in .28s cubic-bezier(.2, .9, .3, 1.1); }
.chat[hidden] { display: none; }
#overlay:not([hidden]) ~ .chat { z-index: 19; }
@keyframes chat-in { from { opacity: 0; transform: translateY(18px) scale(.98); } }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.chat-head h2 { font: 400 22px/1 var(--f-display); color: var(--paper, var(--fg)); }
.chat-x { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--glass); color: var(--fg); font: 400 24px/1 var(--f-body); cursor: pointer; }
.chat-x:hover { background: color-mix(in srgb, var(--fg) 14%, transparent); }

/* Messages */
.chat-list { list-style: none; margin: 0; padding: 12px 12px 8px; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px;
  overscroll-behavior: contain; scrollbar-width: thin; }
.chat-empty { margin: auto; color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }
.cm { display: flex; flex-direction: column; align-items: flex-start; max-width: 86%; margin-top: 8px; }
.cm.cont { margin-top: 0; }
.cm-who { font-size: 12px; font-weight: 800; color: var(--pc); margin: 0 0 2px 10px; }
.cm-txt { padding: 7px 12px 8px; border-radius: 16px 16px 16px 6px; background: var(--glass); border: 1px solid var(--line); border-left: 3px solid var(--pc);
  font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; white-space: pre-wrap; }
.cm.cont .cm-txt { border-top-left-radius: 6px; }
.cm.mine { align-self: flex-end; align-items: flex-end; }
.cm.mine .cm-txt { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 16px 16px 6px 16px; }
.cm.emo .cm-txt { background: none; border: 0; padding: 0 4px; font-size: 34px; line-height: 1.15; }
.cm.mine.emo .cm-txt { color: inherit; }
.chat-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Réponses rapides et saisie */
.chat-quick { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; scrollbar-width: none; flex: none; }
.chat-quick::-webkit-scrollbar { display: none; }
.chat-q { flex: none; font: 700 13px var(--f-body); color: var(--fg); background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 6px 11px; cursor: pointer; white-space: nowrap; }
.chat-q.emo { font-size: 18px; padding: 3px 8px; line-height: 1.2; }
.chat-q:hover { background: color-mix(in srgb, var(--fg) 12%, transparent); }
.chat-q:active { transform: scale(.94); }
.chat-form { display: flex; gap: 8px; padding: 10px 12px 12px; flex: none; }
.chat-form input { flex: 1 1 auto; font-size: 16px; padding: 10px 14px; }
.chat-form .btn { padding: 10px 16px; }

/* Bulles d'aperçu quand le panneau est fermé */
#chat-peek { position: fixed; z-index: 23; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; width: min(320px, calc(100vw - 32px)); }
.chat-pk { pointer-events: auto; max-width: 100%; text-align: left; cursor: pointer; font: 600 14px/1.35 var(--f-body); color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--pc); border-radius: 14px; padding: 8px 12px; box-shadow: 0 12px 28px -8px rgba(0, 0, 0, .65);
  overflow-wrap: anywhere; animation: chat-in .3s cubic-bezier(.2, .9, .3, 1.2); transition: opacity .3s, transform .3s; }
.chat-pk b { color: var(--pc); margin-right: 4px; }
.chat-pk.out { opacity: 0; transform: translateY(8px); }
body.chat-open #chat-peek { display: none; }

@media (max-width: 640px) {
  .chat { left: 0; right: 0; bottom: 0; width: auto; height: min(60dvh, 540px); border-radius: 20px 20px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px); animation-name: chat-up; }
  @keyframes chat-up { from { transform: translateY(100%); } }
  .chat-head::before { content: ""; position: absolute; left: 50%; top: 6px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--line); }
  #chat-peek { left: 12px; right: 12px; width: auto; bottom: auto; top: var(--peek-top, calc(56px + env(safe-area-inset-top, 0px))); align-items: stretch; }
  .tb-bar .chat-btn { width: 34px; min-width: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  .chat, .chat-pk, .chat-badge { animation: none; }
}
