/**
 * SPA 过渡动画 + 骨架屏样式
 * 实现无抖动的页面切换体验
 */

/* ===== 基础过渡 ===== */
#main-content {
    transition: opacity 0.3s ease, transform 0.3s ease;
    will-change: opacity, transform;
}

#main-content.spa-loading {
    position: relative;
    overflow: hidden;
}

/* ===== 骨架屏覆盖层 ===== */
.spa-skeleton-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary, #060a10);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 1.5rem;
}

.spa-skeleton-overlay.show {
    opacity: 1;
}

/* ===== 骨架屏内容 ===== */
.skeleton-content {
    max-width: 1400px;
    margin: 0 auto;
}

.skeleton-header {
    height: 32px;
    width: 200px;
    background: linear-gradient(90deg, #1a2332 25%, #243044 50%, #1a2332 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 6px;
    margin-bottom: 1.5rem;
}

.skeleton-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.skeleton-card {
    height: 200px;
    background: linear-gradient(90deg, #1a2332 25%, #243044 50%, #1a2332 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 12px;
}

.skeleton-card:nth-child(2) { animation-delay: 0.1s; }
.skeleton-card:nth-child(3) { animation-delay: 0.2s; }
.skeleton-card:nth-child(4) { animation-delay: 0.3s; }
.skeleton-card:nth-child(5) { animation-delay: 0.4s; }
.skeleton-card:nth-child(6) { animation-delay: 0.5s; }

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== 页面内容骨架屏 ===== */
.skeleton-text {
    height: 1em;
    background: linear-gradient(90deg, #1a2332 25%, #243044 50%, #1a2332 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 70%; }
.skeleton-text.long { width: 100%; }

.skeleton-image {
    background: linear-gradient(90deg, #1a2332 25%, #243044 50%, #1a2332 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 8px;
}

.skeleton-circle {
    border-radius: 50%;
    background: linear-gradient(90deg, #1a2332 25%, #243044 50%, #1a2332 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
}

/* ===== 卡片骨架屏 ===== */
.skeleton-match-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 12px;
    padding: 1rem;
    height: 180px;
}

.skeleton-match-card .skeleton-teams {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.skeleton-match-card .skeleton-team {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.skeleton-match-card .skeleton-team-logo {
    width: 48px;
    height: 48px;
}

.skeleton-match-card .skeleton-team-name {
    width: 60px;
    height: 14px;
}

.skeleton-match-card .skeleton-score {
    width: 60px;
    height: 32px;
    border-radius: 8px;
}

.skeleton-news-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 12px;
    overflow: hidden;
    height: 280px;
}

.skeleton-news-card .skeleton-news-image {
    height: 140px;
    width: 100%;
}

.skeleton-news-card .skeleton-news-content {
    padding: 1rem;
}

.skeleton-news-card .skeleton-news-title {
    height: 20px;
    margin-bottom: 0.5rem;
}

.skeleton-news-card .skeleton-news-desc {
    height: 14px;
    margin-bottom: 0.25rem;
}

/* ===== 锁定布局尺寸（避免 CLS）===== */

/* 比赛卡片固定高度 */
.match-card {
    min-height: 180px;
    contain: layout style;
}

/* 新闻卡片固定高度 */
.news-card {
    min-height: 280px;
    contain: layout style;
}

/* 标题限制行数 */
.news-title,
.match-title,
.article-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 摘要限制行数 */
.news-summary-text,
.news-summary,
.article-summary {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 图片占位 */
.news-image,
.match-image,
.article-image,
.team-logo,
.league-logo {
    background: #1a2332;
    object-fit: cover;
}

/* 新闻卡片图片固定宽高比 */
.news-card .news-image {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
}

/* 队徽固定尺寸 */
.team-logo,
.match-team-logo {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
}

/* 联赛 logo 固定尺寸 */
.league-logo {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    background-color: white;
}

/* ===== 图片懒加载过渡 ===== */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img.loaded {
    opacity: 1;
}

/* ===== 页面淡入动画 ===== */
.page-fade-in {
    animation: pageFadeIn 0.4s ease forwards;
}

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

/* ===== 列表项交错动画 ===== */
.stagger-fade-in > * {
    opacity: 0;
    animation: staggerFadeIn 0.4s ease forwards;
}

.stagger-fade-in > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-fade-in > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-fade-in > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-fade-in > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-fade-in > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-fade-in > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-fade-in > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-fade-in > *:nth-child(8) { animation-delay: 0.4s; }

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

/* ===== 导航切换动画 ===== */
.nav-link {
    position: relative;
    transition: color 0.2s ease;
}

/* 原本這裡是導航鏈接的底部下劃線動畫（.nav-link::after）
 * 應用需求：移除該下劃線效果，因此將其清空
 */

.nav-link::after {
    content: none;
}

.nav-link.active::after,
.nav-link.nav-active::after {
    content: none;
}



/* ===== 加载指示器 ===== */
.spa-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;              /* 起点在左侧，从 0 宽度开始 */
    height: 3px;
    background: linear-gradient(90deg, #0ea5e9, #22d3ee);
    background-size: 100% 100%;
    z-index: 99999;
    opacity: 1;
    transition: width 0.3s ease, opacity 0.3s ease;
}

.spa-loading-bar.loading {
    width: 70%;            /* 加载中：从左侧向右扩展到 70% */
}

.spa-loading-bar.complete {
    width: 100%;           /* 补满到 100% */
    opacity: 0;            /* 然后淡出 */
}

/* ===== 响应式适配 ===== */
@media (max-width: 768px) {
    .skeleton-cards {
        grid-template-columns: 1fr;
    }
    
    .match-card {
        min-height: 160px;
    }
    
    .news-card {
        min-height: 240px;
    }
}

/* ===== 减少动画（用户偏好）===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
