:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --canvas: #ffffff;
  --canvas-subtle: #f6f8fa;
  --canvas-inset: #eef2f5;
  --border: #d1d9e0;
  --border-muted: #d8dee4;
  --fg: #1f2328;
  --fg-muted: #59636e;
  --accent: #0969da;

  --radius: 6px;
  --tab-w: 28px;
  --sidebar-w: 264px;
  --sidebar-inner-w: 240px;
  --content-w: 1160px; /* 正文宽度：固定值，不随目录展开/收起变化 */
  --aside-w: 320px; /* 右侧预留栏基准宽度 */
  --gutter: 40px;
  --ease: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  /* 窄屏下也不出现横向滚动条（会传播到视口，不影响 sticky） */
  overflow-x: hidden;
  /* 主题装饰色：每个页面在 <body data-page="..."> 上指定自己的颜色 */
  --deco: #8250df; /* 默认：前言紫 */
  background:
    /* 全站细点阵纹理 */
    radial-gradient(circle, rgba(31, 35, 40, 0.05) 1px, transparent 1.4px) 0 0 / 26px 26px,
    var(--canvas-subtle);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* 各页主题色 */
body[data-page="intro"] {
  --deco: #8250df; /* 前言：紫 */
}

body[data-page="learn"] {
  --deco: #1a7f37; /* 学习：绿 */
}

body[data-page="practice"] {
  --deco: #bf8700; /* 实战：黄 */
}

/* ---------- 两侧装饰图案（随页面主题色变化） ---------- */
body::before,
body::after {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(360px, 26vw);
  z-index: 0;
  pointer-events: none;
}

/* 左侧：两团柔光 + 一圈细线圆环 */
body::before {
  left: 0;
  background:
    radial-gradient(circle at 14% 22%, transparent 108px, color-mix(in srgb, var(--deco) 20%, transparent) 109px, transparent 112px),
    radial-gradient(240px at 10% 24%, color-mix(in srgb, var(--deco) 16%, transparent), transparent),
    radial-gradient(200px at 4% 72%, color-mix(in srgb, var(--deco) 11%, transparent), transparent);
}

/* 右侧：镜像的柔光 + 圆环 */
body::after {
  right: 0;
  background:
    radial-gradient(circle at 86% 30%, transparent 128px, color-mix(in srgb, var(--deco) 16%, transparent) 129px, transparent 132px),
    radial-gradient(240px at 92% 28%, color-mix(in srgb, var(--deco) 13%, transparent), transparent),
    radial-gradient(220px at 96% 74%, color-mix(in srgb, var(--deco) 10%, transparent), transparent);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* 目录里的条目现在是真正的链接（可新窗口打开、可被搜索引擎抓取），去掉默认下划线 */
a.group__btn,
a.topic {
  text-decoration: none;
}

/* 键盘 Tab 聚焦时给一圈淡蓝轮廓 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 布局：整体靠左，不居中 ---------- */
/* ---------- 布局：正文在视口内居中，两侧留给装饰 ---------- */
.layout {
  min-width: 0;
  padding: 32px 24px 64px;
}

/* ---------- 目录抽屉（悬浮层，不占布局空间 → 正文永远不动） ---------- */
.drawer {
  position: fixed;
  top: 32px;
  left: calc(var(--tab-w) + 12px);
  z-index: 30;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

/* 收起时不再清零宽度：目录占位保持不变，正文就不会跟着左右移动 */
.drawer.is-collapsed {
  gap: 8px;
}

/* 贴着屏幕最左边、永远固定不滚走的白色小标签 */
.drawer__tab {
  position: fixed;
  top: 32px;
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: var(--tab-w);
  padding: 12px 0;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--canvas);
  color: var(--fg-muted);
  box-shadow: 1px 1px 4px rgba(31, 35, 40, 0.06);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.drawer__tab:hover {
  background: var(--canvas-inset);
  border-color: var(--border-muted);
  color: var(--fg);
}

.drawer__label {
  writing-mode: vertical-rl;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.drawer__chevron {
  transition: transform var(--ease);
}

/* 收起 → 箭头朝右；展开 → 箭头朝左 */
.drawer.is-collapsed .drawer__chevron {
  transform: rotate(180deg);
}

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  max-width: 100%;
  max-height: calc(100vh - 64px);
  overflow: hidden auto;
  padding: 12px;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: width var(--ease), flex-basis var(--ease), max-height var(--ease), padding var(--ease),
    opacity 0.16s ease;
}

/* 内容固定宽度：展开时整块滑出，文字不会被挤成一团 */
.sidebar__inner {
  width: var(--sidebar-inner-w);
}

/* 收起时只隐藏面板本身，宽度占位保留 → 正文位置恒定不动 */
.drawer.is-collapsed .sidebar {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: visibility 0s linear 0.2s, opacity 0.16s ease;
}

/* ---------- 面板头部（目录标题 + 关闭）：桌面端不显示 ---------- */
.panelhead {
  display: none;
}

/* ---------- 搜索框 ---------- */
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas-subtle);
  color: var(--fg-muted);
  transition: background 0.15s, border-color 0.15s;
}

.search:focus-within {
  background: var(--canvas);
  border-color: var(--accent);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-size: 13px;
}

.search input::placeholder {
  color: var(--fg-muted);
}

/* ---------- 大主题 ---------- */
.group + .group {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-muted);
}

.group__btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius);
  text-align: left;
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.group__btn:hover {
  background: var(--canvas-inset);
  color: var(--fg);
}

.group__name {
  flex: 1;
}

.count {
  flex: 0 0 auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--canvas-inset);
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- 小主题（缩进 + 浅灰竖线） ---------- */
.topiclist {
  margin: 4px 0 0;
  padding: 0 0 0 12px;
  list-style: none;
  border-left: 1px solid var(--border-muted);
}

.topiclist li + li {
  margin-top: 2px;
}

.topic {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius);
  text-align: left;
  color: var(--fg);
  font-size: 14px;
  transition: background 0.15s;
}

.topic:hover {
  background: var(--canvas-subtle);
}

.topic.is-active {
  background: var(--canvas-inset);
  font-weight: 600;
}

.dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}

.topic.is-active .dot {
  background: var(--accent);
}

.topic__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 大主题前面的小色条 */
.bar {
  flex: 0 0 auto;
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: var(--border);
}

.bar--intro {
  background: #8250df;
}

.bar--learn {
  background: #1a7f37;
}

.bar--practice {
  background: #bf8700;
}

/* ---------- 右侧预留栏：固定在屏幕右缘，后续内容写进各页面的 <aside class="aside"> ---------- */
.aside {
  position: fixed;
  top: 32px;
  right: 24px;
  z-index: 1;
  width: var(--aside-w);
  max-height: calc(100vh - 64px);
  overflow: hidden auto;
  min-height: 240px;
}

/* ---------- 中间正文：在视口内水平居中，宽度不随目录变化 ---------- */
.content {
  position: relative;
  z-index: 1;
  width: min(var(--content-w), calc(100vw - 760px));
  margin: 0 auto;
  min-width: 0;
}

.crumbs {
  margin: 0 0 4px;
  color: var(--fg-muted);
  font-size: 13px;
}

.crumbs__sep {
  margin: 0 6px;
}

.panel__title {
  margin: 0 0 16px;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.3;
}

.card {
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--canvas-subtle);
  border-bottom: 1px solid var(--border);
}

.card__label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
}

.badge {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--canvas);
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 600;
}

.card__body {
  padding: 20px;
}

/* ---------- 可折叠卡片（点击标题栏收起 / 展开内容） ----------
   用法：给 .card 再加 .card--collapse，标题栏换成 button.card__toggle，
   内容包一层 .card__collapse > .card__collapse-inner。
   默认展开加 .is-open，收起去掉即可；展开/收起由 assets/site.js 处理。 */
.card--collapse > .card__toggle {
  display: flex;
  width: 100%;
  text-align: left;
  cursor: pointer;
  user-select: none;
}

.card--collapse > .card__toggle:hover {
  background: var(--canvas-inset);
}

/* 收起时：去掉标题栏那条多余的横线，整张卡片只留标题，不占多余高度 */
.card--collapse:not(.is-open) > .card__toggle {
  border-bottom: 0;
}

/* 收起后内容区彻底归零，不留残高 */
.card--collapse:not(.is-open) .card__collapse > .card__collapse-inner {
  padding-top: 0;
  padding-bottom: 0;
}

.card__chevron {
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--fg-muted);
  transition: transform var(--ease);
}

/* 展开时箭头朝下，收起时转成朝右 */
.card--collapse:not(.is-open) .card__chevron {
  transform: rotate(-90deg);
}

/* 用 grid 0fr/1fr 做高度动画，不需要 JS 去量内容高度 */
.card__collapse {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--ease);
}

.card--collapse:not(.is-open) .card__collapse {
  grid-template-rows: 0fr;
}

.card__collapse > .card__collapse-inner {
  min-height: 0;
  overflow: hidden;
}

.prose {
  margin: 0;
  font-size: 15px;
  line-height: 1.8;
}

.prose .link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.prose .link:hover {
  text-decoration: underline;
}

/* ---------- 学习笔记正文（Markdown 层级，字号严格按比例推导） ---------- */
.doc {
  /* 基准字号 = 站点正文 15px，下面所有层级都由它乘出来 */
  --doc-fs: 15px;
  font-size: var(--doc-fs);
  line-height: 1.8;
}

/* 三级标题 = 正文 × 1.25 → 18.75px（Markdown 标准 h3 比例） */
.doc__h3 {
  margin: 24px 0 8px;
  font-size: calc(var(--doc-fs) * 1.25);
  line-height: 1.45;
  font-weight: 600;
}

.doc__h3:first-child {
  margin-top: 0;
}

/* 原文用 ** 加粗的标题，字重再加一级，字号不变 */
.doc__h3--strong {
  font-weight: 700;
}

.doc__p {
  margin: 0 0 12px;
  font-size: var(--doc-fs);
}

.doc__list {
  margin: 0 0 12px;
  padding-left: 1.4em; /* 缩进用 em，跟着字号等比走 */
  font-size: var(--doc-fs);
}

.doc__list li {
  margin: 0 0 6px;
}

.doc__list li::marker {
  color: var(--fg-muted);
}

/* 分类名：只加粗，字号与正文一致，不破坏比例 */
.doc__tag {
  font-weight: 600;
}

/* 行内代码 = 正文 × 0.85 → 12.75px（Markdown 行内代码 85% 比例） */
.doc__code {
  padding: 2px 6px;
  border-radius: var(--radius);
  background: var(--canvas-inset);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: calc(var(--doc-fs) * 0.85);
}

.doc .link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.doc .link:hover {
  text-decoration: underline;
}

/* 文末的「提示词参考」：用一条细分隔线和正文隔开 */
.doc__ref {
  margin: 20px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border-muted);
}

/* 五级标题 = 正文 × 0.875 → 13.125px（Markdown 标准 h5 比例） */
.doc__h5 {
  margin: 0 0 12px;
  font-size: calc(var(--doc-fs) * 0.875);
  line-height: 1.5;
  font-weight: 600;
  color: var(--fg-muted);
}

/* 对话段：左侧细竖线与正文区分 */
.doc__chat {
  margin: 0 0 16px;
  padding-left: 12px;
  border-left: 2px solid var(--border-muted);
}

/* 说话人：只加粗，字号与正文一致 */
.doc__who {
  font-weight: 700;
}

/* 有序列表 = 正文 1.0；序号用次要色 */
.doc__olist {
  margin: 0 0 12px;
  padding-left: 1.5em;
  font-size: var(--doc-fs);
}

.doc__olist > li {
  margin: 0 0 8px;
}

.doc__olist > li::marker {
  color: var(--fg-muted);
  font-weight: 600;
}

/* 列表里嵌套的补充说明，字号不缩水 */
.doc__olist .doc__list {
  margin: 4px 0 0;
  font-size: var(--doc-fs);
}

/* 代码块 = 正文 × 0.85 → 12.75px，与行内代码同比例 */
.doc__pre {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  background: var(--canvas-subtle);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: calc(var(--doc-fs) * 0.85);
  line-height: 1.75;
  /* 自动换行，窄屏也不会把页面撑出横向滚动条 */
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.doc__pre code {
  font: inherit;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 140px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--canvas-subtle);
}

.empty__title {
  margin: 0;
  color: var(--fg-muted);
  font-size: 14px;
}

.clonebox {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas);
}

.clonebox__url {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 13px;
}

.copybtn {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas-subtle);
  color: var(--fg);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}

.copybtn:hover {
  background: var(--canvas-inset);
}

/* ---------- 窄屏遮罩 ---------- */
/* 桌面上不需要；窄屏下由 site.js 在打开目录时加上 .is-open */
.scrim {
  display: none;
}

@media (max-width: 1024px) {
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(31, 35, 40, 0.32);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  }
}

/* ---------- 窄屏：目录从左侧滑出，内容在下方 ---------- */
@media (max-width: 1024px) {
  .layout {
    padding: 16px 12px 48px;
  }

  /* 窄屏：目录从屏幕左侧滑出，不占正文上方位置 */
  .drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: auto;
    height: 100%;
    gap: 0;
    z-index: 41;
  }

  /* 抽屉打开后「目录」小标签让位给面板头部的关闭按钮 */
  .drawer__tab {
    top: 16px;
    z-index: 42;
    transition: opacity 0.16s ease, visibility 0s;
  }

  .drawer:not(.is-collapsed) .drawer__tab {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.16s ease, visibility 0s linear 0.16s;
  }

  /* 全屏抽屉：铺满整屏，背景沿用页面底图（点阵 + 主题色），不用纯白
     高度用 100vh（大视口）而不是 100dvh：手机上 dvh 会随浏览器工具栏伸缩，
     会在面板底部露出一条缝；vh 会让面板一直延伸到浏览器底栏后面，视觉上才是贴满的。 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    /* 用 left/right + width: auto 铺满，别用 100vw：
       100vw 会把滚动条宽度也算进去，右侧内容会被截断 */
    width: auto;
    height: 100vh;
    max-width: none;
    max-height: none;
    padding: 18px 16px 96px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background:
      radial-gradient(circle, rgba(31, 35, 40, 0.05) 1px, transparent 1.4px) 0 0 / 26px 26px,
      radial-gradient(120% 55% at 0% 0%, color-mix(in srgb, var(--deco) 18%, transparent), transparent 70%),
      radial-gradient(90% 45% at 100% 100%, color-mix(in srgb, var(--deco) 10%, transparent), transparent 72%),
      var(--canvas-subtle);
    overscroll-behavior: contain;
    transform: translateX(0);
    transition: transform var(--ease), visibility 0s;
  }

  .sidebar__inner {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    /* 目录内容区框成一张卡片：白底 + 边框，和带色调的面板背景分清楚 */
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--canvas);
  }

  /* 面板头部：标题 + 关闭按钮 */
  .panelhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
  }

  .panelhead__title {
    font-size: 18px;
    font-weight: 600;
  }

  .panelhead__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--canvas);
    color: var(--fg-muted);
    transition: background 0.15s, color 0.15s;
  }

  .panelhead__close:hover {
    background: var(--canvas-inset);
    color: var(--fg);
  }

  /* 收起 = 整块滑出屏幕左侧（visibility 延迟到动画结束再隐藏） */
  .drawer.is-collapsed .sidebar {
    flex-basis: auto;
    width: auto;
    max-height: none;
    padding: 18px 16px 96px;
    transform: translateX(-100%);
    opacity: 1;
    visibility: hidden;
    transition: transform var(--ease), visibility 0s linear 0.2s;
  }

  .card__body {
    padding: 16px;
  }

  /* 窄屏：正文恢复占满整行 */
  .content {
    width: 100%;
  }

  /* 抽屉打开时的遮罩：点它收起目录 */
  .scrim.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0s;
  }

  /* 窄屏下右侧预留栏和两侧装饰先让位给正文 */
  .aside,
  body::before,
  body::after {
    display: none;
  }
}

/* ==========================================================================
   页面转场：点目录（或任何站内链接）时先淡出旧页面，新页面再淡入
   --------------------------------------------------------------------------
   由 assets/site.js 动态创建 <div class="pagefade"> 并控制三个类：
     .is-animated  挂上过渡（进场那一下不加过渡，才能瞬间铺满）
     .is-covering  铺满整屏
   body 上的 .page-enter 用来让正文轻轻上浮，配合遮罩淡出更有“换页”感。
   ========================================================================== */
.pagefade {
  position: fixed;
  inset: 0;
  z-index: 9999;
  /* 覆盖期间也不挡点击，避免脚本异常时页面卡住 */
  pointer-events: none;
  opacity: 0;
  background: var(--canvas-subtle);
  background:
    radial-gradient(
      58% 46% at 50% 42%,
      color-mix(in srgb, var(--deco) 14%, transparent),
      transparent 72%
    ),
    radial-gradient(circle, rgba(31, 35, 40, 0.05) 1px, transparent 1.4px) 0 0 / 26px 26px,
    var(--canvas-subtle);
}

.pagefade.is-animated {
  transition: opacity 0.24s ease;
}

.pagefade.is-covering {
  opacity: 1;
}

/* 进场：正文从下方轻轻浮上来 */
@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

body.page-enter .content {
  animation: page-enter 0.36s ease both;
}

/* 尊重系统的“减少动态效果”设置 */
@media (prefers-reduced-motion: reduce) {
  .pagefade,
  .pagefade.is-animated {
    transition: none;
  }

  body.page-enter .content {
    animation: none;
  }
}
