/* ============================================
   AI Assistant — 花花助手 样式表
   固体物理虚拟实验室 · 玻璃拟态风格
   ============================================ */

/* ===== 浮动入口按钮 ===== */
#huahua-entry {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

#huahua-entry.panel-open {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

#huahua-entry:hover {
  transform: scale(1.08);
}

#huahua-entry:active {
  transform: scale(0.92);
}

#huahua-entry .hua-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1.5px solid rgba(168, 85, 247, 0.3);
  background: rgba(15, 15, 35, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(168, 85, 247, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  position: relative;
  animation: hua-float 4s ease-in-out infinite;
  transition: box-shadow 0.3s;
}

#huahua-entry:hover .hua-btn {
  box-shadow:
    0 6px 32px rgba(0, 0, 0, 0.6),
    0 0 60px rgba(168, 85, 247, 0.2);
  border-color: rgba(168, 85, 247, 0.5);
}

/* 呼吸光晕 */
#huahua-entry .hua-btn::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, rgba(168, 85, 247, 0.2), transparent, rgba(99, 102, 241, 0.2), transparent);
  animation: hua-ring 6s linear infinite;
  pointer-events: none;
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px), #000 100%);
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px), #000 100%);
}

#huahua-entry .hua-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: rgba(168, 85, 247, 0.7);
  font-weight: 500;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(168, 85, 247, 0.15);
}

@keyframes hua-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes hua-ring {
  to { transform: rotate(360deg); }
}

/* ===== 聊天面板 ===== */
#huahua-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  z-index: 10000;
  width: 760px;
  height: 620px;
  max-height: calc(100vh - 60px);
  max-width: calc(100vw - 40px);
  border-radius: 20px;
  background: rgba(12, 12, 30, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(168, 85, 247, 0.15);
  border-top-color: rgba(168, 85, 247, 0.25);
  box-shadow:
    0 12px 64px rgba(0, 0, 0, 0.7),
    0 0 120px rgba(168, 85, 247, 0.06);
  display: flex;
  flex-direction: row;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: center center;
}

#huahua-panel.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

/* ===== 左侧人物列 ===== */
.character-column {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(168, 85, 247, 0.08), transparent 70%);
  border-right: 1px solid rgba(168, 85, 247, 0.08);
  overflow: hidden;
  padding: 12px;
}

.character-column img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity 0.6s ease;
}

/* ===== 右侧聊天列 ===== */
.chat-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ===== 面板头部 ===== */
#huahua-panel .hua-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(168, 85, 247, 0.08);
  flex-shrink: 0;
}

#huahua-panel .hua-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(99, 102, 241, 0.1));
  border: 1.5px solid rgba(168, 85, 247, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  overflow: hidden;
  transition: all 0.3s;
}

#huahua-panel .hua-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

#huahua-panel .hua-header-info {
  flex: 1;
  min-width: 0;
}

#huahua-panel .hua-header-name {
  font-size: 15px;
  font-weight: 600;
  color: #e2e8f0;
  letter-spacing: 0.3px;
}

#huahua-panel .hua-header-sub {
  font-size: 11px;
  color: rgba(168, 85, 247, 0.6);
  margin-top: 1px;
}

#huahua-panel .hua-header-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(168, 85, 247, 0.08);
  background: transparent;
  color: rgba(148, 163, 184, 0.6);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-family: inherit;
}

#huahua-panel .hua-header-close:hover {
  background: rgba(168, 85, 247, 0.08);
  color: #e2e8f0;
  border-color: rgba(168, 85, 247, 0.15);
}

/* ===== TTS 音色菜单 ===== */
.hua-tts-picker {
  position: relative;
  flex-shrink: 0;
}

.hua-tts-picker[hidden],
.hua-tts-menu[hidden] {
  display: none !important;
}

.hua-tts-menu-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(6, 182, 212, 0.14);
  background: transparent;
  color: rgba(103, 232, 249, 0.72);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  font-family: inherit;
}

.hua-tts-menu-btn:hover,
.hua-tts-menu-btn[aria-expanded="true"] {
  background: rgba(6, 182, 212, 0.1);
  color: #cffafe;
  border-color: rgba(6, 182, 212, 0.28);
}

.hua-tts-menu {
  position: absolute;
  z-index: 30;
  top: 56px;
  right: -80px;
  display: flex;
  flex-direction: column;
  width: 300px;
  max-width: calc(100vw - 44px);
  max-height: min(303px, calc(100vh - 240px));
  overflow: hidden;
  border: 1px solid rgba(71, 85, 105, 0.72);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.98);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.46);
}

.hua-tts-menu-title {
  flex-shrink: 0;
  padding: 10px 12px 8px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid rgba(71, 85, 105, 0.45);
}

.hua-tts-choices {
  flex: 1;
  min-height: 0;
  max-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hua-tts-choice {
  position: relative;
  display: flex;
  align-items: stretch;
  min-height: 48px;
  border-bottom: 1px solid rgba(71, 85, 105, 0.32);
}

.hua-tts-choice:last-child {
  border-bottom: 0;
}

.hua-tts-choice.selected::before {
  content: '';
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 0;
  width: 3px;
  background: #22d3ee;
  border-radius: 0 2px 2px 0;
}

.hua-tts-choice-select {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 7px 8px 7px 13px;
  border: 0;
  background: transparent;
  color: #e2e8f0;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.hua-tts-choice-select:hover {
  background: rgba(30, 41, 59, 0.72);
}

.hua-tts-choice-label,
.hua-tts-choice-detail {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hua-tts-choice-label {
  font-size: 12px;
  line-height: 17px;
}

.hua-tts-choice-detail {
  color: #94a3b8;
  font-size: 10px;
  line-height: 14px;
}

.hua-tts-preview-btn {
  align-self: center;
  width: 30px;
  height: 30px;
  margin: 0 9px 0 4px;
  flex: 0 0 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(34, 211, 238, 0.18);
  border-radius: 50%;
  background: rgba(8, 145, 178, 0.08);
  color: #67e8f9;
  font-size: 10px;
  cursor: pointer;
}

.hua-tts-preview-btn:hover:not(:disabled) {
  background: rgba(8, 145, 178, 0.2);
  border-color: rgba(34, 211, 238, 0.38);
}

.hua-tts-preview-btn:disabled {
  cursor: wait;
  opacity: 0.55;
}

.hua-tts-preview-btn.loading {
  animation: hua-tts-pulse 0.8s ease-in-out infinite alternate;
}

.hua-tts-empty,
.hua-tts-feedback {
  color: #94a3b8;
  font-size: 11px;
}

.hua-tts-empty {
  padding: 14px 12px;
}

.hua-tts-feedback {
  flex-shrink: 0;
  min-height: 27px;
  padding: 6px 12px;
  border-top: 1px solid rgba(71, 85, 105, 0.4);
  color: #67e8f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes hua-tts-pulse {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

/* ===== 身份卡按钮 ===== */
.hua-status-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(168, 85, 247, 0.08);
  background: transparent;
  color: rgba(148, 163, 184, 0.6);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-family: inherit;
  margin-right: 2px;
}

.hua-status-btn:hover {
  background: rgba(168, 85, 247, 0.08);
  color: #e2e8f0;
  border-color: rgba(168, 85, 247, 0.15);
}

/* ===== 身份卡面板 ===== */
#huahua-panel .hua-status-card {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  min-height: 0;
}

#huahua-panel .hua-status-card.active {
  display: block;
}

.hua-sc-bio {
  font-size: 15px;
  line-height: 1.9;
  color: rgba(194, 204, 220, 0.92);
  padding: 20px 24px;
  background: rgba(168, 85, 247, 0.04);
  border: 1px solid rgba(168, 85, 247, 0.08);
  border-radius: 14px;
  letter-spacing: 0.3px;
}

/* ===== 语音状态提示 ===== */
.hua-voice-status {
  text-align: center;
  font-size: 11px;
  color: #ef4444;
  padding: 4px 16px;
  animation: hua-pulse-text 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes hua-pulse-text {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ===== 消息区域 ===== */
#huahua-panel .hua-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

#huahua-panel .hua-messages::-webkit-scrollbar { width: 3px; }
#huahua-panel .hua-messages::-webkit-scrollbar-track { background: transparent; }
#huahua-panel .hua-messages::-webkit-scrollbar-thumb { background: rgba(168, 85, 247, 0.15); border-radius: 2px; }

/* ===== 消息气泡 ===== */
.hua-bubble {
  max-width: 86%;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.7;
  word-break: break-word;
  animation: hua-pop 0.3s ease-out;
}

@keyframes hua-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* AI 气泡 */
.hua-bubble-ai {
  align-self: flex-start;
  max-width: 100%;
  background: rgba(168, 85, 247, 0.06);
  border: 1px solid rgba(168, 85, 247, 0.1);
  border-radius: 4px 16px 16px 16px;
  color: rgba(194, 204, 220, 0.95);
}

/* AI 气泡内 Markdown 渲染样式 */
.hua-bubble-ai p {
  margin: 4px 0;
  line-height: 1.7;
}

.hua-bubble-ai h3 {
  font-size: 14px;
  font-weight: 700;
  color: #c084fc;
  margin: 10px 0 4px;
}

.hua-bubble-ai h4 {
  font-size: 13px;
  font-weight: 600;
  color: #a78bfa;
  margin: 8px 0 3px;
}

.hua-bubble-ai hr {
  border: none;
  border-top: 1px solid rgba(168, 85, 247, 0.1);
  margin: 8px 0;
}

.hua-bubble-ai code {
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  color: #e2e8f0;
}

.hua-bubble-ai .hua-li {
  display: block;
  padding: 1px 0;
  font-size: 13px;
  line-height: 1.6;
}

.hua-bubble-ai .hua-formula {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(168, 85, 247, 0.08);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 6px 0;
  font-size: 14px;
  color: #f0f0ff;
  text-align: center;
  letter-spacing: 0;
  overflow-wrap: normal;
  word-break: normal;
  scrollbar-width: thin;
  scrollbar-color: rgba(168, 85, 247, 0.2) transparent;
}

.hua-bubble-ai .hua-formula .katex-display {
  min-width: max-content;
  margin: 0;
}

.hua-bubble-ai .hua-inline-formula {
  display: inline-block;
  max-width: 100%;
  color: #e2e8f0;
  padding: 0 2px;
  vertical-align: -0.14em;
  letter-spacing: 0;
  overflow-wrap: normal;
  word-break: normal;
}

.hua-bubble-ai .hua-formula-fallback {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-style: normal;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
}

/* 用户气泡 */
.hua-bubble-user {
  align-self: flex-end;
  background: rgba(168, 85, 247, 0.03);
  border: 1px solid rgba(168, 85, 247, 0.08);
  border-radius: 16px 4px 16px 16px;
  color: #e2e8f0;
}

/* 打字指示器 */
.hua-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 16px;
  align-self: flex-start;
}

.hua-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(168, 85, 247, 0.4);
  animation: hua-dot 1.4s infinite ease-in-out;
}

.hua-typing span:nth-child(2) { animation-delay: 0.2s; }
.hua-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes hua-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 0.8; }
}

/* 建议标签 */
.hua-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 2px 0;
  align-self: flex-start;
}

.hua-chip {
  padding: 4px 12px;
  font-size: 11px;
  color: rgba(168, 85, 247, 0.7);
  background: rgba(168, 85, 247, 0.05);
  border: 1px solid rgba(168, 85, 247, 0.08);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.hua-chip:hover {
  background: rgba(168, 85, 247, 0.1);
  color: #e2e8f0;
  border-color: rgba(168, 85, 247, 0.15);
}

/* ===== 输入区域 ===== */
#huahua-panel .hua-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(168, 85, 247, 0.06);
  flex-shrink: 0;
  align-items: center;
}

#huahua-panel .hua-input-area input {
  flex: 1;
  padding: 9px 14px;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(168, 85, 247, 0.08);
  border-radius: 10px;
  color: #e2e8f0;
  font-family: inherit;
  outline: none;
  transition: border-color 0.25s;
}

#huahua-panel .hua-input-area input:focus {
  border-color: rgba(168, 85, 247, 0.2);
}

#huahua-panel .hua-input-area input::placeholder {
  color: rgba(148, 163, 184, 0.35);
}

#huahua-panel .hua-input-area .hua-voice-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(168, 85, 247, 0.06);
  background: transparent;
  color: rgba(148, 163, 184, 0.4);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: inherit;
  opacity: 0.5;
}

#huahua-panel .hua-input-area .hua-send-btn {
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.3), rgba(99, 102, 241, 0.2));
  border: 1px solid rgba(168, 85, 247, 0.12);
  border-radius: 10px;
  color: rgba(226, 232, 240, 0.8);
  cursor: pointer;
  transition: all 0.25s;
  font-family: inherit;
  flex-shrink: 0;
}

#huahua-panel .hua-input-area .hua-send-btn:hover {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.4), rgba(99, 102, 241, 0.3));
  color: #e2e8f0;
  box-shadow: 0 2px 12px rgba(168, 85, 247, 0.12);
}

/* ===== 移动端适配 ===== */
@media (max-width: 860px) {
  #huahua-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 80px);
    max-height: none;
    max-width: none;
    border-radius: 14px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
  }
  #huahua-panel.active {
    transform: translate(-50%, -50%) scale(1);
  }
  #huahua-entry {
    bottom: 18px;
    right: 18px;
  }
  #huahua-entry .hua-btn {
    width: 48px;
    height: 48px;
    font-size: 22px;
  }
  .character-column {
    width: 140px;
  }
}

@media (max-width: 580px) {
  #huahua-panel {
    width: calc(100vw - 16px);
    border-radius: 12px;
  }
  #huahua-entry {
    bottom: 14px;
    right: 14px;
  }
  #huahua-entry .hua-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
  .character-column {
    display: none;
  }
  #huahua-panel .hua-header {
    gap: 9px;
    padding-left: 13px;
    padding-right: 13px;
  }
  #huahua-panel .hua-avatar {
    width: 48px;
    height: 48px;
  }
  .hua-tts-menu {
    right: -74px;
    width: 292px;
    max-width: calc(100vw - 36px);
  }
  #huahua-panel .hua-input-area .hua-voice-btn { display: none; }
}
