/* ============================================================
   杂记 · 个人网站 样式表
   响应式适配：手机端（默认）/ 平板 / PC 宽屏
   断点：640px（手机→平板）、1080px（平板→PC 宽屏）
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf9f7;
  --card: #ffffff;
  --line: #e8e5df;
  --line-strong: #d6d2c9;
  --text: #2b2a26;
  --body-text: #3a3833;
  --sub: #5f5c55;      /* 6.34:1 on --bg —— WCAG AA 通过 */
  --faint: #6f6c64;    /* 4.98:1 on --bg / 5.24:1 on --card / 4.73:1 on --footer-bg —— AA 通过 */
  --accent: #4a6b52;
  --accent-soft: #eef3ef;
  --footer-bg: #f5f3ef;
  --radius: 10px;
  --wrap: 760px;
  --gap: 14px;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  /* iPhone 刘海屏 / 底部横条安全区 */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a { -webkit-tap-highlight-color: rgba(74, 107, 82, .12); }
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 18px;
}

/* ==================== 顶栏 ==================== */
.site-header {
  border-bottom: 1px solid var(--line);
  background: rgba(250, 249, 247, .93);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  padding-bottom: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  flex: none;
}
.brand-mark {
  width: 34px; height: 34px; flex: none;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 600;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; font-weight: 600; letter-spacing: .5px; }
.brand-text em { font-style: normal; font-size: 11px; color: var(--faint); letter-spacing: .6px; }

/* 导航：手机端横向滚动，不换行不挤压。
   右侧渐隐提示"还有更多"——15 个导航项实测 scrollWidth 1222px，390px 下被
   裁掉 832px、414px 下 808px（真机量过；内容一加这个数就会变，别信旧值），
   没有提示时读者会直接判定"这里没有国学/技术笔记"。 */
.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin: 0 -18px;
  padding: 0 18px;
  scroll-padding: 0 18px;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;              /* WCAG 2.5.5 触控目标 */
  text-decoration: none;
  color: var(--sub);
  font-size: 14px;
  padding: 0 12px;
  border-radius: 8px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--accent-soft); color: var(--accent); }
.nav a.active { color: var(--accent); font-weight: 600; background: var(--accent-soft); }

/* ==================== 主体 ==================== */
main { flex: 1; padding: 28px 0 48px; }
.loading { color: var(--faint); text-align: center; padding: 40px 0; }

/* ---------- 首屏 ---------- */
.hero { padding-bottom: 26px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.hero h1 { font-size: clamp(24px, 6vw, 30px); font-weight: 600; letter-spacing: 1px; line-height: 1.3; }
.hero-sub { color: var(--accent); font-size: 13px; letter-spacing: 3px; margin-top: 6px; }
.hero-desc { color: var(--sub); margin-top: 14px; font-size: 15px; }
.hero-sm { padding-bottom: 20px; margin-bottom: 22px; }
.hero-sm h1 { font-size: clamp(21px, 5vw, 24px); }

/* ---------- 分类卡 ---------- */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  margin-bottom: 34px;
}
.cat-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  min-height: 44px;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.cat-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(30, 28, 20, .06);
}
.cat-card h2 { font-size: 16px; font-weight: 600; color: var(--accent); }
.cat-card p { font-size: 13px; color: var(--sub); margin-top: 6px; line-height: 1.65; padding-right: 46px; }
.cat-count { position: absolute; top: 16px; right: 18px; font-size: 12px; color: var(--faint); }

.section-title { font-size: 15px; font-weight: 600; color: var(--faint); letter-spacing: 1px; margin-bottom: 14px; }

/* ---------- 文章列表 ---------- */
.list { display: flex; flex-direction: column; gap: var(--gap); }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;            /* 供 .card-link::after 铺满整卡 */
  transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: var(--line-strong); box-shadow: 0 2px 10px rgba(30, 28, 20, .05); }
/* 标题链接是卡片主入口，但它只包住 26px 高的标题，命中区太小。
   用「拉伸链接」把伪元素铺满整张卡：命中区变成整块卡片，且不改变任何高度
   （给 .card-link 加 padding 也能达标，但会让 230 张卡各长高 19px）。
   卡内另一个链接 .card-more 指向同一地址且已 tabindex="-1" aria-hidden，
   被覆盖也没有冲突。 */
.card-link { text-decoration: none; color: inherit; }
.card-link::after { content: ""; position: absolute; inset: 0; }
.card-title { font-size: 17px; font-weight: 600; line-height: 1.5; }
.card-link:hover .card-title { color: var(--accent); }
.card-meta { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--faint); flex-wrap: wrap; }
.tag { padding: 2px 9px; border-radius: 999px; font-size: 11px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
/* 12 个分类各自的标签配色（两两不同；文字对比度均 ≥5.1:1） */
.tag-mech       { background: #eef2f7; color: #46617f; }
.tag-rail       { background: #eaf1f4; color: #3d6373; }
.tag-logistics  { background: #f0f2ea; color: #5a6b3a; }
.tag-ecom       { background: #fdf0ea; color: #8a4f33; }
.tag-marketing  { background: #f9eef2; color: #7f4159; }
.tag-hotel      { background: #f2f0e9; color: #7a6a3d; }
.tag-accounting { background: #eef4f1; color: #3f6b58; }
.tag-mobile     { background: #f0eef7; color: #544a80; }
.tag-frontend   { background: #e9f4f6; color: #2f6472; }
.tag-tech       { background: #eef0f2; color: #45505c; }
.tag-guoxue     { background: #f3f0e6; color: #6f6335; }
.tag-life       { background: #f4eef1; color: #7a4a5c; }
.card-summary { color: var(--sub); font-size: 14px; margin-top: 10px; }
.card-more {
  display: inline-block;
  margin-top: 12px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  padding: 12px 0 10px;          /* 触控目标 ≥44px（原 4px 0 仅 31px 高） */
}
.card-more:hover { text-decoration: underline; }

/* ---------- 文章详情 ---------- */
.post {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 20px 22px;
}
.post-crumb { font-size: 13px; color: var(--faint); margin-bottom: 14px; }
.post-crumb a { color: var(--sub); text-decoration: none; padding: 4px 0; }
.post-crumb a:hover { color: var(--accent); }
.post-title { font-size: clamp(21px, 5.5vw, 26px); font-weight: 600; line-height: 1.45; }
.post-meta { font-size: 13px; color: var(--faint); margin-top: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.post-body { margin-top: 18px; }
.post-body p { margin-bottom: 15px; color: var(--body-text); }
.post-body a { color: var(--accent); }
.post-body h2 { font-size: 17px; font-weight: 600; margin: 26px 0 12px; }
.post-body h3 { font-size: 16px; font-weight: 600; margin: 22px 0 10px; }
.post-body strong { font-weight: 600; color: var(--text); }
.post-body ul { margin: 0 0 15px 1.25em; color: var(--body-text); }
.post-body li { margin-bottom: 6px; }
.post-back { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 14px; }
.post-back a { color: var(--accent); text-decoration: none; display: inline-block; padding: 4px 0; }
.post-back a:hover { text-decoration: underline; }

/* ---------- 文末同分类推荐 ---------- */
.post-more { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.post-more-title { font-size: 14px; font-weight: 600; color: var(--faint); letter-spacing: 1px; }
.post-more ul { list-style: none; margin-top: 12px; }
.post-more li { margin-bottom: 4px; }
.post-more a { color: var(--accent); text-decoration: none; display: inline-block; padding: 9px 0; font-size: 15px; }
.post-more a:hover { text-decoration: underline; }

/* ---------- 正文图表（内联 SVG，无外部依赖） ---------- */
/* viewBox 固定 0 0 320 205；窄屏字号 17、≥640px 覆盖为 12，
   使 SVG 内文字在 320–1440 全区间落在约 12.9–16.5px 可读区间 */
.fig {
  margin: 22px 0;
  padding: 0;
  text-align: center;
}
.fig svg {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  margin: 0 auto;
  overflow: visible;
}
.fig text { font-size: 17px; fill: var(--sub); }
.fig .g-axis { stroke: var(--line-strong); stroke-width: 1; }
.fig .g-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
.fig .g-line { stroke: var(--accent); stroke-width: 1.5; fill: none; }
.fig .g-area { fill: var(--accent-soft); }
.fig .g-bar { fill: var(--accent); opacity: .78; }
.fig .g-dot { fill: var(--accent); }
.fig .g-label { fill: var(--text); }
.fig .g-muted { fill: var(--faint); }
.fig figcaption {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--faint);
  line-height: 1.6;
  text-align: center;
}

.empty { text-align: center; color: var(--sub); padding: 50px 0; }
.empty a { color: var(--accent); }

/* ---------- 自撰文章载入失败的提示条 ----------
   定位：可见但不阻断。用左侧色条 + 浅底而不是红色告警框 —— 静态内容完全正常，
   只有"补充的那部分"没取到，红色会让读者以为整站坏了。
   配色沿用 --accent-soft / --accent：与分类卡、标签同族，不引入新色。 */
.notice {
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 22px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--sub);
}
.notice p + p { margin-top: 6px; }
.notice a { color: var(--accent); }

/* ---------- 首页"查看全部"与分页 ---------- */
.more-all { text-align: center; margin: 22px 0 4px; }
.more-all a { color: var(--accent); text-decoration: none; display: inline-block; padding: 12px 0; font-size: 15px; }
.more-all a:hover { text-decoration: underline; }
.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 26px 0 6px; }
.pg { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
      padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--sub);
      text-decoration: none; font-size: 14px; }
.pg:hover { border-color: var(--accent); color: var(--accent); }
.pg-cur { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- 标签：分类是"领域"轴，标签是"主题"轴 ---------- */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }
.tag-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
            padding: 0 12px; border: 1px solid var(--line); border-radius: 6px;
            color: var(--sub); text-decoration: none; font-size: 14px; }
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-n { font-size: 12px; color: var(--faint); }
.tag-inline { color: var(--sub); text-decoration: none; border-bottom: 1px dotted var(--line); }
.tag-inline:hover { color: var(--accent); border-bottom-color: var(--accent); }
.tag-plain { color: var(--faint); }

/* ---------- 跳转到正文（键盘/读屏） ---------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 60;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ==================== 页脚 ==================== */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--footer-bg);
  padding: 22px 0 calc(26px + env(safe-area-inset-bottom));
}
.footer-inner { font-size: 12.5px; color: var(--faint); line-height: 1.9; }
.footer-line { word-break: break-word; }
.footer-line a { color: var(--sub); text-decoration: none; display: inline-block; padding: 11px 0; }
.footer-line a:hover { color: var(--accent); text-decoration: underline; }
.footer-note { margin-top: 8px; font-size: 11.5px; color: #6f6c64; }  /* 原 #a8a49a 在 --footer-bg 上仅 2.24:1，不达 AA；改后 4.73:1 */

/* ============================================================
   平板及以上（≥640px）
   ============================================================ */
@media (min-width: 640px) {
  :root { --wrap: 720px; --gap: 16px; }

  .wrap { padding: 0 24px; }

  /* 导航：640px 起换行，不再横向滚动。
     实测 15 个中文标签总宽 1186px（padding 12px 版），单个宽度
     [52,80,80,80,80,94,80,80,80,80,80,80,80,52,52]。

     两条被实测否决的做法：
       a) brand 与导航同一行换行：640px 只剩 425px，被挤成 5/4/5/1 四行，
          最后一行孤零零一个「关于」，顶栏 189px；
       b) 640–1024px 继续单行横向滚动：顶栏降到 65px，但把「标签」「关于」
          等 660–757px 的标签藏到滚动区外 —— 桌面端没有滚动条、也没有
          触屏惯性，读者根本不会发现右边还有内容，比破格行更糟。

     采用：brand 独占一行 + 导航均匀换行 + 左右 padding 收到 8px。
     收到 8px 后总宽约 1066px，640px 下排成 7/8 两行（无孤行），
     768–1239px 排成 9/6，顶栏均约 132–140px。 */
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 6px;
    padding-top: 10px;
    padding-bottom: 10px;
    min-height: 0;
  }
  .brand { align-self: flex-start; }
  .nav {
    margin: 0;
    padding: 0;
    overflow: visible;
    flex-wrap: wrap;
    -webkit-mask-image: none;
    mask-image: none;
  }
  .nav a { padding: 0 8px; }

  .cat-grid { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 20px 22px; }
  .card-title { font-size: 18px; }
  .post { padding: 30px 32px 26px; }
  main { padding: 36px 0 56px; }

  /* 图表：限制放大倍数，并把 SVG 内字号按放大倍数反向补偿。
     .fig svg 的 max-width 从 320 提到 440，等于把整个 viewBox 放大 440/320 = 1.375 倍；
     SVG 里的 font-size 是用户单位，会跟着一起放大，所以声明的值必须除以 1.375。
     17 / 1.375 ≈ 12.4 —— 不是 12。写 12 的渲染结果是 16.5px，比窄屏（320 宽、缩放 1.0）
     的 17px 更小：视口变宽、图表变大，图里的字反而变小。
     _figcheck.js 会静态核对这条耦合（渲染字号 = max-width / 320 × font-size ≥ 窄屏 17px）。 */
  .fig svg { max-width: 440px; }
  .fig text { font-size: 12.4px; }
  .fig figcaption { font-size: 13px; }
}

/* ============================================================
   PC 宽屏（≥1080px）—— 更宽的版心 + 双列文章卡
   ============================================================ */
@media (min-width: 1080px) {
  /* --measure：正文的可读行宽（em 计，随字号缩放）。
     与 --wrap 分开是为了让这两件事各自可控：
       - 卡片铺满 --wrap（视觉"占满电脑端"）
       - 正文行宽受 --measure 约束（"一行别太长"）
     混成一个宽度的话，要么卡片窄得居中留空、要么一行 63 个汉字读不下去。 */
  :root { --wrap: 1000px; --gap: 18px; --measure: 52em; }

  .wrap { padding: 0 32px; }

  /* ≥1080px 时 brand 回到与导航同一行。
     640–1079px 段把 brand 挪到导航上方是为了多拿 150px 宽度（否则 640px
     下只能排 3–4 行）。但这一档版心 1000px，brand 136px + gap 12 之后
     还有 788px，导航排成 2 行即可 —— 实测 brand 单独占一行会让顶栏从
     93px 涨到 135px，是把 640px 的限制错误地延续到了宽屏。 */
  .header-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 0;
    padding-bottom: 0;
    min-height: 68px;
  }
  .brand { align-self: center; }

  /* 1080px 起写一整套换行规则（与 640 段同形，避免继承关系靠猜）。
     可用宽度 = 1000 − 64(padding) − 136(brand) − 12(gap) ≈ 788px，
     标签总宽约 1066px，因此稳定落在 2 行，不会出现只剩一项的孤行。
     换行后必须同时去掉 mobile 那套横向滚动与右端渐隐：留着 mask 会把
     最后一行的尾字淡成半透明，读者会以为导航被截断了。
     行内按左对齐（flex-start）：中文标签是从左往右读的，两行都靠左时
     第一行末尾换到第二行行首的衔接是连续的；靠右会让第二行整体缩进。 */
  .nav {
    overflow: visible;
    flex-wrap: wrap;
    justify-content: flex-start;
    -webkit-mask-image: none;
    mask-image: none;
    margin: 0;
    padding: 0;
  }
  .brand-mark { width: 36px; height: 36px; font-size: 18px; }
  .brand-text strong { font-size: 18px; }
  .nav a { font-size: 14.5px; padding: 8px 12px; }

  main { padding: 44px 0 64px; }

  .hero { padding-bottom: 30px; margin-bottom: 30px; }
  .hero h1 { font-size: 32px; }
  .hero-desc { max-width: 720px; }

  .cat-grid { grid-template-columns: repeat(3, 1fr); margin-bottom: 40px; }

  /* 文章列表改为双列，阅读型页面仍保持单列窄版心 */
  .list { display: grid; grid-template-columns: repeat(2, 1fr); align-items: start; }
  .card { height: 100%; display: flex; flex-direction: column; }
  .card-more { margin-top: auto; padding-top: 12px; }

  /* 文章页占满电脑端版心。
     改前：`.post { max-width: 780px; margin: 0 auto }` 在 1120px 的 main 里
     左右各留 170px 空白（实测 1280px 视口下正文仅 698px 宽）。

     现在卡片（背景、边框）铺满 main，文字列用 --measure 居中约束。
     为什么不把文字也拉满：main 内宽 920–1040px，中文 16.5px 下约
     56–63 字一行，眼睛回行时会丢行；40–45 字是中文正文的舒适区间。
     所以「占满」体现在卡片边界，而不是行长。 */
  .post { max-width: none; margin: 0; padding: 36px 40px 30px; }
  .post-crumb,
  .post-title,
  .post-meta,
  .post-body,
  .post-back,
  .post-more {
    max-width: var(--measure);
    margin-left: auto;
    margin-right: auto;
  }
  .post-body p { font-size: 16.5px; }

  .footer-inner { font-size: 13px; }
}

/* ============================================================
   超宽屏（≥1440px）
   ============================================================ */
@media (min-width: 1440px) {
  :root { --wrap: 1120px; }
}

/* ============================================================
   触屏设备优化（无 hover 能力时去掉悬停位移）
   ============================================================ */
@media (hover: none) {
  .cat-card:hover { transform: none; box-shadow: none; border-color: var(--line); }
  .card:hover { box-shadow: none; border-color: var(--line); }
  .cat-card:active { border-color: var(--accent); background: var(--accent-soft); }
  .card:active { border-color: var(--accent); }
}

/* ============================================================
   打印
   ============================================================ */
@media print {
  .site-header, .site-footer, .card-more, .post-back, .skip-link { display: none; }
  body { background: #fff; }
  .post { border: 0; padding: 0; max-width: none; }
  .card { break-inside: avoid; }
  /* 图表不跨页断裂 */
  .fig { break-inside: avoid; page-break-inside: avoid; }
  .fig svg { max-width: 320px; }
  .fig text { font-size: 12px; }
}

/* ============================================================
   减少动效偏好
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}
