/* ==========================================================================
   UI-258 右下角悬浮的 AI 入口：小玩偶「星环小灵」
   样子是模板里的内联 SVG（project_tools/art/make_ai_mascot.py 写进八个页面），
   颜色、动作都在这份样式里；什么时候做哪个动作由 static/js/fz_ai_mascot.js 决定。
   按钮本身还是 .ai-fab（各页的位置、显示与隐藏规则照旧），这里只换它的样子；
   fz_theme.css 第 11 节给旧金色圆按钮的底色、描边、光晕在这里用更具体的选择器盖掉。
   平时只做漂浮（最外一层位移，合成线程上做、不重画图）；
   转身、抖一抖、绕星、笑、跳一下、张望、眨眼由脚本偶尔加 .is-… 类名触发，演完即摘。
   系统开了“减少动态效果”只留静态形象；页面在后台或 AI 面板开着时脚本加 .is-paused 停下。
   ========================================================================== */

.ai-fab.fz-ai-mascot {
    width: 64px; height: 64px; padding: 0;
    border: 0 !important; border-radius: 50%;
    background: transparent !important; box-shadow: none !important;
    color: var(--fz-gold-bright) !important; font: inherit;
    overflow: visible; isolation: isolate;
    transition: transform var(--fz-motion-fast) var(--fz-ease-out);
}
.ai-fab.fz-ai-mascot:hover { transform: none; }
.ai-fab.fz-ai-mascot:active { transform: scale(.92); }
.ai-fab.fz-ai-mascot:focus { outline: none; }
.ai-fab.fz-ai-mascot:focus-visible { box-shadow: var(--fz-ring) !important; }

/* 身后一团淡淡的紫光；悬停、聚焦时换成月金色、略放大 */
.fz-ai-mascot::before, .fz-ai-mascot::after {
    content: ""; position: absolute; inset: 2px; border-radius: 50%; z-index: -1; pointer-events: none;
    transition: transform var(--fz-motion) var(--fz-ease-out), opacity var(--fz-motion) var(--fz-ease-out);
}
.fz-ai-mascot::before {
    background: radial-gradient(circle at 50% 58%, rgba(var(--fz-violet-rgb), .26), rgba(var(--fz-violet-rgb), .08) 52%, rgba(var(--fz-violet-rgb), 0) 72%);
}
.fz-ai-mascot::after {
    background: radial-gradient(circle at 50% 58%, rgba(var(--fz-gold-rgb), .26), rgba(var(--fz-gold-rgb), .07) 54%, rgba(var(--fz-gold-rgb), 0) 72%);
    opacity: 0;
}
.ai-fab.fz-ai-mascot:focus-visible::before { transform: scale(1.12); opacity: .4; }
.ai-fab.fz-ai-mascot:focus-visible::after { transform: scale(1.12); opacity: 1; }

.fzm-shadow {
    position: absolute; left: 15px; right: 15px; bottom: 0; height: 7px; border-radius: 50%; pointer-events: none;
    background: radial-gradient(closest-side, rgba(var(--fz-gold-rgb), .36), rgba(var(--fz-gold-rgb), 0));
}
.fzm-float { position: absolute; inset: 0; pointer-events: none; }
.fzm {
    position: absolute; left: 0; top: 0; width: 64px; height: 64px; overflow: visible; display: block;
    transform-origin: 50% 92%;
}

/* ---- “AI”对话气泡：平时只露“AI”，说话时向左展开一句（点按穿过气泡落到下面的页面上） ---- */
.fzm-say {
    position: absolute; right: 41px; top: -9px; height: 20px; padding: 0 7px;
    display: flex; align-items: center; white-space: nowrap;
    border-radius: var(--fz-radius-pill);
    background: rgba(var(--fz-surface-rgb), .94);
    border: 1px solid rgba(var(--fz-gold-rgb), .6);
    box-shadow: 0 0 12px rgba(var(--fz-gold-rgb), .18), var(--fz-shadow-1);
    color: var(--fz-gold-bright); font: 600 11px/1 var(--fz-font-serif); letter-spacing: .06em;
}
.fzm-say b { font-weight: 700; font-family: var(--fz-font-serif); }
.fzm-say::after {
    content: ""; position: absolute; right: 7px; bottom: -4px; width: 6px; height: 6px;
    background: rgb(var(--fz-surface-rgb));
    border-right: 1px solid rgba(var(--fz-gold-rgb), .6); border-bottom: 1px solid rgba(var(--fz-gold-rgb), .6);
    transform: rotate(45deg);
}
.fzm-say-t {
    display: inline-block; max-width: 0; overflow: hidden; opacity: 0; margin-left: 0;
    color: var(--fz-text); font-weight: 500; letter-spacing: .04em;
    transition: max-width var(--fz-motion-slow) var(--fz-ease-out), opacity var(--fz-motion) var(--fz-ease-out), margin var(--fz-motion-slow) var(--fz-ease-out);
}
.fz-ai-mascot.is-tip .fzm-say-t { max-width: 10em; opacity: 1; margin-left: 6px; }

/* ---- 颜色：全部来自设计变量 ---- */
.fzm .fzm-s1 { stop-color: var(--fz-violet-fill); }
.fzm .fzm-s2 { stop-color: var(--fz-surface-4); }
.fzm .fzm-s3 { stop-color: var(--fz-surface-1); }
.fzm .fzm-edge { stroke: var(--fz-gold); stroke-width: 1.3; }
.fzm .fzm-ln { fill: none; stroke: var(--fz-gold); stroke-width: 1.5; stroke-linecap: round; }
.fzm .fzm-star, .fzm .fzm-cdot, .fzm .fzm-moon { fill: var(--fz-gold-bright); }
.fzm .fzm-halo { fill: rgba(var(--fz-gold-rgb), .22); }
.fzm .fzm-sheen { fill: none; stroke: rgba(var(--fz-sheen-rgb), .32); stroke-width: 1.2; stroke-linecap: round; }
.fzm .fzm-cline { fill: none; stroke: rgba(var(--fz-gold-rgb), .55); stroke-width: .8; }
.fzm .fzm-blush { fill: rgba(var(--fz-wx-huo-rgb), .3); }
.fzm .fzm-eye { fill: var(--fz-cyan); }
.fzm .fzm-eyeglow { fill: rgba(var(--fz-cyan-rgb), .2); }
.fzm .fzm-hl { fill: var(--fz-on-fill); }
.fzm .fzm-eye-happy { fill: none; stroke: var(--fz-cyan); stroke-width: 1.7; stroke-linecap: round; opacity: 0; }
.fzm .fzm-mouth { fill: none; stroke: var(--fz-gold-bright); stroke-width: 1.3; stroke-linecap: round; }
.fzm .fzm-ring { fill: none; stroke: var(--fz-gold); stroke-width: 1.3; stroke-linecap: round; }
.fzm .fzm-ring-back { stroke: rgba(var(--fz-gold-rgb), .42); }

/* ---- 会动的部件 ---- */
.fzm .fzm-eye-open, .fzm .fzm-face, .fzm .fzm-back, .fzm .fzm-star, .fzm .fzm-halo { transform-box: fill-box; transform-origin: 50% 50%; }
.fzm .fzm-back { opacity: 0; }
/* 小月亮：在星轨自己的坐标里平移（星轨整体斜着，月亮跟着斜）；后面那颗平时藏着 */
.fzm .fzm-moon { transform-box: view-box; transform: translate(21.71px, 3.79px); }
.fzm .fzm-moon-b { opacity: 0; }

/* 悬停、键盘聚焦：笑眼（减少动态效果时也换，只是不动） */
@media (hover: hover) {
    .ai-fab.fz-ai-mascot:hover .fzm-eye-open { opacity: 0; }
    .ai-fab.fz-ai-mascot:hover .fzm-eye-happy { opacity: 1; }
}
.ai-fab.fz-ai-mascot:focus-visible .fzm-eye-open { opacity: 0; }
.ai-fab.fz-ai-mascot:focus-visible .fzm-eye-happy { opacity: 1; }

@media (prefers-reduced-motion: no-preference) {
    /* 平时：上下浮、轻轻呼吸 */
    .fzm-float { animation: fzm-float 4.8s ease-in-out infinite; }
    .fzm-shadow { animation: fzm-shadow 4.8s ease-in-out infinite; }

    .fz-ai-mascot.is-blink .fzm-eye-open { animation: fzm-blink .24s ease-in-out; }
    .fz-ai-mascot.is-shake .fzm { animation: fzm-shake .9s ease-in-out; }
    .fz-ai-mascot.is-hop .fzm { animation: fzm-hop 1s ease-in-out; }
    .fz-ai-mascot.is-hop .fzm-shadow { animation: fzm-hop-shadow 1s ease-in-out; }
    .fz-ai-mascot.is-turn .fzm { animation: fzm-turn-body 1.7s ease-in-out; }
    .fz-ai-mascot.is-turn .fzm-face { animation: fzm-turn-face 1.7s ease-in-out; }
    .fz-ai-mascot.is-turn .fzm-back { animation: fzm-turn-back 1.7s ease-in-out; }
    .fz-ai-mascot.is-look .fzm-face { animation: fzm-look 1.8s ease-in-out; }
    .fz-ai-mascot.is-smile .fzm-eye-open { animation: fzm-off 1.9s linear; }
    .fz-ai-mascot.is-smile .fzm-eye-happy { animation: fzm-on 1.9s linear; }
    .fz-ai-mascot.is-smile .fzm-star { animation: fzm-twinkle 1.9s ease-in-out; }
    .fz-ai-mascot.is-smile .fzm-halo { animation: fzm-halo 1.9s ease-in-out; }
    .fz-ai-mascot.is-orbit .fzm-moon-f { animation: fzm-orbit 1.8s linear, fzm-front 1.8s linear; }
    .fz-ai-mascot.is-orbit .fzm-moon-b { animation: fzm-orbit 1.8s linear, fzm-behind 1.8s linear; }
    .fz-ai-mascot.is-orbit .fzm-star { animation: fzm-twinkle 1.8s ease-in-out; }
    .fz-ai-mascot.is-orbit .fzm-eye-open { animation: fzm-off 1.8s linear; }
    .fz-ai-mascot.is-orbit .fzm-eye-happy { animation: fzm-on 1.8s linear; }

    /* 悬停：身后光变金、小月亮一圈圈绕着飞 */
    @media (hover: hover) {
        .ai-fab.fz-ai-mascot:hover::before { transform: scale(1.12); opacity: .4; }
        .ai-fab.fz-ai-mascot:hover::after { transform: scale(1.12); opacity: 1; }
        .ai-fab.fz-ai-mascot:hover .fzm-moon-f { animation: fzm-orbit 1.8s linear infinite, fzm-front 1.8s linear infinite; }
        .ai-fab.fz-ai-mascot:hover .fzm-moon-b { animation: fzm-orbit 1.8s linear infinite, fzm-behind 1.8s linear infinite; }
    }
}

/* 页面在后台、AI 面板开着：停下 */
.fz-ai-mascot.is-paused *, .fz-ai-mascot.is-paused::before, .fz-ai-mascot.is-paused::after { animation-play-state: paused !important; }

@keyframes fzm-float {
    0%, 100% { transform: translateY(0) scale(1, 1); }
    50% { transform: translateY(-3px) scale(.99, 1.02); }
}
@keyframes fzm-shadow {
    0%, 100% { transform: scaleX(1); opacity: 1; }
    50% { transform: scaleX(.82); opacity: .62; }
}
@keyframes fzm-blink {
    0%, 100% { transform: scaleY(1); }
    45%, 55% { transform: scaleY(.12); }
}
@keyframes fzm-shake {
    0%, 100% { transform: rotate(0); }
    14% { transform: rotate(-9deg); }
    30% { transform: rotate(8deg); }
    46% { transform: rotate(-6deg); }
    62% { transform: rotate(4deg); }
    78% { transform: rotate(-2deg); }
}
@keyframes fzm-hop {
    0%, 100% { transform: none; }
    14% { transform: scale(1.1, .86); }
    38% { transform: translateY(-11px) scale(.94, 1.08); }
    60% { transform: translateY(0) scale(1.1, .88); }
    76% { transform: scale(.97, 1.04); }
}
@keyframes fzm-hop-shadow {
    0%, 100% { transform: scaleX(1); opacity: 1; }
    38% { transform: scaleX(.55); opacity: .35; }
    60% { transform: scaleX(1.1); opacity: 1; }
}
/* 转身：脸滑向一侧淡出，背面的星宿从另一侧转过来，再转回正面 */
@keyframes fzm-turn-body {
    0%, 100% { transform: scaleX(1); }
    25%, 75% { transform: scaleX(.92); }
    50% { transform: scaleX(.97); }
}
@keyframes fzm-turn-face {
    0% { transform: translateX(0) scaleX(1); opacity: 1; }
    25% { transform: translateX(13px) scaleX(.5); opacity: 0; }
    75% { transform: translateX(-13px) scaleX(.5); opacity: 0; }
    100% { transform: translateX(0) scaleX(1); opacity: 1; }
}
@keyframes fzm-turn-back {
    0%, 22% { transform: translateX(-13px) scaleX(.5); opacity: 0; }
    50% { transform: translateX(0) scaleX(1); opacity: 1; }
    78%, 100% { transform: translateX(13px) scaleX(.5); opacity: 0; }
}
@keyframes fzm-look {
    0%, 100% { transform: translateX(0); }
    18%, 40% { transform: translateX(-2.6px); }
    58%, 80% { transform: translateX(2.6px); }
}
@keyframes fzm-off { 0%, 100% { opacity: 1; } 6%, 90% { opacity: 0; } }
@keyframes fzm-on { 0%, 100% { opacity: 0; } 6%, 90% { opacity: 1; } }
@keyframes fzm-twinkle {
    0%, 100% { transform: scale(1) rotate(0); }
    30% { transform: scale(1.5) rotate(45deg); }
    60% { transform: scale(.9) rotate(90deg); }
}
@keyframes fzm-halo {
    0%, 100% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.6); opacity: .6; }
}
/* 绕星：小月亮沿星轨绕一圈；前半圈在脑袋前面，后半圈被脑袋挡住（两颗轮流露面） */
@keyframes fzm-orbit {
    0%, 100% { transform: translate(21.71px, 3.79px); }
    8.3% { transform: translate(11.2px, 5.98px); }
    16.7% { transform: translate(-2.31px, 6.57px); }
    25% { transform: translate(-15.2px, 5.41px); }
    33.3% { transform: translate(-24.02px, 2.79px); }
    40.3% { transform: translate(-26.5px, 0); }
    50% { transform: translate(-21.71px, -3.79px); }
    58.3% { transform: translate(-11.2px, -5.98px); }
    66.7% { transform: translate(2.31px, -6.57px); }
    75% { transform: translate(15.2px, -5.41px); }
    83.3% { transform: translate(24.02px, -2.79px); }
    90.3% { transform: translate(26.5px, 0); }
}
@keyframes fzm-front { 0%, 40.2%, 90.4%, 100% { opacity: 1; } 40.3%, 90.3% { opacity: 0; } }
@keyframes fzm-behind { 0%, 40.2%, 90.4%, 100% { opacity: 0; } 40.3%, 90.3% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
    .fz-ai-mascot, .fz-ai-mascot *, .fz-ai-mascot::before, .fz-ai-mascot::after { animation: none !important; transition: none !important; }
}
