/* =====================================================
   天机阁 - 动效样式 (3.7节)
   星点飘动、打字机、铜钱翻转、卷轴展开、卦象旋转、
   淡入淡出、按钮hover、加载动画
   ===================================================== */

/* ==================== 星点飘动背景 ==================== */
.starfield {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
}

.starfield::before,
.starfield::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 200%;
    background-image:
        radial-gradient(2px 2px at 20% 30%, rgba(230, 199, 133, 0.3), transparent),
        radial-gradient(1px 1px at 60% 70%, rgba(240, 230, 210, 0.2), transparent),
        radial-gradient(1px 1px at 80% 10%, rgba(212, 165, 116, 0.2), transparent),
        radial-gradient(2px 2px at 30% 80%, rgba(230, 199, 133, 0.15), transparent),
        radial-gradient(1px 1px at 90% 50%, rgba(240, 230, 210, 0.15), transparent),
        radial-gradient(1px 1px at 45% 45%, rgba(212, 165, 116, 0.2), transparent),
        radial-gradient(2px 2px at 15% 60%, rgba(230, 199, 133, 0.15), transparent),
        radial-gradient(1px 1px at 70% 20%, rgba(240, 230, 210, 0.2), transparent);
    background-size: 300px 300px;
    animation: starDrift 60s linear infinite;
}

.starfield::after {
    background-size: 400px 400px;
    animation-duration: 90s;
    animation-direction: reverse;
    opacity: 0.5;
}

@keyframes starDrift {
    from {
        transform: translate(0, 0);
    }
    to {
        transform: translate(-50%, -50%);
    }
}

/* 星点闪烁 */
.star-twinkle {
    animation: twinkle 3s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* ==================== 打字机效果 ==================== */
.typewriter {
    overflow: hidden;
    white-space: pre-wrap;
    border-right: 2px solid var(--color-gold-bright);
    animation: blinkCursor 0.8s step-end infinite;
}

@keyframes blinkCursor {
    0%, 100% { border-right-color: var(--color-gold-bright); }
    50% { border-right-color: transparent; }
}

.typewriter-done {
    border-right: none;
    animation: none;
}

/* 打字机逐字显示 */
.typewriter-char {
    opacity: 0;
    display: inline-block;
    animation: charAppear 0.1s ease forwards;
}

@keyframes charAppear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== 铜钱翻转动画 ==================== */
.coin-flip {
    display: inline-block;
    width: 40px;
    height: 40px;
    perspective: 200px;
}

.coin-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    animation: coinFlip 1.2s ease-in-out infinite;
}

.coin-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: radial-gradient(circle, var(--color-gold), var(--color-gold-dark));
    border: 2px solid var(--color-gold-bright);
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.3);
}

.coin-front {
    transform: rotateY(0deg);
}

.coin-back {
    transform: rotateY(180deg);
}

@keyframes coinFlip {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(180deg); }
    100% { transform: rotateY(360deg); }
}

/* 摇卦动画容器 */
.divination-coins {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
    padding: var(--spacing-lg) 0;
}

/* ==================== 卷轴展开效果 ==================== */
.scroll-expand {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.8s ease-in-out, opacity 0.5s ease;
    opacity: 0;
}

.scroll-expand.active {
    max-height: 2000px;
    opacity: 1;
}

/* 付费墙卷轴展开 */
.paywall .paywall-scroll {
    transform: scaleY(0);
    transform-origin: top;
    animation: scrollUnroll 0.6s ease-out forwards;
}

@keyframes scrollUnroll {
    from {
        transform: scaleY(0);
        opacity: 0;
    }
    to {
        transform: scaleY(1);
        opacity: 1;
    }
}

/* ==================== 卦象旋转 ==================== */
.hexagram-rotate {
    display: inline-block;
    animation: hexagramSpin 2s ease-in-out;
}

@keyframes hexagramSpin {
    0% {
        transform: rotate(0deg) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: rotate(180deg) scale(1.2);
    }
    100% {
        transform: rotate(360deg) scale(1);
        opacity: 1;
    }
}

/* 卦象持续旋转 */
.hexagram-spinning {
    animation: continuousSpin 3s linear infinite;
}

@keyframes continuousSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==================== 淡入淡出 ==================== */
.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.fade-out {
    animation: fadeOut 0.5s ease forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.fade-in-up {
    animation: fadeInUp 0.6s ease forwards;
    opacity: 0;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-down {
    animation: fadeInDown 0.6s ease forwards;
    opacity: 0;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 延迟淡入 */
.fade-delay-1 { animation-delay: 0.1s; }
.fade-delay-2 { animation-delay: 0.2s; }
.fade-delay-3 { animation-delay: 0.3s; }
.fade-delay-4 { animation-delay: 0.4s; }
.fade-delay-5 { animation-delay: 0.5s; }

/* ==================== 按钮hover动画 ==================== */
.btn-glow {
    position: relative;
    overflow: hidden;
}

.btn-glow::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
}

.btn-glow:hover::after {
    width: 300px;
    height: 300px;
}

/* 按钮按下效果 */
.btn:active {
    transform: translateY(0) !important;
    transition: transform 0.05s;
}

/* ==================== 加载动画 ==================== */
.loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-card-border);
    border-top-color: var(--color-gold-bright);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 加载点 */
.loading-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.loading-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-gold-bright);
    animation: loadingDot 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes loadingDot {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 加载遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 46, 0.8);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    backdrop-filter: blur(2px);
}

.loading-text {
    font-family: var(--font-title);
    color: var(--color-gold-bright);
    font-size: 1.1rem;
    letter-spacing: 0.1em;
}

/* 八字逐字浮现 */
.bazi-char-appear {
    opacity: 0;
    animation: baziCharAppear 0.5s ease forwards;
}

@keyframes baziCharAppear {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.8);
        filter: blur(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

/* 脉冲发光 */
.pulse-glow {
    animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 5px rgba(230, 199, 133, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(230, 199, 133, 0.6);
    }
}

/* ==================== 减少动画偏好 ==================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .starfield::before,
    .starfield::after {
        animation: none;
    }
}
