:root{
  --blue:#2563EB;--blue-d:#1D4ED8;--blue-l:#3B82F6;--blue-xl:#93C5FD;
  --indigo:#4F46E5;--purple:#7C3AED;--purple-l:#A78BFA;
  --green:#059669;--green-l:#34D399;--teal:#0D9488;
  --amber:#D97706;--amber-l:#FBBF24;--orange:#EA580C;
  --red:#EF4444;--yellow:#F59E0B;
  --slate:#2e333f;--slate-2:#1E293B;--slate-3:#334155;
  --muted:#64748B;--muted-l:#94A3B8;--muted-xl:#CBD5E1;
  --bg:#F8FAFF;--bg2:#F1F5F9;--white:#FFFFFF;
  --border:rgba(15,23,42,.07);--border-m:rgba(15,23,42,.12);
  --shadow-s:0 1px 4px rgba(15,23,42,.06);
  --shadow-m:0 4px 20px rgba(15,23,42,.08);
  --shadow-l:0 12px 48px rgba(15,23,42,.1);
  --r:12px;--r-l:18px;--r-xl:24px;
  --en:'Outfit',sans-serif;--cn:'Noto Sans SC',sans-serif;--mono:'JetBrains Mono',monospace;

  /* ── Type Scale — Major Third 1.25 ratio ── */
  --text-xs:10px;     /* 角标、badge */
  --text-sm:12.5px;   /* 辅助说明 */
  --text-base:15px;   /* 正文 */
  --text-lg:18px;     /* 小标题 */
  --text-xl:24px;     /* 区块标题 */
  --text-2xl:36px;    /* Section标题（移动端）*/
  --text-3xl:48px;    /* Section标题（桌面端）*/
  --text-hero:72px;   /* Hero主标题 */
}

/* --- HIGH-END TECH AESTHETIC - LIGHT THEME --- */
#toggle-history:hover {
  transform: scale(1.08);
  border-color: var(--accent-cyan);
  box-shadow: 0 4px 16px rgba(0, 112, 243, 0.2);
}

#toggle-history.active {
  background: linear-gradient(
    135deg,
    rgba(0, 112, 243, 0.1),
    rgba(121, 40, 202, 0.1)
  );
  border-color: var(--accent-cyan);
  box-shadow: 0 4px 16px rgba(0, 112, 243, 0.2);
}

#toggle-history.active > div {
  color: var(--accent-cyan);
}

/* When hidden we will add the class manually via JS if user clicks */
.chat-panel.hidden ~ .header #toggle-history {
  color: var(--text-primary);
  border-color: var(--glass-border);
}

.status-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  /* backdrop-filter: blur(10px); */
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #ccc;
  transition: all 0.3s;
}

.status-dot.healthy {
  background-color: #00cc66;
  box-shadow: 0 0 10px rgba(0, 204, 102, 0.5);
}

.status-dot.busy {
  background-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 112, 243, 0.5);
  animation: blink 0.5s infinite alternate;
}

.status-dot.offline {
  background-color: var(--accent-error);
  box-shadow: 0 0 10px rgba(255, 0, 85, 0.6);
  animation: blink 1s infinite alternate;
}

.status-text {
  font-family: "Inter", sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 500;
}

.track-info {
  font-family: "Inter", sans-serif;
  font-size: 0.8rem;
  color: var(--accent-cyan);
  letter-spacing: 0.5px;
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- CHAT PANEL --- */
.chat-panel {
  z-index: 15;
  position: relative;
  width: 100%;
  max-width: 1200px;
  flex: 1;
  min-height: 200px;
  background: var(--bg);
  backdrop-filter: blur(25px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  box-shadow: var(--shadow-subtle);
  /* 过渡动画 */
  opacity: 0;
  transform: translateY(30px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.3s ease;
}

.chat:not(.hidden) .chat-panel {
  opacity: 0.95;
  transform: translateY(0);
}

.panel-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
  max-height: 5rem;
}

.panel-header> .buttons{
  display: flex;
  gap: 1rem;
}

.panel-header> .buttons> button{
    font-size: 1.3rem;
    border: none;
    color: var(--red);
    background: transparent;
}

#close-chat{
  color: var(--slate-2);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-history::-webkit-scrollbar {
  width: 4px;
}
.chat-history::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 2px;
}

.message {
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  animation: fadeIn 0.4s easeOut;
}

.message.user {
  align-self: flex-end;
  background: rgba(0, 112, 243, 0.05);
  color: var(--text-primary);
  border-bottom-right-radius: 2px;
}

.message.assistant {
  align-self: flex-start;
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.message.system {
  align-self: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  background: transparent;
  font-style: italic;
  padding: 0;
}

.message.error {
  align-self: center;
  font-size: 0.75rem;
  color: var(--accent-error);
  background: rgba(255, 0, 85, 0.05);
  border: 1px solid rgba(255, 0, 85, 0.2);
  border-radius: 8px;
  padding: 8px 14px;
  max-width: 90%;
  text-align: center;
}
/* Markdown 样式微调 */
.message-content p {
  margin-bottom: 8px;
}
.message-content p:last-child {
  margin-bottom: 0;
}
.message-content code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: inherit;
}
.message-content pre {
  background: #f8f9fa;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.message-content ul,
.message-content ol {
  padding-left: 20px;
  margin: 8px 0;
}

/* --- SEND BUTTON LOADING STATE --- */
#send-btn.loading {
  background: var(--muted-xl);
  box-shadow: none;
  cursor: not-allowed;
  pointer-events: none;
  position: relative;
}
#send-btn.loading i { display: none; }
#send-btn.loading::after {
  content: '';
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- TYPING INDICATOR --- */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
}
.typing-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted-xl);
  animation: dotBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* --- AI CHOICE BUTTONS --- */
.message-content .choice-btn-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 5px;
}

.choice-btn {
  background: white;
  border: 1px solid var(--blue-l);
  color: var(--blue-l);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-weight: 500;
}

.choice-btn:hover {
  background: var(--blue-l);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 112, 243, 0.2);
}

.choice-btn:active {
  transform: translateY(0);
}

.role-label {
  font-size: 0.6rem;
  margin-bottom: 4px;
  font-weight: 700;
  opacity: 0.3;
  text-transform: uppercase;
}

/* --- BOTTOM BAR --- */
.controller {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 1200px;
  pointer-events: none;
  margin-top: auto;
  z-index: 9;
  padding: 0 20px;
  background: var(--bg);
  border-radius: 1rem;
  opacity: 0;
  transform: translateY(20px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s,
              opacity 0.3s ease 0.1s;
}
.chat:not(.hidden) .controller {
  opacity: 1;
  transform: translateY(0);
}

.footer {
  margin-top: -1rem !important; /* 抵消 #ui-layer 的 gap，使其紧贴 controller */
}

.controller-status {
  display: flex;
  width: 100%;
  justify-content: space-between;
  padding: 0 1rem;
}

.status-panel {
  display: flex;
  /* justify-content: center; */
  align-items: center;
  /* flex-wrap: wrap; */
  /* width: 100%; */
  margin-top: 5px;
}

.controller-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  /* max-width: 600px; */
  pointer-events: auto;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 1rem;
  padding: 0.5rem 1rem;
  box-shadow: var(--shadow-subtle);
}

.input-group {
  display: flex;
  flex: 1;
  /* background: white; */
  /* box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05); */
  border-radius: 0.5rem;
  padding: 8px 12px;
  border: none;
  transition: all 0.3s;
}

.input-group:focus-within {
  box-shadow: inset 0 2px 6px rgba(0, 112, 243, 0.1);
  background: var(--panel-bg);
}

#text-input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 0 12px;
  width: 100%;
  height: 3rem;
  outline: none;
  font-size: 0.95rem;
  font-family: inherit;
}

#text-input::placeholder {
  color: var(--text-dim);
}

#send-btn {
  background: linear-gradient(135deg, var(--blue-l), var(--purple-l));
  border: none;
  width: 3rem;
  height: 3rem;
  border-radius: 0.5rem;
  color: white;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 112, 243, 0.25);
  flex-shrink: 0;
}

#send-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 112, 243, 0.35);
}

#send-btn:active {
  transform: scale(0.95);
}

.main-ctrl-btn,
#toggle-history {
  position: relative;
  width: 3rem;
  height: 3rem;
  border-radius: 0.5rem;
  background: white;
  border: 1px solid var(--glass-border);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* .main-ctrl-btn:hover,
#toggle-history:hover {
  transform: scale(1.08);
  border-color: var(--accent-cyan);
  box-shadow: 0 4px 16px rgba(0, 112, 243, 0.2); 
}*/

.main-ctrl-btn.active,
#toggle-history.active {
  background: linear-gradient(
    135deg,
    rgba(0, 112, 243, 0.1),
    rgba(121, 40, 202, 0.1)
  );
  border-color: var(--accent-cyan);
  box-shadow: 0 4px 16px rgba(0, 112, 243, 0.2);
}

.main-ctrl-btn.active .mic-icon,
#toggle-history.active .mic-icon {
  color: var(--accent-cyan);
}

.mic-icon {
  font-size: 1rem;
  color: var(--text-secondary);
  transition: color 0.3s;
}

.main-ctrl-btn.recording {
  background: white;
  border-color: var(--accent-error);
  box-shadow: 0 0 0 0 rgba(255, 0, 85, 0.4);
  animation: pulse-light 1.5s infinite;
}

.main-ctrl-btn.recording .mic-icon {
  color: var(--accent-error);
}

.monitor-container {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  /* width: 100%; */
  margin-top: 4px;
}

#mini-monitor {
  width: 140px;
  height: 32px;
  opacity: 0.6;

  backdrop-filter: blur(5px);
  padding: 4px;
}

/* 3D Canvas */
#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100% - 200px); /* 减去底部高度，防止能量球进入Footer */
  z-index: 1;
  pointer-events: auto; /* Enable interaction by default */
}

/* PC Portrait Mode: Move ball above chat history */
@media (min-width: 769px) and (orientation: portrait) {
  #canvas-container {
    position: relative;
    height: 350px;
    flex-shrink: 0;
    z-index: 5;
    background: transparent;
  }
}

canvas {
  display: block;
}

/* Animations */
@keyframes blink {
  from {
    opacity: 0.4;
  }
  to {
    opacity: 1;
  }
}

@keyframes pulse-light {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 0, 85, 0.2);
  }
  70% {
    transform: scale(1.1);
    box-shadow: 0 0 0 15px rgba(255, 0, 85, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 0, 85, 0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive Sphere & UI */
@media (max-width: 768px) {
  .chat{
    padding: 1rem 1rem 5rem 1rem;
  }

  .chat-panel {
    flex: 1;
    max-width: 95%;
    width: 100%;
    min-height: 150px;
  }

  .controller {
    padding: 0 15px 15px;
    gap: 10px;
  }

  .status-panel {
    text-align: center;
  }

  .controller-main {
    gap: 0.5rem;
    padding: 6px;
    max-width: 100%;
    display: grid;
    align-items: center;
    grid-template-columns: 2fr 2fr 1fr;
    grid-template-rows: 1fr 1fr;
    justify-content: center;
    align-content: center;
    justify-items: center;
  }

  .input-group {
    grid-column: 1 / 5;
    width: 100%;
    max-width: none;
    padding: 6px 10px;
  }

  #text-input {
    font-size: 0.9rem;
    padding: 0 10px;
  }

  .main-ctrl-btn,
  #toggle-history {
    /* order: 1; */
    width: 52px;
    height: 52px;
  }

  .mic-icon {
    font-size: 1.25rem;
  }

  #toggle-history {
    grid-column: 1 / 1;
  }
  #record-btn {
    grid-column: 3 / 4;
  }

  #send-btn {
    grid-column: 4 / 5;
  }
  .monitor-container{
    display: none;
  }
}

@media (max-height: 700px) {
  .chat-panel {
    min-height: 100px;
  }
}

/* ==================== z-index 层级规范 ==================== */
/*
 * 1    - 背景装饰 (.bg-decoration)
 * 1    - canvas-container（能量球）
 * 10   - ui-layer（UI容器）
 * 15   - chat-panel（聊天面板）
 * 100  - reply-bubble（浮动气泡）
 * 1000 - guidance-tooltip（引导提示）
 */

/* ==================== Canvas 能量球容器 ==================== */

#canvas-container {
  position: absolute;
  width: 100%;
  height: calc(100% - 200px);
  z-index: 1;
  pointer-events: auto;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  background: transparent;
}

#sphere-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* 记录面板打开时的能量球位置调整 - 由JS的adjustSpherePosition()函数处理 */

/* ==================== 浮动对话气泡 ==================== */

.reply-bubble {
  position: fixed;
  right: 40px;
  top: 120px; /* 留出header的空间 */
  max-width: 420px;
  max-height: 60vh;
  background: var(--bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  z-index: 100;
  opacity: 1;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.reply-bubble.hidden {
  opacity: 0;
  transform: translateX(30px);
  pointer-events: none;
}

/* 记录面板打开时，气泡自动隐藏 */
.chat-panel:not(.hidden) ~ .reply-bubble {
  display: none !important;
}

.bubble-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.6);
}

.ai-label {
  color: var(--accent-cyan);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--text-dim);
  cursor: pointer;
  line-height: 1;
  transition: all 0.2s;
  padding: 0 5px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.close-btn:hover {
  color: var(--accent-error);
  background: rgba(255, 0, 85, 0.1);
}

.bubble-content {
  padding: 18px;
  max-height: calc(60vh - 60px);
  overflow-y: auto;
  line-height: 1.7;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.bubble-content::-webkit-scrollbar {
  width: 4px;
}

.bubble-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 2px;
}

.bubble-content::-webkit-scrollbar-track {
  background: transparent;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .reply-bubble {
    left: 15px;
    /* right: 15px; */
    max-width: none;
    /* bottom: 140px; 避免与底部控制栏重叠 */
    /* top: auto; */
    max-height: 35vh;
    border-radius: 12px;
  }

  .reply-bubble.hidden {
    transform: translateY(20px);
  }

  .bubble-header {
    padding: 12px 16px;
  }

  .bubble-content {
    padding: 14px 16px;
    max-height: calc(35vh - 50px);
  }
}

/* ==================== 引导提示动画 ==================== */

.guidance-tooltip {
  animation: fadeInOut 4s forwards;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  10% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
}

/* ==================== 响应式优化 ==================== */

/* 超宽屏适配 */
@media (min-width: 1920px) {
  .chat-panel:not(.hidden) ~ #canvas-container {
    left: 30%;
  }
}

/* 竖屏手机适配 */
@media (orientation: portrait) and (max-width: 768px) {
  #canvas-container {
    height: 60vh;
    top: 10%;
  }
}

/* ==================== 无障碍支持 ==================== */

/* 焦点可见性 */
:focus-visible {
  outline: 3px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
  .message.user {
    background: #e3f2fd;
    border: 2px solid #1976d2;
  }

  .message.assistant {
    background: #f5f5f5;
    border: 2px solid #424242;
  }

  .reply-bubble {
    border-width: 2px;
    border-color: var(--text-primary);
  }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .reply-bubble.hidden {
    transform: translateY(-50%);
  }
}

/* ==================== 打印优化 ==================== */

@media print {
  #canvas-container,
  .reply-bubble,
  .controller {
    display: none;
  }

  .chat-panel {
    width: 100%;
    max-width: none;
  }
}
