/* =========================================================
   Extra工作室 · 顶层可拖拽虚拟管理者 Eirene（Studio Mascot Layer）
   位于全站所有图层与弹窗之上（z-index: 9999），透明穿透不遮挡底部交互
   支持：思考动作 / 阅读上下文动作 / 指针视线跟随 / 点击拖拽离地 & 松开弹性落地
   ========================================================= */

.mascot-layer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  overflow: visible;
}

#auth-overlay {
  z-index: 20000 !important;
}
#auth-overlay:not(.hidden) ~ #studio-mascot-layer {
  display: none !important;
}

.mascot-wrap {
  position: fixed;
  left: 0;
  top: 0;
  width: 126px;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  will-change: transform;
  --gaze-x: 0px;
  --gaze-y: 0px;
  --gaze-rot: 0deg;
  --drag-tilt: 0deg;
}

.mascot-wrap.is-lifted,
.mascot-wrap.is-dragging {
  cursor: grabbing;
}

.mascot-wrap.is-minimized {
  width: 54px;
}

/* 角色舞台容器：负责离地/落地、拖拽惯性摆动 */
.mascot-lift-rig {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: center bottom;
  transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

/* 点击按下 / 拖拽中：立刻离地悬空 + 惯性摆动 */
.mascot-wrap.is-lifted .mascot-lift-rig,
.mascot-wrap.is-dragging .mascot-lift-rig {
  transform: translate3d(0, -18px, 0) rotate(var(--drag-tilt)) scale(1.06);
  transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1);
}

.mascot-wrap.is-dragging .mascot-lift-rig {
  transition: transform 0.06s linear;
}

/* 松开落地：Q 弹挤压回弹动画 */
.mascot-wrap.is-landing .mascot-lift-rig {
  animation: mascotLandBounce 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

/* 角色动作层：负责呼吸、思考、阅读、视线微倾 */
.mascot-stage {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center bottom;
  filter: drop-shadow(0 8px 16px rgba(15, 23, 42, 0.16));
  transition: filter 0.18s ease;
}

.mascot-wrap.is-lifted .mascot-stage,
.mascot-wrap.is-dragging .mascot-stage {
  filter: drop-shadow(0 20px 26px rgba(59, 103, 224, 0.28));
}

.mascot-gaze {
  width: 112px;
  height: 184px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transform-origin: center 68%;
  transform: translate3d(var(--gaze-x), var(--gaze-y), 0) rotate(var(--gaze-rot));
  transition: transform 0.14s ease-out;
  will-change: transform;
}

.mascot-visual {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  transform-origin: center bottom;
  animation: mascotIdleBreathe 3.8s ease-in-out infinite;
  transition: transform 0.18s ease;
}

.mascot-wrap.is-flipped .mascot-visual-inner {
  transform: scaleX(-1);
}

.mascot-visual-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.mascot-visual img,
.mascot-visual svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* 状态动作：思考中 */
.mascot-wrap.is-thinking .mascot-visual {
  animation: mascotThinkBob 1.35s ease-in-out infinite;
}

/* 状态动作：阅读上下文 */
.mascot-wrap.is-reading .mascot-visual {
  animation: mascotReadScan 1.5s ease-in-out infinite;
}

/* 悬空/拖拽时暂停地面呼吸 */
.mascot-wrap.is-lifted .mascot-visual,
.mascot-wrap.is-dragging .mascot-visual {
  animation: mascotAirDangle 0.9s ease-in-out infinite;
}

/* 脚底投影（离地时缩小变淡，落地时回弹） */
.mascot-shadow {
  width: 68px;
  height: 12px;
  margin-top: -5px;
  border-radius: 999px;
  background: radial-gradient(ellipse at center, rgba(11, 14, 20, 0.30) 0%, rgba(59, 103, 224, 0.10) 55%, transparent 78%);
  transform: scale(1);
  opacity: 0.9;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease, filter 0.2s ease;
  pointer-events: none;
}

.mascot-wrap.is-lifted .mascot-shadow,
.mascot-wrap.is-dragging .mascot-shadow {
  transform: scale(0.58);
  opacity: 0.34;
  filter: blur(2.5px);
}

.mascot-wrap.is-landing .mascot-shadow {
  animation: mascotShadowLand 0.38s ease-out;
}

/* 落地冲击微光环 */
.mascot-land-ring {
  position: absolute;
  bottom: 22px;
  left: 50%;
  width: 64px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid rgba(59, 103, 224, 0.55);
  transform: translateX(-50%) scale(0.5);
  opacity: 0;
  pointer-events: none;
}

.mascot-wrap.is-landing .mascot-land-ring {
  animation: mascotLandRing 0.42s ease-out;
}

/* 头顶动作特效标（思考火花 / 阅读扫描） */
.mascot-fx {
  position: absolute;
  top: -18px;
  left: 50%;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  color: #3B67E0;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(59, 103, 224, 0.28);
  box-shadow: 0 4px 12px rgba(59, 103, 224, 0.18);
  opacity: 0;
  transform: translateX(-50%) translateY(4px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.mascot-wrap.is-thinking .mascot-fx,
.mascot-wrap.is-reading .mascot-fx {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

.mascot-wrap.is-lifted .mascot-fx,
.mascot-wrap.is-dragging .mascot-fx,
.mascot-wrap.has-menu .mascot-fx,
.mascot-wrap.has-bubble .mascot-fx {
  opacity: 0 !important;
}

/* 最小化后的圆章形态 */
.mascot-mini-pill {
  display: none;
  width: 50px;
  height: 50px;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg-strong, rgba(255, 255, 255, 0.88));
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border: 1.5px solid var(--glass-border, rgba(255, 255, 255, 0.92));
  box-shadow: 0 8px 24px rgba(59, 103, 224, 0.22);
  color: var(--ink, #0B0E14);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.mascot-wrap.is-minimized .mascot-lift-rig,
.mascot-wrap.is-minimized .mascot-shadow,
.mascot-wrap.is-minimized .mascot-land-ring,
.mascot-wrap.is-minimized .mascot-bubble,
.mascot-wrap.is-minimized .mascot-cmd-panel,
.mascot-wrap.is-minimized .mascot-toolbar,
.mascot-wrap.is-minimized .mascot-badge {
  display: none !important;
}

.mascot-wrap.is-minimized .mascot-mini-pill {
  display: flex;
}

/* 角色名牌 */
.mascot-badge {
  margin-top: 2px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: rgba(11, 14, 20, 0.86);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 4px 12px rgba(11, 14, 20, 0.16);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.mascot-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.85);
}

.mascot-wrap.is-thinking .mascot-status-dot {
  background: #60a5fa;
  box-shadow: 0 0 8px rgba(96, 165, 250, 0.95);
  animation: mascotPulse 0.85s ease-in-out infinite alternate;
}

.mascot-wrap.is-reading .mascot-status-dot {
  background: #a78bfa;
  box-shadow: 0 0 8px rgba(167, 139, 250, 0.95);
}

/* 对话气泡 */
.mascot-bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: 20;
  transform: translateX(-50%) translateY(4px);
  min-width: 126px;
  max-width: 236px;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink, #0B0E14);
  background: var(--glass-bg-strong, rgba(255, 255, 255, 0.96));
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.9));
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  white-space: normal;
  word-break: break-word;
}

.mascot-bubble.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mascot-bubble.show.is-actionable {
  pointer-events: auto;
  cursor: pointer;
  border-color: rgba(59, 103, 224, 0.45);
}

.mascot-bubble.show.is-alert {
  border-color: rgba(234, 88, 12, 0.55);
  box-shadow: 0 10px 28px rgba(234, 88, 12, 0.18);
}

.mascot-bubble-cta {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #3B67E0;
}

.mascot-wrap.has-menu .mascot-bubble {
  opacity: 0 !important;
  pointer-events: none !important;
}

.mascot-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--glass-bg-strong, rgba(255, 255, 255, 0.96));
}

/* 管理员快捷指令盘（与状态气泡互斥，支持视口边缘自动翻转） */
.mascot-cmd-panel {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  z-index: 30;
  width: 232px;
  padding: 10px;
  border-radius: 16px;
  background: var(--glass-bg-strong, rgba(255, 255, 255, 0.96));
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid rgba(59, 103, 224, 0.22);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateX(-50%);
  transform-origin: bottom center;
  opacity: 0;
  scale: 0.96;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 180ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    scale 180ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    visibility 0s linear 180ms;
}

.mascot-cmd-panel.open {
  opacity: 1;
  scale: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 180ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    scale 180ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    visibility 0s linear 0s;
}
.mascot-cmd-panel.pos-bottom { transform-origin: top center; }

.mascot-cmd-panel.pos-bottom {
  bottom: auto;
  top: calc(100% + 8px);
}

.mascot-cmd-panel.align-left {
  left: 0;
  right: auto;
  transform: none;
}

.mascot-cmd-panel.align-right {
  left: auto;
  right: 0;
  transform: none;
}

.mascot-cmd-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink, #334155);
  padding: 0 2px;
}

.mascot-cmd-close {
  border: none;
  background: transparent;
  color: var(--muted, #64748b);
  font-size: 13px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.mascot-cmd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mascot-cmd-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid var(--glass-stroke, var(--border, rgba(15, 23, 42, 0.1)));
  background: var(--glass-inset, var(--surface-2, rgba(248, 250, 252, 0.92)));
  color: var(--ink, #0f172a);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.12s ease;
}

.mascot-cmd-btn:hover {
  background: #3B67E0;
  border-color: #3B67E0;
  color: #ffffff;
  transform: translateY(-1px);
}

/* 划词悬浮「交给 Eirene 追问 / 总结」条 */
.mascot-sel-bar {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10005;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  scrollbar-width: none;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.28);
  opacity: 0;
  scale: 0.96;
  visibility: hidden;
  pointer-events: none;
  transform-origin: 50% 100%;
  transition:
    opacity 160ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    scale 160ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    visibility 0s linear 160ms;
}
.mascot-sel-bar::-webkit-scrollbar {
  display: none;
}

.mascot-sel-bar.show {
  opacity: 1;
  scale: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 160ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    scale 160ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)),
    visibility 0s linear 0s;
}

.mascot-sel-btn {
  border: none;
  border-radius: 999px;
  padding: 4px 9px;
  background: transparent;
  color: #f8fafc;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s ease;
}

.mascot-sel-btn:hover {
  background: #3B67E0;
}

/* 悬浮快捷操作条 */
.mascot-toolbar {
  position: absolute;
  top: 2px;
  right: -12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  transform: translateX(4px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.mascot-wrap:hover .mascot-toolbar,
.mascot-wrap:focus-within .mascot-toolbar {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.mascot-wrap.is-lifted .mascot-toolbar,
.mascot-wrap.is-dragging .mascot-toolbar {
  opacity: 0 !important;
  pointer-events: none !important;
}

.mascot-tool-btn {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.85));
  background: var(--glass-bg-strong, rgba(255, 255, 255, 0.92));
  color: var(--ink, #0B0E14);
  font-size: 11px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.14);
  transition: transform 0.12s ease, background 0.12s ease;
}

.mascot-tool-btn:hover {
  transform: scale(1.1);
  background: var(--accent, #3B67E0);
  color: #ffffff;
}

/* 关键帧动画 */
@keyframes mascotIdleBreathe {
  0%, 100% { transform: translateY(0px) scaleY(1); }
  50% { transform: translateY(-2.5px) scaleY(1.012); }
}

@keyframes mascotThinkBob {
  0%, 100% { transform: translateY(0px) rotate(-1.5deg); }
  50% { transform: translateY(-6px) rotate(2.2deg) scale(1.015); }
}

@keyframes mascotReadScan {
  0%, 100% { transform: translateX(-2px) rotate(-2deg) scaleY(0.99); }
  50% { transform: translateX(2.5px) rotate(2deg) scaleY(1.01); }
}

@keyframes mascotAirDangle {
  0%, 100% { transform: rotate(-1.8deg) scaleY(1.02); }
  50% { transform: rotate(1.8deg) scaleY(1.03); }
}

@keyframes mascotLandBounce {
  0%   { transform: translate3d(0, -14px, 0) scaleX(0.95) scaleY(1.06); }
  38%  { transform: translate3d(0, 2px, 0) scaleX(1.13) scaleY(0.86); }
  68%  { transform: translate3d(0, -4px, 0) scaleX(0.96) scaleY(1.04); }
  100% { transform: translate3d(0, 0, 0) scaleX(1) scaleY(1); }
}

@keyframes mascotShadowLand {
  0%   { transform: scale(0.62); opacity: 0.4; }
  45%  { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 0.9; }
}

@keyframes mascotLandRing {
  0%   { transform: translateX(-50%) scale(0.45); opacity: 0.85; }
  100% { transform: translateX(-50%) scale(1.45); opacity: 0; }
}

@keyframes mascotPulse {
  from { opacity: 0.55; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.15); }
}

@media (max-width: 640px) {
  .mascot-wrap:not(.is-minimized) { transform-origin: right bottom; width: 88px; }
  .mascot-wrap:not(.is-minimized) .mascot-gaze { width: 78px; height: 128px; }
}

@media (prefers-reduced-motion: reduce) {
  .mascot-visual, .mascot-status-dot, .mascot-lift-rig, .mascot-land-ring {
    animation: none !important;
  }
  .mascot-cmd-panel, .mascot-sel-bar { scale: 1 !important; transition-duration: 80ms, 80ms, 0s !important; }
}
