.twod-global-chat-root {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px));
  bottom: max(96px, calc(env(safe-area-inset-bottom, 0px) + 88px));
  z-index: 102500;
  font-family: Arial, sans-serif;
  pointer-events: none;
}

.twod-global-chat-root * {
  box-sizing: border-box;
}

.twod-global-chat-fab {
  pointer-events: auto;
  position: relative;
  width: 52px;
  height: 52px;
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background: rgba(10, 14, 22, 0.94);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.twod-global-chat-fab:hover {
  transform: scale(1.04);
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.twod-global-chat-root.open .twod-global-chat-fab {
  border-color: rgba(34, 211, 238, 0.55);
  background: rgba(14, 22, 34, 0.98);
}

.twod-global-chat-fab img {
  width: 30px;
  height: 30px;
  display: block;
  object-fit: contain;
}

.twod-global-chat-fab-label {
  position: absolute;
  right: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.twod-global-chat-fab:hover .twod-global-chat-fab-label {
  opacity: 1;
}

.twod-global-chat-panel {
  pointer-events: auto;
  position: absolute;
  right: 0;
  bottom: 62px;
  width: min(460px, calc(100vw - 24px));
  height: min(680px, calc(100vh - 100px));
  height: min(680px, calc(var(--app-vh, 100vh) - 100px));
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 16px;
  background: rgba(8, 12, 20, 0.98);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  transform: translateY(16px) scale(0.96);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s;
  transform-origin: bottom right;
}

.twod-global-chat-root.open .twod-global-chat-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
}

.twod-global-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.85);
}

.twod-global-chat-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
}

.twod-global-chat-head small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: rgba(148, 163, 184, 0.95);
}

.twod-global-chat-close {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(100, 116, 139, 0.35);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.twod-global-chat-feed {
  flex: 1;
  overflow: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.twod-global-chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.twod-global-chat-msg.mine {
  flex-direction: row-reverse;
}

.twod-global-chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 34px;
  background: rgba(30, 41, 59, 0.9);
}

.twod-global-chat-bubble {
  max-width: calc(100% - 46px);
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(30, 41, 59, 0.92);
  border: 1px solid rgba(100, 116, 139, 0.25);
}

.twod-global-chat-msg.mine .twod-global-chat-bubble {
  background: rgba(14, 116, 144, 0.35);
  border-color: rgba(34, 211, 238, 0.28);
}

.twod-global-chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
  font-size: 11px;
  color: rgba(148, 163, 184, 0.95);
}

.twod-global-chat-name {
  font-weight: 700;
  color: #e2e8f0;
}

.twod-global-chat-clan {
  color: #67e8f9;
}

.twod-global-chat-text {
  font-size: 14px;
  line-height: 1.45;
  color: #f1f5f9;
  white-space: pre-wrap;
  word-break: break-word;
}

.twod-global-chat-gif {
  display: block;
  max-width: 100%;
  margin-top: 6px;
  border-radius: 10px;
  max-height: 300px;
  min-height: 80px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.25);
}

.twod-global-chat-compose {
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  padding: 10px;
  background: rgba(15, 23, 42, 0.88);
}

.twod-global-chat-login-hint {
  font-size: 13px;
  line-height: 1.45;
  color: rgba(203, 213, 225, 0.95);
  text-align: center;
  padding: 8px 4px;
}

.twod-global-chat-login-hint a {
  color: #38bdf8;
}

.twod-global-chat-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.twod-global-chat-toolbtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(100, 116, 139, 0.35);
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
  cursor: pointer;
  font-size: 17px;
}

.twod-global-chat-toolbtn.active {
  border-color: rgba(34, 211, 238, 0.55);
  background: rgba(14, 116, 144, 0.35);
}

.twod-global-chat-input-row {
  display: flex;
  gap: 8px;
}

.twod-global-chat-input-row input {
  flex: 1;
  min-width: 0;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(100, 116, 139, 0.35);
  background: rgba(15, 23, 42, 0.95);
  color: #f8fafc;
  padding: 0 12px;
  font-size: 14px;
}

.twod-global-chat-send {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #0891b2, #0284c7);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.twod-global-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.twod-global-chat-picker {
  margin-bottom: 8px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid rgba(100, 116, 139, 0.25);
  background: rgba(15, 23, 42, 0.92);
  max-height: 320px;
  overflow: auto;
}

.twod-global-chat-picker.hidden {
  display: none;
}

.twod-global-chat-emoji-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.twod-global-chat-emoji-tab {
  border: 1px solid rgba(100, 116, 139, 0.3);
  background: rgba(30, 41, 59, 0.7);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
}

.twod-global-chat-emoji-tab.active {
  border-color: rgba(34, 211, 238, 0.55);
  background: rgba(14, 116, 144, 0.35);
  color: #f0f9ff;
}

.twod-global-chat-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.twod-global-chat-emoji-grid button {
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
  padding: 3px;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}

.twod-global-chat-emoji-grid button:hover {
  background: rgba(51, 65, 85, 0.85);
  transform: scale(1.06);
}

.twod-gemoji {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55em;
  height: 1.55em;
  vertical-align: -0.28em;
}

.twod-gemoji-bg {
  position: absolute;
  inset: 0;
  border-radius: 34%;
  background: linear-gradient(135deg, var(--g1, #22d3ee), var(--g2, #d946ef));
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

.twod-gemoji-char {
  position: relative;
  z-index: 1;
  font-size: 0.92em;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.twod-gemoji-btn {
  width: 36px;
  height: 36px;
}

.twod-gemoji-btn .twod-gemoji-char {
  font-size: 1.15em;
}

.twod-gemoji-sm {
  width: 1.25em;
  height: 1.25em;
  vertical-align: -0.2em;
}

.twod-gemoji-inline {
  margin: 0 1px;
}

.twod-global-chat-gif-hint {
  font-size: 11px;
  color: #67e8f9;
  margin-bottom: 6px;
  line-height: 1.35;
}

.twod-global-chat-gif-hint.hidden {
  display: none;
}

.twod-global-chat-gif-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.twod-global-chat-gif-grid button {
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
}

.twod-global-chat-gif-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.twod-global-chat-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.twod-global-chat-reaction {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(100, 116, 139, 0.35);
  background: rgba(15, 23, 42, 0.75);
  border-radius: 999px;
  padding: 2px 8px 2px 4px;
  cursor: pointer;
  color: #e2e8f0;
  font-size: 11px;
  line-height: 1;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.twod-global-chat-reaction-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  min-width: 80px;
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(8, 12, 20, 0.98);
  color: #e2e8f0;
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  z-index: 30;
}

.twod-global-chat-reaction:hover .twod-global-chat-reaction-tip,
.twod-global-chat-reaction:focus-visible .twod-global-chat-reaction-tip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.twod-global-chat-reaction:hover {
  border-color: rgba(34, 211, 238, 0.45);
  transform: translateY(-1px);
}

.twod-global-chat-reaction.mine {
  border-color: rgba(34, 211, 238, 0.65);
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(217, 70, 239, 0.16));
}

.twod-global-chat-reaction-count {
  font-weight: 700;
  min-width: 0.75em;
  text-align: center;
}

.twod-global-chat-msg-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.twod-global-chat-msg-actions button {
  border: none;
  background: transparent;
  color: rgba(148, 163, 184, 0.95);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  line-height: 1.2;
}

.twod-global-chat-msg-actions button:hover {
  color: #67e8f9;
}

.twod-global-chat-react-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.28) !important;
  background: rgba(15, 23, 42, 0.5) !important;
  cursor: pointer;
  flex-shrink: 0;
  vertical-align: middle;
}

.twod-global-chat-react-open:hover {
  border-color: rgba(34, 211, 238, 0.5) !important;
  background: rgba(30, 41, 59, 0.85) !important;
}

.twod-react-open-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
}

.twod-react-open-gemoji {
  width: 18px;
  height: 18px;
}

.twod-react-open-gemoji .twod-gemoji-char {
  font-size: 0.75em;
}

.twod-global-chat-reaction-picker {
  position: fixed;
  z-index: 102600;
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 300px;
  padding: 10px;
  border-radius: 16px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(8, 12, 20, 0.98);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.twod-global-chat-reaction-picker button {
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
  padding: 4px;
  pointer-events: auto;
}

.twod-global-chat-reaction-picker button:hover {
  background: rgba(51, 65, 85, 0.85);
  transform: scale(1.08);
}

.twod-emoji-visual {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.twod-emoji-visual .twod-emoji-fallback {
  display: none;
}

.twod-emoji-visual .twod-fluent-emoji.broken,
.twod-emoji-visual:not(:has(.twod-fluent-emoji:not(.broken))) .twod-emoji-fallback {
  display: inline-flex;
}

.twod-emoji-visual .twod-fluent-emoji.broken {
  display: none;
}

.twod-fluent-emoji {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.twod-gemoji-btn .twod-fluent-emoji,
.twod-gemoji-btn.twod-fluent-emoji {
  width: 36px;
  height: 36px;
}

.twod-gemoji-sm .twod-fluent-emoji,
.twod-gemoji-sm.twod-fluent-emoji {
  width: 22px;
  height: 22px;
}

.twod-gemoji-inline .twod-fluent-emoji,
.twod-gemoji-inline.twod-fluent-emoji {
  width: 1.45em;
  height: 1.45em;
  vertical-align: -0.28em;
}

.twod-global-chat-blocked {
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.18);
  color: #fecaca;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

.twod-global-chat-blocked strong {
  display: block;
  color: #fca5a5;
  font-size: 14px;
  margin-bottom: 6px;
}

.twod-global-chat-blocked small {
  display: block;
  margin-top: 8px;
  color: rgba(254, 202, 202, 0.82);
  font-size: 11px;
}

.twod-global-chat-blocked-reason {
  margin-top: 4px;
  color: #fde68a;
  font-size: 12px;
}

.twod-global-chat-msg-actions button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.twod-global-chat-slow-hint {
  font-size: 11px;
  color: #fbbf24;
  margin-bottom: 6px;
  min-height: 14px;
}

.twod-global-chat-gif-search {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.twod-global-chat-gif-search input {
  flex: 1;
  min-width: 0;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(100, 116, 139, 0.35);
  background: rgba(15, 23, 42, 0.95);
  color: #f8fafc;
  padding: 0 10px;
}

.twod-global-chat-empty {
  text-align: center;
  color: rgba(148, 163, 184, 0.9);
  font-size: 13px;
  padding: 24px 8px;
}

.twod-global-chat-msg.focus {
  animation: twodChatFocus 1.6s ease;
}

@keyframes twodChatFocus {
  0%, 100% { background: transparent; }
  20%, 60% { background: rgba(34, 211, 238, 0.12); border-radius: 12px; }
}

.twod-global-chat-reply-preview {
  margin-bottom: 6px;
  padding: 6px 8px;
  border-left: 3px solid rgba(34, 211, 238, 0.55);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.65);
  font-size: 12px;
  color: rgba(203, 213, 225, 0.92);
}

.twod-global-chat-reply-preview strong {
  color: #67e8f9;
}

.twod-global-chat-reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(14, 116, 144, 0.18);
  border: 1px solid rgba(34, 211, 238, 0.25);
  font-size: 12px;
  color: #e2e8f0;
}

.twod-global-chat-reply-bar button {
  border: none;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.twod-global-chat-mention {
  color: #67e8f9;
  font-weight: 700;
}

.twod-global-chat-mention-me {
  color: #fbbf24;
}

.twod-global-chat-mention-box {
  position: relative;
}

.twod-global-chat-mention-list {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  max-height: 160px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid rgba(100, 116, 139, 0.35);
  background: rgba(10, 14, 22, 0.98);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 5;
}

.twod-global-chat-mention-list.hidden {
  display: none;
}

.twod-global-chat-mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  color: #e2e8f0;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
}

.twod-global-chat-mention-item:hover,
.twod-global-chat-mention-item.active {
  background: rgba(51, 65, 85, 0.85);
}

.twod-global-chat-mention-item img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

@media (max-width: 640px) {
  .twod-global-chat-root {
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(78px, calc(env(safe-area-inset-bottom, 0px) + 72px));
  }

  .twod-global-chat-fab {
    width: 48px;
    height: 48px;
  }

  .twod-global-chat-fab img {
    width: 28px;
    height: 28px;
  }

  .twod-global-chat-fab-label {
    display: none;
  }

  .twod-global-chat-panel {
    width: calc(100vw - 16px);
    height: min(72vh, 620px);
    right: -4px;
  }

  .twod-global-chat-gif-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
