/* ===== Chat Toggle Button ===== */
#chatToggle {
  position: fixed;
  bottom: 96px;
  left: 24px;
  z-index: 400;
  background: var(--surface);
  border: 1px solid rgba(6,182,212,0.25);
  border-radius: 50px;
  padding: 9px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: border-color 0.3s, box-shadow 0.3s, opacity 0.3s, max-width 0.4s, padding 0.3s;
  font-family: 'Inter', sans-serif;
  overflow: hidden;
  max-width: 160px;
}
/* Subtle state — first visit, not yet joined */
#chatToggle.subtle {
  max-width: 28px;
  padding: 9px 10px;
  border-color: rgba(6,182,212,0.15);
  background: rgba(9,9,26,0.7);
  box-shadow: none;
}
#chatToggle.subtle .chat-toggle-label,
#chatToggle.subtle .chat-toggle-count {
  opacity: 0;
  width: 0;
  overflow: hidden;
}
#chatToggle:hover {
  max-width: 160px;
  padding: 9px 16px;
  border-color: rgba(6,182,212,0.5);
  box-shadow: 0 4px 20px rgba(6,182,212,0.15);
}
#chatToggle.subtle:hover .chat-toggle-label,
#chatToggle.subtle:hover .chat-toggle-count {
  opacity: 1;
  width: auto;
}

.chat-toggle-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--cyan);
  flex-shrink: 0;
  animation: blink 1.4s ease-in-out infinite;
}
.chat-toggle-label { white-space: nowrap; transition: opacity 0.3s, width 0.3s; }
.chat-toggle-count {
  background: var(--cyan); color: #000;
  border-radius: 10px; padding: 1px 7px;
  font-size: 11px; font-weight: 700;
  white-space: nowrap; transition: opacity 0.3s, width 0.3s;
}

/* ===== Chat Panel ===== */
#chatPanel {
  position: fixed;
  bottom: 84px;
  left: 24px;
  width: 340px;
  height: 500px;
  z-index: 400;
  background: rgba(9,9,26,0.97);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(6,182,212,0.25);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 60px rgba(0,0,0,0.7);
  transform: scale(0.95) translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  min-width: 280px;
  min-height: 300px;
  max-width: 700px;
  max-height: 800px;
}
#chatPanel.open {
  opacity: 1;
  pointer-events: all;
  transform: scale(1) translateY(0);
}
#chatPanel.expanded {
  width: 500px;
  height: 660px;
}

/* ===== Chat Header (drag handle) ===== */
.chat-header {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
}
.chat-header:active { cursor: grabbing; }
.chat-header-left { display:flex; align-items:center; gap:10px; }
.chat-header-title { font-family:'Syne',sans-serif; font-size:14px; font-weight:700; }
.chat-online-pill {
  background: rgba(6,182,212,0.1);
  border: 1px solid rgba(6,182,212,0.2);
  border-radius: 20px; padding: 2px 10px;
  font-size: 11px; font-weight: 600; color: var(--cyan);
}
.chat-icon-btn {
  background: none; border: none;
  color: var(--dim); font-size: 15px;
  cursor: pointer; padding: 4px 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.chat-icon-btn:hover { color: var(--text); background: var(--surface2); }

/* ===== Resize Handle ===== */
.chat-resize-handle {
  position: absolute;
  top: 0; right: 0;
  width: 18px; height: 18px;
  cursor: nwse-resize;
  z-index: 10;
}
.chat-resize-handle::after {
  content: '';
  position: absolute;
  top: 4px; right: 4px;
  width: 8px; height: 8px;
  border-top: 2px solid rgba(6,182,212,0.3);
  border-right: 2px solid rgba(6,182,212,0.3);
  border-radius: 1px;
}

/* ===== Online Users ===== */
.chat-users {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 6px;
  overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none;
}
.chat-users::-webkit-scrollbar { display:none; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--purple2);
  flex-shrink: 0;
}
.user-avatar.author {
  background: rgba(6,182,212,0.15);
  border-color: var(--cyan); color: var(--cyan);
}

/* ===== Messages ===== */
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 12px; display: flex;
  flex-direction: column; gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
}
.chat-messages::-webkit-scrollbar { width:4px; }
.chat-messages::-webkit-scrollbar-thumb { background:var(--surface2); border-radius:2px; }

.chat-msg { display:flex; flex-direction:column; gap:2px; animation:fadeUp 0.2s ease; }
.chat-msg-system { text-align:center; font-size:11px; color:var(--dim); padding:4px 0; }
.chat-msg-header { display:flex; align-items:baseline; gap:6px; }
.chat-msg-name { font-size:12px; font-weight:700; color:var(--purple2); }
.chat-msg-name.author { color:var(--cyan); }
.chat-msg-time { font-size:10px; color:var(--dim); }
.chat-msg-bubble {
  background: var(--surface2); border:1px solid var(--border);
  border-radius:10px 10px 10px 3px;
  padding:8px 12px; font-size:13px; line-height:1.6;
  color:var(--text); max-width:92%; word-break:break-word;
}
.chat-msg.author-msg .chat-msg-bubble {
  background:rgba(6,182,212,0.07); border-color:rgba(6,182,212,0.2);
}
.chat-msg.own-msg { align-items:flex-end; }
.chat-msg.own-msg .chat-msg-bubble {
  background:rgba(139,92,246,0.12); border-color:rgba(139,92,246,0.25);
  border-radius:10px 10px 3px 10px;
}
.chat-msg.own-msg .chat-msg-name { color:var(--purple2); }

/* ===== Input ===== */
.chat-input-row {
  padding: 10px 12px; border-top:1px solid var(--border);
  display:flex; gap:8px; flex-shrink:0;
}
.chat-input {
  flex:1; background:var(--surface2);
  border:1px solid var(--border); border-radius:8px;
  padding:9px 12px; font-size:13px; color:var(--text);
  outline:none; font-family:'Inter',sans-serif;
  height:38px; transition:border-color 0.2s;
}
.chat-input:focus { border-color:var(--purple); }
.chat-send-btn {
  background:var(--purple); border:none; border-radius:8px;
  color:#fff; width:38px; height:38px; font-size:15px;
  cursor:pointer; transition:background 0.15s; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
}
.chat-send-btn:hover { background:var(--purple2); }
.chat-send-btn:disabled { opacity:0.5; cursor:not-allowed; }

/* ===== Typing Indicator ===== */
.typing-bubble {
  display:flex !important; align-items:center;
  gap:5px; padding:10px 16px !important; width:fit-content;
}
.typing-dot {
  width:7px; height:7px; border-radius:50%;
  background:var(--cyan); opacity:0.4;
  animation:typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay:0.2s; }
.typing-dot:nth-child(3) { animation-delay:0.4s; }
@keyframes typingBounce {
  0%,60%,100% { transform:translateY(0); opacity:0.4; }
  30%          { transform:translateY(-5px); opacity:1; }
}

/* ===== Name Modal ===== */
#nameModal {
  position:fixed; inset:0; z-index:600;
  background:rgba(4,4,14,0.9); backdrop-filter:blur(10px);
  display:flex; align-items:center; justify-content:center; padding:24px;
  opacity:0; pointer-events:none; transition:opacity 0.25s;
}
#nameModal.open { opacity:1; pointer-events:all; }
.name-modal-box {
  background:var(--surface); border:1px solid rgba(6,182,212,0.3);
  border-radius:16px; padding:36px; max-width:360px; width:100%; text-align:center;
}
.name-modal-icon { font-size:36px; margin-bottom:12px; }
.name-modal-title { font-family:'Syne',sans-serif; font-size:20px; font-weight:800; margin-bottom:8px; }
.name-modal-sub { font-size:13px; color:var(--dim); margin-bottom:20px; line-height:1.6; }
.name-modal-input {
  width:100%; background:var(--bg); border:1px solid var(--border);
  border-radius:8px; padding:12px 16px; font-size:14px; color:var(--text);
  outline:none; margin-bottom:12px; font-family:'Inter',sans-serif; text-align:center;
}
.name-modal-input:focus { border-color:var(--cyan); }
.name-error { font-size:12px; color:var(--red); margin-bottom:10px; min-height:16px; }

/* ===== Host Mode ===== */
.host-login-btn {
  opacity: 0.18;
  font-size: 12px !important;
  transition: opacity 0.2s !important;
}
.host-login-btn:hover { opacity: 0.7 !important; }

#chatPanel.host-mode .chat-header { border-bottom-color: rgba(6,182,212,0.4); }
#chatPanel.host-mode .chat-input  { border-color: rgba(6,182,212,0.4); color: var(--cyan); }
#chatPanel.host-mode .chat-send-btn { background: var(--cyan); }
#chatPanel.host-mode .chat-send-btn:hover { background: #0891b2; }

/* ===== Host Modal ===== */
#hostModal {
  position: fixed; inset: 0; z-index: 700;
  background: rgba(4,4,14,0.85); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#hostModal.open { opacity: 1; pointer-events: all; }

/* ===== Animations ===== */
@keyframes fadeUp {
  from { opacity:0; transform:translateY(6px); }
  to   { opacity:1; transform:translateY(0); }
}

/* ===== Mobile ===== */
@media(max-width:480px) {
  #chatPanel { left:8px; right:8px; width:auto; bottom:76px; }
  #chatToggle { left:16px; bottom:88px; }
  #chatPanel.expanded { width:auto; height:70vh; }
}
