/* WebLive2D - L2D Customer Service Assistant (Game Module) */
:root {
  --l2d-primary: #0077ed;
  --l2d-primary-hover: #0060c4;
  --l2d-accent: #ff7a18;
  --l2d-bubble-bg: rgba(255, 255, 255, 0.96);
  --l2d-bubble-text: #1d1d1f;
  --l2d-bubble-border: rgba(0, 119, 237, 0.25);
  --l2d-shadow: 0 12px 36px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* 主容器 */
.l2d-assistant-container {
  position: fixed;
  bottom: 24px;
  right: 28px;
  z-index: 99998;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  user-select: none;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

.l2d-assistant-container * {
  box-sizing: border-box;
}

/* 允許互動元素點擊 */
.l2d-interactive {
  pointer-events: auto;
}

/* 對話氣泡 */
.l2d-speech-bubble {
  position: relative;
  max-width: 250px;
  margin-bottom: 8px;
  margin-right: 12px;
  padding: 10px 14px;
  background: var(--l2d-bubble-bg);
  border: 1px solid var(--l2d-bubble-border);
  border-radius: 16px 16px 4px 16px;
  box-shadow: var(--l2d-shadow);
  color: var(--l2d-bubble-text);
  font-size: 13px;
  line-height: 1.48;
  opacity: 0;
  transform: translateY(10px) scale(0.92);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(12px);
  cursor: pointer;
  word-break: break-word;
}

.l2d-speech-bubble.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.l2d-speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 18px;
  width: 12px;
  height: 12px;
  background: var(--l2d-bubble-bg);
  border-right: 1px solid var(--l2d-bubble-border);
  border-bottom: 1px solid var(--l2d-bubble-border);
  transform: rotate(45deg);
}

/* 角色本體舞台 Stage */
.l2d-avatar-stage {
  position: relative;
  width: 180px;
  height: 220px;
  cursor: pointer;
  perspective: 700px;
  transform-style: preserve-3d;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.16));
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), height 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 全身立繪模式時的舞台尺寸 */
.l2d-avatar-stage.is-fullbody {
  width: 150px;
  height: 310px;
}

/* 內部圖層包裹 - 執行呼吸動畫與滑鼠 3D 視差 */
.l2d-avatar-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: center bottom;
  animation: l2d-breathe 4s ease-in-out infinite alternate;
  transition: transform 0.12s ease-out;
}

/* 角色立繪圖片容器 */
.l2d-avatar-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.l2d-avatar-img.is-active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

/* 呼吸律動動畫 */
@keyframes l2d-breathe {
  0% {
    transform: translateY(0) scale(1, 1);
  }
  50% {
    transform: translateY(-4px) scale(1.015, 0.995);
  }
  100% {
    transform: translateY(-8px) scale(1.025, 1.01);
  }
}

/* 說話時的微頻律動 */
.l2d-talking .l2d-avatar-inner {
  animation: l2d-speaking 0.28s ease-in-out infinite alternate;
}

@keyframes l2d-speaking {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
  }
  100% {
    transform: translateY(-5px) rotate(1deg) scale(1.02);
  }
}

/* 點擊時彈跳回饋 */
.l2d-bounce {
  animation: l2d-jiggle 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes l2d-jiggle {
  0% { transform: scale(1); }
  25% { transform: scale(0.92, 1.08) translateY(-10px); }
  50% { transform: scale(1.06, 0.94) translateY(2px); }
  75% { transform: scale(0.98, 1.02) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}

/* 快捷動作工具列 */
.l2d-toolbar {
  position: absolute;
  left: -48px;
  top: 50%;
  transform: translateY(-50%) translateX(10px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  background: rgba(255, 255, 255, 0.88);
  padding: 6px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(8px);
}

.l2d-assistant-container:hover .l2d-toolbar,
.l2d-toolbar.is-locked {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0);
}

.l2d-tool-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #ffffff;
  color: #333333;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

.l2d-tool-btn:hover {
  background: var(--l2d-primary);
  color: #ffffff;
  transform: scale(1.15);
}

.l2d-tool-btn.is-active {
  background: var(--l2d-primary);
  color: #ffffff;
}

/* 工具按鈕 Tooltip */
.l2d-tool-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  right: 42px;
  top: 50%;
  transform: translateY(-50%) scale(0.85);
  background: rgba(0, 0, 0, 0.8);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: all 0.2s ease;
}

.l2d-tool-btn:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* 狀態徽章 (例如正在思考、正在說話) */
.l2d-status-pill {
  position: absolute;
  bottom: 0;
  right: 0;
  background: rgba(0, 119, 237, 0.92);
  color: #ffffff;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0, 119, 237, 0.35);
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.l2d-status-pill .pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 6px #34d399;
  animation: l2d-pulse 1.5s infinite;
}

@keyframes l2d-pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

/* 最小化徽章 Mini Badge */
.l2d-mini-launcher {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 28px;
  z-index: 99998;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--l2d-primary);
  box-shadow: var(--l2d-shadow);
  cursor: pointer;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 0;
}

.l2d-mini-launcher:hover {
  transform: scale(1.1);
}

.l2d-mini-launcher img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.l2d-assistant-container.is-minimized {
  display: none;
}

.l2d-assistant-container.is-minimized + .l2d-mini-launcher {
  display: flex;
}

/* 手機版適配 */
@media (max-width: 768px) {
  .l2d-assistant-container {
    bottom: 16px;
    right: 12px;
  }
  .l2d-avatar-stage {
    width: 135px;
    height: 165px;
  }
  .l2d-avatar-stage.is-fullbody {
    width: 115px;
    height: 235px;
  }
  .l2d-speech-bubble {
    max-width: 200px;
    font-size: 12px;
    padding: 8px 12px;
  }
  .l2d-toolbar {
    left: -40px;
    padding: 4px;
  }
  .l2d-tool-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
}


/* 與官網既有 weblive-ai-widget 深度整合樣式 */
.weblive-ai-widget {
  z-index: 99997 !important;
}

/* 隱藏舊版純圓鈕，由 L2D 角色接管開啟客服的觸發器 */
.weblive-ai-widget > .weblive-ai-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* 客服面板在角色左側展開，形成看板娘伴讀與諮詢效果 */
.weblive-ai-widget .weblive-ai-panel {
  position: fixed !important;
  right: 215px !important;
  bottom: 24px !important;
  width: min(390px, calc(100vw - 240px)) !important;
  z-index: 99999 !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22), 0 4px 16px rgba(0, 0, 0, 0.08) !important;
  border-radius: 16px !important;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease !important;
}

@media (max-width: 768px) {
  .weblive-ai-widget .weblive-ai-panel {
    right: 12px !important;
    bottom: 180px !important;
    width: calc(100vw - 24px) !important;
  }
}

