/**
 * 天机阁 · 特效样式（配合 effects/tianji-fx.js）
 *
 * 只放「程序运转时」的动效；所有类都必须有终态：
 * 未加类 / 无 JS / prefers-reduced-motion 时，元素保持正常可见。
 */

/* ============================================================
   音效开关（低调，左下角；移动端让开底部标签栏）
   ============================================================ */
.tjg-fx-sound {
    position: fixed; left: 16px; bottom: 16px; z-index: 200;
    width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--line-strong, #cfc3a9);
    background: var(--paper-raised, #fffcf6);
    color: var(--ink-2, #55504a); font-size: 16px; line-height: 1;
    cursor: pointer; padding: 0;
    display: grid; place-items: center;
    box-shadow: 0 4px 14px rgba(29, 26, 22, .14);
    transition: color .2s, border-color .2s, transform .2s;
}
.tjg-fx-sound:hover { color: var(--cinnabar, #b0392b); border-color: var(--cinnabar, #b0392b); transform: translateY(-1px); }
.tjg-fx-sound:focus-visible { outline: 2px solid var(--cinnabar, #b0392b); outline-offset: 2px; }
@media (max-width: 860px) { .tjg-fx-sound { bottom: 78px; } }

/* ============================================================
   爻变翻转（本卦 ↔ 变卦，动爻绕横轴翻面）
   ============================================================ */
.hxf-yao.hxf-flipping { transform-origin: 50% 50%; will-change: transform; }
.hxf-yao.hxf-flip-done { }

/* ============================================================
   毛笔书写：爻线自左向右「写」出
   ============================================================ */
.hxf-yao.hxf-writing i { transform-origin: left center; }

/* ============================================================
   太极吐爻：从太极飞出的爻线残影
   ============================================================ */
.tjg-spit {
    position: fixed; z-index: 9500; pointer-events: none;
    height: 10px; border-radius: 2px; background: #d4af37;
    box-shadow: 0 0 12px rgba(212, 175, 55, .8);
    transform: translate(-50%, -50%);
    will-change: transform, opacity;
}

/* ============================================================
   排盘逐列盖印
   ============================================================ */
.paipan { position: relative; }
@keyframes pp-stamp-in {
    0%   { opacity: 0; transform: scale(1.55) rotate(-7deg); }
    55%  { opacity: 1; }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
.paipan-table td.pp-stamp { animation: pp-stamp-in .42s cubic-bezier(.2, .85, .25, 1) both; }
.paipan-table th.pp-stamp { animation: pp-stamp-in .42s cubic-bezier(.2, .85, .25, 1) both; }
/* 逐列盖印时，抑制原有的整行滑入，避免两套动画打架 */
.paipan-table.is-stamping tbody tr { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
    .paipan-table td.pp-stamp,
    .paipan-table th.pp-stamp { animation: none !important; }
}

/* ============================================================
   用神连线
   ============================================================ */
.tjg-ys-svg { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 4; overflow: visible; }
.tjg-ys-svg path {
    fill: none; stroke: var(--cinnabar, #b0392b); stroke-width: 2;
    stroke-dasharray: 7 7; stroke-linecap: round;
    filter: drop-shadow(0 0 4px rgba(176, 57, 43, .5));
}
.tjg-ys-svg circle { fill: var(--cinnabar, #b0392b); }
.tjg-ys-svg text {
    font-size: 11px; fill: var(--cinnabar, #b0392b);
    font-family: var(--font-sans, sans-serif); font-weight: 600;
}
.td-yongshen {
    box-shadow: inset 0 0 0 2px var(--cinnabar, #b0392b) !important;
    border-radius: 6px;
}
.td-yongshen::after {
    content: "用神"; position: absolute; top: -9px; right: 4px;
    font-size: 10px; line-height: 1; padding: 1px 5px; border-radius: 999px;
    background: var(--cinnabar, #b0392b); color: #fff; font-family: var(--font-sans, sans-serif);
}
.pp-relative, .pp-yao, .pp-seat, .pp-spirit { position: relative; }

/* ============================================================
   跨页墨迹：首页问题"化墨"飞出
   ============================================================ */
.tjg-ink {
    position: fixed; z-index: 9998; pointer-events: none;
    width: 14px; height: 14px; border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #55504a, #1d1a16 70%);
    box-shadow: 0 0 14px rgba(29, 26, 22, .5);
    transform: translate(-50%, -50%);
    will-change: transform, opacity;
}

/* ============================================================
   紫微：十二宫展开 + 四化盖印
   ============================================================ */
.zw-cell.zw-reveal-init { opacity: 0; transform: translateY(10px) scale(.97); }
.zw-cell.zw-in {
    opacity: 1; transform: none;
    transition: opacity .45s var(--p-ease, ease), transform .45s var(--p-ease, ease);
}
@keyframes zw-seal-in {
    0%   { opacity: 0; transform: scale(1.7) rotate(-10deg); }
    60%  { opacity: 1; }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
.zw-star .mut.zw-seal { display: inline-block; animation: zw-seal-in .4s cubic-bezier(.2, .85, .25, 1) both; }
@media (prefers-reduced-motion: reduce) {
    .zw-cell.zw-reveal-init { opacity: 1; transform: none; }
    .zw-star .mut.zw-seal { animation: none !important; }
}

/* ============================================================
   首页起卦：透明模态（原页面可见的丝滑飞入）
   ------------------------------------------------------------
   与 aihi 炼丹一致：飞入发生在原页面上，不整屏遮黑。
   仅有一层极淡的聚焦晕影；飞入结束后才有一层很短的暗场收束转场。
   ============================================================ */
.p-ritual.p-ritual--clear {
    background: transparent;
    display: none;
    place-items: center;
}
.p-ritual.p-ritual--clear.is-active { display: grid; opacity: 1; }

/* 聚焦晕影：中心完全透明，仅四周略提亮，原页面始终可见 */
.p-ritual--clear .p-ritual-veil {
    position: absolute; inset: 0; pointer-events: none;
    background: radial-gradient(circle at 50% 46%, rgba(247, 243, 234, 0) 30%, rgba(247, 243, 234, .38) 100%);
    opacity: 0; transition: opacity .5s ease;
}
.p-ritual--clear.is-active .p-ritual-veil { opacity: 1; }

/* 纸色衬底：让墨色八卦落在干净纸面上，避免与页面内容互相干扰。
   不是黑幕——中心微亮、边缘渐隐，整体几乎不可见。 */
.p-ritual--clear .p-ritual-backplate {
    position: absolute; left: 50%; top: 50%;
    width: 320px; height: 320px; margin: -160px 0 0 -160px; border-radius: 50%;
    background: radial-gradient(circle,
        rgba(250, 247, 239, .92) 0%,
        rgba(250, 247, 239, .9) 90%,
        rgba(250, 247, 239, .45) 97%,
        rgba(250, 247, 239, 0) 100%);
    box-shadow: 0 0 28px rgba(29, 26, 22, .05);
    opacity: 0; pointer-events: none;
    transition: opacity .55s ease;
}
.p-ritual--clear.is-active .p-ritual-backplate { opacity: 1; }
@media (max-width: 420px) {
    .p-ritual--clear .p-ritual-backplate {
        width: 280px; height: 280px; margin: -140px 0 0 -140px;
    }
}

/* 浅色场景下，八卦改用「墨 + 朱」两色（宣纸本来的语言），不再金色撞色 */
.p-ritual--clear .tj-tg {
    color: rgba(29, 26, 22, .82);
    filter: drop-shadow(0 1px 1px rgba(255, 255, 255, .7));
}
.p-ritual--clear .tj-bg-rot--mid i { background: rgba(29, 26, 22, .26); }
.p-ritual--clear .tj-bg-rot--mid i:nth-child(3n + 1) { background: rgba(29, 26, 22, .48); }
.p-ritual--clear .tj-bg-rot--inner span { color: rgba(140, 41, 30, .72); text-shadow: none; }
.p-ritual--clear .tj-bagua::before {
    border-color: rgba(29, 26, 22, .2);
    box-shadow: inset 0 0 30px rgba(29, 26, 22, .05), 0 0 24px rgba(29, 26, 22, .06);
}
.p-ritual--clear .tj-bagua::after { border-color: rgba(29, 26, 22, .13); }
.p-ritual--clear .tj-bagua.is-charging .tj-tg {
    color: rgba(140, 41, 30, .98);
    filter: drop-shadow(0 0 8px rgba(176, 57, 43, .45));
}
.p-ritual--clear .tj-bagua.is-charging::before {
    box-shadow: inset 0 0 40px rgba(176, 57, 43, .1), 0 0 30px rgba(176, 57, 43, .12);
}
.p-ritual--clear .p-ritual-taiji.tj-taiji {
    box-shadow: 0 0 28px rgba(124, 97, 24, .34), inset 0 0 0 1px rgba(124, 97, 24, .55);
}

/* 透明模态里符箓需要一点投影，才能在浅色纸面上"浮"起来 */
.p-ritual--clear .p-talisman {
    box-shadow: 0 8px 20px rgba(29, 26, 22, .26), 0 0 18px rgba(212, 175, 55, .5),
        inset 0 0 0 2px rgba(176, 57, 43, .16);
}

/* 墨染式圆形蒙版：飞入结束后由中心扩散，过渡到书写页 */
.p-ritual--clear .p-ritual-portal {
    position: absolute; left: 50%; top: 50%;
    width: 150px; height: 150px; margin: -75px 0 0 -75px; border-radius: 50%;
    background: radial-gradient(circle,
        #0b0a0f 50%, rgba(11, 10, 15, .88) 68%,
        rgba(11, 10, 15, .4) 82%, rgba(11, 10, 15, 0) 92%);
    transform: scale(0); opacity: 0; pointer-events: none;
}
.p-ritual--clear.is-closing .p-ritual-portal {
    opacity: 1;
    transform: scale(30);
    transition: transform .95s cubic-bezier(.55, 0, .3, 1), opacity .25s linear;
}

/* 符字如纸般飘动（叠在飞行轨迹之上） */
@keyframes talisman-flutter {
    0%, 100% { transform: rotateZ(-7deg) rotateX(16deg) translateY(0); }
    50%      { transform: rotateZ(7deg)  rotateX(-12deg) translateY(-5px); }
}
.p-talisman > i { display: block; animation: talisman-flutter 2.4s ease-in-out infinite; }
.p-talisman { perspective: 360px; }

/* 太极"浮现" */
@keyframes p-taiji-in { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.p-ritual--clear.is-active .p-ritual-stage { animation: p-taiji-in .5s var(--p-ease, ease) both; }

/* 透明变体下，底部文字在纸面上可读 */
.p-ritual--clear .p-ritual-text {
    color: var(--cinnabar, #b0392b);
    text-shadow: 0 1px 10px rgba(247, 243, 234, .9);
}

/* ============================================================
   罗盘式星盘（八卦）—— 多层：真爻线八卦 / 节气刻度 / 地支 / 太极
   ============================================================ */
.tj-bagua {
    position: absolute; inset: 0; display: grid; place-items: center;
    pointer-events: none;
}
/* 外圈：蚀刻金环 */
.tj-bagua::before {
    content: ""; position: absolute; left: 50%; top: 50%;
    width: 300px; height: 300px; margin: -150px 0 0 -150px; border-radius: 50%;
    border: 1px solid rgba(212, 175, 55, .26);
    box-shadow:
        inset 0 0 44px rgba(212, 175, 55, .10),
        inset 0 0 0 6px rgba(212, 175, 55, .05),
        0 0 34px rgba(212, 175, 55, .12);
}
.tj-bagua::after {
    content: ""; position: absolute; left: 50%; top: 50%;
    width: 236px; height: 236px; margin: -118px 0 0 -118px; border-radius: 50%;
    border: 1px dashed rgba(212, 175, 55, .18);
}

.tj-bg-rot { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.tj-bg-rot--outer { animation: tj-spin 26s linear infinite; }
.tj-bg-rot--mid   { animation: tj-spin-rev 44s linear infinite; }
.tj-bg-rot--inner { animation: tj-spin 64s linear infinite; }
@keyframes tj-spin { to { transform: rotate(360deg); } }
@keyframes tj-spin-rev { to { transform: rotate(-360deg); } }

/* 八经卦：三条真爻线，绕环布置且始终保持正立 */
.tj-tg {
    position: absolute; left: 0; top: 0;
    width: 36px; height: 30px; margin: -15px 0 0 -18px;
    display: flex; flex-direction: column; justify-content: space-between;
    color: rgba(230, 214, 166, .9);
    transform: rotate(var(--a)) translateY(-134px) rotate(calc(-1 * var(--a)));
    filter: drop-shadow(0 0 6px rgba(212, 175, 55, .55));
}
.tj-tg i { display: block; height: 4.5px; border-radius: 2px; background: currentColor; }
.tj-tg i.n {
    background: linear-gradient(90deg,
        currentColor 0 40%, transparent 40% 60%, currentColor 60% 100%);
}

/* 二十四节气刻度 */
.tj-bg-rot--mid i {
    position: absolute; left: 0; top: 0;
    width: 1px; height: 11px; margin: -5.5px 0 0 0;
    background: rgba(212, 175, 55, .34);
    transform: rotate(var(--a)) translateY(-112px);
}
.tj-bg-rot--mid i:nth-child(3n + 1) { height: 16px; margin-top: -8px; background: rgba(212, 175, 55, .6); }

/* 十二地支 */
.tj-bg-rot--inner span {
    position: absolute; left: 0; top: 0;
    width: 26px; margin-left: -13px; text-align: center;
    font-family: var(--font-serif, 'Noto Serif SC', serif);
    font-size: 15px; line-height: 1;
    color: rgba(212, 175, 55, .72);
    text-shadow: 0 0 8px rgba(212, 175, 55, .35);
    transform: rotate(var(--a)) translateY(-86px) rotate(calc(-1 * var(--a)));
}

/* 中心太极（覆盖旧版样式） */
.p-ritual-taiji.tj-taiji {
    position: relative; width: 100px; height: 100px; border-radius: 50%;
    background: linear-gradient(90deg, #d4af37 0 50%, #14110c 50% 100%);
    box-shadow: 0 0 46px rgba(212, 175, 55, .5), inset 0 0 0 1px rgba(212, 175, 55, .5);
    animation: tj-taiji-spin 7s linear infinite;
}
.p-ritual-taiji.tj-taiji::before {
    content: ""; position: absolute; top: 0; left: 25%;
    width: 50%; height: 50%; border-radius: 50%; background: #d4af37;
}
.p-ritual-taiji.tj-taiji::after {
    content: ""; position: absolute; bottom: 0; left: 25%;
    width: 50%; height: 50%; border-radius: 50%; background: #14110c;
}
.p-ritual-taiji.tj-taiji .tj-dot {
    position: absolute; left: 50%; width: 12px; height: 12px; margin-left: -6px;
    border-radius: 50%;
}
.p-ritual-taiji.tj-taiji .tj-dot.a { top: 19px; background: #14110c; }
.p-ritual-taiji.tj-taiji .tj-dot.b { bottom: 19px; background: #d4af37; }
@keyframes tj-taiji-spin { to { transform: rotate(360deg); } }

/* 聚气：飞入期间星盘加速、增亮 */
.tj-bagua.is-charging .tj-bg-rot--outer { animation-duration: 9s; }
.tj-bagua.is-charging .tj-bg-rot--mid { animation-duration: 16s; }
.tj-bagua.is-charging::before { box-shadow: inset 0 0 60px rgba(212,175,55,.2), 0 0 50px rgba(212,175,55,.28); }
.tj-bagua.is-charging .tj-tg { filter: drop-shadow(0 0 10px rgba(255, 215, 94, .85)); color: rgba(255, 236, 190, 1); }

@media (max-width: 420px) {
    .p-ritual-stage { transform: scale(.82); }
}

/* ============================================================
   符箓（首页飞入 + 推演页飞入共用）
   ============================================================ */
.p-talisman-layer {
    position: absolute; inset: 0; overflow: hidden;
    pointer-events: none; z-index: 6;
}
.p-talisman {
    position: absolute; left: 0; top: 0;
    width: 40px; height: 104px;
    display: grid; place-items: center;
    background: linear-gradient(180deg, #f8f1de, #ecdfbf);
    border: 1px solid rgba(176, 57, 43, .8);
    border-radius: 5px;
    color: #b0392b;
    font-family: var(--font-serif, 'Noto Serif SC', serif); font-size: 26px; font-weight: 700;
    text-shadow: 0 0 8px rgba(176, 57, 43, .25);
    box-shadow: 0 0 18px rgba(212, 175, 55, .5), inset 0 0 0 2px rgba(176, 57, 43, .16);
    will-change: transform, opacity;
    transform: translate(-50%, -50%);
}
.p-talisman::before {
    content: ""; position: absolute; top: 9px; left: 50%;
    width: 1px; height: 14px; transform: translateX(-50%);
    background: rgba(176, 57, 43, .35);
}
.p-talisman::after {
    content: ""; position: absolute; bottom: 7px;
    width: 11px; height: 11px; border-radius: 2px;
    background: #b0392b; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .45);
}
@media (prefers-reduced-motion: reduce) {
    .p-talisman { display: none; }
}

/* ============================================================
   太极接收脉冲（承接首页飞入）
   ============================================================ */
@keyframes tjg-absorb {
    0%   { transform: translate(-50%, -50%) scale(.35); opacity: .9; }
    100% { transform: translate(-50%, -50%) scale(2.4); opacity: 0; }
}
.tjg-absorb-ring {
    position: absolute; left: 50%; top: 50%;
    width: 116px; height: 116px; border-radius: 50%;
    border: 2px solid rgba(212, 175, 55, .8);
    box-shadow: 0 0 24px rgba(212, 175, 55, .6);
    pointer-events: none;
    animation: tjg-absorb .9s ease-out forwards;
}
@media (prefers-reduced-motion: reduce) {
    .tjg-absorb-ring { display: none; }
}

/* ============================================================
   通用：墨入
   ============================================================ */
@keyframes tjg-ink-in {
    0%   { opacity: 0; filter: blur(4px); }
    100% { opacity: 1; filter: blur(0); }
}
.tjg-ink-in { animation: tjg-ink-in .5s ease both; }
