/* ============================================================================
   tag.css —— 标签页（`/tags/` 与 `/tag/<name>/`；P96 立）

   底盘照 policy.css 那类**简单文档页**（导航条居中品牌 + 650px 外壳），但两点不同：
     · wrapper 走**文档流型**（skill §2.5-B）：内容长由**文档**承接滚动，
       `min-height` 撑满短内容；🔴 **不得声明任何 overflow**（那是 sticky 祖先链红线，
       本页虽无吸顶，也照 B 型规范走 —— 将来要加吸顶不会踩雷）。
     · 本页**零自研 JS**（网格是服务端渲染的真锚点 `<a>`，爬虫直接跟）。

   🔴 与个人页网格的**四个值刻意复制**：列数（2 / ≥651 三列）、`gap`、瓦片
      `aspect-ratio: 4 / 5`、`border-radius: 8px` —— 逐值对拍有守卫测试钉着
      （`TagPageContractTests.test_tag_grid_matches_the_profile_grid_values`）。
      改这里必须同时看 profile.css 的 `.image-grid` / `.image-card`。
   🆕 P98：索引页另有一套 `.tag-cards`（1:1 目录卡片 + 文字遮罩）—— **不是同一类**、
      不复用详情页的瓦片类；它的列数同样与个人页网格对拍，gap/圆角/比例独立。
   ⚠️ 列数与缩略图档位是配着调的（P49 算式：卡片宽 × 目标 DPR ≤ THUMB_MAX_EDGE）。
      本页外壳 650px 封顶与个人页相同 ⇒ 现档位继续成立；档位数值以
      `app_picllery/image_derivatives.py` 的 `THUMB_MAX_EDGE` 为准（此处不再抄数字，
      抄一次就多一处会漂移的副本）；**改封顶或列数前先算一遍**。
   ============================================================================ */

:root {
    /* 底盘（值照 policy.css / 个人页既有档） */
    --tp-bg: #eeeeee;          /* = policy.css --bg-color */
    --tp-nav-h: 50px;          /* = policy.css --nav-height（≤640 档 44px） */
    --tp-ink: #1d2731;         /* = policy.css --title-color */
    --tp-text: #334455;
    --tp-muted: #6a7c8d;       /* = policy.css --muted-color */
    --tp-card: #ffffff;

    /* 网格（四值与个人页网格对拍，见文件头） */
    --tp-grid-gap: 6px;        /* = profile.css .image-grid 的 gap */
    --tp-tile-radius: 8px;     /* = .image-card 的 border-radius */
    --tp-tile-ratio: 4 / 5;    /* = .image-card 的 aspect-ratio */

    /* P98：索引页的「目录卡片」（1:1、带文字遮罩；与详情页瓦片**不是同一类**） */
    --tp-card-gap: 10px;
    --tp-card-radius: 12px;
    --tp-card-ratio: 1 / 1;

    /* P102：索引页 chip 云（第 7 名以后的标签） */
    --tp-pill-h: 30px;
    --tp-pill-gap: 8px;

    --tp-gutter: 12px;
    --tp-dur: 0.22s;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: #1a1a1a;   /* 桌面列侧描边（= policy.css 同款） */
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--tp-text);
}

/* 文档流型外壳：短内容撑满、长内容由文档承接；🔴 绝不声明 overflow */
.tag-wrapper {
    max-width: 650px;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    background: var(--tp-bg);
    padding-bottom: calc(var(--tp-gutter) + env(safe-area-inset-bottom));
}

/* 导航条：与登录/注册/政策页同一条基线（居中品牌 + 50/≤640:44 + 1.5em/1.3em） */
.tag-navbar {
    height: var(--tp-nav-h);
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.tag-navbar h1 {
    margin: 0;
    font-size: 1.5em;
    color: #1f1f1f;
    text-shadow: 0 0 6px rgba(0, 0, 0, 0.1);
}

.home-link {
    color: inherit;
    text-decoration: none;
}

@media (hover: hover) {
    .home-link:hover {
        color: #1f1f1f;
    }
}

.tag-content {
    padding: clamp(10px, 3vw, 16px);
}

/* ---- 头部区（标签名 + 张数/返回链）---- */
.tag-head {
    padding: 2px 2px 12px;
}

.tag-head-name {
    margin: 0;
    font-size: 1.35em;
    color: var(--tp-ink);
    overflow-wrap: anywhere;   /* 长标签名（用户内容）不许撑破 320 */
}

.tag-head-meta {
    margin: 6px 0 0;
    color: var(--tp-muted);
    font-size: 12px;
}

.tag-head-link {
    color: inherit;
    text-decoration: underline;
}

/* ---- 网格（列数与 profile.css .image-grid 对拍）---- */
.tag-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--tp-grid-gap);
}

@media only screen and (min-width: 651px) {
    .tag-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.tag-tile {
    display: block;
    aspect-ratio: var(--tp-tile-ratio);
    border-radius: var(--tp-tile-radius);
    overflow: hidden;
    background: #eef2ee;
    transition: box-shadow var(--tp-dur) ease;
}

.tag-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
}

@media (hover: hover) {
    .tag-tile:hover {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    }
}

.tag-tile:active {
    opacity: 0.92;
}

/* ---- 分页 ---- */
.tag-pager {
    margin: 16px 0 4px;
    display: flex;
    justify-content: center;
}

.tag-pager-link {
    display: inline-block;
    min-height: 44px;      /* 触控目标（视觉是胶囊，命中区即本体） */
    line-height: 42px;
    padding: 0 22px;
    border-radius: 999px;
    background: var(--tp-card);
    border: 1px solid rgba(143, 179, 154, 0.28);
    color: var(--tp-text);
    text-decoration: none;
    font-size: 14px;
}

@media (hover: hover) {
    .tag-pager-link:hover {
        border-color: #98e0ac;
    }
}

/* ---- 索引页：封面卡片网格（P98）----
   🔴 与上面的 `.tag-grid` / `.tag-tile`（详情页 4:5 纯图瓦片）**不是同一类**，刻意不共用：
      索引页是「目录卡片」（1:1 封面 + 文字遮罩），详情页是「图集瓦片」。
      两者列数都与个人页 `.image-grid` 对拍（2 / ≥651 三列），但 gap/圆角/比例各自成立
      （守卫：`TagPageContractTests`）。 */
.tag-cards {
    /* 列表重置：漏了会冒 UA 的项目符号与缩进 */
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--tp-card-gap);
}

@media only screen and (min-width: 651px) {
    .tag-cards {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.tag-card-item {
    min-width: 0;   /* 网格项允许收缩 —— 长标签省略号的前提 */
}

.tag-card {
    position: relative;
    display: block;
    aspect-ratio: var(--tp-card-ratio);
    border-radius: var(--tp-card-radius);
    overflow: hidden;
    background: #eef2ee;
    text-decoration: none;
    transition: box-shadow var(--tp-dur) ease, transform var(--tp-dur) ease;
}

.tag-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
    transition: transform var(--tp-dur) ease;
}

/* 底部渐变遮罩。⚠️ 它画在 img 之上、meta 之下：meta 提了 z-index:1 ——
   否则（同为 auto 时）树序更晚的 ::after 会把文字也压暗。 */
.tag-card::after {
    content: '';
    position: absolute;
    inset: auto 0 0 0;
    height: 58%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
    pointer-events: none;
}

.tag-card-meta {
    position: absolute;
    inset: auto 0 0 0;
    z-index: 1;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 0 10px 8px;
}

.tag-card-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    /* 亮封面上的可读性兜底（与查看器叠层同一语汇） */
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.45), 0 1px 4px rgba(0, 0, 0, 0.35);
}

.tag-card-count {
    flex: 0 0 auto;
    color: rgba(255, 255, 255, 0.82);
    font-size: 12px;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.45);
}

@media (hover: hover) {
    .tag-card:hover {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    }
    .tag-card:hover img {
        transform: scale(1.03);
    }
}

.tag-card:active {
    transform: scale(0.99);
}

/* ---- 索引页：小节标题与 chip 云（P102）----
   双层结构的第二段：第 7 名以后的标签用纯文本 chip（整颗可点、自动换行）。
   🔴 触控目标 30px < 44px 指南 —— 标签云/文本链接的通行取舍（与查看器里的标签
      chip 同定位），用「行距 8 + 整颗可点」换密度（用户拍板接受）。 */
.tag-section-title {
    margin: 20px 0 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--tp-ink);
}

.tag-pills {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--tp-pill-gap);
}

.tag-pill-item {
    flex: 0 1 auto;
    min-width: 0;      /* 允许收缩 —— 长名省略号的前提 */
    max-width: 100%;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    min-height: var(--tp-pill-h);
    padding: 0 12px;
    box-sizing: border-box;
    border-radius: 999px;
    background: var(--tp-card);
    border: 1px solid rgba(143, 179, 154, 0.18);
    color: var(--tp-ink);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background-color var(--tp-dur) ease, border-color var(--tp-dur) ease;
}

.tag-pill-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-pill-count {
    flex: 0 0 auto;
    margin-left: 6px;
    color: var(--tp-muted);
    font-size: 12px;
    font-weight: 400;
}

@media (hover: hover) {
    .tag-pill:hover {
        border-color: #98e0ac;
        background: #f5f5f5;
    }
}

.tag-pill:active {
    background: #ebebeb;
}

.tag-empty {
    color: var(--tp-muted);
    padding: 24px 4px;
}

.tag-foot-note {
    margin-top: 18px;
    color: var(--tp-muted);
    font-size: 12px;
    line-height: 1.5;
}

/* ⚠️ reduced-motion 覆盖块必须写在**基础规则之后**（同特异性后者胜；P75/P43 教训）。 */
@media (prefers-reduced-motion: reduce) {
    .tag-tile,
    .tag-card,
    .tag-card img,
    .tag-pill {
        transition: none;
    }
}

@media only screen and (max-width: 640px) {
    .tag-navbar {
        height: 44px;
    }
    .tag-navbar h1 {
        font-size: 1.3em;
    }
}
