/* Chat floats above the game: a corner card on wide screens, a bottom sheet on phones. */
.game-toolbar { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(44px, 1fr); }
.chat-unread { position: absolute; top: 5px; left: calc(50% + 5px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; line-height: 17px; text-align: center; box-shadow: 0 0 0 2px var(--bg); }
#open-chat[aria-expanded='true'] { background: var(--surface-2); }

.chat-toast { position: absolute; top: 8px; left: 50%; z-index: 8; transform: translateX(-50%); display: flex; gap: 6px; align-items: baseline; max-width: calc(100% - 24px); min-height: 36px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 12px 12px 12px 4px; background: var(--surface); color: var(--ink); font-size: 12px; text-align: left; box-shadow: 0 6px 20px #19303d33; cursor: pointer; animation: chat-toast-in 180ms ease-out; }
.chat-toast b { flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chat-toast span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes chat-toast-in { from { opacity: 0; translate: 0 -6px; } }

.chat-panel { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 40; display: flex; flex-direction: column; width: min(340px, calc(100vw - 32px)); max-height: min(470px, calc(100dvh - 32px)); border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 18px 60px -12px #19303d55; animation: chat-panel-in 160ms ease-out; }
@keyframes chat-panel-in { from { opacity: 0; translate: 0 10px; } }
.chat-header { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.chat-header h2 { flex: 1; min-width: 0; margin: 0; overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.chat-icon { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.chat-icon:hover { background: var(--surface-2); color: var(--ink); }
.chat-icon svg, .chat-send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chat-bell-off { display: none; }
#chat-mute[aria-pressed='true'] { color: var(--danger); }
#chat-mute[aria-pressed='true'] .chat-bell-off { display: initial; }
.chat-messages { flex: 1 1 auto; min-height: 90px; margin: 0; padding: 12px 12px 4px; overflow-y: auto; overscroll-behavior: contain; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.chat-message { display: grid; gap: 1px; max-width: 82%; }
.chat-message.mine { align-self: flex-end; justify-items: end; }
.chat-author { padding: 0 4px; color: var(--muted); font-size: 10px; }
.chat-message.continued .chat-author { display: none; }
.chat-message.continued { margin-top: -3px; }
.chat-text { padding: 7px 11px; border-radius: 14px 14px 14px 4px; background: var(--surface-2); font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.chat-message.mine .chat-text { border-radius: 14px 14px 4px 14px; background: #dbe4d7; color: #1f3d2c; }
.chat-message.pending .chat-text { opacity: .55; }
.chat-note, .chat-empty { margin: 0; color: var(--muted); font-size: 11px; text-align: center; }
.chat-empty { padding: 0 16px 8px; }
.chat-error { margin: 0; padding: 0 16px 6px; color: var(--danger); font-size: 11px; }
.chat-quick { display: flex; gap: 6px; padding: 6px 12px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
.chat-quick::-webkit-scrollbar { display: none; }
.chat-phrase { flex: none; min-height: 32px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 16px; background: transparent; font-size: 12px; white-space: nowrap; cursor: pointer; }
.chat-phrase:hover { background: var(--surface-2); }
.chat-form { display: flex; gap: 6px; padding: 6px 10px 10px 12px; }
#chat-input { flex: 1; min-width: 0; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface-2); font-size: 14px; -webkit-user-select: text; user-select: text; }
#chat-input:focus { outline: 2px solid var(--focus); outline-offset: -1px; background: var(--surface); }
.chat-send { flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: var(--ink); color: var(--surface); cursor: pointer; }
.chat-send:hover { background: #2a4a59; }
.chat-icon:focus-visible, .chat-send:focus-visible, .chat-phrase:focus-visible, .chat-toast:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

@media (max-width: 719px) and (orientation: portrait), (pointer: coarse) and (max-width: 900px) {
  .chat-panel { left: 0; right: 0; bottom: var(--keyboard, 0px); width: auto; max-height: min(60dvh, calc(100dvh - var(--keyboard, 0px) - 56px)); border-width: 1px 0 0; border-radius: 18px 18px 0 0; padding-bottom: max(0px, env(safe-area-inset-bottom), var(--tg-inset-bottom, 0px)); box-shadow: 0 -12px 40px -12px #19303d55; animation-name: chat-sheet-in; }
  @keyframes chat-sheet-in { from { translate: 0 30%; opacity: 0; } }
  /* iOS zooms into inputs below 16px. */
  #chat-input { font-size: 16px; min-height: 44px; }
  .chat-send { width: 44px; height: 44px; }
  .chat-phrase { min-height: 36px; font-size: 13px; }
}
