/* ============================================================
   AI 助手 · 悬浮机器人 + 对话面板
   卡通形象沿用 about/join.html 首屏那只（墨色机身 · 青柠屏幕 · 紫罗兰天线），
   缩成一只坐在白色圆舱里、脑袋探出舱沿的小家伙。

   全部 .ai- 前缀，不覆写 aw.css / vibe.css 任何选择器。
   层级：滚动进度条 999 > 面板 986 > 悬浮球 984 > 顶栏 130。
   ============================================================ */

.ai-root {
  --ai-w: 384px;            /* 面板宽 */
  --ai-r: 18px;
  --ai-edge: 28px;          /* 距视口右 / 下 */
  --ai-shadow: 0 2px 6px rgba(34, 34, 34, .05), 0 18px 44px -12px rgba(34, 34, 34, .28);
  position: fixed;
  right: var(--ai-edge);
  bottom: var(--ai-edge);
  z-index: 984;
  font-family: var(--font);
  font-size: 14px;
  line-height: 22px;
}

/* ---------------------------------------------------------- 悬浮机器人 */

.ai-launch {
  position: relative;
  display: block;
  width: 66px;
  height: 66px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  /* 进场：从右下角弹进来一次，别一上来就在那儿杵着 */
  animation: aiPop .7s var(--ease) backwards .9s;
}

.ai-launch__pod {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--ai-shadow);
  transition: transform .34s var(--ease), box-shadow .34s var(--ease);
  overflow: hidden;
}

/* 青柠光晕：默认收着，hover / 有新消息时扩出来 */
.ai-launch__ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  transform: scale(.86);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  pointer-events: none;
}

.ai-launch__bot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  max-width: none;                      /* aw.css 的 svg{max-width:100%} 会把它压扁 */
  transform: translate(-50%, -50%);
  transition: scale .34s var(--ease);
  animation: aiFloat 4.4s ease-in-out infinite;
}

.ai-launch:hover .ai-launch__pod,
.ai-launch:focus-visible .ai-launch__pod { transform: scale(1.06); }
.ai-launch:hover .ai-launch__ring,
.ai-launch:focus-visible .ai-launch__ring { opacity: 1; transform: scale(1); }
.ai-launch:hover .ai-launch__bot { scale: 1.05; }
.ai-launch:hover .ai-b-arm--wave { animation: aiWave .62s ease-in-out 2; }
.ai-launch:active .ai-launch__pod { transform: scale(.97); }
.ai-launch:focus-visible { outline: none; }
.ai-launch:focus-visible .ai-launch__ring { border-color: var(--violet); }

/* 机器人配色 —— 与 join.css 里那只同源 */
.ai-bot .ai-b-body,
.ai-bot .ai-b-head,
.ai-bot .ai-b-eye   { fill: var(--ink); }
.ai-bot .ai-b-arm   { stroke: var(--ink); stroke-linecap: round; }
.ai-bot .ai-b-arm--wave { transform-origin: 36px 80px; }
.ai-bot .ai-b-ant   { stroke: var(--ink); }
.ai-bot .ai-b-scr   { fill: var(--accent); }
.ai-bot .ai-b-tag   { fill: var(--accent); }
.ai-bot .ai-b-dot   { fill: var(--violet); }
.ai-bot .ai-b-ear   { fill: #5a5a5a; }
.ai-bot .ai-b-hand  { fill: #fff; stroke: var(--ink); stroke-width: 3; }
.ai-bot .ai-b-mouth { stroke: var(--ink); fill: none; }
.ai-bot .ai-b-glare { fill: #fff; opacity: .18; }

/* 眨眼：眼睛压扁一下。用 scale 而不是换形状，省一个元素 */
.ai-bot .ai-b-eyes { transform-origin: 60px 40px; animation: aiBlink 6.2s ease-in-out infinite; }
.ai-bot .ai-b-dot  { transform-origin: 60px 2px; animation: aiAnt 2.6s ease-in-out infinite; }
/* 眼珠跟着光标偏一点点（JS 写 --ai-ex / --ai-ey，范围 ±1） */
.ai-bot .ai-b-eyes { translate: calc(var(--ai-ex, 0) * 2.4px) calc(var(--ai-ey, 0) * 1.8px); }

@keyframes aiFloat {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 -3.5px; }
}
@keyframes aiBlink {
  0%, 92%, 100% { transform: scaleY(1); }
  95%           { transform: scaleY(.12); }
}
@keyframes aiAnt {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.3); opacity: .68; }
}
@keyframes aiWave {
  0%, 100% { transform: rotate(0); }
  35%      { transform: rotate(-17deg); }
  70%      { transform: rotate(9deg); }
}
@keyframes aiPop {
  0%   { opacity: 0; transform: translateY(14px) scale(.6); }
  60%  { opacity: 1; transform: translateY(0) scale(1.06); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* 打开时悬浮球让位（缩掉，不是直接 display:none —— 关面板要能弹回来） */
.ai-root[data-open="true"] .ai-launch {
  opacity: 0;
  transform: scale(.55);
  pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--ease);
}

/* ---------------------------------------------------------- 招呼气泡 */

.ai-hi {
  position: absolute;
  right: 76px;
  bottom: 12px;
  width: max-content;
  max-width: 220px;
  padding: 11px 34px 12px 15px;
  background: var(--ink);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  font-size: 13px;
  line-height: 20px;
  font-weight: 400;
  box-shadow: var(--ai-shadow);
  opacity: 0;
  transform: translateX(8px) scale(.94);
  transform-origin: 100% 100%;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  pointer-events: none;
}
.ai-hi[data-show="true"] { opacity: 1; transform: none; pointer-events: auto; }
/* 重点色走伪元素：行内塞 <b> 会把这句话劈成两个翻译单元（见 i18n 那条教训） */
.ai-hi__t::before { content: "✦"; color: var(--accent); margin-right: 6px; }

.ai-hi__x {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
  transition: background .2s var(--ease);
}
.ai-hi__x:hover { background: rgba(255, 255, 255, .26); }

/* ---------------------------------------------------------- 面板 */

.ai-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: var(--ai-w);
  height: min(600px, calc(100vh - 2 * var(--ai-edge) - 12px));
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--ai-r);
  box-shadow: 0 4px 10px rgba(34, 34, 34, .05), 0 32px 70px -16px rgba(34, 34, 34, .34);
  overflow: hidden;
  transform-origin: 100% 100%;
  opacity: 0;
  transform: translateY(10px) scale(.94);
  pointer-events: none;
  transition: opacity .26s var(--ease), transform .3s var(--ease), visibility .3s;
  visibility: hidden;
}
.ai-root[data-open="true"] .ai-panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  visibility: visible;
}

/* 头部 */
.ai-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 14px 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.ai-head__ava {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ground);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.ai-head__ava svg { width: 30px; margin-top: 5px; }
.ai-head__id { flex: 1 1 auto; min-width: 0; }
.ai-head__name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  letter-spacing: -.01em;
}
.ai-head__live {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 242, 79, .3);
}
.ai-head__sub {
  font-size: 11.5px;
  line-height: 16px;
  color: var(--mut-2);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-head__btn {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--mut);
  cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.ai-head__btn:hover { background: var(--grey-2); color: var(--ink); }
.ai-head__btn .ai-i-close { display: none; }

/* 消息区 */
.ai-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 18px 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 34, 34, .2) transparent;
}
.ai-log::-webkit-scrollbar { width: 6px; }
.ai-log::-webkit-scrollbar-thumb { background: rgba(34, 34, 34, .18); border-radius: 3px; }

.ai-msg { display: flex; margin-bottom: 14px; animation: aiIn .34s var(--ease) both; }
.ai-msg--me { justify-content: flex-end; }

.ai-msg__b {
  max-width: 86%;
  padding: 10px 14px 11px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 23px;
  font-weight: 400;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ai-msg--ai .ai-msg__b {
  background: var(--ground);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: var(--ink);
}
.ai-msg--me .ai-msg__b {
  background: var(--ink);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.ai-msg__b strong { font-weight: 600; }
.ai-msg__b a:not(.ai-ref) { color: var(--violet); text-decoration: underline; text-underline-offset: 2px; }
.ai-msg__b code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(34, 34, 34, .07);
  padding: 1px 5px;
  border-radius: 4px;
}

@keyframes aiIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* 光标：流式输出时跟在末尾 */
.ai-caret {
  display: inline-block;
  width: 2px;
  height: 14px;
  vertical-align: -2px;
  margin-left: 2px;
  background: var(--violet);
  animation: aiCaret 1s steps(2) infinite;
}
@keyframes aiCaret { 50% { opacity: 0; } }

/* 三点等待 */
.ai-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.ai-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mut-2);
  animation: aiDot 1.3s ease-in-out infinite;
}
.ai-dots i:nth-child(2) { animation-delay: .16s; }
.ai-dots i:nth-child(3) { animation-delay: .32s; }
@keyframes aiDot {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-3px); }
}

/* 回答里带出来的页面链接 */
.ai-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
/* 胶囊在气泡里，得压过 .ai-msg__b a —— 单行、超长省略号，别撑成三行 */
.ai-msg__b .ai-ref,
.ai-ref {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 4px 10px 5px;
  text-decoration: none;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  line-height: 18px;
  font-weight: 500;
  text-decoration: none;
  transition: background .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease);
}
.ai-ref:hover { background: var(--accent); border-color: transparent; transform: translateY(-1px); }
.ai-ref svg { flex: none; opacity: .5; }
.ai-ref span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 快捷问题 */
.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 2px 18px 14px;
}
.ai-chip {
  padding: 6px 13px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 19px;
  font-weight: 400;
  cursor: pointer;
  transition: background .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease);
}
.ai-chip:hover { background: var(--ink); border-color: var(--ink); color: #fff; transform: translateY(-1px); }
.ai-chips[hidden] { display: none; }

/* 输入区 */
.ai-foot {
  flex: none;
  padding: 12px 16px 13px;
  border-top: 1px solid var(--line);
  background: var(--card);
}
.ai-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 5px 5px 5px 15px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 22px;
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.ai-form:focus-within { border-color: var(--ink); background: var(--card); }
.ai-input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 108px;
  padding: 6px 0 7px;
  border: 0;
  background: none;
  resize: none;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 22px;
  font-weight: 400;
  color: var(--ink);
  outline: none;
  scrollbar-width: none;
}
/* fx.css 给所有表单控件加了紫罗兰焦点晕；这个 textarea 没有边框，晕出来是一块
   悬空的淡紫方块。焦点由外层药丸的 :focus-within 表达，可见性不减，这里只掐晕。 */
.ai-input:focus-visible { outline: none; box-shadow: none; }
.ai-input::-webkit-scrollbar { display: none; }
.ai-input::placeholder { color: var(--mut-2); }

.ai-send {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  transition: background .2s var(--ease), transform .2s var(--ease), opacity .2s var(--ease);
}
.ai-send:hover:not(:disabled) { background: var(--violet); transform: scale(1.06); }
.ai-send:disabled { opacity: .28; cursor: default; }

.ai-tip {
  margin-top: 8px;
  padding: 0 4px;
  font-size: 11px;
  line-height: 16px;
  color: var(--mut-2);
  font-weight: 400;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.ai-tip a { color: var(--mut); text-decoration: none; border-bottom: 1px solid var(--line); }
.ai-tip a:hover { color: var(--ink); border-color: var(--ink); }

/* ---------------------------------------------------------- 移动端：整屏 */

@media (max-width: 640px) {
  .ai-root { --ai-edge: 16px; }
  .ai-panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    border: 0;
    padding-top: env(safe-area-inset-top);        /* 刘海屏别把头部顶到状态栏里 */
    padding-bottom: env(safe-area-inset-bottom);
    transform-origin: 100% 100%;
  }
  /* 整屏形态下「收起」要读作「关闭」：换成 ✕，横杠藏掉 */
  .ai-head__btn .ai-i-min { display: none; }
  .ai-head__btn .ai-i-close { display: block; }
  /* Enter / Shift+Enter 是桌面话术，手机上没有意义 */
  .ai-tip__kbd { display: none; }
  .ai-tip { justify-content: flex-end; }
  .ai-root[data-open="true"] { inset: 0; right: 0; bottom: 0; }
  .ai-hi { max-width: min(220px, 58vw); }
  .ai-launch { width: 58px; height: 58px; }
  .ai-launch__bot { width: 49px; }
}

/* 打开面板时锁住页面滚动（只在移动端整屏形态下需要） */
body.ai-lock { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .ai-launch, .ai-launch__bot, .ai-bot .ai-b-eyes, .ai-bot .ai-b-dot, .ai-bot .ai-b-arm--wave,
  .ai-msg, .ai-dots i, .ai-caret { animation: none !important; }
  .ai-panel, .ai-launch__pod, .ai-launch__bot, .ai-hi { transition-duration: .01ms !important; }
}
