/* ===== 万能麻将 - 极致动画系统 ===== */

/* ============ 3D 牌桌透视 ============ */
.game-table {
    perspective: 1200px;
    transform-style: preserve-3d;
}

.table-center {
    transform-style: preserve-3d;
    transform: rotateX(5deg);
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.player-area {
    transform-style: preserve-3d;
}

.player-area.top {
    transform: translateZ(-30px);
}

.player-area.left {
    transform: translateZ(-20px) rotateY(5deg);
}

.player-area.right {
    transform: translateZ(-20px) rotateY(-5deg);
}

.player-area.bottom {
    transform: translateZ(10px);
}

/* ============ 3D 麻将牌翻转 ============ */
/* 牌面3D翻转效果由 game.css 中的 preserve-3d/backface-visibility 支持 */

/* 3D翻转动画 - 摸牌 */
@keyframes tileFlipIn {
    0% {
        transform: rotateY(-90deg) scale(0.5) translateZ(-100px);
        opacity: 0;
    }
    40% {
        transform: rotateY(-30deg) scale(1.1) translateZ(20px);
        opacity: 1;
    }
    70% {
        transform: rotateY(10deg) scale(0.95) translateZ(10px);
    }
    100% {
        transform: rotateY(0deg) scale(1) translateZ(0);
    }
}

.tile-flip-in {
    animation: tileFlipIn calc(0.5s * var(--anim-speed, 1)) cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* 3D翻转 - 打牌飞出 */
@keyframes tileFlyOut {
    0% {
        transform: translateZ(0) rotateY(0deg) scale(1);
        opacity: 1;
    }
    30% {
        transform: translateZ(80px) rotateY(-45deg) scale(1.2);
        opacity: 0.9;
    }
    100% {
        transform: translateZ(-200px) rotateY(-90deg) scale(0.3);
        opacity: 0;
    }
}

.tile-fly-out {
    animation: tileFlyOut calc(0.4s * var(--anim-speed, 1)) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* ============ 牌面高级效果（动画部分） ============ */
/* 牌面基础样式、悬停、选中效果由 game.css 统一管理 */
/* 此处仅保留额外的动画关键帧 */

@keyframes selectedPulse {
    0%, 100% {
        box-shadow: 0 0 0 3px var(--accent-gold), 0 0 30px rgba(212, 168, 67, 0.4), 0 16px 32px rgba(0, 0, 0, 0.35);
        filter: brightness(1.05);
    }
    50% {
        box-shadow: 0 0 0 4px var(--accent-gold-light), 0 0 50px rgba(212, 168, 67, 0.6), 0 16px 32px rgba(0, 0, 0, 0.35);
        filter: brightness(1.15);
    }
}

/* 牌面光泽扫过效果由 game.css 的 hover 效果覆盖 */
@keyframes shineSweep {
    from { left: -50%; }
    to { left: 150%; }
}

/* ============ 摸牌/打牌动画 ============ */
@keyframes tileDrawn3D {
    0% {
        transform: rotateY(-180deg) scale(0.3) translateZ(-150px);
        opacity: 0;
    }
    50% {
        transform: rotateY(-20deg) scale(1.15) translateZ(30px);
        opacity: 1;
    }
    75% {
        transform: rotateY(5deg) scale(0.97) translateZ(10px);
    }
    100% {
        transform: rotateY(0deg) scale(1) translateZ(0);
        opacity: 1;
    }
}

/* .tile-drawn 动画类定义在 game.css */

@keyframes tileDiscard3D {
    0% {
        transform: translateZ(50px) scale(1.3) rotateY(0deg);
        opacity: 0.8;
    }
    50% {
        transform: translateZ(0) scale(1.1) rotateY(180deg);
        opacity: 1;
    }
    100% {
        transform: translateZ(0) scale(1) rotateY(180deg);
        opacity: 1;
    }
}

/* .tile-discarded 动画类定义在 game.css */

/* ============ 弃牌堆最新牌特效 ============ */
/* .discard-pile .mahjong-tile:last-child 样式定义在 game.css */

@keyframes latestDiscardGlow {
    0%, 100% {
        box-shadow: 0 0 0 2px var(--accent-gold), 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 0 0 3px var(--accent-gold-light), 0 0 20px rgba(212, 168, 67, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    }
}

/* ============ 吃碰杠胡大字特效 ============ */
.action-effect {
    position: fixed;
    top: 40%;
    left: 50%;
    will-change: transform, opacity;
    transform: translate(-50%, -50%);
    font-size: 4.5rem;
    font-weight: 900;
    color: transparent;
    background: linear-gradient(135deg, var(--accent-gold-light), var(--accent-gold), var(--accent-gold-dark), var(--accent-gold-light));
    background-size: 300% 300%;
    -webkit-background-clip: text;
    background-clip: text;
    text-shadow: none;
    animation:
        actionPop 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
        gradientShift 2s ease infinite;
    z-index: 500;
    pointer-events: none;
    white-space: nowrap;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes actionPop {
    0% {
        transform: translate(-50%, -50%) scale(0) rotateZ(-10deg);
        opacity: 0;
        filter: blur(10px);
    }
    30% {
        transform: translate(-50%, -50%) scale(1.4) rotateZ(3deg);
        opacity: 1;
        filter: blur(0px);
    }
    50% {
        transform: translate(-50%, -50%) scale(0.95) rotateZ(-1deg);
    }
    70% {
        transform: translate(-50%, -50%) scale(1.05) rotateZ(1deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.2) rotateZ(0deg);
        opacity: 0;
        filter: blur(5px);
    }
}

/* ============ 胡牌/自摸全屏特效 ============ */
.win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 450;
    overflow: hidden;
}

.win-flash {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(212, 168, 67, 0.3) 0%, transparent 70%);
    animation: winFlash 1.5s ease-out forwards;
}

@keyframes winFlash {
    0% { opacity: 1; transform: scale(0); }
    50% { opacity: 0.8; transform: scale(1.5); }
    100% { opacity: 0; transform: scale(2); }
}

.win-rings {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.win-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 3px solid var(--accent-gold);
    border-radius: 50%;
    opacity: 0;
    animation: winRingExpand 1.5s ease-out forwards;
}

.win-ring:nth-child(1) { animation-delay: 0s; }
.win-ring:nth-child(2) { animation-delay: 0.2s; }
.win-ring:nth-child(3) { animation-delay: 0.4s; }

@keyframes winRingExpand {
    0% {
        width: 0;
        height: 0;
        opacity: 0.8;
        border-width: 8px;
    }
    100% {
        width: 600px;
        height: 600px;
        opacity: 0;
        border-width: 0px;
    }
}

/* ============ 彩虹光效 ============ */
.rainbow-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 460;
    background: linear-gradient(
        45deg,
        rgba(255, 0, 0, 0.1),
        rgba(255, 165, 0, 0.1),
        rgba(255, 255, 0, 0.1),
        rgba(0, 255, 0, 0.1),
        rgba(0, 0, 255, 0.1),
        rgba(238, 130, 238, 0.1),
        rgba(255, 0, 0, 0.1)
    );
    background-size: 400% 400%;
    animation: rainbowShift 3s ease infinite;
    opacity: 0;
}

.rainbow-glow.active {
    opacity: 1;
    animation: rainbowShift 3s ease infinite, rainbowFade 2s ease forwards;
}

@keyframes rainbowShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes rainbowFade {
    0% { opacity: 0.6; }
    100% { opacity: 0; }
}

/* ============ 分数跳动动画 ============ */
.score-pop {
    animation: scorePop calc(0.6s * var(--anim-speed, 1)) cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scorePop {
    0% { transform: scale(1); }
    30% { transform: scale(1.4); color: var(--accent-gold-light); }
    60% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* 分数变化浮动文字 */
.score-float {
    position: absolute;
    font-size: 1.2rem;
    font-weight: 700;
    pointer-events: none;
    animation: scoreFloat calc(1.2s * var(--anim-speed, 1)) ease-out forwards;
    z-index: 200;
}

.score-float.positive {
    color: var(--win-color);
    text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.score-float.negative {
    color: var(--lose-color);
    text-shadow: 0 0 10px rgba(244, 67, 54, 0.5);
}

@keyframes scoreFloat {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    30% {
        transform: translateY(-15px) scale(1.3);
        opacity: 1;
    }
    100% {
        transform: translateY(-50px) scale(0.8);
        opacity: 0;
    }
}

/* ============ 连击特效 ============ */
.combo-text {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 900;
    color: var(--accent-gold);
    text-shadow: 0 0 30px rgba(212, 168, 67, 0.8), 0 4px 8px rgba(0, 0, 0, 0.5);
    animation: comboPop 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    z-index: 500;
    pointer-events: none;
}

@keyframes comboPop {
    0% {
        transform: translate(-50%, -50%) scale(0) rotateZ(-15deg);
        opacity: 0;
    }
    40% {
        transform: translate(-50%, -50%) scale(1.3) rotateZ(5deg);
        opacity: 1;
    }
    70% {
        transform: translate(-50%, -50%) scale(0.95) rotateZ(-2deg);
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotateZ(0deg);
        opacity: 0;
    }
}

/* ============ 手牌整理流动动画 ============ */
.hand-sorting .mahjong-tile {
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), left 0.4s ease;
}

/* ============ 粒子系统增强 ============ */
@keyframes particleBurst {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 1;
    }
    30% {
        opacity: 0.9;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0) rotate(720deg);
        opacity: 0;
    }
}

.particle-gold {
    background: radial-gradient(circle, var(--accent-gold-light), var(--accent-gold)) !important;
    box-shadow: 0 0 6px var(--accent-gold) !important;
}

.particle-star {
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    background: var(--accent-gold) !important;
}

/* ============ 霓虹边框效果 ============ */
.neon-border {
    position: relative;
}

.neon-border::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    background: linear-gradient(45deg, var(--accent-gold), var(--accent-gold-light), var(--accent-gold));
    background-size: 200% 200%;
    z-index: -1;
    animation: neonGlow 2s ease infinite;
    opacity: 0.6;
}

@keyframes neonGlow {
    0%, 100% {
        background-position: 0% 50%;
        filter: blur(3px) brightness(1);
    }
    50% {
        background-position: 100% 50%;
        filter: blur(5px) brightness(1.3);
    }
}

/* ============ 菜单按钮增强 ============ */
.menu-btn {
    position: relative;
    overflow: hidden;
    transform: translateZ(0);
    transition:
        transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.3s ease;
}

.menu-btn:hover {
    transform: translateY(-4px) scale(1.02);
}

.menu-btn:active {
    transform: translateY(-1px) scale(0.98);
    transition: transform 0.1s ease;
}

/* ============ 模态框增强 ============ */
.modal-content {
    animation: modalIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: center;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.7) translateY(30px) rotateX(10deg);
        filter: blur(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0) rotateX(0deg);
        filter: blur(0);
    }
}

/* ============ Toast增强 ============ */
@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to   { opacity: 0; transform: translateY(10px) scale(0.95); }
}

/* ============ 经验条流动光效 ============ */
.exp-fill {
    position: relative;
    overflow: hidden;
}

.exp-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: expShine 2s ease-in-out infinite;
}

@keyframes expShine {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* ============ 成就解锁特效 ============ */
.achievement-unlock {
    animation: achievementUnlock 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes achievementUnlock {
    0% {
        transform: scale(0.8);
        filter: brightness(2) saturate(2);
    }
    50% {
        transform: scale(1.05);
        filter: brightness(1.2) saturate(1.5);
    }
    100% {
        transform: scale(1);
        filter: brightness(1) saturate(1);
    }
}

/* ============ 拖拽时的牌效果 ============ */
.mahjong-tile.dragging {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    will-change: transform, left, top;
    transform: scale(1.2) rotateZ(5deg) translateZ(100px) !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 0 3px var(--accent-gold);
    opacity: 0.9;
    cursor: grabbing;
}

.mahjong-tile.drag-source {
    opacity: 0.3;
    transform: scale(0.9);
}

/* 拖拽目标区域高亮 */
.discard-target {
    animation: discardTargetPulse 1s ease-in-out infinite;
    border: 2px dashed var(--accent-gold);
    border-radius: var(--border-radius);
}

@keyframes discardTargetPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(212, 168, 67, 0.2);
        border-color: rgba(212, 168, 67, 0.5);
    }
    50% {
        box-shadow: 0 0 20px 5px rgba(212, 168, 67, 0.15);
        border-color: var(--accent-gold);
    }
}

/* ============ 视差背景层 ============ */
.parallax-bg {
    position: fixed;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    pointer-events: none;
    z-index: -1;
    opacity: 0.03;
    background-image:
        radial-gradient(circle at 20% 30%, var(--accent-gold) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, var(--accent-gold) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, var(--accent-gold-dark) 0%, transparent 30%);
    animation: parallaxDrift 20s ease-in-out infinite;
}

@keyframes parallaxDrift {
    0%, 100% {
        transform: translate(0, 0) scale(1);
    }
    33% {
        transform: translate(-2%, 1%) scale(1.02);
    }
    66% {
        transform: translate(1%, -1%) scale(0.98);
    }
}

/* ============ 入场动画序列 ============ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px) rotateX(-10deg);
        filter: blur(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotateX(0deg);
        filter: blur(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px) rotateX(10deg);
        filter: blur(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotateX(0deg);
        filter: blur(0);
    }
}

/* ============ 倒计时紧迫感 ============ */
.turn-timer.urgent {
    animation: timerUrgent 0.5s ease-in-out infinite;
    background: linear-gradient(135deg, #ff5722, #f44336) !important;
}

@keyframes timerUrgent {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(244, 67, 54, 0.4);
    }
    50% {
        transform: scale(1.2);
        box-shadow: 0 4px 16px rgba(244, 67, 54, 0.6);
    }
}

/* ============ 牌桌中心发光 ============ */
.table-center::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at center, rgba(212, 168, 67, 0.05) 0%, transparent 70%);
    pointer-events: none;
    animation: tableGlow 4s ease-in-out infinite;
}

@keyframes tableGlow {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ============ 风标旋转 ============ */
.wind-indicator {
    animation: windSpin 8s ease-in-out infinite;
}

@keyframes windSpin {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(5deg); }
    75% { transform: rotate(-5deg); }
}

/* ============ 操作按钮弹跳 ============ */
.action-bar .action-btn:not(:disabled) {
    animation: actionBtnReady calc(0.5s * var(--anim-speed, 1)) cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes actionBtnReady {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

/* ============ 动画级别控制 ============ */
.anim-minimal .particle-explosion,
.anim-minimal .confetti,
.anim-minimal .rainbow-overlay,
.anim-minimal .parallax-bg {
    display: none !important;
}

.anim-minimal .tile-flip-in,
.anim-minimal .tile-fly-out {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
}

.anim-minimal .screen-shake-4,
.anim-minimal .screen-shake-5,
.anim-minimal .screen-shake-6,
.anim-minimal .screen-shake-7,
.anim-minimal .screen-shake-8 {
    animation: none !important;
}

.anim-normal .confetti,
.anim-normal .rainbow-overlay {
    display: none !important;
}

.anim-normal .screen-shake-6,
.anim-normal .screen-shake-7,
.anim-normal .screen-shake-8 {
    animation: none !important;
}

/* ============ 响应式动画调整 ============ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
