/* Text chat: see-through window on PC (drag it anywhere), bottom sheet on phones */
.chat{
  position:fixed;right:calc(16px + var(--sa-r));bottom:calc(16px + var(--sa-b));z-index:70;width:340px;height:min(420px,62vh * var(--vz,1));height:min(420px,62dvh * var(--vz,1));
  display:flex;flex-direction:column;border-radius:14px;overflow:hidden;
  background:rgba(16,9,7,.78);
  border:1px solid rgba(228,195,116,.32);box-shadow:0 18px 40px rgba(0,0,0,.5);
  opacity:.86;transition:opacity .2s,background .2s;
}
.chat:hover,.chat:focus-within{opacity:1;background:rgba(16,9,7,.92)}
.chat[hidden]{display:none}
.chat-head{display:flex;align-items:center;gap:6px;padding:6px 6px 6px 8px;cursor:move;touch-action:none;
  background:rgba(0,0,0,.35);border-bottom:1px solid rgba(228,195,116,.16)}
.chat-tabs{display:flex;gap:4px;flex:1;min-width:0;overflow-x:auto;scrollbar-width:none}
.chat-tabs button{position:relative;flex:none;cursor:pointer;border:1px solid transparent;border-radius:999px;padding:5px 11px;
  background:none;color:var(--muted);font:700 12px Inter,system-ui,sans-serif;white-space:nowrap}
.chat-tabs button[aria-selected="true"]{color:#2a1a00;background:linear-gradient(180deg,var(--gold-hi),var(--gold))}
.chat-tabs button:focus-visible{outline:2px solid var(--gold);outline-offset:1px}
.chat-tab{flex:none;display:inline-flex;align-items:center;border-radius:999px}
.chat-tab.on{background:linear-gradient(180deg,var(--gold-hi),var(--gold))}
.chat-tab button[data-room]{padding-right:4px}
.chat-tab.on button[data-room]{background:none}
.chat-tabs .chat-tab-x{flex:none;width:18px;height:18px;padding:0;margin:0 5px 0 0;border-radius:50%;border:none;
  display:grid;place-items:center;font:700 13px/1 Inter,system-ui,sans-serif;color:var(--muted);background:rgba(255,255,255,.08);cursor:pointer}
.chat-tabs .chat-tab-x:hover{color:#fff;background:var(--lose)}
.chat-tab.on .chat-tab-x{color:#2a1a00;background:rgba(0,0,0,.12)}
.chat-tabs i{margin-left:5px;font-style:normal;font-size:10px;font-weight:800;padding:1px 5px;border-radius:999px;background:var(--lose);color:#fff}
.chat-x{flex:none;width:28px;height:28px;border-radius:50%;border:1px solid rgba(255,255,255,.18);background:none;color:var(--muted);font-size:16px;cursor:pointer}
.chat-x:hover{color:var(--ink);border-color:var(--gold)}
.chat-log{list-style:none;margin:0;padding:10px;flex:1;overflow-y:auto;display:flex;flex-direction:column;gap:7px;font-size:13px;line-height:1.35}
.chat-msg{display:grid;grid-template-columns:auto 1fr;column-gap:6px;align-items:baseline}
.chat-msg b{color:var(--gold);font-size:12.5px}
.chat-msg.me b{color:var(--win)}
.chat-msg time{font-size:10px;color:rgba(247,241,225,.4);justify-self:end}
.chat-msg span{grid-column:1 / -1;overflow-wrap:anywhere;color:var(--ink)}
.chat-join{grid-column:1 / -1;justify-self:start;margin-top:4px;padding:7px 12px;font-size:12.5px}
.chat-invite-sent{grid-column:1 / -1;font-size:11px;color:var(--muted);font-style:italic}
.chat-note{color:var(--muted);font-size:12px;text-align:center;font-style:italic;padding:6px 0}
.chat-form{display:flex;gap:6px;padding:8px;border-top:1px solid rgba(228,195,116,.16);background:rgba(0,0,0,.25)}
.chat-form input{flex:1;min-width:0;padding:9px 11px;border-radius:10px;border:1px solid var(--gold-dim);background:rgba(0,0,0,.55);
  color:var(--ink);font:15px Inter,system-ui,sans-serif}
.chat-form input:focus{outline:2px solid var(--gold);outline-offset:0}
.chat-form .btn{padding:8px 13px;font-size:15px}

.chat-fab{
  position:fixed;right:calc(16px + var(--sa-r));bottom:calc(16px + var(--sa-b));z-index:69;width:52px;height:52px;border-radius:50%;cursor:pointer;font-size:22px;
  background:radial-gradient(circle at 35% 30%,#3a1d10,#140906);border:1px solid var(--gold);
  box-shadow:0 8px 20px rgba(0,0,0,.55),0 0 0 3px rgba(228,195,116,.12);
}
.chat-fab[hidden]{display:none}
.chat-fab:hover{transform:translateY(-2px)}
.chat-fab:focus-visible{outline:2px solid var(--gold);outline-offset:3px}
body.chat-open .chat-fab{display:none}
.chat-badge{position:absolute;top:-4px;right:-4px;min-width:20px;height:20px;padding:0 5px;border-radius:999px;
  background:var(--lose);color:#fff;font:800 11px/20px Inter,system-ui,sans-serif;box-shadow:0 2px 6px rgba(0,0,0,.5)}
.chat-badge[hidden]{display:none}

/* phones: a sheet at the bottom, the bubble out of the way of the game buttons */
@media (max-width:600px){
  .chat{left:0 !important;right:0 !important;top:auto !important;bottom:0 !important;width:auto;height:min(48vh,380px);height:min(48dvh,380px);
    border-radius:16px 16px 0 0;opacity:1;background:rgba(16,9,7,.94);padding-bottom:env(safe-area-inset-bottom)}
  .chat-head{cursor:default}
  .chat-fab{top:calc(64px + var(--sa-t));bottom:auto;right:calc(10px + var(--sa-r));width:44px;height:44px;font-size:19px}
  .chat-form input{font-size:16px}          /* 16 px: iPhone doesn't zoom in when typing */
}
@media (prefers-reduced-motion:reduce){.chat{transition:none}}

/* Wide computer screens: the open chat is a sidebar on the right, the table moves left (nothing is covered) */
@media (min-width:1400px) and (pointer:fine){
  body.chat-open{padding-right:340px}
  body.chat-open .chat{top:0 !important;bottom:0 !important;right:0 !important;left:auto !important;width:340px;height:auto;
    border-radius:0;border-width:0 0 0 1px;opacity:1;background:rgba(16,9,7,.97);box-shadow:-12px 0 30px rgba(0,0,0,.45)}
  body.chat-open .chat-head{cursor:default}
  body.chat-open .chat-fab{display:none}
}

/* private room: who it is + « Inviter à ma table » (chat.js renderDMBar) */
.chat-dmbar{display:flex;align-items:center;gap:8px;padding:6px 8px;border-bottom:1px solid rgba(228,195,116,.16);background:rgba(0,0,0,.2)}
.chat-dmbar[hidden]{display:none}
.chat-dmbar .chat-who{flex:1;min-width:0;text-align:left;background:none;border:none;padding:0;color:var(--gold);font:700 12.5px Inter,system-ui,sans-serif;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.chat-inv{flex:none;padding:6px 10px;font-size:12px}
.chat-inv.off{filter:grayscale(1);opacity:.55}
.chat-inv[hidden]{display:none}
.chat-msg b.chat-who{cursor:pointer}
.chat-msg b.chat-who:hover,.chat-msg b.chat-who:focus-visible{text-decoration:underline;outline:none}
/* « Annonces »: messages framed in gold, the field greyed for players */
.chat-msg.chat-ann{padding:8px 10px;border-radius:10px;background:rgba(228,195,116,.08);border:1px solid rgba(228,195,116,.3)}
.chat-msg.chat-ann b{color:var(--gold-hi)}
.chat-msg.chat-ann b::before{content:"📢 "}
.chat-form.ro input{opacity:.6;font-style:italic}
.chat-form.ro .btn{opacity:.35}
