/* ==========================================================================
   最新文章 latest_articles
   全部使用主题 CSS 变量，浅色 / 深色模式自动适配

   渐变说明：
     表面用的是「强调色低比例混入底色」的浅色渐变（color-mix），
     不是叠加半透明图层——所以深浅色模式下都自然。
     渐变尺寸放大到 200%，靠 background-position 位移来做 hover 过渡
     （CSS 无法插值渐变本身，只能位移）。
     浏览器不支持 color-mix 时整条 background-image 失效，
     自动回落到前面的 background-color，不会翻车。
   ========================================================================== */

.af {
    --af-accent: var(--theme-color);
    --af-grad: linear-gradient(135deg, var(--af-accent), var(--theme-color));

    /* 浅色渐变强度：由后台「浅色渐变强度」下发 */
    --af-tint: 11%;
    --af-tint-hover: 17%;

    /* 疏密：由「疏密」档位覆盖，移动端会再覆盖一次 */
    --af-pad-y: 22px;
    --af-pad-x: 24px;
    --af-head-mb: 18px;
    --af-list-gap: 10px;
    --af-item-pad: 12px;
    --af-item-gap: 16px;
    --af-body-gap: 6px;

    position: relative;
    margin-bottom: 16px;
    padding: var(--af-pad-y) var(--af-pad-x) calc(var(--af-pad-y) + 2px);

    background-color: var(--bg-card);
    background-image: linear-gradient(
        158deg,
        color-mix(in srgb, var(--af-accent) calc(var(--af-tint) * 0.6), var(--bg-card)) 0%,
        var(--bg-card) 58%
    );

    border: 1px solid var(--border-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

/* hidden 属性只是 UA 样式表里的 display:none，会被作者样式里的 display:inline-flex 覆盖。
   组件内部的按钮就是 inline-flex，所以必须补这条重置，否则「隐藏」按钮会失效。 */
.af [hidden] {
    display: none !important;
}

/* 顶部渐变高光条：与「资源下载卡片」保持同一套设计语言 */
.af::after {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--af-grad);
    pointer-events: none;
}

/* 右上角柔光：给表面一点空气感 */
.af__wash {
    position: absolute;
    top: -70px;
    right: -90px;
    width: 460px;
    height: 280px;
    background: radial-gradient(circle at 68% 32%, var(--af-accent), transparent 68%);
    opacity: 0.08;
    pointer-events: none;
}

/* ---------- 区块头 ---------- */

.af__head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: var(--af-head-mb);
}

.af__head-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

/* 渐变竖条 + 光晕 */
.af__mark {
    position: relative;
    flex: 0 0 auto;
    width: 4px;
    height: 20px;
    background: var(--af-grad);
    border-radius: 3px;
}

.af__mark::after {
    content: '';
    position: absolute;
    inset: -3px;
    background: var(--af-grad);
    border-radius: 6px;
    filter: blur(7px);
    opacity: 0.55;
}

.af__title {
    margin: 0;
    padding: 0;
    font-size: 19px;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.01em;
    color: var(--caption-color);
    white-space: nowrap;
}

.af__subtitle {
    padding-left: 10px;
    border-left: 1px solid var(--border-primary);
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 右上角更多按钮：浅色渐变底，悬停填充实心渐变 */
.af__more {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 13px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    text-decoration: none;
    background-color: var(--bg-secondary);
    background-image: linear-gradient(
        135deg,
        color-mix(in srgb, var(--af-accent) calc(var(--af-tint) * 0.7), var(--bg-card)),
        var(--bg-secondary)
    );
    border: 1px solid var(--border-primary);
    border-radius: 999px;
    transition: color 0.25s ease, background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.af__more svg {
    width: 14px;
    height: 14px;
    transition: transform 0.25s ease;
}

.af__more:hover {
    color: #fff;
    background-color: transparent;
    background-image: var(--af-grad);
    border-color: transparent;
    box-shadow: 0 4px 14px -4px var(--af-accent);
}

.af__more:hover svg {
    transform: translateX(2px);
}

/* ---------- 列表容器 ---------- */

.af__list {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--af-list-gap);
}

.af--cols-2 .af__list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* ---------- 单条 ---------- */

.af-item {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: var(--af-item-gap);
    padding: var(--af-item-pad);

    background-color: var(--bg-secondary);
    /* 三停靠点 + 放大尺寸，靠位移做 hover 过渡 */
    background-image: linear-gradient(
        135deg,
        color-mix(in srgb, var(--af-accent) var(--af-tint), var(--bg-card)) 0%,
        var(--bg-secondary) 50%,
        color-mix(in srgb, var(--af-accent) calc(var(--af-tint) * 0.55), var(--bg-card)) 100%
    );
    background-size: 200% 200%;
    background-position: 0% 0%;

    border: 1px solid var(--border-secondary);
    border-radius: var(--border-radius);
    transition: background-position 0.45s ease, border-color 0.25s ease,
                box-shadow 0.25s ease, transform 0.25s ease;
}

/* 左侧渐变条：悬停时从中间展开 */
.af-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 14px;
    bottom: 14px;
    width: 3px;
    background: var(--af-grad);
    border-radius: 0 3px 3px 0;
    opacity: 0;
    transform: scaleY(0.25);
    transform-origin: center;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.af-item:hover {
    background-position: 100% 100%;
    border-color: transparent;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.af-item:hover::before {
    opacity: 1;
    transform: scaleY(1);
}

/* ---------- 缩略图 ---------- */

.af-item__thumb {
    position: relative;
    flex: 0 0 auto;
    display: block;
    width: var(--af-thumb-w, 176px);
    aspect-ratio: var(--af-ratio, 16 / 10);
    overflow: hidden;
    background: var(--bg-hover);
    border-radius: calc(var(--border-radius) - 2px);
}

.af-item__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.af-item:hover .af-item__thumb img {
    transform: scale(1.06);
}

/* 底部压暗：保证分类角标在任何亮度的图上都读得清 */
.af-item__thumb::after {
    content: '';
    position: absolute;
    inset: auto 0 0 0;
    height: 52%;
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.42));
    pointer-events: none;
    z-index: 1;
}

/* 斜向扫光 */
.af-item__sheen {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: linear-gradient(105deg, transparent 32%, rgba(255, 255, 255, 0.34) 50%, transparent 68%);
    transform: translateX(-130%);
    pointer-events: none;
}

.af-item:hover .af-item__sheen {
    transform: translateX(130%);
    transition: transform 0.75s ease;
}

/* 分类角标：毛玻璃 */
.af-item__cat {
    position: absolute;
    left: 8px;
    bottom: 8px;
    z-index: 2;
    padding: 2px 9px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.6;
    color: #fff;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    -webkit-backdrop-filter: blur(8px) saturate(160%);
    backdrop-filter: blur(8px) saturate(160%);
}

/* 序号徽标 */
.af-item__rank {
    position: absolute;
    left: 8px;
    top: 8px;
    z-index: 2;
    min-width: 22px;
    padding: 1px 5px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.7;
    text-align: center;
    color: #fff;
    background: var(--af-grad);
    border-radius: 6px;
    box-shadow: 0 2px 8px -2px var(--af-accent);
}

.af-item__rank--inline {
    position: static;
    display: inline-block;
    flex: 0 0 auto;
    margin-right: 2px;
    vertical-align: 2px;
}

/* ---------- 文本区 ---------- */

.af-item__body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--af-body-gap);
    padding: 2px 4px 2px 0;
}

.af-item__title {
    margin: 0;
    padding: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text-primary);
}

.af-item__title a {
    display: -webkit-box;
    -webkit-line-clamp: var(--af-title-lines, 2);
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.af-item__title a:hover {
    color: var(--theme-color);
}

.af-item__today {
    display: inline-block;
    margin-right: 6px;
    padding: 0 6px;
    font-size: 11px;
    font-style: normal;
    font-weight: 500;
    line-height: 1.7;
    color: #fff;
    background: var(--af-grad);
    border-radius: 4px;
    vertical-align: 2px;
}

.af-item__excerpt {
    margin: 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-tertiary);
    display: -webkit-box;
    -webkit-line-clamp: var(--af-excerpt-lines, 2);
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---------- 元信息 ---------- */

.af-item__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-top: auto;
    padding-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
}

.af-item__author {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.af-item__author img {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.af-item__date {
    position: relative;
    padding-left: 15px;
}

.af-item__date::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 50%;
    width: 3px;
    height: 3px;
    margin-top: -1.5px;
    background: var(--border-hover);
    border-radius: 50%;
}

.af-item__stats {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.af-item__stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s ease;
}

.af-item__stat svg {
    width: 13px;
    height: 13px;
}

.af-item__stat:hover {
    color: var(--theme-color);
}

/* ---------- 无缩略图时 ---------- */

.af-item--no-thumb .af-item__body {
    padding: 4px 2px;
}

/* ==========================================================================
   版式：紧凑列表
   ========================================================================== */

.af--list .af__list {
    gap: 0;
}

.af--list .af-item {
    padding: 13px 4px;
    /* 行式布局不铺底，靠 hover 的浅渐变 + 左侧渐变条区分 */
    background-color: transparent;
    background-image: none;
    border: none;
    border-bottom: 1px solid var(--border-secondary);
    border-radius: 0;
}

.af--list .af-item:last-child {
    border-bottom: none;
}

.af--list .af-item:hover {
    background-image: linear-gradient(
        100deg,
        color-mix(in srgb, var(--af-accent) calc(var(--af-tint) * 0.8), var(--bg-card)) 0%,
        transparent 68%
    );
    box-shadow: none;
    transform: none;
}

.af--list .af-item::before {
    left: -4px;
    border-radius: 3px;
}

.af--list .af-item__thumb {
    width: 152px;
}

/* ==========================================================================
   版式：头条 + 卡片
   ========================================================================== */

.af--featured .af-item.is-hero {
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg-card);
    background-image: linear-gradient(
        150deg,
        color-mix(in srgb, var(--af-accent) calc(var(--af-tint) * 0.7), var(--bg-card)) 0%,
        var(--bg-card) 55%
    );
    background-size: auto;
    border-color: var(--border-secondary);
}

.af--featured .af-item.is-hero:hover {
    background-position: 0% 0%;
}

.af--featured .af-item.is-hero::before {
    top: 0;
    bottom: 0;
    width: 4px;
}

.af--featured .af-item.is-hero .af-item__thumb {
    width: 100%;
    aspect-ratio: var(--af-hero-ratio, 21 / 9);
    border-radius: 0;
}

.af--featured .af-item.is-hero .af-item__body {
    gap: 8px;
    padding: 16px 18px 18px;
}

.af--featured .af-item.is-hero .af-item__title {
    font-size: 19px;
}

.af--featured .af-item.is-hero .af-item__excerpt {
    font-size: 13.5px;
}

/* ==========================================================================
   外观开关（全部由后台配置，CSS 里不留写死的观感）
   ========================================================================== */

/* 顶部渐变高光条 */
.af--no-topbar::after {
    display: none;
}

/* 悬停抬升 */
.af--no-lift .af-item:hover {
    transform: none;
}

/* ==========================================================================
   疏密档位（紧凑 / 标准 / 宽松）
   覆盖的是一组变量而不是直接写属性，这样移动端能再定义一套自己的档位值，
   否则移动端媒体查询会把档位整个盖掉、疏密在手机上失效。
   ========================================================================== */

.af--density-compact {
    --af-pad-y: 16px;
    --af-pad-x: 18px;
    --af-head-mb: 12px;
    --af-list-gap: 6px;
    --af-item-pad: 9px;
    --af-item-gap: 12px;
    --af-body-gap: 4px;
}

.af--density-compact .af-item__excerpt {
    line-height: 1.6;
}

.af--density-loose {
    --af-pad-y: 28px;
    --af-pad-x: 30px;
    --af-head-mb: 22px;
    --af-list-gap: 16px;
    --af-item-pad: 16px;
    --af-item-gap: 20px;
    --af-body-gap: 9px;
}

.af--density-loose .af-item__excerpt {
    line-height: 1.85;
}

/* ==========================================================================
   移动端
   ========================================================================== */

@media (max-width: 768px) {
    /* 窄屏给一套自己的疏密基线；注意不要覆盖 --af-tint，那是用户选的 */
    .af {
        --af-pad-y: 16px;
        --af-pad-x: 14px;
        --af-head-mb: 14px;
        --af-list-gap: 8px;
        --af-item-pad: 11px;
        --af-item-gap: 12px;
        --af-body-gap: 6px;
    }

    /* 档位在手机上依然可分辨 */
    .af--density-compact {
        --af-pad-y: 12px;
        --af-pad-x: 12px;
        --af-head-mb: 10px;
        --af-list-gap: 5px;
        --af-item-pad: 9px;
        --af-item-gap: 10px;
        --af-body-gap: 4px;
    }

    .af--density-loose {
        --af-pad-y: 19px;
        --af-pad-x: 16px;
        --af-head-mb: 16px;
        --af-list-gap: 12px;
        --af-item-pad: 13px;
        --af-item-gap: 14px;
        --af-body-gap: 7px;
    }

    .af__title {
        font-size: 17px;
    }

    .af__subtitle {
        display: none;
    }

    /* 移动端列数一律降为单列 */
    .af--cols-2 .af__list {
        display: flex;
        flex-direction: column;
    }

    /* 缩略图仍按用户选的比例，只改宽度 */
    .af-item__thumb,
    .af--list .af-item__thumb {
        width: 116px;
    }

    .af-item__title {
        font-size: 15px;
    }

    .af-item__excerpt {
        font-size: 12.5px;
    }

    .af-item__meta {
        gap: 5px 10px;
        font-size: 11.5px;
    }

    .af-item__author img {
        width: 16px;
        height: 16px;
    }

    /* 数据统计独占一行、左对齐 */
    .af-item__stats {
        flex: 1 0 100%;
        margin-left: 0;
    }

    .af--featured .af-item.is-hero .af-item__body {
        padding: 13px 14px 15px;
    }

    .af--featured .af-item.is-hero .af-item__title {
        font-size: 16.5px;
    }

    /* 触摸设备取消抬升，避免悬停态粘住 */
    .af-item:hover {
        transform: none;
    }
}

@media (max-width: 768px) {
    .af--hide-mobile {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .af--hide-pc {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .af-item,
    .af-item::before,
    .af-item__thumb img,
    .af-item__sheen,
    .af__more,
    .af__more svg {
        transition: none;
    }

    .af-item:hover {
        transform: none;
        background-position: 0% 0%;
    }
}

/* ==========================================================================
   分页
   ========================================================================== */

.af__pager {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}

.af__pager-count {
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-muted);
}

.af__pager-count b {
    font-weight: 600;
    color: var(--text-secondary);
}

.af__pager-end {
    padding: 2px 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-muted);
}

.af__pager-end::before,
.af__pager-end::after {
    content: '';
    display: inline-block;
    width: 36px;
    height: 1px;
    margin: 0 10px;
    vertical-align: middle;
    background: var(--border-primary);
}

/* 图标：idle / busy 两份，靠 class 切换，避免 JS 改 innerHTML */
.af__load-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
}

.af__load-btn .af__load-icon--busy,
.af__load-pill .af__load-icon--busy { display: none; }

.af__load-btn.is-loading .af__load-icon--idle,
.af__load-pill.is-loading .af__load-icon--idle { display: none; }

.af__load-btn.is-loading .af__load-icon--busy,
.af__load-pill.is-loading .af__load-icon--busy { display: inline-flex; }

.af__load-btn.is-loading .af__load-icon--busy svg,
.af__load-pill.is-loading .af__load-icon--busy svg { animation: af-spin 0.8s linear infinite; }

/* --- A. 描边幽灵按钮：与主题自带 .load-more-btn 规格一致 --- */
.af__load-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 32px;
    font: inherit;
    font-size: 14px;
    line-height: 1.6;
    color: var(--theme-color);
    background: transparent;
    border: 1px solid var(--theme-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.af__load-btn:hover {
    background: color-mix(in srgb, var(--theme-color) 7%, transparent);
}

.af__load-btn.is-loading,
.af__load-btn:disabled {
    cursor: default;
    opacity: 0.72;
}

/* --- B. 渐变胶囊：与本组件的设计语言一致 --- */
.af__load-pill {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 20px 9px 24px;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.6;
    color: #fff;
    background: var(--af-grad);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 6px 18px -7px var(--af-accent);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.af__load-pill:hover {
    transform: translateY(-2px);
    box-shadow: 0 11px 24px -9px var(--af-accent);
}

.af__load-pill:active { transform: translateY(0); }

.af__load-pill.is-loading {
    pointer-events: none;
    opacity: 0.75;
    transform: none;
}

.af__load-rest {
    font-style: normal;
    font-weight: 400;
    opacity: 0.8;
}

/* --- C. 无限滚动 --- */
.af__infinite {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 34px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
}

.af__infinite.is-end::before,
.af__infinite.is-end::after {
    content: '';
    width: 36px;
    height: 1px;
    background: var(--border-primary);
}

.af__spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-hover);
    border-top-color: var(--af-accent);
    border-radius: 50%;
}

.af__infinite.is-loading .af__spinner {
    display: block;
    animation: af-spin 0.7s linear infinite;
}

@keyframes af-spin {
    to { transform: rotate(360deg); }
}

/* --- D. 数字分页：沿用主题 .archive-pagination 规格，current 换成渐变 --- */
.af__pages {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
}

.af__pages a,
.af__pages span {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    text-decoration: none;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border-input);
    border-radius: var(--border-radius-sm);
    transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.af__pages a:hover {
    color: var(--af-accent);
    border-color: var(--af-accent);
    transform: translateY(-1px);
}

.af__pages .is-current {
    color: #fff;
    font-weight: 600;
    background: var(--af-grad);
    border-color: transparent;
    box-shadow: 0 4px 12px -5px var(--af-accent);
}

.af__pages .is-gap {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.af__pages-arrow {
    color: var(--text-secondary);
}

.af__pages-arrow svg {
    width: 15px;
    height: 15px;
}

/* --- 加载中时禁止重复点击 --- */
.af.is-af-busy .af__load-btn,
.af.is-af-busy .af__load-pill {
    pointer-events: none;
}

/* ==========================================================================
   分页 · 移动端
   ========================================================================== */

@media (max-width: 768px) {
    .af__load-btn,
    .af__load-pill {
        width: 100%;
        justify-content: center;
    }

    .af__pages a,
    .af__pages span {
        min-width: 32px;
        height: 32px;
        padding: 0 8px;
    }

    .af__pages-arrow {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .af__load-btn,
    .af__load-pill,
    .af__pages a {
        transition: none;
    }

    .af__load-pill:hover,
    .af__pages a:hover {
        transform: none;
    }

    .af .af__spinner,
    .af__load-icon--busy svg {
        animation: none;
    }
}
