/* ==================== 易算AI - 六爻风格加载动画 ==================== */
/* 版本: 1.0.0 | 用途: 雷师傅（AI）思考/回答时的等待动画 */
/* 依赖: 01-design-tokens.css（仅使用 var(--*) 时需要；动画本身独立可运行） */
/* 设计意象: 传统三钱法占卜（三枚铜钱翻动） + 卦象（六个爻位依次显现） */

/* ==================== 整体容器 ==================== */
.yixue-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 24px 24px;
    background: linear-gradient(135deg, #fafbfc 0%, #f3f6fa 100%);
    border-radius: 12px;
    margin: 0;
    min-height: 160px;
    border: 1px solid var(--border-color, #e9ecef);
    box-shadow: 0 2px 8px rgba(28, 150, 241, 0.06);
    animation: yixueLoaderFadeIn 0.4s ease-out;
    position: relative;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

/* 当 .yixue-loader 是 .thinking-placeholder 的子元素时，
   取消外层 .thinking-placeholder 的内边距/边框/背景，避免双层样式叠加 */
.thinking-placeholder:has(> .yixue-loader) {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    min-height: 0;
    margin: 16px 0;
}

@keyframes yixueLoaderFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 背景八卦纹样（极淡，仅作装饰） */
.yixue-loader::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(30, 159, 255, 0.04) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(30, 159, 255, 0.04) 0%, transparent 40%);
    pointer-events: none;
    z-index: 0;
}

.yixue-loader > * {
    position: relative;
    z-index: 1;
}

/* ==================== 三铜钱动画 ==================== */
.coins-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 64px;
    margin-bottom: 20px;
    perspective: 600px;
}

.coin {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #ffd97a 0%, #f0a500 65%, #b87d00 100%);
    box-shadow:
        inset 0 -3px 6px rgba(120, 60, 0, 0.35),
        inset 0 2px 3px rgba(255, 240, 200, 0.6),
        0 3px 8px rgba(180, 120, 0, 0.25);
    position: relative;
    transform-style: preserve-3d;
    animation: coinFlip 1.6s cubic-bezier(0.45, 0, 0.55, 1) infinite;
    will-change: transform;
}

/* 铜钱方孔（中央） */
.coin::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    background: linear-gradient(135deg, #fafbfc 0%, #e5e7eb 100%);
    transform: translate(-50%, -50%) rotate(45deg);
    box-shadow:
        inset 0 0 2px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(120, 60, 0, 0.3);
    border-radius: 2px;
}

/* 铜钱外圈文字（用纯CSS伪元素简化） */
.coin::after {
    content: '乾';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'KaiTi', 'STKaiti', 'SimSun', serif;
    font-size: 8px;
    color: rgba(120, 60, 0, 0.55);
    font-weight: 600;
    letter-spacing: 0;
    z-index: -1;
}

/* 三枚铜钱错位翻转 */
.coin:nth-child(1) {
    animation-delay: 0s;
}

.coin:nth-child(2) {
    animation-delay: 0.2s;
    background: radial-gradient(circle at 30% 30%, #ffe199 0%, #f5b400 65%, #c08800 100%);
}

.coin:nth-child(3) {
    animation-delay: 0.4s;
    background: radial-gradient(circle at 30% 30%, #ffd97a 0%, #f0a500 65%, #b87d00 100%);
}

@keyframes coinFlip {
    0% {
        transform: rotateY(0deg) translateY(0);
    }
    25% {
        transform: rotateY(180deg) translateY(-6px);
    }
    50% {
        transform: rotateY(360deg) translateY(0);
    }
    75% {
        transform: rotateY(540deg) translateY(-6px);
    }
    100% {
        transform: rotateY(720deg) translateY(0);
    }
}

/* 减少动画偏好支持 */
@media (prefers-reduced-motion: reduce) {
    .coin {
        animation: coinPulse 1.6s ease-in-out infinite;
    }

    @keyframes coinPulse {
        0%, 100% {
            transform: scale(1);
            opacity: 1;
        }
        50% {
            transform: scale(0.92);
            opacity: 0.7;
        }
    }
}

/* ==================== 卦象形成动画（六爻依次点亮） ==================== */
.gua-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    border: 1px solid rgba(30, 159, 255, 0.12);
}

.gua-line {
    width: 56px;
    height: 6px;
    background: linear-gradient(90deg, #d1d5db 0%, #9ca3af 100%);
    border-radius: 3px;
    position: relative;
    animation: guaLineAppear 0.6s ease-out forwards;
    opacity: 0;
}

/* 阳爻（实线） */
.gua-line.yang {
    background: linear-gradient(90deg, #1e9fff 0%, #0073d1 100%);
    box-shadow: 0 0 8px rgba(30, 159, 255, 0.4);
}

/* 阴爻（中间断开） */
.gua-line.yin {
    background: transparent;
}

.gua-line.yin::before,
.gua-line.yin::after {
    content: '';
    position: absolute;
    top: 0;
    width: 45%;
    height: 100%;
    background: linear-gradient(90deg, #1e9fff 0%, #0073d1 100%);
    border-radius: 3px;
    box-shadow: 0 0 8px rgba(30, 159, 255, 0.4);
}

.gua-line.yin::before {
    left: 0;
}

.gua-line.yin::after {
    right: 0;
}

/* 六爻从下到上依次出现 */
.gua-loader .gua-line:nth-child(1) { animation-delay: 0.1s; }
.gua-loader .gua-line:nth-child(2) { animation-delay: 0.3s; }
.gua-loader .gua-line:nth-child(3) { animation-delay: 0.5s; }
.gua-loader .gua-line:nth-child(4) { animation-delay: 0.7s; }
.gua-loader .gua-line:nth-child(5) { animation-delay: 0.9s; }
.gua-loader .gua-line:nth-child(6) { animation-delay: 1.1s; }

@keyframes guaLineAppear {
    0% {
        opacity: 0;
        transform: scaleX(0.3);
    }
    60% {
        opacity: 1;
        transform: scaleX(1.1);
    }
    100% {
        opacity: 1;
        transform: scaleX(1);
    }
}

/* 循环模式：六爻全部显示完成后重置 */
.gua-loader.cyclic .gua-line {
    animation: guaLineCycle 4.5s ease-in-out infinite;
}

.gua-loader.cyclic .gua-line:nth-child(1) { animation-delay: 0s; }
.gua-loader.cyclic .gua-line:nth-child(2) { animation-delay: 0.2s; }
.gua-loader.cyclic .gua-line:nth-child(3) { animation-delay: 0.4s; }
.gua-loader.cyclic .gua-line:nth-child(4) { animation-delay: 0.6s; }
.gua-loader.cyclic .gua-line:nth-child(5) { animation-delay: 0.8s; }
.gua-loader.cyclic .gua-line:nth-child(6) { animation-delay: 1.0s; }

@keyframes guaLineCycle {
    0%, 100% {
        opacity: 0.25;
        transform: scaleX(0.85);
    }
    20%, 80% {
        opacity: 1;
        transform: scaleX(1);
    }
}

/* ==================== 文字提示 ==================== */
.yixue-loader-text {
    font-size: 15px;
    color: var(--text-primary, #1f2937);
    font-weight: 500;
    margin-bottom: 6px;
    text-align: center;
    letter-spacing: 0.02em;
    line-height: 1.5;
}

.yixue-loader-hint {
    font-size: 12px;
    color: var(--text-tertiary, #9ca3af);
    text-align: center;
    letter-spacing: 0.05em;
    min-height: 16px;
}

/* ==================== 阶段指示器（起卦 → 装卦 → 解读） ==================== */
.yixue-loader-stages {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
    font-size: 12px;
    color: var(--text-tertiary, #9ca3af);
}

.yixue-stage {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.04);
    transition: all 0.3s ease;
}

.yixue-stage-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #d1d5db;
    transition: all 0.3s ease;
}

.yixue-stage.active {
    background: rgba(30, 159, 255, 0.12);
    color: var(--primary, #1e9fff);
    font-weight: 600;
}

.yixue-stage.active .yixue-stage-dot {
    background: var(--primary, #1e9fff);
    box-shadow: 0 0 6px rgba(30, 159, 255, 0.5);
    animation: stageDotPulse 1.2s ease-in-out infinite;
}

.yixue-stage.done {
    color: var(--success, #52c41a);
    background: rgba(82, 196, 26, 0.08);
}

.yixue-stage.done .yixue-stage-dot {
    background: var(--success, #52c41a);
}

@keyframes stageDotPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.7);
    }
}

/* ==================== 内联小加载器（用于按钮/小区域） ==================== */
.yixue-loader-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary, #4b5563);
    font-size: 13px;
}

.yixue-loader-inline .mini-coin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #ffd97a 0%, #f0a500 100%);
    box-shadow: inset 0 -1px 2px rgba(120, 60, 0, 0.3);
    animation: miniCoinFlip 1s linear infinite;
    will-change: transform;
}

.yixue-loader-inline .mini-coin:nth-child(2) {
    animation-delay: 0.15s;
}

.yixue-loader-inline .mini-coin:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes miniCoinFlip {
    0%, 100% {
        transform: rotateY(0deg);
    }
    50% {
        transform: rotateY(180deg);
    }
}

/* ==================== 响应式设计 ==================== */
@media (max-width: 767px) {
    .yixue-loader {
        padding: 22px 16px 20px;
        min-height: 140px;
        border-radius: 10px;
        margin: 12px 0;
    }

    .coins-container {
        height: 56px;
        gap: 10px;
        margin-bottom: 16px;
    }

    .coin {
        width: 32px;
        height: 32px;
    }

    .coin::before {
        width: 10px;
        height: 10px;
    }

    .coin::after {
        font-size: 7px;
    }

    .gua-loader {
        padding: 10px 14px;
        margin-bottom: 12px;
    }

    .gua-line {
        width: 48px;
        height: 5px;
    }

    .yixue-loader-text {
        font-size: 14px;
    }

    .yixue-loader-hint {
        font-size: 11px;
    }

    .yixue-loader-stages {
        gap: 4px;
        margin-top: 12px;
    }

    .yixue-stage {
        padding: 2px 8px;
        font-size: 11px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .yixue-loader {
        padding: 26px 20px 22px;
    }
}

/* ==================== 触摸设备优化 ==================== */
@media (hover: none) and (pointer: coarse) {
    .coin {
        /* 触摸设备降低动画频率以节省电量 */
        animation-duration: 2s;
    }

    .gua-line {
        /* 触摸设备减少光晕效果 */
    }

    .gua-line.yang {
        box-shadow: 0 0 4px rgba(30, 159, 255, 0.3);
    }

    .gua-line.yin::before,
    .gua-line.yin::after {
        box-shadow: 0 0 4px rgba(30, 159, 255, 0.3);
    }
}

/* ==================== 暗色模式预留 ==================== */
@media (prefers-color-scheme: dark) {
    .yixue-loader {
        background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
        border-color: #374151;
    }

    .gua-loader {
        background: rgba(255, 255, 255, 0.04);
        border-color: rgba(30, 159, 255, 0.2);
    }

    .yixue-loader-text {
        color: #f3f4f6;
    }
}
