/* ── Chat Widget ────────────────────────────────────────── */
#chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

/* Bubble toggle button */
#chat-bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c5cfc, #6040e0);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(124,92,252,0.5);
  transition: transform .2s, box-shadow .2s;
  position: relative;
}
#chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(124,92,252,0.7);
}
#chat-bubble svg { width: 26px; height: 26px; color: #fff; }

/* Unread badge */
#chat-unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #f87171;
  color: #fff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}
#chat-unread-badge.visible { display: flex; }

/* Chat window */
#chat-window {
  position: absolute;
  bottom: 68px;
  right: 0;
  width: 340px;
  background: #0d1025;
  border: 1px solid rgba(46,50,96,0.9);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.7), 0 0 0 1px rgba(124,92,252,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity .2s, transform .2s;
}
#chat-window.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92) translateY(8px);
}

/* Header */
.chat-header {
  background: linear-gradient(135deg, #2a1a6e, #4a2aaf);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-name { font-size: 14px; font-weight: 700; color: #fff; }
.chat-header-status { font-size: 11px; color: rgba(255,255,255,0.65); margin-top: 1px; }
.chat-header-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.65);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px;
}
.chat-header-close:hover { color: #fff; }

/* Start screen (name input) */
#chat-start {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-welcome {
  font-size: 13px;
  color: rgba(167,139,250,0.8);
  line-height: 1.5;
}
.chat-name-input {
  background: rgba(124,92,252,0.08);
  border: 1px solid rgba(124,92,252,0.2);
  border-radius: 8px;
  color: #dde1f5;
  padding: 10px 14px;
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.chat-name-input:focus {
  border-color: #7c5cfc;
  box-shadow: 0 0 0 3px rgba(124,92,252,0.12);
}
.chat-name-input::placeholder { color: rgba(107,116,168,0.8); }
.chat-start-btn {
  background: linear-gradient(135deg, #7c5cfc, #6040e0);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.chat-start-btn:hover { opacity: .85; }

/* Messages area */
#chat-messages {
  height: 280px;
  overflow-y: auto;
  padding: 14px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: rgba(124,92,252,0.25); border-radius: 2px; }

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}
.chat-msg.player { align-self: flex-end; align-items: flex-end; }
.chat-msg.admin  { align-self: flex-start; }
.chat-msg.system { align-self: center; max-width: 100%; }

.chat-bubble-msg {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}
.chat-msg.player .chat-bubble-msg {
  background: linear-gradient(135deg, #7c5cfc, #6040e0);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.admin .chat-bubble-msg {
  background: rgba(124,92,252,0.12);
  color: #dde1f5;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(124,92,252,0.15);
}
.chat-msg.system .chat-bubble-msg {
  background: transparent;
  color: rgba(167,139,250,0.5);
  font-size: 11px;
  text-align: center;
  padding: 4px 0;
}
.chat-msg-time {
  font-size: 10px;
  color: rgba(107,116,168,0.6);
  margin-top: 2px;
  padding: 0 2px;
}

/* Typing indicator */
#chat-typing-indicator {
  padding: 6px 14px;
  font-size: 11px;
  color: rgba(167,139,250,0.5);
  min-height: 22px;
  font-style: italic;
}

/* Input area */
#chat-input-area {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(46,50,96,0.8);
}
#chat-input {
  flex: 1;
  background: rgba(124,92,252,0.07);
  border: 1px solid rgba(124,92,252,0.18);
  border-radius: 8px;
  color: #dde1f5;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: 80px;
  transition: border-color .15s, box-shadow .15s;
}
#chat-input:focus {
  border-color: #7c5cfc;
  box-shadow: 0 0 0 3px rgba(124,92,252,0.1);
}
#chat-input::placeholder { color: rgba(107,116,168,0.7); }
#chat-send {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #7c5cfc, #6040e0);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s;
  align-self: flex-end;
}
#chat-send:hover { opacity: .85; }
#chat-send svg { width: 16px; height: 16px; color: #fff; }

/* Closed state */
#chat-closed-msg {
  padding: 20px;
  text-align: center;
  color: rgba(167,139,250,0.5);
  font-size: 13px;
}

@media (max-width: 400px) {
  #chat-window { width: calc(100vw - 32px); right: -8px; }
}
