/* 3x-ui 主题 · 站点外壳（顶栏、左目录、正文、右目录）与原站部件。
   移植自「小小东 VPS 教程」vps.xiaoxiaodong.ai 的 site.css（MIT License, Copyright (c) 2026 小小东 xiaoxiaodong.ai），
   在此之上重做了三栏居中的版面、左侧目录的层级与正文阅读尺度；博客专用部件在 blog.css。
   颜色、间距、圆角仍然全部来自 /xxd/xxd.css 的令牌。 */

/* ---------- 令牌覆盖 ----------
   xxd.css 里的 :root 没有写进 @layer，按 CSS 层叠规则，分层的规则压不过不分层的规则，
   所以这里必须同样不分层（写在 @layer site 里会失效）。 */
:root {
  /* 全站改用系统字体：macOS / iOS 是 SF + 苹方，Windows 是 Segoe UI + 微软雅黑，Android / Linux 是思源黑体。
     不加载任何网络字体，也不再用 Avenir Next 这类「像系统字体但不是系统默认」的字体。 */
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro SC", "Segoe UI Variable Text", "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC",
    "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-title: var(--font-body);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", "PingFang SC",
    "Microsoft YaHei", monospace;

  /* 字号阶梯：阅读正文 17px，标题 1.4 倍起跳，正文加粗永远小于三级标题 */
  --text-base: 15px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-xxl: 26px;
  --text-display: 32px;

  --read-width: 780px;         /* 正文阅读列 */
  --shell-max: 1480px;         /* 三栏外壳最大宽度 */
  --nav-w: clamp(216px, 17vw, 248px);
  --toc-w: clamp(232px, 21vw, 304px);
  --gutter: clamp(24px, 2.6vw, 44px);
  --content-max: 780px;
  --wide-max: 1080px;          /* 首页、分类总览这类宽栏 */
}

/* 繁体页面（站点语言 zh-Hant）同样走系统字体：xxd.css 在 [lang=zh-Hant] 上重新声明过一次 */
[lang="zh-Hant"],
[lang="zh-TW"],
[lang="zh-HK"] {
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI",
    "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Source Han Sans TC", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-title: var(--font-body);
}

@layer site {
  html { scroll-padding-top: 80px; }
  body { min-height: 100vh; }
  .xxd-page { text-rendering: optimizeLegibility; }

  /* 全站图标统一：Lucide 的 1.25 描边 + 圆头圆角（xxd.js 自带的搜索 / 关闭等小图标也一起统一） */
  .ui-icon { stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }

  /* ---------- 顶栏 ---------- */
  .site-top {
    position: sticky; top: 0; z-index: var(--z-dock);
    display: flex; align-items: center; gap: var(--space-3);
    height: 56px;
    padding-inline: max(20px, calc((100vw - var(--shell-max)) / 2));
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: saturate(150%) blur(12px);
  }
  .site-menu { display: none; }
  .site-brand {
    display: inline-flex; align-items: center; gap: 9px;
    color: var(--ink); font: var(--weight-strong) 15px / 1 var(--font-body);
    text-decoration: none; white-space: nowrap;
  }
  .site-mark {
    width: 18px; height: 18px; border-radius: var(--r-xs);
    background:
      linear-gradient(var(--on-ink), var(--on-ink)) 4px 4px / 4px 4px no-repeat,
      linear-gradient(color-mix(in srgb, var(--on-ink) 70%, transparent), color-mix(in srgb, var(--on-ink) 70%, transparent)) 10px 4px / 4px 4px no-repeat,
      linear-gradient(color-mix(in srgb, var(--on-ink) 45%, transparent), color-mix(in srgb, var(--on-ink) 45%, transparent)) 4px 10px / 4px 4px no-repeat,
      linear-gradient(color-mix(in srgb, var(--on-ink) 22%, transparent), color-mix(in srgb, var(--on-ink) 22%, transparent)) 10px 10px / 4px 4px no-repeat,
      var(--ink);
  }
  .site-top__spacer { flex: 1; }
  .site-appearance { display: flex; align-items: center; gap: var(--space-2); }

  /* ---------- 三栏外壳 ----------
     整体居中：左边目录 / 中间正文 / 右边目录。宽屏不再把内容顶在左边、右边留一大片空白。 */
  .site-body {
    display: grid;
    grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--toc-w);
    align-items: start;
    column-gap: var(--gutter);
    max-width: var(--shell-max);
    margin-inline: auto;
    padding-inline: 20px;
  }
  /* 没有右侧目录的页面（首页、404 等）不再保留那一栏 */
  .site-body:not(:has(> .site-toc)) { grid-template-columns: var(--nav-w) minmax(0, 1fr); }

  /* ---------- 左侧目录 ---------- */
  .site-nav {
    position: sticky; top: 56px;
    height: calc(100vh - 56px);
    padding: 26px 14px 48px 0;
    overflow-y: auto; overscroll-behavior: contain;
    border-right: 1px solid var(--line);
    scrollbar-width: thin;
  }
  .site-nav__group + .site-nav__group { margin-top: 30px; }
  .site-nav__title {
    display: flex; align-items: center; gap: 6px;
    margin: 0 0 8px; padding: 0 10px;
    color: var(--muted-2);
    font: var(--weight-medium) 11px / 20px var(--font-body);
    letter-spacing: 0.12em;
  }
  .site-nav__title-n {
    margin-left: 2px; color: var(--muted-2);
    font: var(--weight-regular) 11px / 1 var(--font-mono); letter-spacing: 0;
  }
  .site-nav ul { margin: 0; padding: 0; list-style: none; }
  .site-nav a {
    position: relative;
    display: flex; align-items: center; gap: 9px;
    min-height: 34px; padding: 6px 10px;
    border-radius: var(--r-sm);
    color: color-mix(in srgb, var(--ink) 84%, var(--bg));
    font: var(--weight-regular) 13.5px / 20px var(--font-body);
    text-decoration: none;
    transition: background-color var(--motion-quick) ease, color var(--motion-quick) ease;
  }
  .site-nav a:hover { background: var(--wash); color: var(--ink); transition-duration: 0s; }
  .site-nav a[aria-current] {
    background: var(--wash);
    color: var(--ink);
    font-weight: var(--weight-medium);
    box-shadow: inset 2px 0 0 var(--ink);
  }
  .site-nav__label { flex: 1; min-width: 0; }
  .site-nav__tag { flex: none; color: var(--muted-2); font: 11px / 1 var(--font-mono); font-variant-numeric: tabular-nums; }
  .site-nav__ext { flex: none; display: inline-flex; width: 12px; height: 12px; color: var(--muted-2); }

  /* 菜单：图标 + 更大的行高与间距 */
  .site-nav__menus a { gap: 10px; min-height: 38px; padding: 8px 10px; font-size: 14px; }
  .site-nav__icon {
    flex: none; display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; color: var(--muted-2);
    transition: color var(--motion-quick) ease;
  }
  .site-nav__menus a:hover .site-nav__icon,
  .site-nav__menus a[aria-current] .site-nav__icon { color: var(--ink); }
  .site-nav__sub { margin: 2px 0 6px 19px; padding-left: 10px; border-left: 1px solid var(--line); }
  .site-nav__sub a { min-height: 30px; padding: 5px 8px; color: var(--muted); font-size: 13px; }
  .site-nav__sub a:hover { color: var(--ink); }

  /* 分类：等宽序号 + 名称 + 篇数 */
  .site-nav__cats a { gap: 10px; min-height: 32px; padding: 6px 10px; font-size: 13px; }
  /* 序号和菜单图标占同一列（16px），分类名称才能和菜单名称左对齐 */
  .site-nav__num {
    flex: none; width: 16px; color: var(--muted-2);
    font: var(--weight-medium) 10.5px / 1 var(--font-mono);
    font-variant-numeric: tabular-nums; text-align: center;
  }

  /* 标签：默认展开，# 前缀，和标签页 / 文章标签的写法一致 */
  .site-nav__tags { margin-top: 30px; }
  .site-nav__tags > summary { list-style: none; cursor: pointer; user-select: none; position: relative; }
  .site-nav__tags > summary::-webkit-details-marker { display: none; }
  .site-nav__tags > summary::after {
    content: ""; position: absolute; right: 10px; top: 50%;
    width: 12px; height: 12px; margin-top: -6px;
    background: currentColor;
    -webkit-mask: var(--xxd-chevron-down, none) center / contain no-repeat;
    mask: var(--xxd-chevron-down, none) center / contain no-repeat;
    transform: rotate(-90deg);
    transition: transform var(--motion-quick) ease;
  }
  .site-nav__tags[open] > summary::after { transform: none; }
  .site-nav__tagscroll {
    max-height: min(50vh, 460px);
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: thin;
    -webkit-mask: linear-gradient(to bottom, #000 calc(100% - 18px), transparent);
    mask: linear-gradient(to bottom, #000 calc(100% - 18px), transparent);
  }
  .site-nav__tags a { gap: 10px; min-height: 30px; padding: 5px 10px; font-size: 13px; color: var(--muted); }
  .site-nav__tags a:hover { color: var(--ink); }
  .site-nav__tags a[aria-current] { color: var(--ink); }
  .site-nav__hash {
    flex: none; width: 16px; color: var(--muted-2); text-align: center;
    font: var(--weight-regular) 12px / 1 var(--font-mono);
  }

  /* ---------- 正文列 ---------- */
  .site-main {
    display: flex; flex-direction: column;
    width: 100%; min-width: 0;
    max-width: var(--content-max);
    min-height: calc(100dvh - 56px);
    margin-inline: auto;
    padding: 44px 0 0;
  }
  /* 内容不够长时，页脚也停在视口底部 */
  .site-main > * { flex: 0 0 auto; }
  .site-main > .site-foot-wrap { margin-top: auto; padding-top: 56px; }
  .site-main--wide { grid-column: 2 / -1; max-width: var(--wide-max); }

  /* ---------- 右侧目录 ---------- */
  .site-toc {
    position: sticky; top: 56px;
    max-height: calc(100vh - 56px);
    padding: 44px 0 48px;
    overflow-y: auto; scrollbar-width: thin;
    font-size: 13px;
  }
  .site-toc h2,
  .site-toc__title {
    margin: 0 0 10px;
    color: var(--muted-2);
    font: var(--weight-medium) 11px / 20px var(--font-body);
    letter-spacing: 0.12em;
  }
  .site-toc ul { margin: 0; padding: 0; list-style: none; }
  .site-toc a { display: block; padding: 3px 0; color: var(--muted); text-decoration: none; }
  /* 右栏里「年份 / 标签 / 分类」这种简单列表：名称靠左、篇数靠右 */
  .site-toc > ul > li > a,
  .site-toc > div > ul > li > a { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; }
  .site-toc a:hover { color: var(--ink); }
  .site-toc__n { margin-left: auto; padding-left: 8px; color: var(--muted-2); font: 11px / 1 var(--font-mono); }
  .site-toc__top {
    display: inline-flex; align-items: center; gap: 4px;
    margin-top: 16px; color: var(--muted-2); font-size: 11px; letter-spacing: 0.06em;
  }
  .site-toc__top:hover { color: var(--ink); }

  /* ---------- 页脚 ---------- */
  .site-foot {
    padding: 24px 0 56px;
    border-top: 1px solid var(--line);
    color: var(--muted-2); font-size: 12px; line-height: 20px;
    text-align: center;
  }
  .site-foot p { margin: 0; }
  .site-foot a { color: inherit; }

  .site-nav-scrim { display: none; }

  /* ---------- 首页 ---------- */
  .home { max-width: 100%; }
  .home__hero { max-width: 860px; }
  .home h1 {
    margin: 0;
    font: var(--weight-strong) clamp(28px, 2.6vw, 36px) / 1.28 var(--font-title);
    letter-spacing: -0.012em;
    text-wrap: balance;
  }
  .home__lead { max-width: 660px; margin: 14px 0 0; color: var(--muted); font-size: 16px; line-height: 1.75; }
  .home__cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
  .home section { margin-top: 56px; }
  .home section + section { padding-top: 36px; border-top: 1px solid var(--line); }

  .sec-head { margin-bottom: 20px; }
  .sec-head h2 {
    margin: 0;
    font: var(--weight-strong) 20px / 28px var(--font-title);
    letter-spacing: 0.005em;
  }
  .sec-head__lead { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; line-height: 20px; }

  /* 文章路线（首页最新文章 / 归档共用） */
  .roadmap { margin: 0; padding: 0; list-style: none; }
  .roadmap li {
    display: grid; grid-template-columns: 2.4em minmax(0, 1fr) auto;
    gap: 16px; align-items: start;
    padding: 14px 0;
  }
  .roadmap li + li { border-top: 1px solid var(--line); }
  .roadmap__n { color: var(--muted-2); font: var(--weight-medium) 12px / 22px var(--font-mono); font-variant-numeric: tabular-nums; }
  .roadmap__main { min-width: 0; }
  .roadmap__title {
    display: block;
    font-size: 15px; font-weight: var(--weight-medium); line-height: 23px;
  }
  .roadmap__title .xxd-badge { margin-right: 8px; vertical-align: 1px; }
  .roadmap__title a { color: var(--ink); text-decoration: none; }
  .roadmap__title a:hover { text-decoration: underline; text-underline-offset: 3px; }
  .roadmap__sum {
    display: block; margin-top: 3px; color: var(--muted);
    font-size: 13px; line-height: 20px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .roadmap__time { color: var(--muted-2); font-size: 12px; line-height: 22px; white-space: nowrap; font-variant-numeric: tabular-nums; }

  /* 分类卡片（分类总览页） */
  .routes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .route { padding: 20px; border: 1px solid var(--line); }
  .route h3 { display: flex; align-items: center; gap: 8px; margin: 0; font: var(--weight-strong) 15px / 22px var(--font-body); }
  .route p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 20px; }

  /* ---------- 文章头 ---------- */
  .step-head { margin-bottom: 32px; }
  .step-head__eyebrow {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    color: var(--muted); font-size: 12.5px; line-height: 20px;
  }
  .step-head .xxd-progress { width: 100%; height: 2px; margin-top: 10px; background: var(--line); }
  .step-head .xxd-progress::-webkit-progress-bar { background: var(--line); }
  .step-head .xxd-progress::-webkit-progress-value { border-radius: 0; }
  .step-head h1 {
    margin: 18px 0 0;
    font: var(--weight-strong) clamp(27px, 2.6vw, 34px) / 1.32 var(--font-title);
    letter-spacing: -0.012em;
    text-wrap: balance;
  }
  .step-head__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }

  /* 正文里的按钮链接：用按钮自己的颜色，不吃正文链接的颜色和下划线 */
  .xxd-prose a.xxd-btn { color: var(--btn-fg); text-decoration: none; }
  .xxd-prose .xxd-banner { margin: 24px 0; }
  .xxd-prose .xxd-banner p { margin: 0; }
  .xxd-prose td:first-child, .xxd-prose th:first-child { white-space: nowrap; }

  /* 代码块 */
  .copy-block { margin: 24px 0; }
  .copy-block .xxd-code { white-space: pre; overflow-x: auto; }
  .copy-block .xxd-code__head .xxd-btn { gap: 4px; }

  /* ---------- 搜索按钮 ---------- */
  .site-search {
    display: inline-flex; flex: 0 1 280px; align-items: center; gap: 8px;
    height: 34px; margin-left: var(--space-4); padding: 0 8px 0 10px;
    border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper);
    color: var(--muted); font: 13px / 1 var(--font-body); cursor: pointer;
    transition: border-color var(--motion-quick) ease, background-color var(--motion-quick) ease;
  }
  .site-search:hover { border-color: var(--line-strong); background: var(--wash); }
  .site-search span { flex: 1; text-align: left; }

  /* ---------- 图片 ---------- */
  .shot { margin: 24px 0; }
  .shot img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); background: #fff; }
  .shot figcaption { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 20px; }

  /* ---------- 文末反馈 / 上下篇 ---------- */
  .feedback {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
    margin-top: 40px; padding: 14px 18px;
    background: var(--wash); color: var(--muted);
    font-size: 13px; line-height: 20px;
  }
  .feedback a { color: var(--ink); }

  .prevnext { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 40px; }
  .prevnext a, .prevnext span {
    display: block; padding: 16px 18px;
    border: 1px solid var(--line); color: var(--ink); text-decoration: none;
    font-size: 14px; line-height: 22px;
    transition: border-color var(--motion-quick) ease, background-color var(--motion-quick) ease;
  }
  .prevnext a:hover { border-color: var(--line-strong); background: var(--wash); transition-duration: 0s; }
  .prevnext small { display: block; margin-bottom: 2px; color: var(--muted-2); font-size: 11px; line-height: 16px; }
  .prevnext [data-dir="next"] { text-align: right; grid-column: 2; }
  .prevnext span { color: var(--muted); }

  a.xxd-badge { text-decoration: none; color: inherit; }
  .site-lang { min-width: 3em; }

  /* 列表行（博客 / 标签 / 分类页共用）：整行可点，悬停给底色 */
  .list-link { display: flex; flex-direction: column; gap: 2px; min-width: 0; color: var(--ink); text-decoration: none !important; }
  .xxd-prose .xxd-list { padding-left: 0; }
  .xxd-prose .xxd-list__item { margin: 0; }

  /* ---------- 响应式 ---------- */
  @media (max-width: 1180px) {
    .site-body { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
    .site-toc { display: none; }
    .site-main--wide { grid-column: auto; max-width: 100%; }
  }
  @media (max-width: 900px) {
    .site-menu { display: inline-flex; }
    .site-body { display: block; padding-inline: 20px; }
    .site-nav {
      position: fixed; top: 56px; left: 0; z-index: var(--z-dialog);
      width: min(320px, 86vw); height: calc(100dvh - 56px);
      padding: 22px 16px 40px;
      background: var(--bg);
      border-right: 1px solid var(--line);
      transform: translateX(-100%);
      transition: transform var(--motion-panel) var(--ease-out-quart);
      visibility: hidden;
    }
    .site-nav[data-open] { transform: none; visibility: visible; }
    html.nav-open, html.nav-open body { overflow: hidden; }
    .site-nav-scrim {
      position: fixed; inset: 56px 0 0; z-index: calc(var(--z-dialog) - 1); display: block;
      background: rgba(var(--shadow-rgb), 0.2); opacity: 0; pointer-events: none;
      transition: opacity var(--motion-panel) ease;
    }
    .site-nav-scrim[data-open] { opacity: 1; pointer-events: auto; }
    .site-main { padding: 32px 0 96px; }
    .site-search span, .site-search kbd { display: none; }
    .site-search { flex: none; width: 34px; margin-left: 0; padding: 0; justify-content: center; }
    .home section { margin-top: 44px; }
    .routes, .prevnext { grid-template-columns: 1fr; }
    .prevnext [data-dir="next"] { grid-column: auto; }
    .roadmap__sum { -webkit-line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; white-space: normal; }
  }
  @media (max-width: 640px) {
    .site-top { padding-inline: 14px; gap: 8px; }
    .site-body { padding-inline: 16px; }
    .site-brand__name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .home h1 { font-size: 27px; }
    .home section + section { padding-top: 28px; }
    .roadmap li { grid-template-columns: 2em minmax(0, 1fr); gap: 12px; padding: 13px 0; }
    .roadmap__time { grid-column: 2; margin-top: -2px; }
    .roadmap__sum { margin-top: 4px; }
    .step-head { margin-bottom: 24px; }
    .step-head h1 { font-size: 26px; }
    .prevnext { gap: 10px; }
    .feedback { padding: 12px 14px; }
  }
}
