/* ==========================================================================
   Layout Styles - 页面布局样式 (v5.1 - 微信/Safari Flexbox 修复)
   ========================================================================== */

/* --- PC端默认样式 --- */
.app-header {
    text-align: center;
    padding: 2rem 1rem;
    background-color: var(--bg-secondary-color);
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease, opacity 0.3s ease;
    position: relative;
    z-index: 100;
}

body.mode-immersive .app-header {
    transform: translateY(-100%);
    opacity: 0;
    position: absolute;
    width: 100%;
    pointer-events: none;
}

.app-header h1 {
    font-size: 1.8rem;
    color: var(--text-highlight);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
}

.header-logo {
    width: 32px;
    height: 32px;
}

.subtitle {
    display: block;
    font-size: 0.9rem;
    color: var(--text-sub);
    font-weight: normal;
    margin-top: 0.2rem;
}

.app-slogan {
    margin: 1.5rem auto;
    max-width: 600px;
    font-size: 0.95rem;
    color: var(--text-sub);
    line-height: 1.6;
    position: relative;
    padding: 0 1rem;
}

.app-slogan p { margin-bottom: 0.3rem; }
.app-slogan strong { color: var(--text-main); font-weight: 700; }
.app-slogan .highlight { color: var(--text-main); font-weight: 600; border-bottom: 2px solid var(--border-color); padding-bottom: 1px; }

.grade-filter-container,
.content-type-filter-container,
.filter-container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

.grade-filter-container {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    transition: border-color 0.3s ease;
}

.content-type-filter-container { margin-bottom: 1.5rem; }

.tool-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

.search-container {
    position: relative;
    max-width: 400px;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-sub);
    pointer-events: none;
}

.search-input {
    width: 100%;
    height: 48px;
    padding: 10px 20px 10px 48px;
    font-size: 1rem;
    font-weight: 500;
    border: 2px solid var(--border-color);
    border-radius: 50px;
    background-color: var(--bg-secondary-color);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--theme-color) 20%, transparent); }
.search-input::placeholder { color: var(--text-sub); opacity: 0.8; }
.search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    height: 18px;
    width: 18px;
    display: inline-block;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%239ca3af'><path d='M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z'/></svg>");
    cursor: pointer;
    opacity: 0.6;
}
.search-input:focus::-webkit-search-cancel-button { opacity: 1; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 4rem;
    transition: padding-top 0.3s ease;
}

.load-more-trigger {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem 0;
    min-height: 80px;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s 0.2s, opacity 0.2s ease-in-out;
}
.load-more-trigger.is-visible { visibility: visible; opacity: 1; transition-delay: 0s; }

.app-footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-sub);
    font-size: 0.85rem;
    margin-bottom: 80px;
}
.app-footer p { margin: 0.3rem 0; }
.footer-meta { margin-top: 10px; }
.footer-meta a { color: inherit; text-decoration: none; }
body.mode-immersive .app-footer { display: none; }

/* ==========================================================================
   移动端响应式适配 (Breakpoint: 768px)
   ========================================================================== */
@media screen and (max-width: 768px) {

    /* 1. Body 转为 Flex Column */
    body {
        display: flex;
        flex-direction: column;
        /* 高度已在 base.css 中被固定为 100% fixed */
        height: 100%;
        overflow: hidden;
    }

    /* 2. Header 适配 */
    .app-header {
        padding: 0.5rem 0.8rem;
        flex-shrink: 0; /* 防止被挤压 */
    }
    .app-header h1 { font-size: 1.1rem; margin-bottom: 0; justify-content: flex-start; }
    .header-logo { width: 22px; height: 22px; }
    .subtitle, .app-slogan { display: none; }

    /* 3. 筛选器适配 */
    .grade-filter-container,
    .content-type-filter-container,
    .filter-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 0;
        margin-bottom: 0.5rem;
        gap: 0.5rem;
        flex-shrink: 0; /* 防止被挤压 */
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE */
    }
    .grade-filter-container::-webkit-scrollbar,
    .content-type-filter-container::-webkit-scrollbar,
    .filter-container::-webkit-scrollbar { display: none; }

    .grade-filter-container { margin-bottom: 0.5rem; padding-bottom: 0.5rem; }

    /* 4. 搜索框适配 */
    .tool-group { width: 100%; margin-top: 0.2rem; }
    .search-container { max-width: 100%; margin: 0; }
    .search-input { height: 36px; font-size: 0.9rem; min-width: 250px;}

    /* 5. 卡片网格 (Flexbox 撑满剩余空间) */
    .card-grid {
        /* 核心修复：min-height: 0 允许 flex 子项在需要时收缩，防止溢出 */
        flex: 1 1 auto;
        min-height: 0;

        display: flex;
        flex-wrap: nowrap;
        flex-direction: row;

        overflow-x: auto; /* 水平滚动 */
        overflow-y: hidden; /* 禁止垂直滚动 */

        padding: 0 1rem;
        gap: 1rem;
        margin: 0;

        /* 底部留白：适配固定在底部的导航栏 (60px) + 安全区域 */
        /* 使用 margin-bottom 而不是 padding-bottom，防止计算误差 */
        padding-bottom: calc(60px + env(safe-area-inset-bottom) + 10px);

        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;

        align-items: center; /* 垂直居中卡片 */
    }

    /* 沉浸模式下，头部消失，网格自动占据更多空间 */
    body.mode-immersive .card-grid {
        padding-top: 1rem;
    }

    /* 6. 移除页脚 */
    .app-footer {
        display: none !important;
    }

    /* 7. 加载触发器 */
    .load-more-trigger {
        min-width: 60px;
        height: 100%;
        margin: 0;
        scroll-snap-align: end;
        flex-shrink: 0;
    }
}