/* ==========================================================================
   Live2D 看板娘
   - 右下角常驻，可拖动，点头部 / 身体会播放不同动作
   - 只在首页与登录页出现，移动端与后台自动隐藏
   - 所有颜色都走主题变量，暗色 / 亮色自动跟随
   ========================================================================== */

#tch-waifu {
  position: fixed;
  right: 16px;
  bottom: 0;
  width: clamp(196px, 17.5vw, 242px);
  height: clamp(276px, 26vw, 352px);
  z-index: 1200;
  pointer-events: none;
  transform: translate3d(var(--waifu-x, 0px), var(--waifu-y, 0px), 0);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: transform;
}
#tch-waifu.is-dragging {
  transition: none;
  cursor: grabbing;
}
#tch-waifu.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
#tch-waifu::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 96%;
  height: 72%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 158, 199, 0.22), rgba(184, 166, 255, 0.1) 46%, transparent 70%);
  filter: blur(20px);
  opacity: 0.9;
  pointer-events: none;
}
html:not(.dark) #tch-waifu::before {
  opacity: 0.55;
}
#tch-waifu::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 1%;
  width: 46%;
  height: 12px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(20, 12, 34, 0.42), transparent 72%);
  filter: blur(4px);
  pointer-events: none;
}
html.dark #tch-waifu::after {
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.55), transparent 72%);
}

#tch-waifu-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  filter: drop-shadow(0 18px 26px rgba(24, 12, 42, 0.45));
}
html:not(.dark) #tch-waifu-canvas {
  /* 浅色天空下白裙子容易糊在一起，用一圈极细的描边把轮廓拉出来 */
  filter: drop-shadow(0 0 1px rgba(58, 40, 92, 0.42)) drop-shadow(0 16px 22px rgba(90, 60, 130, 0.26));
}
#tch-waifu.is-dragging #tch-waifu-canvas {
  cursor: grabbing;
}

/* ---------- 对话气泡 ---------- */
.tch-waifu-bubble {
  position: absolute;
  right: 4px;
  bottom: calc(100% - 6px);
  max-width: 232px;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--tch-surface-strong, rgba(255, 251, 254, 0.86));
  border: 1px solid var(--tch-border, rgba(255, 255, 255, 0.7));
  color: var(--tch-ink, #1b1e34);
  font: 12.5px/1.65 Avenir, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0.02em;
  box-shadow:
    0 18px 40px -22px rgba(20, 12, 40, 0.55),
    0 0 0 1px rgba(255, 158, 199, 0.12);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  white-space: normal;
}
.tch-waifu-bubble::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: inherit;
  border-right: 1px solid var(--tch-border, rgba(255, 255, 255, 0.7));
  border-bottom: 1px solid var(--tch-border, rgba(255, 255, 255, 0.7));
  transform: rotate(45deg);
  border-radius: 0 0 3px 0;
}
.tch-waifu-bubble.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ---------- 收起按钮 ---------- */
.tch-waifu-tools {
  position: absolute;
  top: 2px;
  right: 2px;
  display: flex;
  gap: 6px;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#tch-waifu:hover .tch-waifu-tools,
#tch-waifu:focus-within .tch-waifu-tools {
  opacity: 1;
  transform: none;
}
.tch-waifu-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--tch-border, rgba(255, 255, 255, 0.7));
  background: var(--tch-surface, rgba(255, 255, 255, 0.6));
  color: var(--tch-ink-soft, #454b63);
  cursor: pointer;
  box-shadow: 0 6px 16px -8px rgba(20, 12, 40, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: color 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}
.tch-waifu-btn:hover {
  color: var(--tch-pink, #ff9ec7);
  border-color: rgba(255, 158, 199, 0.6);
  transform: scale(1.06);
}
.tch-waifu-btn svg {
  width: 12px;
  height: 12px;
}

/* ---------- 召回按钮 ---------- */
#tch-waifu-restore {
  position: fixed;
  right: 18px;
  bottom: 6px;
  z-index: 1200;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--tch-border, rgba(255, 255, 255, 0.7));
  background: var(--tch-surface, rgba(255, 255, 255, 0.6));
  color: var(--tch-pink, #ff9ec7);
  cursor: pointer;
  box-shadow: var(--tch-shadow-sm, 0 10px 26px -14px rgba(20, 12, 40, 0.5));
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
#tch-waifu-restore:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 16px 34px -16px rgba(255, 158, 199, 0.7);
}
#tch-waifu-restore[hidden] {
  display: none;
}
#tch-waifu-restore svg {
  width: 20px;
  height: 20px;
}

/* ---------- 出现动画 ---------- */
@keyframes tch-waifu-in {
  from {
    opacity: 0;
    transform: translate3d(var(--waifu-x, 0px), calc(var(--waifu-y, 0px) + 18px), 0) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translate3d(var(--waifu-x, 0px), var(--waifu-y, 0px), 0) scale(1);
  }
}
#tch-waifu.is-ready {
  animation: tch-waifu-in 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* ---------- 移动端 / 后台：不出现 ---------- */
@media (max-width: 720px) {
  #tch-waifu,
  #tch-waifu-restore {
    display: none !important;
  }
}
body.tch-admin #tch-waifu,
body.tch-admin #tch-waifu-restore,
body.tch-browse #tch-waifu,
body.tch-browse #tch-waifu-restore {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  #tch-waifu.is-ready {
    animation: none;
  }
  .tch-waifu-bubble {
    transition: opacity 0.01ms;
  }
}

/* 看板娘出现时，把应用自带的右下快捷工具栏抬到她的头顶，避免遮挡与误触 */
body.tch-waifu-on .quick-toolbar {
  transform: translateY(-364px);
  transition: transform 0.45s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@media (max-height: 780px) {
  body.tch-waifu-on .quick-toolbar {
    transform: translateY(-296px);
  }
}
