/* 三國天命 - 動畫效果 */

/* 淡入淡出效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* 滑入效果 */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 縮放效果 */
@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* 搖晃效果 */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

/* 發光效果 */
@keyframes glow {
    0% {
        box-shadow: 0 0 5px var(--secondary-color);
    }
    50% {
        box-shadow: 0 0 20px var(--secondary-color), 0 0 30px var(--secondary-color);
    }
    100% {
        box-shadow: 0 0 5px var(--secondary-color);
    }
}

/* 打字機效果 */
@keyframes typing {
    from {
        width: 0;
    }
    to {
        width: 100%;
    }
}

@keyframes blink {
    0%, 50% {
        border-color: transparent;
    }
    51%, 100% {
        border-color: var(--primary-color);
    }
}

/* 應用動畫的類別 */
.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

.fade-out {
    animation: fadeOut 0.3s ease-in forwards;
}

.slide-in-up {
    animation: slideInUp 0.4s ease-out forwards;
}

.slide-in-down {
    animation: slideInDown 0.4s ease-out forwards;
}

.zoom-in {
    animation: zoomIn 0.3s ease-out forwards;
}

.pulse {
    animation: pulse 2s infinite;
}

.shake {
    animation: shake 0.5s ease-in-out;
}

.glow {
    animation: glow 2s ease-in-out infinite;
}

/* 技能卡片特殊動畫 */
.skill-card.animate-select {
    animation: zoomIn 0.3s ease-out, glow 0.5s ease-in-out;
}

.skill-card.animate-deselect {
    animation: pulse 0.2s ease-out;
}

/* 事件訊息動畫 */
.event-message {
    animation: slideInLeft 0.6s ease-out;
    transform-origin: left center;
}

.event-message.removing {
    animation: fadeOut 0.3s ease-in forwards;
}

/* 左滑入效果 */
@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 右滑入效果 */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 漸現打字效果 */
@keyframes typewriter {
    from {
        width: 0;
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    to {
        width: 100%;
        opacity: 1;
    }
}

/* 滑動加淡入組合動畫 */
@keyframes slideInFade {
    0% {
        opacity: 0;
        transform: translateX(-50px) scale(0.95);
    }
    50% {
        opacity: 0.7;
        transform: translateX(-10px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* 彈跳入場效果 */
@keyframes bounceInLeft {
    0% {
        opacity: 0;
        transform: translateX(-100%);
    }
    60% {
        opacity: 1;
        transform: translateX(10px);
    }
    80% {
        transform: translateX(-5px);
    }
    100% {
        transform: translateX(0);
    }
}

/* 應用新動畫的類別 */
.slide-in-left {
    animation: slideInLeft 0.6s ease-out forwards;
}

.slide-in-right {
    animation: slideInRight 0.6s ease-out forwards;
}

.slide-in-fade {
    animation: slideInFade 0.8s ease-out forwards;
}

.bounce-in-left {
    animation: bounceInLeft 0.8s ease-out forwards;
}

.typewriter-effect {
    animation: typewriter 1s ease-out forwards;
    overflow: hidden;
    white-space: nowrap;
}

/* 特殊的訊息類型動畫 */
.event-message.battle-result {
    animation: bounceInLeft 0.8s ease-out forwards;
}

.event-message.resource-change {
    animation: slideInFade 0.7s ease-out forwards;
}

.event-message.level-up {
    animation: zoomIn 0.5s ease-out forwards, glow 1s ease-in-out;
}

.event-message.random-event {
    animation: slideInLeft 0.6s ease-out forwards;
}

/* 延遲動畫類別 */
.delay-1 { animation-delay: 0.2s; }
.delay-2 { animation-delay: 0.4s; }
.delay-3 { animation-delay: 0.6s; }
.delay-4 { animation-delay: 0.8s; }
.delay-5 { animation-delay: 1.0s; }

/* 事件訊息容器樣式 */
.event-message {
    transition: all 0.6s ease-out;
    opacity: 0;
    transform: translateX(-100%);
    margin-bottom: 8px;
    padding: 12px;
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
}

/* 不同類型事件的邊框顏色 */
.event-message.positive {
    border-left-color: #22C55E;
}

.event-message.negative {
    border-left-color: var(--accent-color);
}

.event-message.neutral {
    border-left-color: var(--secondary-color);
}

.event-message.special {
    border-left-color: #F59E0B;
    background: rgba(245, 158, 11, 0.1);
}

/* 事件訊息內容樣式 */
.event-timestamp {
    font-size: 0.8em;
    opacity: 0.7;
    margin-bottom: 4px;
}

.event-title {
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.event-description {
    line-height: 1.4;
}

/* 數值變化動畫 */
.value-increase {
    animation: pulse 0.3s ease-out, glow 0.5s ease-in-out;
    color: #22C55E !important;
}

.value-decrease {
    animation: shake 0.3s ease-in-out;
    color: var(--accent-color) !important;
}

/* 按鈕互動動畫 */
.btn {
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transition: width 0.3s ease, height 0.3s ease;
    transform: translate(-50%, -50%);
    z-index: 0;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

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

/* 載入動畫 */
.loading-dots {
    display: inline-block;
}

.loading-dots::after {
    content: '';
    animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}

/* 地圖動畫 */
.city-node {
    transition: var(--transition);
}

.city-node:hover {
    transform: scale(1.1);
    filter: brightness(1.2);
}

.city-node.player-controlled {
    animation: glow 3s ease-in-out infinite;
}

.city-node.under-attack {
    animation: pulse 1s ease-in-out infinite;
}

/* 響應式動畫設定 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .pulse,
    .glow,
    .loading-spinner {
        animation: none !important;
    }
}

/* 觸控設備優化 */
@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .skill-card:hover,
    .city-node:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.95);
    }
}