:root {
  --bg: #04070f;
  --bg-2: #0a1220;
  --cyan: #00e5ff;
  --cyan-soft: rgba(0, 229, 255, 0.35);
  --blue: #4d8dff;
  --purple: #7a5cff;
  --text: #c8e6f0;
  --text-dim: #5a7a8a;
  --font-ui: "SF Mono", "Cascadia Code", "Consolas", "PingFang SC", "Microsoft YaHei", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  background: radial-gradient(120% 120% at 50% 45%, var(--bg-2) 0%, var(--bg) 60%, #02040a 100%);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ===== 画布 ===== */
#core-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* ===== 叠加层 ===== */
.overlay-scan {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 229, 255, 0.012) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: overlay;
}

.overlay-grid {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 229, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(80% 80% at 50% 50%, #000 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(80% 80% at 50% 50%, #000 30%, transparent 100%);
}

/* ===== 四角边框 ===== */
.hud-corners { position: fixed; inset: 18px; z-index: 2; pointer-events: none; }
.corner {
  position: absolute; width: 34px; height: 34px;
  border: 2px solid var(--cyan-soft);
}
.corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }

/* ===== 顶部状态栏 ===== */
.hud-header {
  position: fixed; top: 34px; left: 40px; right: 40px; z-index: 3;
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan), 0 0 26px var(--cyan);
  animation: blink 2s ease-in-out infinite;
}
.brand-name {
  font-size: 20px; letter-spacing: 4px; font-weight: 600;
  color: #eafcff; text-shadow: 0 0 14px var(--cyan-soft);
}
.brand-sub {
  font-size: 10px; letter-spacing: 3px; color: var(--text-dim);
  align-self: flex-end; padding-bottom: 3px;
}
.header-stats { display: flex; gap: 34px; }
.stat { text-align: right; }
.stat-label {
  display: block; font-size: 9px; letter-spacing: 2px; color: var(--text-dim);
  margin-bottom: 3px;
}
.stat-value {
  font-size: 14px; letter-spacing: 1px; color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan-soft);
}

/* ===== 左右面板 ===== */
.hud-panel {
  position: fixed; z-index: 3; width: 220px;
  padding: 16px 18px;
  background: rgba(8, 18, 30, 0.5);
  border: 1px solid rgba(0, 229, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.hud-panel.left { left: 40px; top: 50%; transform: translateY(-50%); }
.hud-panel.right { right: 40px; top: 50%; transform: translateY(-50%); }
.panel-title {
  font-size: 10px; letter-spacing: 3px; color: var(--text-dim);
  padding-bottom: 10px; margin-bottom: 10px;
  border-bottom: 1px solid rgba(0, 229, 255, 0.15);
}

.diag-list { list-style: none; }
.diag-list li {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--text); padding: 7px 0;
}
.bar {
  width: 90px; height: 5px; background: rgba(0, 229, 255, 0.1);
  border-radius: 3px; overflow: hidden;
}
.bar i {
  display: block; height: 100%; width: var(--p, 0%);
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  box-shadow: 0 0 8px var(--cyan-soft);
  transition: width 0.5s ease;
}

.activity {
  font-size: 10px; line-height: 1.9; color: var(--text-dim);
  min-height: 120px; max-height: 160px; overflow: hidden;
}
.activity .entry { opacity: 0; animation: fadeIn 0.5s forwards; }
.activity .entry .ts { color: var(--cyan); margin-right: 6px; }

/* 活动日志：有活动亮起，几秒无新活动后自动淡出隐藏 */
.hud-panel.right { transition: opacity 0.45s ease; }
.hud-panel.right.dim { opacity: 0; pointer-events: none; }

/* ===== 对话流 ===== */
.conversation {
  position: fixed; z-index: 3;
  left: 50%; bottom: 150px; transform: translateX(-50%);
  width: min(620px, 84vw);
  display: flex; flex-direction: column; gap: 12px;
  align-items: center;
  pointer-events: none;
}
.message {
  max-width: 100%;
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  padding: 12px 18px;
  border-radius: 4px;
  background: rgba(8, 18, 30, 0.62);
  border: 1px solid rgba(0, 229, 255, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 14px; line-height: 1.7;
  animation: fadeUp 0.4s ease;
}
.message .tag {
  font-size: 9px; letter-spacing: 2px; color: var(--cyan);
  margin-right: 8px;
}
.message.user .tag { color: var(--purple); }
.message .text { color: var(--text); }
.message .meta {
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.4px;
  color: rgba(0, 229, 255, 0.45);
  text-align: right;
  user-select: text;
  -webkit-user-select: text;
}
.message .msg-imgs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.message .msg-img {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid rgba(0, 229, 255, 0.35);
  background: rgba(0, 0, 0, 0.4);
  display: block;
}
/* 视频消息：封面图 + ▶ 角标 */
.message .msg-vid {
  position: relative;
  background-size: cover;
  background-position: center;
  background-color: rgba(0, 0, 0, 0.55);
}
.message .msg-vid i {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-style: normal; font-size: 18px; color: #fff;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
}

/* ===== 底部控制 ===== */
.control-bar {
  position: fixed; bottom: 44px; left: 0; right: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.mic-btn {
  position: relative; width: 84px; height: 84px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(0, 229, 255, 0.14), rgba(0, 229, 255, 0.03));
  border: 1px solid rgba(0, 229, 255, 0.35);
  cursor: pointer; outline: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}
.mic-btn:hover { box-shadow: 0 0 30px var(--cyan-soft); }
.mic-ring {
  position: absolute; inset: -1px; border-radius: 50%;
  border: 1px solid var(--cyan-soft);
  animation: pulseRing 2.4s ease-out infinite;
}
.mic-icon {
  position: absolute; inset: 50%; width: 20px; height: 28px; transform: translate(-50%, -50%);
  border-radius: 12px;
  background: var(--cyan);
  box-shadow: 0 0 14px var(--cyan);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 15a4 4 0 0 0 4-4V6a4 4 0 1 0-8 0v5a4 4 0 0 0 4 4z'/%3E%3Cpath d='M19 11a1 1 0 1 0-2 0 5 5 0 0 1-10 0 1 1 0 1 0-2 0 7 7 0 0 0 6 6.92V21a1 1 0 1 0 2 0v-3.08A7 7 0 0 0 19 11z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 15a4 4 0 0 0 4-4V6a4 4 0 1 0-8 0v5a4 4 0 0 0 4 4z'/%3E%3Cpath d='M19 11a1 1 0 1 0-2 0 5 5 0 0 1-10 0 1 1 0 1 0-2 0 7 7 0 0 0 6 6.92V21a1 1 0 1 0 2 0v-3.08A7 7 0 0 0 19 11z'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform 0.2s ease;
}
.mic-btn.listening .mic-icon { transform: translate(-50%, -50%) scale(1.2); }
.mic-btn.listening { border-color: var(--cyan); box-shadow: 0 0 44px var(--cyan-soft); }
.mic-hint { font-size: 11px; letter-spacing: 2px; color: var(--text-dim); }

/* ===== 动画 ===== */
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes pulseRing {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.7); opacity: 0; }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .hud-panel.left { display: none; } /* 手机/小屏隐藏左侧诊断面板；右侧活动日志保留（平时自动隐藏） */
  .header-stats { gap: 16px; }
  .stat:nth-child(2) { display: none; }
}

/* ===== 手机端 ===== */
@media (max-width: 640px) {
  .hud-header { top: 22px; left: 22px; right: 22px; }
  .brand-name { font-size: 16px; letter-spacing: 3px; }
  .brand-sub { display: none; }
  .header-stats { gap: 12px; }
  .stat-label { font-size: 8px; }
  .stat-value { font-size: 12px; }
  .stat:nth-child(3) { display: none; }

  .hud-corners { inset: 12px; }
  .corner { width: 24px; height: 24px; }

  /* 活动日志：手机端改为顶部居中横幅，平时隐藏、有活动淡入几秒 */
  .hud-panel.right {
    left: 50%; right: auto; top: 74px;
    transform: translateX(-50%);
    width: min(320px, 88vw);
    padding: 10px 14px;
  }
  .hud-panel.right .panel-title { display: none; }
  .activity { min-height: 0; max-height: 92px; font-size: 11px; line-height: 1.7; }

  .conversation { bottom: 140px; width: 90vw; gap: 10px; }
  .message { padding: 10px 14px; font-size: 13px; }

  .control-bar { bottom: 30px; }
  .mic-btn { width: 74px; height: 74px; }
  .mic-hint { font-size: 10px; }
}

/* 横屏（手机高度不足时压缩） */
@media (max-height: 500px) and (orientation: landscape) {
  .conversation { bottom: 100px; }
  .control-bar { bottom: 16px; }
  .hud-header { top: 14px; }
  .brand-sub { display: none; }
  .stat:nth-child(3) { display: none; }
}

/* Knowledge base quick access */
.kb-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--txt2);
  background: rgba(99,102,241,0.12);
  border: 1px solid rgba(99,102,241,0.2);
  text-decoration: none;
  transition: all .2s ease;
}
.kb-link-btn:hover, .kb-link-btn:active {
  background: rgba(99,102,241,0.25);
  color: #fff;
  border-color: rgba(99,102,241,0.4);
}
@media (max-width: 600px) {
  .kb-link-btn { font-size: 11px; padding: 5px 8px; }
}
