.room-chat-toggle{display:flex;align-items:center;justify-content:center;gap:5px;position:relative;min-height:35px;padding:6px 10px;border-radius:12px;background:#7850ed;color:#fff;font-size:12px;font-weight:800;box-shadow:0 2px 0 #5b35cc}
.room-chat-toggle svg{width:18px;height:18px;display:block}
.room-chat-unread{position:absolute;right:-5px;top:-7px;min-width:19px;height:19px;padding:0 4px;display:grid;place-items:center;background:#ffcf52;color:#573700;border:2px solid #f8f6ff;border-radius:10px;font-size:10px;font-variant-numeric:tabular-nums}
.race-active .header-right .languages{display:none}
#room-chat{position:fixed;inset:auto max(16px,var(--safe-right)) auto auto;top:calc(var(--chat-viewport-top,0px) + max(12px,var(--safe-top)));margin:0;width:min(410px,calc(100% - var(--safe-left) - var(--safe-right) - 24px));height:min(580px,calc(var(--chat-viewport-height,100dvh) - var(--safe-top) - var(--safe-bottom) - 24px));max-height:none;border:1px solid #e5daf9;border-radius:24px;background:#fff;box-shadow:0 18px 80px #4b2c7a33;overflow:hidden}
#room-chat::backdrop{background:#3b285b28;backdrop-filter:blur(3px)}
.room-chat-header{display:flex;align-items:center;justify-content:space-between;gap:12px;flex:none;padding:15px 16px 12px;background:linear-gradient(125deg,#f1eaff,#f5fbff);border-bottom:1px solid #ece4f7}
.room-chat-title{font-size:19px;line-height:1.3;margin:0;color:#3f2b67;letter-spacing:-.4px}
.room-chat-hint{font-size:11px;line-height:1.4;color:#77688b;margin:4px 0 0}
.room-chat-close{width:40px;height:40px;flex:none;border-radius:12px;background:#fff;color:#76638d;font-size:26px}
.room-chat-log{display:flex;flex-direction:column;align-items:flex-start;gap:12px;flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:#cbb8ef transparent;padding:16px;touch-action:pan-y}
.room-chat-empty{margin:auto;max-width:220px;text-align:center;color:#8a779f;font-size:15px;line-height:1.6}
.room-chat-message{flex:none;max-width:88%;padding:10px 13px;border-radius:16px 16px 16px 4px;background:#f1edfa;animation:chat-arrive .16s ease-out}
.room-chat-message.is-own{align-self:flex-end;border-radius:16px 16px 4px 16px;background:#ece5ff}
.room-chat-name{display:block;font-size:11px;font-weight:800;color:#7954bd;overflow-wrap:anywhere;unicode-bidi:plaintext}
.room-chat-text{margin:4px 0 0;color:#332845;font-size:16px;line-height:1.45;white-space:pre-wrap;overflow-wrap:anywhere;unicode-bidi:plaintext}
.room-chat-delivery{display:block;font-size:10px;margin-top:5px;color:#7c6a97}
.room-chat-delivery:empty{display:none}
.room-chat-message[data-status=failed] .room-chat-delivery{color:#a75032}
.room-chat-retry{font-size:12px;font-weight:800;background:#fff;color:#7547d7;border-radius:8px;margin-top:6px;padding:6px 10px}
.room-chat-quick-list{display:flex;gap:7px;overflow-x:auto;flex:none;padding:10px 14px 8px;overscroll-behavior-x:contain;touch-action:pan-x;scrollbar-width:thin;border-top:1px solid #f0e9fa}
.room-chat-quick{white-space:nowrap;flex:none;min-width:42px;min-height:40px;padding:8px 11px;border-radius:13px;background:#f6f0ff;color:#65428e;font-size:14px;font-weight:750;border:1px solid #e8dcfa}
.room-chat-compose{display:flex;align-items:center;gap:8px;flex:none;padding:3px 14px 0}
#room-chat-input{flex:1;min-width:0;height:44px;padding:10px 12px;border:1px solid #dbcfef;border-radius:13px;background:#fcfaff;color:#332845;font:inherit;font-size:16px;outline:none;user-select:text;-webkit-user-select:text;-webkit-touch-callout:default;touch-action:auto}
#room-chat-input:focus{border-color:#9976ed;background:#f8f4ff}
.room-chat-send{height:44px;padding:0 14px;background:#7950ec;color:white;border-radius:13px;font-size:13px;font-weight:800;box-shadow:0 2px 0 #5d37c7}
.room-chat-footer{display:flex;gap:8px;align-items:center;justify-content:space-between;flex:none;min-height:30px;padding:5px 16px 10px;font-size:11px;color:#8d769f}
.room-chat-count{margin-left:auto;flex:none;font-variant-numeric:tabular-nums}.room-chat-count.is-over{color:#b64b45}
#room-chat button:focus-visible,.room-chat-toggle:focus-visible{outline:none;box-shadow:inset 0 0 0 2px #b39ae7;background:#e8ddfc;color:#48237c}
@keyframes chat-arrive{from{opacity:0;transform:translateY(5px)}to{opacity:1;transform:none}}
@media(max-width:760px){
  .room-chat-toggle{padding:5px 9px;min-height:33px;font-size:11px}
  #room-chat{inset:auto max(12px,var(--safe-right)) auto max(12px,var(--safe-left));top:calc(var(--chat-viewport-top,0px) + max(8px,var(--safe-top)));margin:0 auto;height:min(620px,calc(var(--chat-viewport-height,100dvh) - var(--safe-top) - var(--safe-bottom) - 16px))}
}
/* Narrow phones: the chat button keeps its icon (its name stays in aria-label) so the header fits. */
@media(max-width:370px){.room-chat-toggle{padding-inline:8px}.room-chat-label{display:none}}
@media(max-height:500px){
  .room-chat-header{padding:8px 12px}.room-chat-title{font-size:16px}.room-chat-hint{display:none}
  .room-chat-close{height:32px;width:32px}.room-chat-log{padding:10px 12px;gap:8px}
  .room-chat-quick-list{padding-block:6px}.room-chat-quick{min-height:36px;padding:6px 9px}
  .room-chat-footer{padding-bottom:6px;min-height:25px}
}
@media(prefers-reduced-motion:reduce){.room-chat-message{animation:none}}

/* A landscape software keyboard can leave less than 200px of visible height. */
#room-chat.is-keyboard-compact .room-chat-hint,#room-chat.is-keyboard-compact .room-chat-quick-list{display:none}
#room-chat.is-keyboard-compact .room-chat-header{padding:3px 12px}
#room-chat.is-keyboard-compact .room-chat-title{font-size:16px}
#room-chat.is-keyboard-compact .room-chat-close{width:32px;height:32px}
#room-chat.is-keyboard-compact .room-chat-log{padding:4px 12px;gap:6px}
#room-chat.is-keyboard-compact .room-chat-footer{padding:3px 16px 5px;min-height:23px}

/* Keep the inert game from extending the page when a keyboard resizes its viewport. */
html:has(#room-chat[open]){overflow:hidden}
body:has(#room-chat[open]) .app-shell{overflow:hidden}
