/* 右下角小人助手：Canvas 骨架 + 对话面板 */

.ladder-buddy {
  position: fixed;
  right: 18px;
  bottom: 16px;
  z-index: 120;
  width: 92px;
  height: 122px;
  cursor: grab;
  touch-action: none;
  transition: transform 200ms var(--ease);
  filter: drop-shadow(0 12px 20px rgba(9, 28, 19, 0.28));
}
.ladder-buddy.grabbing { cursor: grabbing; }
.ladder-buddy:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 10px; }
.ladder-buddy canvas { display: block; width: 100%; height: 100%; }

.buddy-say {
  position: absolute;
  right: 84px;
  bottom: 74px;
  max-width: 210px;
  padding: 8px 11px;
  border: 1px solid var(--ink-green);
  border-radius: 9px;
  background: var(--cream);
  color: var(--ink-green);
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
  pointer-events: none;
}
.buddy-say.show { opacity: 1; transform: none; }
.buddy-say::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 12px;
  width: 9px;
  height: 9px;
  background: var(--cream);
  border-right: 1px solid var(--ink-green);
  border-bottom: 1px solid var(--ink-green);
  transform: rotate(-45deg);
}

/* ---------------- 对话面板 ---------------- */

.buddy-chat {
  position: fixed;
  right: 18px;
  bottom: 148px;
  z-index: 130;
  display: flex;
  flex-direction: column;
  width: min(392px, calc(100vw - 36px));
  height: min(560px, calc(100dvh - 190px));
  border: 1px solid var(--ink-green);
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink-green);
  overflow: hidden;
  box-shadow: 0 30px 80px -28px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(205, 255, 94, 0.16);
  opacity: 0;
  transform: translateY(14px) scale(0.975);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 220ms var(--ease), transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
}
.buddy-chat.open { opacity: 1; transform: none; pointer-events: auto; }
.buddy-chat[hidden] { display: none !important; }

.bc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 12px;
  background: var(--ink-green);
  color: var(--cream);
  border-bottom: 1px solid rgba(205, 255, 94, 0.4);
}
.bc-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 7px;
  background: var(--lime);
  color: var(--ink-green);
}
.bc-mark svg { width: 18px; height: 18px; }
.bc-title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.bc-title b { font-size: 14px; line-height: 1.25; letter-spacing: -0.01em; }
.bc-title span { font-size: 10px; color: rgba(244, 240, 226, 0.6); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.bc-mode {
  margin-left: auto;
  flex: none;
  padding: 3px 6px;
  border: 1px solid rgba(205, 255, 94, 0.36);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--lime);
  white-space: nowrap;
}
.bc-close {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: var(--cream);
  font-size: 19px;
  line-height: 1;
  opacity: 0.75;
}
.bc-close:hover { opacity: 1; background: rgba(244, 240, 226, 0.12); }

.bc-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bc-hello { display: flex; flex-direction: column; gap: 10px; }
.bc-hello p { font-size: 13px; line-height: 1.62; color: rgba(9, 28, 19, 0.78); }
.bc-ctx {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 9px;
  border-radius: 7px;
  background: rgba(205, 255, 94, 0.22);
  font-size: 11.5px;
  color: var(--ink-green);
}
.bc-ctx b { font-weight: 800; }

.bc-chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.bc-chips button {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 8px 9px;
  border: 1px solid rgba(9, 28, 19, 0.18);
  border-radius: 7px;
  background: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-align: left;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
    border-color var(--fast) var(--ease);
}
.bc-chips button span { font-family: var(--font-mono); font-size: 9px; color: rgba(9, 28, 19, 0.4); }
.bc-chips button:hover { background: var(--ink-green); color: var(--cream); border-color: var(--ink-green); }
.bc-chips button:hover span { color: var(--lime); }

.bc-msg { display: flex; flex-direction: column; gap: 4px; }
.bc-msg.me { align-items: flex-end; }
.bc-msg p {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
}
.bc-msg.bot p { background: #fff; border: 1px solid rgba(9, 28, 19, 0.14); color: var(--ink-green); }
.bc-msg.bot.warn p { background: #fdf6e8; border-color: rgba(143, 93, 29, 0.38); color: #6b4512; }
.bc-msg.me p { background: var(--ink-green); color: var(--cream); }
.bc-citations { font-size: 10.5px; color: var(--accent-deep); font-family: var(--font-mono); padding-left: 2px; }
.bc-jumps { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.bc-jump-btn {
  padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: var(--accent-soft); color: var(--ink-green); border: 1px solid rgba(44, 106, 76, 0.25);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.bc-jump-btn:hover { background: var(--ink-green); color: var(--lime); }
.bc-msg .bc-meta {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(9, 28, 19, 0.42);
}
.bc-msg .bc-meta::before { content: ""; width: 9px; height: 1px; background: rgba(9, 28, 19, 0.22); }

.bc-think { display: flex; align-items: center; gap: 6px; font-size: 11px; color: rgba(9, 28, 19, 0.5); }
.bc-think em {
  width: 4px; height: 4px; border-radius: 50%; background: var(--ink-green);
  animation: bcDots 760ms ease-in-out infinite;
}
.bc-think em:nth-child(3) { animation-delay: 110ms; }
.bc-think em:nth-child(4) { animation-delay: 220ms; }
@keyframes bcDots {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

.bc-form { display: flex; gap: 6px; padding: 8px 10px 4px; border-top: 1px solid rgba(9, 28, 19, 0.1); }
.bc-form input {
  flex: 1;
  height: 38px;
  padding: 0 11px;
  border: 1px solid rgba(9, 28, 19, 0.2);
  border-radius: 7px;
  background: #fff;
  font-size: 13px;
}
.bc-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(44, 106, 76, 0.12); }
.bc-form button {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 7px;
  background: var(--ink-green);
  color: var(--lime);
  font-size: 16px;
  font-weight: 800;
}
.bc-form button:disabled { opacity: 0.45; cursor: not-allowed; }
.bc-foot {
  padding: 0 12px 8px;
  font-size: 10px;
  line-height: 1.5;
  color: rgba(9, 28, 19, 0.5);
}

@media (max-width: 620px) {
  .buddy-chat { left: 10px; right: 10px; bottom: 140px; width: auto; height: min(520px, calc(100dvh - 180px)); }
  .ladder-buddy { width: 72px; height: 96px; right: 12px; bottom: 12px; }
  .buddy-say { right: 68px; bottom: 58px; max-width: 150px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .bc-think em { animation: none; }
}
