/* 桌宠页面 — 兼容 iOS 12 Safari（constant()/env() 双写安全区） */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f3f0e9;
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: linear-gradient(180deg, #dce9fb 0%, #eef1ea 52%, #f6efdf 100%);
  touch-action: none;
}

/* ---- 分 agent 徽章条 ---- */
#badges {
  position: absolute;
  top: calc(8px + constant(safe-area-inset-top));
  top: calc(8px + env(safe-area-inset-top));
  left: calc(10px + constant(safe-area-inset-left));
  left: calc(10px + env(safe-area-inset-left));
  right: calc(150px + constant(safe-area-inset-right));
  right: calc(150px + env(safe-area-inset-right));
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  gap: 6px;
  z-index: 30;
}

.badge {
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  white-space: nowrap;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(74, 90, 120, 0.22);
  color: #38455f;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  box-shadow: 0 2px 8px rgba(46, 64, 96, 0.14);
}

.badge .dot {
  width: 11px; height: 11px;
  margin-right: 7px;
  border-radius: 50%;
  background: #8a96ad;
}

.badge.is-thinking .dot   { background: #f2c94c; }
.badge.is-coding .dot     { background: #56ccf2; }
.badge.is-done .dot       { background: #6fcf97; }
.badge.is-error .dot      { background: #eb5757; }
.badge.is-attention .dot  { background: #f2994a; }

.badge.is-attention,
.badge.is-error {
  -webkit-animation: breathe 1s ease-in-out infinite;
  animation: breathe 1s ease-in-out infinite;
  color: #7a2020;
  background: rgba(255, 241, 230, 0.92);
  border-color: rgba(200, 80, 40, 0.45);
}

@-webkit-keyframes breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* ---- 对话气泡：贴人物右侧。锚点收进画布包围盒（模型两侧有透明边距），
     尾巴指向人物 ---- */
#bubble {
  position: absolute;
  left: calc(50% + 132px);
  top: 52vh;
  max-width: calc(50vw - 146px);
  padding: 12px 18px;
  background: #ffffff;
  color: #2a3242;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 16px;
  border: 1px solid rgba(74, 90, 120, 0.16);
  box-shadow: 0 4px 14px rgba(46, 64, 96, 0.18);
  text-align: left;
  z-index: 20;
  word-break: break-all;
}

#bubble::after {
  content: "";
  position: absolute;
  left: -8px;
  top: 20px;
  border-width: 8px 8px 8px 0;
  border-style: solid;
  border-color: transparent #ffffff transparent transparent;
}

#bubble.hidden { display: none; }

/* ---- 主宠舞台位 ---- */
#pet-holder {
  position: absolute;
  left: 50%;
  bottom: calc(24px + constant(safe-area-inset-bottom));
  bottom: calc(24px + env(safe-area-inset-bottom));
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  width: min(72vw, 340px);
  height: min(58vh, 360px);
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: end;
  -ms-flex-align: end;
  align-items: flex-end;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  z-index: 10;
}

#pet-holder canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- 连接角标 ---- */
#chip {
  position: absolute;
  left: calc(10px + constant(safe-area-inset-left));
  left: calc(10px + env(safe-area-inset-left));
  bottom: calc(8px + constant(safe-area-inset-bottom));
  bottom: calc(8px + env(safe-area-inset-bottom));
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(74, 90, 120, 0.18);
  color: #4a5a75;
  font-size: 12px;
  z-index: 30;
}

#chip-dot {
  width: 7px; height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #f2c94c;
}
#chip.online  #chip-dot { background: #6fcf97; }
#chip.offline #chip-dot { background: #eb5757; }

/* ---- 求关注降噪：stale=超45s自动安静；muted=用户点了「稍后再说」 ---- */
.badge.is-attention.quiet,
.badge.is-attention.muted {
  -webkit-animation: none;
  animation: none;
}
.badge.muted { opacity: 0.55; }
.badge.muted .dot { background: #c9b28a; }

/* ---- 形象切换按钮（live2d 任务启用） ---- */
#model-btn {
  position: absolute;
  top: calc(8px + constant(safe-area-inset-top));
  top: calc(8px + env(safe-area-inset-top));
  right: calc(10px + constant(safe-area-inset-right));
  right: calc(10px + env(safe-area-inset-right));
  width: 38px; height: 38px;
  border: 1px solid rgba(74, 90, 120, 0.22);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 2px 8px rgba(46, 64, 96, 0.14);
  font-size: 19px;
  line-height: 38px;
  text-align: center;
  color: #38455f;
  z-index: 40;
}
#model-btn.hidden { display: none; }

/* 人物下拉选择器：位于切换按钮正下方，避免与顶部徽章条重叠 */
#model-select {
  position: absolute;
  top: calc(54px + constant(safe-area-inset-top));
  top: calc(54px + env(safe-area-inset-top));
  right: calc(10px + constant(safe-area-inset-right));
  right: calc(10px + env(safe-area-inset-right));
  height: 38px;
  max-width: 132px;
  padding: 0 8px;
  border: 1px solid rgba(74, 90, 120, 0.22);
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 2px 8px rgba(46, 64, 96, 0.14);
  font-size: 13px;
  color: #38455f;
  z-index: 40;
}
#model-select.hidden { display: none; }

/* 横屏：人物更宽更高，气泡锚点与头部位置同步 */
@media (orientation: landscape) {
  #pet-holder {
    width: min(46vw, 560px);
    height: min(76vh, 620px);
  }
  #bubble {
    left: calc(50% + 224px);
    top: 30vh;
    max-width: calc(50vw - 240px);
    font-size: 15px;
  }
}

/* ---- 徽章点按详情（iOS 无悬停的替代） ---- */
#badge-tip {
  position: absolute;
  top: calc(96px + constant(safe-area-inset-top));
  top: calc(96px + env(safe-area-inset-top));
  left: calc(10px + constant(safe-area-inset-left));
  left: calc(10px + env(safe-area-inset-left));
  right: calc(150px + constant(safe-area-inset-right));
  right: calc(150px + env(safe-area-inset-right));
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(74, 90, 120, 0.2);
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(46, 64, 96, 0.18);
  color: #38455f;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-line;   /* iOS 12 支持：保留 \n 换行 */
  word-break: break-all;
  z-index: 35;
  pointer-events: none;    /* 纯展示，不挡下方点击 */
}
#badge-tip.hidden { display: none; }
/* 浮层内的「稍后再说」按钮要能点（浮层本身 pointer-events:none） */
#badge-tip button {
  pointer-events: auto;
  margin-top: 8px;
  padding: 6px 14px;
  border: 0;
  border-radius: 8px;
  background: #4d5773;
  color: #fff;
  font-size: 13px;
}

/* 樱花粒子层：垫在桌宠下(z5)，不拦截触控 */
#fx {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

/* ---- 背景图层：z1 垫底，双 img 交叉淡入；外扩32px 吃掉模糊边缘 + Ken Burns 漂移 ---- */
#bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}
#bg img {
  position: absolute;
  left: -32px;
  top: -32px;
  width: calc(100% + 64px);
  height: calc(100% + 64px);
  object-fit: cover;
  filter: blur(2px);
  opacity: 0;
  -webkit-transition: opacity 0.9s ease;
  transition: opacity 0.9s ease;
  animation: bg-drift 44s ease-in-out infinite alternate;
  will-change: transform, opacity;
}
#bg img.ready { opacity: 1; }
@keyframes bg-drift {
  from { transform: scale(1.02) translate3d(-1%, -0.5%, 0); }
  to   { transform: scale(1.08) translate3d(1%, 0.5%, 0); }
}
#bg-scrim {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg,
    rgba(10, 14, 22, 0.3) 0%,
    rgba(10, 14, 22, 0.16) 45%,
    rgba(10, 14, 22, 0.34) 100%);
}

/* 背景切换按钮：右下角（左下角是连接角标），样式对齐 model-btn */
#bg-switch {
  position: absolute;
  right: calc(10px + constant(safe-area-inset-right));
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(8px + constant(safe-area-inset-bottom));
  bottom: calc(8px + env(safe-area-inset-bottom));
  width: 38px; height: 38px;
  border: 1px solid rgba(74, 90, 120, 0.22);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 2px 8px rgba(46, 64, 96, 0.14);
  font-size: 19px;
  line-height: 38px;
  text-align: center;
  color: #38455f;
  z-index: 40;
}
