/**
 * 网址卡片「星星闪烁」特效
 *
 * 参考 page-agent 文档侧边栏（Magic UI SparklesText）。
 *
 * 两个层次：
 *   .onenav-spk-layer  铺在 .card-body 上的星星层（z-index:-1，在文字下层）
 *   .onenav-spk-title  标题的紫→粉渐变字
 *
 * 几何：坐标全部以「星星中心」计，用 calc 减半个尺寸，
 * 所以尺寸变大也不会顶出层的边界被 overflow 裁角。
 */

/* ====================================================================== *
 * 一、渐变标题
 * ====================================================================== */
.onenav-spk-title {
    background-image: linear-gradient(90deg, #9E7AFF 0%, #FE8BBB 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

/* ====================================================================== *
 * 二、星星层
 * ====================================================================== */

/*
 * 建立层叠上下文：父主题 .url-card .card-body 本身已是 position:relative，
 * 补一个 z-index:0 才能让层里 z-index:-1 的星星停在「卡片背景之上、文字之下」。
 * 不这么做的话负 z-index 会穿透到 .card 的白色背景后面，星星直接看不见。
 */
.url-card .card-body.has-spk,
.card-body.has-spk {
    position: relative;
    z-index: 0;
}

.onenav-spk-layer {
    position: absolute;
    inset: 0;
    z-index: -1;
    display: block;
    overflow: hidden;
    pointer-events: none;
    border-radius: inherit;
}

.onenav-spk-layer .spk-star {
    position: absolute;
    /* 变量由 PHP 随机生成、JS 再随机一次；缺值时给一组稳妥的兜底 */
    left: calc(var(--spk-l, 72%) - var(--spk-s, 12px) / 2);
    top: calc(var(--spk-t, 45%) - var(--spk-s, 12px) / 2);
    width: var(--spk-s, 12px);
    height: var(--spk-s, 12px);
    fill: #8B5CF6;
    transform-origin: 50% 50%;
    will-change: opacity, transform;
    animation-name: onenav-spk-twinkle;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-duration: var(--spk-d, 3s);
    animation-delay: var(--spk-dl, 0s);
}

/* 紫 / 粉交替，和标题渐变同色系，在卡片空白处才好看 */
.onenav-spk-layer .spk-star:nth-of-type(even) {
    fill: #EC4899;
}

/*
 * 一段动画里反复「亮→暗→亮」，同时 scale 在 .35 ~ 1.15 之间来回，
 * 就是「时隐时现 + 忽大忽小」。旋转持续累加，避免幅度小时看起来像静止。
 */
@keyframes onenav-spk-twinkle {
    0%   { opacity: 0;    transform: scale(.15)  rotate(0deg); }
    12%  { opacity: .90;  transform: scale(1)    rotate(55deg); }
    26%  { opacity: .18;  transform: scale(.40)  rotate(100deg); }
    40%  { opacity: 1;    transform: scale(1.15) rotate(150deg); }
    58%  { opacity: .12;  transform: scale(.35)  rotate(210deg); }
    74%  { opacity: .85;  transform: scale(.92)  rotate(265deg); }
    88%  { opacity: .20;  transform: scale(.50)  rotate(320deg); }
    100% { opacity: 0;    transform: scale(.15)  rotate(360deg); }
}

/* ====================================================================== *
 * 三、深色模式
 * ====================================================================== */
html.io-black-mode .onenav-spk-layer .spk-star {
    fill: #FFFFFF;
}

html.io-black-mode .onenav-spk-layer .spk-star:nth-of-type(even) {
    fill: #FFD9EC;
}

/* ====================================================================== *
 * 四、减少动态效果
 * ====================================================================== */
@media (prefers-reduced-motion: reduce) {
    .onenav-spk-layer .spk-star {
        animation: none;
        opacity: .65;
        transform: none;
    }
}
