/* =========================================
   1. CSS 变量定义 (主题配置)
   ========================================= */
:root {
    /* 核心颜色 */
    --primary-color: #4a6fa5;
    --primary-hover: #3a5c8c;
    --accent-color: #f39c12;
    /* 背景体系 */
    --bg-body: #f4f6f8;
    --bg-card: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.85); /* 半透明用于毛玻璃 */
    --bg-search: #ffffff;
    --bg-tag: #f0f2f5;
    --bg-footer: #ffffff;
    /* 文字体系 */
    --text-main: #2c3e50;
    --text-secondary: #606f7b;
    --text-light: #9aa5b1;
    /* 边框与阴影 */
    --border-color: #e2e8f0;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
    /* 布局尺寸 */
    --header-height: 70px;
    --border-radius: 12px;
}

/* 深色模式变量覆盖 */
body.dark-mode {
    --bg-body: #121212;
    --bg-card: #1e1e1e;
    --bg-header: rgba(30, 30, 30, 0.85);
    --bg-search: #2d2d2d;
    --bg-tag: #333333;
    --bg-footer: #1e1e1e;
    --text-main: #e0e0e0;
    --text-secondary: #a0aec0;
    --border-color: #333333;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* =========================================
   2. 全局重置与基础样式
   ========================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* 仅对背景色和文字颜色做过渡，提升性能 */
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

ul {
    list-style: none;
}

/* =========================================
   3. 头部样式 (Header)
   ========================================= */
.site-header {
    background-color: var(--bg-header);
    backdrop-filter: blur(10px); /* 毛玻璃效果 */
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    position: sticky; /* 吸顶效果 */
    top: 0;
    z-index: 1000;
    height: var(--header-height);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo img {
    height: 40px;
    width: auto;
    display: block;
}

/* 主题切换开关 */
.theme-switcher-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-icon {
    font-size: 1.1rem;
}

.fa-sun {
    color: #f39c12;
}

.fa-moon {
    color: #5a67d8;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

    .switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e0;
    transition: .4s;
    border-radius: 34px;
}

    .slider:before {
        position: absolute;
        content: "";
        height: 18px;
        width: 18px;
        left: 4px;
        bottom: 4px;
        background-color: white;
        transition: .4s;
        border-radius: 50%;
    }

input:checked + .slider {
    background-color: var(--primary-color);
}

    input:checked + .slider:before {
        transform: translateX(24px);
    }

/* =========================================
   4. 主内容区 (Hero & Search)
   ========================================= */
.container {
    flex: 1; /* 让内容撑开，把页脚挤下去 */
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
}

.hero-section {
    text-align: center;
    margin-bottom: 40px;
}

    .hero-section h1 {
        font-size: 2.5rem;
        color: var(--text-main);
        margin-bottom: 10px;
        font-weight: 700;
    }

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* 搜索框区域 */
.search-section {
    width: 100%;
    max-width: 700px;
    margin: 0 auto 50px;
    position: relative;
}

.search-box {
    display: flex;
    background: var(--bg-search);
    border: 1px solid var(--border-color);
    border-radius: 50px; /* 全圆角 */
    padding: 6px;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    position: relative;
}

    .search-box:focus-within {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 4px rgba(74, 111, 165, 0.15); /* 聚焦光环 */
        transform: translateY(-2px);
    }

#search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 20px;
    font-size: 1rem;
    color: var(--text-main);
    outline: none;
}

#clear-btn {
    background: transparent;
    color: var(--text-light);
    border: none;
    cursor: pointer;
    padding: 8px;
    font-size: 1rem;
    transition: color 0.2s;
    display: none;
}

#clear-btn:hover {
    color: var(--text-secondary);
}

#search-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 40px;
    padding: 0 25px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 搜索建议 */
.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-search);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    z-index: 100;
    margin-top: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.suggestion-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background-color: var(--bg-tag);
}

.suggestion-item.active {
    background-color: var(--bg-tag);
}

    #search-btn:hover {
        background: var(--primary-hover);
    }

.stats {
    text-align: center;
    margin-top: 15px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.highlight {
    color: var(--primary-color);
    font-weight: bold;
    font-size: 1.1em;
}

/* =========================================
   5. 卡片列表 (Grid Layout)
   ========================================= */
.cards-grid {
    display: grid;
    /* 响应式网格：最小宽度280px，自动填充 */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    width: 100%;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease, border-color 0.3s ease;
    /* 初始出现动画 */
    animation: fadeInUp 0.5s ease backwards;
}

    .card:hover {
        transform: translateY(-8px); /* 仅使用transform移动，性能更好 */
        box-shadow: var(--shadow-md);
        border-color: transparent;
    }

/* ID 徽标 */
.card-id {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: bold;
    z-index: 2;
}

/* 图片容器 */
.card-img {
    width: 100%;
    height: 180px; /* 固定高度 */
    overflow: hidden;
    background-color: var(--bg-tag);
}

    .card-img img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        transition: transform 0.5s ease;
    }

.card:hover .card-img img {
    transform: scale(1.08); /* 图片微放大 */
}

/* 内容区域 */
.card-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 1.25rem;
    margin-bottom: 10px;
    color: var(--text-main);
    font-weight: 600;
}

.card-desc {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
    flex-grow: 1; /* 撑满剩余空间 */
    display: -webkit-box;
    -webkit-line-clamp: 3; /* 限制显示3行 */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 标签组 */
.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    background: var(--bg-tag);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.card:hover .tag {
    background: var(--primary-color);
    color: white;
}

/* 标签过滤区域 */
.tags-filter-section {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto 40px;
    padding: 0 20px;
}

.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.filter-tag {
    background: var(--bg-tag);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.filter-tag:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

.filter-tag.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-hover);
}

/* 无结果提示 */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 0;
    color: var(--text-secondary);
}

    .no-results i {
        font-size: 3rem;
        margin-bottom: 15px;
        color: var(--border-color);
    }

/* 加载动画 */
.loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 0;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s ease-in-out infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =========================================
   6. 页脚样式 (Footer)
   ========================================= */
.site-footer {
    background-color: var(--bg-footer);
    border-top: 1px solid var(--border-color);
    padding: 60px 0 20px;
    margin-top: auto; /* 自动置底 */
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 40px;
    justify-content: space-between;
}

.footer-section {
    flex: 1;
    min-width: 200px;
}

    .footer-section h3 {
        font-size: 1.1rem;
        margin-bottom: 20px;
        color: var(--text-main);
    }

.footer-links li {
    margin-bottom: 12px;
}

.footer-links a {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

    .footer-links a:hover {
        color: var(--primary-color);
    }

.footer-social {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

    .footer-social a {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: var(--bg-tag);
        color: var(--text-secondary);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.3s;
    }

        .footer-social a:hover {
            background: var(--primary-color);
            color: white;
            transform: translateY(-3px);
        }

.footer-bottom {
    text-align: center;
    margin-top: 60px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    color: var(--text-light);
    font-size: 0.85rem;
}

/* =========================================
   7. 动画与媒体查询
   ========================================= */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 返回顶部按钮样式 */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 3rem;
  height: 3rem;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
}

.back-to-top:hover {
  background-color: var(--primary-hover);
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 768px) {
    /* 基础容器优化 */
    .container {
        padding: 15px;
    }

    /* 头部优化 */
    header {
        padding: 15px;
    }

    nav ul {
        gap: 15px;
    }

    nav a {
        font-size: 0.9rem;
        padding: 8px 12px;
    }

    /* 主内容区优化 */
    main {
        padding: 15px 0;
    }

    /* 英雄区优化 */
    .hero-section h1 {
        font-size: 1.8rem;
        text-align: center;
        margin-bottom: 20px;
    }

    /* 搜索区域优化 */
    .search-section {
        padding: 15px;
        margin-bottom: 20px;
    }

    .search-box {
        padding: 4px;
        flex-direction: column;
        gap: 10px;
    }

    #search-input {
        padding: 12px 15px;
        font-size: 0.95rem;
    }

    #search-btn {
        padding: 12px 20px;
        width: 100%;
    }

    /* 搜索建议优化 */
    .search-suggestions {
        left: 10px;
        right: 10px;
        width: auto;
    }

    /* 标签过滤区域优化 */
    .tags-filter-section {
        padding: 0 15px 20px;
        margin-bottom: 20px;
    }

    .tags-container {
        gap: 8px;
    }

    .filter-tag {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    /* 卡片网格优化 */
    .card-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .card {
        margin: 0;
    }

    /* 卡片内部元素优化 */
    .card-img {
        height: 150px;
    }

    .card-content {
        padding: 15px;
    }

    .card-title {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    .card-desc {
        font-size: 0.9rem;
        margin-bottom: 15px;
        -webkit-line-clamp: 2;
    }

    .card-tags {
        gap: 6px;
    }

    .tag {
        padding: 3px 8px;
        font-size: 0.75rem;
    }

    /* 页脚优化 */
    footer {
        padding: 20px 15px;
    }

    .footer-content {
        flex-direction: column;
        gap: 20px;
    }

    .footer-section h3 {
        font-size: 1.1rem;
        margin-bottom: 10px;
    }

    .footer-section p {
        font-size: 0.9rem;
    }

    /* 返回顶部按钮响应式 */
    .back-to-top {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.2rem;
    }
}
