/* ====================================================
   电子宠物狗样式表（Canvas 版）
   设计语言：深色宇宙主题 + 玻璃拟态
   功能：程序员博客的 Canvas 电子宠物狗组件
   宠物形象由 Canvas 绘制，本文件仅负责容器/面板/交互样式
   ==================================================== */


/* ====================================================
   一、关键帧动画定义
   Canvas 负责宠物自身的动画，此处仅保留 UI 容器动画
   ==================================================== */

/* --- 入场弹跳动画 --- */
@keyframes petBounceIn {
  0% {
    opacity: 0;
    transform: translateY(60px) scale(0.4);
  }
  50% {
    opacity: 1;
    transform: translateY(-10px) scale(1.06);
  }
  70% {
    transform: translateY(4px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --- 气泡完整展示：淡入 → 停留 → 淡出 --- */
@keyframes bubbleShow {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(8px) scale(0.8);
  }
  12% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  75% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-8px) scale(0.9);
  }
}

/* --- 折叠状态弹跳提示 --- */
@keyframes collapseBounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

/* --- 面板展开动画 --- */
@keyframes panelSlideIn {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --- 进度条填充动画 --- */
@keyframes barFill {
  from {
    width: 0;
  }
}


/* ====================================================
   二、宠物主容器
   固定定位在页面右下角，带入场弹跳动画
   ==================================================== */

.pet-widget {
  position: fixed;
  z-index: 9999;
  top: auto;
  left: auto;
  transition: top 0.8s ease, left 0.8s ease;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  /* 入场弹跳动画，延迟0.5s等待页面加载 */
  animation: petBounceIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: 0.5s;
  opacity: 0;
}

/* 拖拽中：取消过渡动画，跟随鼠标实时移动 */
.pet-widget.pet-dragging {
  transition: none !important;
  cursor: grabbing !important;
  z-index: 10001;
}

/* 去除移动端默认点击高亮 */
.pet-widget * {
  -webkit-tap-highlight-color: transparent;
}


/* ====================================================
   三、宠物角色容器
   作为 Canvas 的外层包裹，点击区域
   ==================================================== */

.pet-character {
  position: relative;
  width: 128px;
  height: 128px;
  cursor: grab;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 折叠时缩小为小尺寸 */
.pet-widget.pet-collapsed .pet-character {
  width: 56px;
  height: 56px;
  animation: collapseBounce 2.5s ease-in-out infinite;
}


/* ====================================================
   四、Canvas 画布
   Canvas 负责绘制宠物狗的全部视觉内容
   ==================================================== */

#pet-canvas {
  display: block;
  width: 128px;
  height: 128px;
  pointer-events: none;
}

/* 折叠时 Canvas 缩小显示头部区域 */
.pet-widget.pet-collapsed #pet-canvas {
  width: 56px;
  height: 56px;
}


/* ====================================================
   五、对话气泡
   宠物头顶出现的对话气泡，玻璃拟态 + 自动淡入淡出
   ==================================================== */

.pet-bubble {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  /* 玻璃拟态 */
  background: var(--glass-dark, rgba(15, 23, 42, 0.85));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.35));
  border-radius: 12px;
  color: #fff;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  /* 默认隐藏 */
  opacity: 0;
  visibility: hidden;
}

/* 气泡小三角（指向下方） */
.pet-bubble::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--glass-dark, rgba(15, 23, 42, 0.85));
}

/* 气泡激活状态：显示并执行完整淡入→停留→淡出动画 */
.pet-bubble--active {
  opacity: 1;
  visibility: visible;
  animation: bubbleShow 2.8s ease forwards;
}


/* ====================================================
   六、状态面板
   点击宠物后显示的玻璃拟态信息面板
   ==================================================== */

.pet-panel {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  width: 260px;
  padding: 16px;
  /* 玻璃拟态背景 */
  background: var(--glass-dark, rgba(15, 23, 42, 0.85));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.35));
  border-radius: var(--border-radius, 14px);
  box-shadow: var(--blue-glow, 0 0 20px rgba(37, 104, 239, 0.4)),
              0 8px 32px rgba(0, 0, 0, 0.3);
  color: #e2e8f0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  line-height: 1.5;
  animation: panelSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  z-index: 10;
  pointer-events: auto;
}

/* --- 面板头部：宠物名 + 等级徽章 + 关闭按钮 --- */
.pet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* 宠物名称 */
.pet-name {
  font-family: 'Fira Code', monospace;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
}

/* 等级徽章：渐变胶囊形 */
.pet-level-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--gradient-primary, linear-gradient(135deg, #2568ef 0%, #00d1b2 100%));
  border-radius: 20px;
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

/* --- 面板关闭按钮 --- */
.pet-panel-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition, all 0.3s ease);
  line-height: 1;
}

.pet-panel-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  transform: rotate(90deg);
}

/* --- 属性条容器 --- */
.pet-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

/* --- 单个属性条 --- */
.pet-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 属性标签 */
.pet-stat-label {
  font-weight: 500;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  min-width: 52px;
}

/* 属性进度条轨道 */
.pet-stat-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

/* 属性填充条 */
.pet-stat-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  animation: barFill 0.6s ease-out;
}

/* 饥饿条 - 橙色/警告色 */
.pet-stat-fill--hunger {
  background: linear-gradient(90deg, var(--warning, #f8961e), #fbbf24);
  box-shadow: 0 0 6px rgba(248, 150, 30, 0.4);
}

/* 心情条 - 粉色/危险色 */
.pet-stat-fill--mood {
  background: linear-gradient(90deg, var(--danger, #f72585), #ff6ba6);
  box-shadow: 0 0 6px rgba(247, 37, 133, 0.4);
}

/* 精力条 - 蓝色/主色 */
.pet-stat-fill--energy {
  background: linear-gradient(90deg, var(--primary, #2568ef), #6b8cff);
  box-shadow: 0 0 6px rgba(37, 104, 239, 0.4);
}

/* 属性数值（等宽字体） */
.pet-stat-value {
  font-family: 'Fira Code', monospace;
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  min-width: 24px;
  text-align: right;
}

/* --- 经验条 --- */
.pet-exp {
  margin-bottom: 14px;
}

/* 经验条头部 */
.pet-exp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 4px;
}

/* 经验填充条：渐变 */
.pet-exp-fill {
  height: 100%;
  background: var(--gradient-primary, linear-gradient(135deg, #2568ef 0%, #00d1b2 100%));
  border-radius: 2px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  animation: barFill 0.8s ease-out;
  box-shadow: 0 0 8px rgba(0, 209, 178, 0.3);
}

/* --- 操作按钮区 --- */
.pet-actions {
  display: flex;
  gap: 6px;
}

/* 操作按钮基础样式：胶囊形 */
.pet-action-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.8);
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition, all 0.3s ease);
  outline: none;
  white-space: nowrap;
}

/* 按钮通用悬停效果 */
.pet-action-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
  transform: translateY(-1px);
}

.pet-action-btn:active {
  transform: translateY(0) scale(0.97);
}

/* 喂食按钮：暖橙色光晕 */
.pet-action-btn--feed:hover {
  border-color: var(--warning, #f8961e);
  box-shadow: 0 0 8px rgba(248, 150, 30, 0.25);
}

/* 玩耍按钮：粉色光晕 */
.pet-action-btn--play:hover {
  border-color: var(--danger, #f72585);
  box-shadow: 0 0 8px rgba(247, 37, 133, 0.25);
}

/* 休息按钮：蓝色光晕 */
.pet-action-btn--rest:hover {
  border-color: var(--primary, #2568ef);
  box-shadow: 0 0 8px rgba(37, 104, 239, 0.25);
}

/* 按钮冷却禁用状态 */
.pet-action-btn.is-cooldown {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}


/* ====================================================
   七、装扮选择区
   面板内展示可切换的宠物装扮/皮肤
   ==================================================== */

/* 装扮区域标题 */
.pet-outfit-header {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 6px;
  margin-top: 4px;
}

/* 装扮列表：弹性换行网格 */
.pet-outfit-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

/* 装扮项：小方形按钮 */
.pet-outfit-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--border-radius-sm, 8px);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  position: relative;
  white-space: nowrap;
}

/* 装扮颜色预览圆点 */
.pet-outfit-preview {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* 装扮名称 */
.pet-outfit-name {
  font-size: 11px;
  color: #ffffff;
  line-height: 1;
}

/* 当前激活的装扮项：高亮边框 */
.pet-outfit-item.active {
  border-color: var(--accent, #00d1b2);
  background: rgba(0, 209, 178, 0.12);
  box-shadow: 0 0 8px rgba(0, 209, 178, 0.2);
}

/* 锁定的装扮项：半透明 + 禁止点击 */
.pet-outfit-item.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 锁定状态叠加锁图标 */
.pet-outfit-item.locked::after {
  display: none;
}

/* 非锁定的装扮项悬停效果 */
.pet-outfit-item:not(.locked):hover {
  transform: scale(1.1);
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
}


/* ====================================================
   八、折叠状态
   .pet-widget.pet-collapsed：缩小为圆形图标，仅显示头部
   ==================================================== */

.pet-widget.pet-collapsed {
  width: 56px;
  height: 56px;
  /* 圆形容器 */
  background: rgba(196, 149, 106, 0.15);
  border-radius: 50%;
  border: 1.5px solid rgba(196, 149, 106, 0.3);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

/* 折叠时隐藏面板和气泡 */
.pet-widget.pet-collapsed .pet-panel,
.pet-widget.pet-collapsed .pet-bubble {
  display: none;
}

/* 折叠状态下悬停放大提示 */
.pet-widget.pet-collapsed:hover {
  background: rgba(196, 149, 106, 0.25);
  border-color: rgba(196, 149, 106, 0.5);
  box-shadow: 0 0 16px rgba(196, 149, 106, 0.2);
}

.pet-widget.pet-collapsed:hover .pet-character {
  transform: scale(1.08);
  animation-play-state: paused;
}


/* ====================================================
   九、悬停交互
   鼠标悬停在宠物上时的反馈效果
   ==================================================== */

.pet-widget:not(.pet-collapsed):hover .pet-character {
  transform: scale(1.04);
}


/* ====================================================
   十、响应式适配
   移动端和不同屏幕尺寸的样式调整
   ==================================================== */

/* 平板及以下 */
@media screen and (max-width: 768px) {
  .pet-widget {
    bottom: 16px;
    right: 16px;
    transform: scale(0.85);
    transform-origin: bottom right;
  }

  .pet-panel {
    width: 230px;
    right: -8px;
    padding: 12px;
    font-size: 12px;
  }

  .pet-name {
    font-size: 13px;
  }

  .pet-action-btn {
    font-size: 10px;
    padding: 5px 0;
  }

  .pet-bubble {
    font-size: 11px;
    padding: 4px 10px;
  }
}

/* 小屏手机 */
@media screen and (max-width: 480px) {
  .pet-widget {
    bottom: 12px;
    right: 12px;
    transform: scale(0.75);
    transform-origin: bottom right;
  }

  .pet-panel {
    width: 210px;
    right: -16px;
    padding: 10px;
  }

  .pet-widget.pet-collapsed {
    width: 44px;
    height: 44px;
  }

  .pet-widget.pet-collapsed .pet-character {
    width: 44px;
    height: 44px;
  }

  .pet-widget.pet-collapsed #pet-canvas {
    width: 44px;
    height: 44px;
  }
}

/* 安全区域适配（避免移动端底部UI遮挡） */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .pet-widget {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }

  @media screen and (max-width: 768px) {
    .pet-widget {
      bottom: calc(16px + env(safe-area-inset-bottom));
    }
  }

  @media screen and (max-width: 480px) {
    .pet-widget {
      bottom: calc(12px + env(safe-area-inset-bottom));
    }
  }
}


/* ====================================================
   十一、辅助工具类
   ==================================================== */

/* 隐藏面板 */
.pet-panel-hidden {
  display: none !important;
}

/* 隐藏气泡 */
.pet-bubble-hidden {
  display: none !important;
}


/* ====================================================
   十二、辅助功能 - 减少动画
   尊重用户系统偏好，禁用所有动画保持静态展示
   ==================================================== */

@media (prefers-reduced-motion: reduce) {
  .pet-widget,
  .pet-widget *,
  .pet-widget *::before,
  .pet-widget *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .pet-widget {
    opacity: 1;
  }
}
