/* ==========================================================================
   看板娘 · 全站右下角
   命名一律 kb- 前缀，变量只在 .kb 作用域内声明，不污染宿主页面。
   层级 9990：低于站内浮动菜单（9999）与弹窗遮罩，高于正文。
   ========================================================================== */

.kb {
  --kb-size: 300px;
  --kb-primary: #1abfc4;
  --kb-primary-deep: #12a3a8;
  --kb-line: #e5e7eb;
  --kb-text: #1f2937;
  --kb-text-sub: #6b7280;
  --kb-radius: 8px;

  position: fixed;
  right: var(--kb-ox, 24px);
  bottom: var(--kb-oy, 0px);
  z-index: 9990;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  pointer-events: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.kb *,
.kb *::before,
.kb *::after {
  box-sizing: border-box;
}

.kb-stage {
  position: relative;
  pointer-events: auto;
  transform-origin: 50% 100%;
  animation: kb-breathe 5.2s ease-in-out infinite;
  will-change: transform;
}

.kb-img {
  display: block;
  height: var(--kb-size);
  width: auto;
  max-width: none;
  border: 0;
  user-select: none;
  -webkit-user-drag: none;
  cursor: pointer;
  transform-origin: 50% 100%;
  animation: kb-sway 9s ease-in-out infinite;
  /* 两层：一层远景落影，一层贴边勾勒轮廓 —— 她是浅色调，
     站内背景又是浅色照片，只给一层会糊在背景里。 */
  filter: drop-shadow(0 12px 18px rgba(15, 23, 42, 0.18))
    drop-shadow(0 1px 2px rgba(15, 23, 42, 0.14));
  transition: filter 0.25s ease;
}

.kb:hover .kb-img {
  filter: drop-shadow(0 16px 24px rgba(15, 23, 42, 0.24))
    drop-shadow(0 1px 2px rgba(15, 23, 42, 0.16));
}

/* 点击她时的小跳，靠 class 触发一次 */
.kb-stage.is-hop {
  animation: kb-hop 0.52s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes kb-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.008, 1.012);
  }
}

@keyframes kb-sway {
  0%,
  100% {
    transform: rotate(-0.5deg);
  }
  50% {
    transform: rotate(0.5deg);
  }
}

@keyframes kb-hop {
  0% {
    transform: translateY(0) scale(1);
  }
  35% {
    transform: translateY(-10px) scale(1.01);
  }
  70% {
    transform: translateY(2px) scale(0.995);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

/* ---------- 气泡 ---------- */

.kb-bubble {
  position: absolute;
  right: 100%;
  bottom: 70%;
  margin-right: 10px;
  width: max-content;
  max-width: 200px;
  pointer-events: auto;
  opacity: 0;
  transform: translate(6px, 6px) scale(0.94);
  transform-origin: 100% 100%;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.kb-bubble.is-in {
  opacity: 1;
  transform: translate(0, 0) scale(1);
}

.kb-bubble-inner {
  position: relative;
  background: #fff;
  border: 1px solid var(--kb-line);
  border-radius: var(--kb-radius);
  padding: 9px 30px 9px 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.kb-bubble-inner::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 16px;
  width: 9px;
  height: 9px;
  background: #fff;
  border-right: 1px solid var(--kb-line);
  border-bottom: 1px solid var(--kb-line);
  transform: rotate(-45deg);
  border-bottom-right-radius: 1px;
  box-shadow: 2px 2px 3px rgba(15, 23, 42, 0.05);
}

.kb-text {
  display: block;
  font-size: 13px;
  line-height: 1.65;
  color: var(--kb-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.kb-text::after {
  content: "|";
  margin-left: 1px;
  color: var(--kb-primary-deep);
  animation: kb-caret 1s steps(1) infinite;
}

.kb-bubble.is-typing .kb-text::after {
  opacity: 1;
}

.kb-bubble.is-done .kb-text::after {
  opacity: 0;
  animation: none;
}

@keyframes kb-caret {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.kb-bubble-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--kb-text-sub);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.kb-bubble-close:hover {
  opacity: 1;
  background: #f1f5f9;
}

.kb-bubble-close svg {
  width: 10px;
  height: 10px;
}

/* ---------- 收起按钮 ---------- */

.kb-hide {
  position: absolute;
  top: 2px;
  right: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--kb-line);
  border-radius: 50%;
  background: #fff;
  color: var(--kb-text-sub);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  opacity: 0;
  transform: scale(0.9);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.1);
  transition: opacity 0.18s ease, transform 0.18s ease, color 0.15s ease;
}

.kb-hide svg {
  width: 10px;
  height: 10px;
}

.kb:hover .kb-hide,
.kb-hide:focus-visible {
  opacity: 1;
  transform: scale(1);
}

.kb-hide:hover {
  color: var(--kb-primary-deep);
  border-color: color-mix(in srgb, var(--kb-primary) 45%, #fff);
}

/* ---------- 收起态小圆点 ---------- */

.kb-pill {
  position: relative;
  pointer-events: auto;
  width: 44px;
  height: 44px;
  margin: 0 0 18px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--kb-primary) 30%, #fff);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.14);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  opacity: 0;
  transform: scale(0.6);
}

/* display:flex 会盖掉 UA 的 [hidden]{display:none}，这一行不能少：
   pill 一旦占着布局宽度，气泡会被推远，立绘也不贴右边。 */
.kb-pill[hidden],
.kb-hide[hidden],
.kb-bubble[hidden],
.kb-stage[hidden] {
  display: none !important;
}

.kb-pill.is-in {
  opacity: 1;
  transform: scale(1);
}

.kb-pill:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.18);
}

.kb-pill img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 8%;
  display: block;
}

.kb-pill-dot {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--kb-primary);
  border: 1.5px solid #fff;
}

/* ---------- 进出场 ---------- */

.kb.is-entering .kb-stage,
.kb.is-entering .kb-pill {
  animation: kb-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes kb-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- 窄屏 ---------- */

@media (max-width: 640px) {
  /* 手机上也把气泡放她左边：上方那条横带正被浮动按钮占着，
     气泡顶上去会互相压。只把宽度收窄，别让它横跨半屏。 */
  .kb-bubble {
    max-width: 170px;
    bottom: 62%;
  }

  .kb-bubble-inner {
    padding: 8px 26px 8px 10px;
  }

  .kb-text {
    font-size: 12px;
    line-height: 1.6;
  }

  .kb-hide {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .kb-stage,
  .kb-img,
  .kb-stage.is-hop {
    animation: none;
  }
  .kb-bubble,
  .kb-hide,
  .kb-pill,
  .kb-img {
    transition: none;
  }
  .kb-text::after {
    animation: none;
  }
}
