:root { 
  --primary: #0070f3; 
  --primary-hover: #005bb5;
  --bg: #f4f7f9; 
  --card-bg: #ffffff;
  --sidebar-bg: #ffffff;
  --sidebar-header-bg: #0052b4;
  --chat-header-bg: #0070f3;
  --chat-bg: #f0f2f5;
  --input-bar-bg: #d5e7ff;
  --border-color: #ddd;
  --text-main: #333333;
  --text-sub: #6c757d;
  --text-muted: #777777;
  
  --msg-other-bg: #ffffff;
  --msg-other-text: #1e293b;
  --msg-mine-bg: #dcf8c6;           
  --msg-mine-text: #0f3818;         
  --msg-private-bg: #fff5f5;
  --msg-mine-private-bg: #fee2e2;
  --msg-private-border: #ff4757;
  --sys-msg-bg: rgba(0,0,0,0.05);
  
  --reply-tag-bg: rgba(0, 112, 243, 0.08);
  --reply-tag-hover: rgba(0, 112, 243, 0.2);
  --hover-item-bg: #e7f3ff;
  --command-active-bg: #e2e8f0;

  --private-room-bg: #f8fafc;
  --private-room-hover: #e2e8f0;
  --private-room-active-bg: #dbeafe;
  --private-room-active-text: #1d4ed8;
  --private-room-border: #cbd5e1;
}

body.dark-mode {
  --primary: #38bdf8;
  --primary-hover: #0284c7;
  --bg: #0f172a;
  --card-bg: #1e293b;
  --sidebar-bg: #1e293b;
  --sidebar-header-bg: #0f172a;
  --chat-header-bg: #1e293b;
  --chat-bg: #0f172a;
  --input-bar-bg: #1e293b;
  --border-color: #334155;
  --text-main: #f1f5f9;
  --text-sub: #94a3b8;
  --text-muted: #64748b;
  
  --msg-other-bg: #1e293b;
  --msg-other-text: #f1f5f9;
  
  --msg-mine-bg: #064e3b;           
  --msg-mine-text: #ecfdf5;         

  --msg-private-bg: #2a1215;
  --msg-mine-private-bg: #37171a;
  --msg-private-border: #ef4444;
  --sys-msg-bg: rgba(255, 255, 255, 0.06);
  
  --reply-tag-bg: rgba(56, 189, 248, 0.15);
  --reply-tag-hover: rgba(56, 189, 248, 0.3);
  --hover-item-bg: #334155;
  --command-active-bg: #334155;

  --private-room-bg: #0f172a;
  --private-room-hover: #1e293b;
  --private-room-active-bg: rgba(56, 189, 248, 0.15);
  --private-room-active-text: #38bdf8;
  --private-room-border: #334155;
}

* { 
  box-sizing: border-box; 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
}

html, body { 
  margin: 0; 
  padding: 0; 
  width: 100%; 
  height: 100%; 
  height: 100dvh; 
  overflow: hidden; 
  background: var(--bg); 
  color: var(--text-main);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.page { 
  display: none; 
  height: 100%; 
  width: 100%; 
}

.active { 
  display: flex !important; 
}

#auth-page { 
  flex-direction: column; 
  justify-content: center; 
  align-items: center; 
  background: var(--bg); 
  padding: 20px; 
  overflow-y: auto; 
}

.auth-card { 
  background: var(--card-bg); 
  color: var(--text-main);
  padding: 30px; 
  border-radius: 15px; 
  box-shadow: 0 5px 25px rgba(0,0,0,0.25); 
  width: 100%; 
  max-width: 360px; 
  transition: background-color 0.3s ease;
}

input, select, textarea { 
  display: block; 
  width: 100%; 
  padding: 10px 12px; 
  margin-bottom: 10px; 
  background: var(--bg);
  color: var(--text-main);
  border: 1px solid var(--border-color); 
  border-radius: 8px; 
  font-size: 15px; 
  outline: none; 
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

button { 
  width: 100%; 
  padding: 10px 12px; 
  border: none; 
  border-radius: 8px; 
  background: var(--primary); 
  color: #ffffff; 
  cursor: pointer; 
  font-weight: bold; 
  transition: background-color 0.2s ease;
}

button:hover {
  background: var(--primary-hover);
}

.disclaimer-box { 
  background: var(--bg); 
  border: 1px solid var(--border-color); 
  border-radius: 8px; 
  padding: 10px; 
  margin-bottom: 12px; 
  font-size: 12px; 
  color: var(--text-sub); 
  max-height: 100px; 
  overflow-y: auto; 
  line-height: 1.4; 
}

.age-check-container {
  margin-bottom: 12px;
  padding: 0 2px;
}

.age-check-label {
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.age-check-label input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

#chat-page { 
  height: 100%; 
  width: 100%; 
  display: flex; 
  flex-direction: row; 
  position: relative; 
  overflow: hidden; 
}

#sidebar { 
  width: 250px; 
  background: var(--sidebar-bg); 
  border-right: 1px solid var(--border-color); 
  display: flex; 
  flex-direction: column; 
  flex-shrink: 0; 
  z-index: 200; 
  transition: transform 0.3s ease, background-color 0.3s ease; 
}

#sidebar.collapsed { 
  transform: translateX(-100%); 
  position: absolute; 
  height: 100%; 
}

@media (max-width: 768px) {
  #sidebar { 
    position: absolute; 
    height: 100%; 
    transform: translateX(-100%); 
  }
  #sidebar:not(.collapsed) { 
    transform: translateX(0); 
    box-shadow: 5px 0 15px rgba(0,0,0,0.3); 
  }
}

#user-list { 
  flex: 1; 
  overflow-y: auto; 
}

.user-item { 
  display: flex; 
  align-items: center; 
  padding: 10px 15px; 
  border-bottom: 1px solid var(--border-color); 
  color: var(--text-main);
  cursor: pointer; 
  white-space: nowrap; 
}

.user-item:hover, .user-item.selected { 
  background: var(--hover-item-bg); 
}

.avatar-container { 
  width: 34px; 
  height: 34px; 
  margin-right: 10px; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  flex-shrink: 0; 
  cursor: pointer; 
}

.avatar-container svg { 
  width: 100%; 
  height: 100%; 
  border-radius: 50%; 
  display: block; 
  pointer-events: none; 
}

/* 🌟 修正私人聊天室清單按鈕排版，強制單行 Flex 顯示、防止房名與 ID 換行擠壓 */
#private-rooms-list button {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  width: 100% !important;
  background: var(--private-room-bg) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--private-room-border) !important;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap !important;
}

#private-rooms-list button:hover {
  background: var(--private-room-hover) !important;
}

#private-rooms-list button.bg-amber-500\/25,
#private-rooms-list button[class*="border-amber-500"] {
  background: var(--private-room-active-bg) !important;
  color: var(--private-room-active-text) !important;
  border-color: var(--private-room-active-text) !important;
  font-weight: bold !important;
}

#main { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  background: var(--card-bg); 
  min-width: 0; 
  height: 100%; 
  position: relative; 
}

#chat-header { 
  height: 48px; 
  min-height: 48px; 
  display: flex; 
  background: var(--chat-header-bg); 
  color: #ffffff; 
  align-items: center; 
  padding: 0 15px; 
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0; 
  z-index: 10; 
}

#toggle-menu { 
  background: rgba(255,255,255,0.15); 
  border: none; 
  color: #ffffff; 
  width: 32px; 
  height: 32px; 
  border-radius: 6px; 
  cursor: pointer; 
  font-size: 15px; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  margin-right: 10px; 
  flex-shrink: 0; 
}

#chat-title { 
  font-weight: bold; 
  font-size: 15px;
  display: flex; 
  align-items: center; 
  gap: 8px; 
  flex-wrap: wrap;
}

.return-lobby-btn {
  display: inline-block !important;
  width: auto !important;
  background: rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.4) !important;
  padding: 2px 8px !important;
  border-radius: 4px !important;
  font-size: 11px !important;
  font-weight: normal !important;
  cursor: pointer !important;
  margin-left: 6px !important;
  transition: background 0.2s !important;
}

.return-lobby-btn:hover {
  background: rgba(255, 255, 255, 0.35) !important;
}

.chat-messages-container { 
  flex: 1; 
  position: relative; 
  display: flex; 
  flex-direction: column; 
  min-height: 0; 
  background: var(--chat-bg); 
  /* 🌟 確保當有背景桌布圖片時，背景色自動透明不遮擋 */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#messages { 
  flex: 1; 
  overflow-y: auto; 
  padding: 12px 15px; 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  min-height: 0; 
}

#scroll-to-bottom-btn { 
  display: none; 
  position: absolute; 
  bottom: 12px; 
  left: 50%; 
  transform: translateX(-50%); 
  background: rgba(15, 23, 42, 0.85); 
  color: #38bdf8; 
  border: 1px solid rgba(56, 189, 248, 0.4); 
  padding: 6px 14px; 
  border-radius: 20px; 
  font-size: 12px; 
  font-weight: bold; 
  box-shadow: 0 4px 12px rgba(0,0,0,0.4); 
  cursor: pointer; 
  z-index: 20; 
  align-items: center; 
  gap: 6px; 
  width: auto;
  backdrop-filter: blur(4px);
  transition: all 0.2s ease;
}

body.dark-mode #scroll-to-bottom-btn {
  background: rgba(30, 41, 59, 0.9);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.5);
}

#scroll-to-bottom-btn:hover { 
  background: var(--primary); 
  color: #ffffff;
}

.msg-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  align-self: flex-start !important;
  flex-direction: row !important;
}

@media (max-width: 768px) {
  .msg-wrapper {
    align-self: flex-start;
  }
  .msg-wrapper.mine {
    align-self: flex-end !important;
    flex-direction: row-reverse !important;
  }
}

.msg { 
  background: var(--msg-other-bg); 
  color: var(--msg-other-text);
  padding: 6px 10px; 
  border-radius: 12px; 
  box-shadow: 0 1px 2px rgba(0,0,0,0.15); 
  max-width: calc(100% - 44px); 
}

.msg.mine { 
  background: var(--msg-mine-bg); 
  color: var(--msg-mine-text); 
}

.msg.private { 
  border: 2px solid var(--msg-private-border); 
  background: var(--msg-private-bg); 
}

.msg.mine.private { 
  background: var(--msg-mine-private-bg); 
  border: 2px solid var(--msg-private-border); 
}

.sys-msg { 
  align-self: center; 
  font-size: 12px; 
  color: var(--text-sub); 
  background: var(--sys-msg-bg); 
  padding: 2px 10px; 
  border-radius: 10px; 
  max-width: 100%; 
  margin: 4px 0; 
}

.msg-meta {
  display: flex;
  align-items: center;
  flex-wrap: nowrap !important;
  gap: 6px;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 6px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.msg-meta::-webkit-scrollbar {
  display: none;
}

.reply-tag {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
  user-select: none;
}

.reply-tag:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.1);
}

.reply-tag:active {
  transform: scale(0.95);
}

.reply-tag.regen-btn {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.reply-tag.regen-btn:hover {
  background: rgba(239, 68, 68, 0.4);
}

.msg-text { 
  font-size: 14px; 
  line-height: 1.35; 
  word-break: break-word; 
  white-space: pre-wrap; 
}

.msg-text a { 
  color: var(--primary); 
  text-decoration: underline; 
}

.msg.mine .msg-text a {
  color: #38bdf8; 
}

.msg-text img { 
  max-width: 100%; 
  border-radius: 6px; 
  margin-top: 4px; 
  display: block; 
}

.msg-text p { 
  margin: 0 !important; 
  padding: 0 !important; 
}

.msg-text table { 
  border-collapse: collapse; 
  width: 100%; 
  margin: 4px 0; 
  font-size: 13px; 
}

.msg-text th, .msg-text td { 
  border: 1px solid var(--border-color); 
  padding: 4px 6px; 
  text-align: left; 
}

.msg-text th { 
  background: var(--reply-tag-bg); 
  color: var(--primary); 
}

.msg-text hr { 
  border: none; 
  border-top: 1px dashed var(--border-color); 
  margin: 2px 0 !important; 
}

#input-bar { 
  padding: 8px 12px; 
  background: var(--input-bar-bg); 
  border-top: 1px solid var(--border-color); 
  flex-shrink: 0; 
  z-index: 10; 
  transition: background-color 0.3s ease;
}

.status-row { 
  font-size: 12px; 
  color: var(--text-sub); 
  margin-bottom: 6px; 
  display: flex; 
  align-items: center; 
  gap: 10px; 
  flex-wrap: nowrap;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.status-row::-webkit-scrollbar {
  height: 3px;
}

.status-row::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.status-row > * {
  flex-shrink: 0;
}

.input-row { 
  display: flex; 
  gap: 8px; 
  align-items: flex-end; 
  position: relative; 
}

.upload-btn {
  width: auto; 
  padding: 4px 8px; 
  font-size: 12px; 
  background: #6c757d; 
  margin-bottom: 0;
}

.emoji-btn {
  width: 40px; 
  height: 40px; 
  margin-bottom: 0; 
  padding: 0; 
  background: var(--bg); 
  border: 1px solid var(--border-color); 
  border-radius: 8px; 
  font-size: 18px;
  color: var(--text-main);
}

.emoji-picker {
  display: none; 
  position: absolute; 
  bottom: 52px; 
  left: 0; 
  background: var(--card-bg); 
  border: 1px solid var(--border-color); 
  padding: 8px; 
  border-radius: 12px; 
  box-shadow: 0 4px 20px rgba(0,0,0,0.3); 
  z-index: 300; 
  width: 310px; 
  max-height: 200px; 
  overflow-y: auto; 
  grid-template-columns: repeat(6, 1fr); 
  gap: 4px; 
  text-align: center; 
  font-size: 20px;
}

.emoji-picker span {
  cursor: pointer;
  user-select: none;
}

#msg-input {
  margin-bottom: 0; 
  flex: 1; 
  height: 60px; 
  padding: 8px 10px; 
  resize: none;
}

.send-btn {
  width: 75px; 
  height: 60px; 
  margin-bottom: 0; 
  padding: 0;
}

.marksix-container {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin: 6px 0;
}

.marksix-ball {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #ffffff;
  font-weight: bold;
  font-size: 16px;
  box-shadow: inset -2px -2px 6px rgba(0,0,0,0.3), 0 2px 5px rgba(0,0,0,0.2);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.ball-red { background-color: #e74c3c; }
.ball-blue { background-color: #3498db; }
.ball-green { background-color: #2ecc71; }

.command-picker {
  display: none;
  position: absolute;
  bottom: 70px;
  left: 50px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 300;
  width: 280px;
  max-height: 200px;
  overflow-y: auto;
}

.command-item {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.command-item.active {
  background: var(--command-active-bg);
}

.command-item .cmd-title {
  font-weight: bold;
  color: var(--primary);
}

.command-item .desc {
  font-size: 12px;
  color: var(--text-sub);
}

.bot-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 6px 8px 6px;
  margin-bottom: 6px;
  border-bottom: 1px dashed var(--border-color);
  white-space: nowrap;
}

.bot-bar::-webkit-scrollbar {
  height: 3px;
}

.bot-bar::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.bot-avatar-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  width: auto;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.bot-avatar-btn:hover {
  transform: scale(1.1);
  background: none;
}

.bot-avatar-btn:active {
  transform: scale(0.95);
}

.bot-avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 55%;
  border: 2px solid var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
}

.bot-avatar-circle svg {
  width: 100%;
  height: 100%;
}

.bot-avatar-name {
  font-size: 11px;
  margin-top: 3px;
  color: var(--text-main);
  font-weight: 600;
  max-width: 50px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.private-msg-user {
  color: #38bdf8 !important; 
  font-weight: bold;
}

body.dark-mode .private-msg-user {
  color: #7dd3fc !important; 
}

.private-msg-bot-speech {
  color: #f43f5e !important; 
  font-weight: bold;
}

.private-msg-bot-action {
  color: var(--text-sub) !important; 
  font-style: italic;
  font-weight: normal;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 🌈 擴大且清晰的 7 色彩虹光擴散（慢速版） */
@keyframes rainbowPulseSlow {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0.95;
    box-shadow: 
      0 0 0 0 rgba(255, 0, 0, 0.8),
      0 0 0 0 rgba(255, 127, 0, 0.8),
      0 0 0 0 rgba(255, 255, 0, 0.8),
      0 0 0 0 rgba(0, 255, 0, 0.8),
      0 0 0 0 rgba(0, 0, 255, 0.8),
      0 0 0 0 rgba(75, 0, 130, 0.8),
      0 0 0 0 rgba(143, 0, 255, 0.8);
  }
  100% {
    transform: translate(-50%, -50%) scale(6.5);
    opacity: 0;
    box-shadow: 
      0 0 70px 40px rgba(255, 0, 0, 0),
      0 0 140px 80px rgba(255, 127, 0, 0),
      0 0 210px 120px rgba(255, 255, 0, 0),
      0 0 280px 160px rgba(0, 255, 0, 0),
      0 0 350px 200px rgba(0, 0, 255, 0),
      0 0 420px 240px rgba(75, 0, 130, 0),
      0 0 490px 280px rgba(143, 0, 255, 0);
  }
}

/* 👍 Emoji 慢速彈出、扭動與脈衝 */
@keyframes thumbPopAndWobbleSlow {
  0% {
    transform: translate(-50%, -50%) scale(0.1) rotate(0deg);
    opacity: 0;
  }
  25% {
    transform: translate(-50%, -50%) scale(1.5) rotate(-20deg);
    opacity: 1;
  }
  40% {
    transform: translate(-50%, -50%) scale(1.2) rotate(20deg);
  }
  55% {
    transform: translate(-50%, -50%) scale(1.4) rotate(-15deg);
  }
  /* 急速變大變細多幾次 (脈衝) */
  70% {
    transform: translate(-50%, -50%) scale(1.7) rotate(10deg);
  }
  80% {
    transform: translate(-50%, -50%) scale(0.95) rotate(-10deg);
  }
  90% {
    transform: translate(-50%, -50%) scale(1.3) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) scale(1.1) rotate(0deg);
    opacity: 0;
  }
}
