/* ============================================
   Site Styles
   组织方式：
   1. 设计变量
   2. 主题变量
   3. 全局基础
   4. 布局
   5. 正文排版
   6. 页面组件
   7. 响应式
   ============================================ */

/* ============================================
   1. 设计变量
   说明：
   - UI 字体用于导航、分页、TOC、元信息
   - 阅读字体用于正文
   - 等宽字体用于代码
   - 保持单文件维护，后续优先改这里
   ============================================ */
:root {
    --font-family-ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
    --font-family-reading: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    --font-family-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Cascadia Code", Consolas, monospace;

    --font-size-body: 17px;
    --font-size-nav: 16px;
    --font-size-meta: 14px;
    --font-size-inline-code: 0.92em;
    --font-size-code-block: 14px;
    --font-size-toc: 14px;

    --line-height-body: 1.82;
    --line-height-code: 1.68;

    --content-max-width: 920px;
    --content-padding-x: 40px;
    --content-padding-y: 40px;

    --post-toc-width: 200px;
    --post-toc-gap: 28px;
}

/* ============================================
   2. 主题变量
   说明：
   - 统一在 html[data-theme] 上定义
   - github-markdown.css 会消费其中一部分变量
   ============================================ */
html[data-theme="light"] {
    color-scheme: light;
    --bgColor-default: #ffffff;
    --bgColor-muted: #f6f8fa;
    --bgColor-neutral-muted: #818b981f;
    --fgColor-default: #1f2328;
    --fgColor-muted: #59636e;
    --fgColor-accent: #0969da;
    --borderColor-default: #d1d9e0;
    --borderColor-muted: #d1d9e0b3;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bgColor-default: #1e1e20;
    --bgColor-muted: #151b23;
    --bgColor-neutral-muted: #656c7633;
    --fgColor-default: #e1e1e5;
    --fgColor-muted: #8b949e;
    --fgColor-accent: #58a6ff;
    --borderColor-default: #3d444d;
    --borderColor-muted: #3d444db3;
}

html[data-theme="light"] .markdown-body {
    --bgColor-default: #ffffff;
    --bgColor-muted: #f6f8fa;
    --fgColor-default: #1f2328;
    --fgColor-muted: #59636e;
    --fgColor-accent: #0969da;
    --borderColor-muted: #d1d9e0b3;
    background-color: var(--bgColor-default);
    color: var(--fgColor-default);
}

html[data-theme="dark"] .markdown-body {
    --bgColor-default: #1e1e20;
    --bgColor-muted: #151b23;
    --fgColor-default: #e1e1e5;
    --fgColor-muted: #8b949e;
    --fgColor-accent: #58a6ff;
    --borderColor-muted: #3d444db3;
    background-color: var(--bgColor-default);
    color: var(--fgColor-default);
}

/* ============================================
   3. 全局基础
   ============================================ */
html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background-color: var(--bgColor-default, #ffffff);
    color: var(--fgColor-default, #1f2328);
    font-family: var(--font-family-ui);
    line-height: 1.75;
    font-weight: 400;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   4. 布局
   说明：
   - 首页、归档、文章页共用同一版心
   - 文章页单独在右侧挂 TOC
   ============================================ */
header {
    background: transparent;
}

header nav {
    box-sizing: border-box;
    min-width: 200px;
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 14px var(--content-padding-x) 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    font-family: var(--font-family-ui);
    font-size: var(--font-size-nav);
}

header nav .nav-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

header nav a {
    color: #111827;
    text-decoration: none;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: color 0.15s ease, opacity 0.15s ease;
}

header nav a:hover {
    color: var(--fgColor-accent);
    text-decoration: underline;
}

html[data-theme="dark"] header nav a {
    color: #8b949e;
}

main.markdown-body,
.page-layout .markdown-body {
    box-sizing: border-box;
    min-width: 200px;
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--content-padding-y) var(--content-padding-x);
}

.page-layout {
    position: relative;
}

.post-content {
    min-width: 0;
}

.post-toc {
    position: fixed;
    top: 90px;
    left: calc(50% + (var(--content-max-width) / 2) + var(--post-toc-gap));
    width: var(--post-toc-width);
    max-height: calc(100vh - 140px);
    overflow: auto;
    padding: 8px 0 8px 14px;
    border-left: 1px solid var(--borderColor-muted);
    color: var(--fgColor-muted);
    font-family: var(--font-family-ui);
}

.post-toc.is-empty {
    display: none;
}

/* ============================================
   5. 正文排版
   说明：
   - 不修改 github-markdown.css 源文件
   - 在这里覆盖默认文档风格，改成中文技术博客节奏
   ============================================ */
.markdown-body {
    font-family: var(--font-family-reading);
    font-size: var(--font-size-body);
    line-height: var(--line-height-body);
    letter-spacing: normal;
    word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    font-family: var(--font-family-ui);
    letter-spacing: 0.01em;
}

.markdown-body h1 {
    font-size: 2em;
    font-weight: 700;
    line-height: 1.28;
    margin-top: 0.12em;
    margin-bottom: 0.72em;
}

.markdown-body h2 {
    font-size: 1.56em;
    font-weight: 650;
    line-height: 1.38;
    margin-top: 1.8em;
    margin-bottom: 0.82em;
    border-bottom: 1px solid var(--borderColor-muted);
    padding-bottom: 0.3em;
}

.markdown-body h3 {
    font-size: 1.28em;
    font-weight: 650;
    line-height: 1.44;
    margin-top: 1.55em;
    margin-bottom: 0.7em;
}

.markdown-body h4 {
    font-size: 1.1em;
    font-weight: 600;
    line-height: 1.44;
    margin-top: 1.35em;
    margin-bottom: 0.56em;
}

.markdown-body p {
    margin-bottom: 1.05em;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 1.75em;
    margin-bottom: 1.05em;
}

.markdown-body li {
    line-height: 1.78;
}

.markdown-body li + li {
    margin-top: 0.34em;
}

.markdown-body blockquote {
    padding: 0.15em 1.05em;
    margin: 1.2em 0;
    font-size: 0.98em;
    line-height: 1.78;
    border-left-width: 3px;
}

.markdown-body table {
    font-size: 0.95em;
}

.markdown-body table th,
.markdown-body table td {
    padding: 9px 14px;
}

.markdown-body img {
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

/* 文章头部单独收紧：
   这一组规则专门解决“标题、时间、正文之间停顿太大”的问题 */
.post-content > h1 {
    margin-bottom: 0.32em;
}

.post-content > p {
    margin-top: 0;
    margin-bottom: 0.8em;
}

.post-content > .post-body {
    margin-top: 0;
}

.markdown-body .meta {
    color: var(--fgColor-muted);
    font-size: var(--font-size-meta);
    white-space: nowrap;
    font-family: var(--font-family-ui);
}

.post-meta-footer {
    margin-top: 24px;
    padding-top: 12px;
    border-top: 1px solid var(--borderColor-muted);
    color: var(--fgColor-muted);
    font-size: 0.9em;
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    font-family: var(--font-family-ui);
}

.post-meta-footer a {
    color: inherit;
    text-decoration: none;
}

.post-meta-footer a:hover {
    color: var(--fgColor-accent);
    text-decoration: underline;
}

/* 代码区域：
   - 内联代码不能太小
   - 代码块比正文更紧凑，但不能显得发挤 */
.markdown-body code,
.markdown-body tt,
.markdown-body pre,
.markdown-body .highlight pre {
    font-family: var(--font-family-mono);
}

.markdown-body code,
.markdown-body tt {
    font-size: var(--font-size-inline-code);
}

.markdown-body pre,
.markdown-body .highlight pre {
    font-size: var(--font-size-code-block);
    line-height: var(--line-height-code);
    border-radius: 10px;
}

.markdown-body pre {
    margin: 1.25em 0;
}

/* Callout */
.markdown-body .callout {
    border: none;
    border-left: 3px solid var(--callout-accent, var(--fgColor-accent));
    background: var(--callout-bg, var(--bgColor-muted));
    padding: 12px 14px;
    border-radius: 6px;
    margin: 16px 0;
}

.markdown-body .callout p {
    margin: 0.4em 0;
}

.markdown-body .callout > :first-child,
.markdown-body .callout-content > :first-child {
    margin-top: 0;
}

.markdown-body .callout > :last-child,
.markdown-body .callout-content > :last-child {
    margin-bottom: 0;
}

.markdown-body .callout-title {
    font-size: 0.92em;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--callout-accent, var(--fgColor-accent));
}

.markdown-body .callout-note {
    --callout-accent: #0969da;
    --callout-bg: rgba(9, 105, 218, 0.06);
}

.markdown-body .callout-tip {
    --callout-accent: #2da44e;
    --callout-bg: rgba(45, 164, 78, 0.06);
}

.markdown-body .callout-warning {
    --callout-accent: #d29922;
    --callout-bg: rgba(210, 153, 34, 0.08);
}

.markdown-body .callout-important {
    --callout-accent: #8250df;
    --callout-bg: rgba(130, 80, 223, 0.06);
}

.markdown-body .callout-caution {
    --callout-accent: #cf222e;
    --callout-bg: rgba(207, 34, 46, 0.06);
}

.dark .markdown-body .callout,
[data-theme="dark"] .markdown-body .callout {
    background: var(--callout-bg-dark, rgba(255, 255, 255, 0.03));
}

.dark .markdown-body .callout-note,
[data-theme="dark"] .markdown-body .callout-note {
    --callout-bg-dark: rgba(9, 105, 218, 0.10);
}

.dark .markdown-body .callout-tip,
[data-theme="dark"] .markdown-body .callout-tip {
    --callout-bg-dark: rgba(45, 164, 78, 0.10);
}

.dark .markdown-body .callout-warning,
[data-theme="dark"] .markdown-body .callout-warning {
    --callout-bg-dark: rgba(210, 153, 34, 0.10);
}

.dark .markdown-body .callout-important,
[data-theme="dark"] .markdown-body .callout-important {
    --callout-bg-dark: rgba(130, 80, 223, 0.10);
}

.dark .markdown-body .callout-caution,
[data-theme="dark"] .markdown-body .callout-caution {
    --callout-bg-dark: rgba(207, 34, 46, 0.10);
}

/* ============================================
   6. 页面组件
   ============================================ */

/* 列表页：
   这一组单独收紧首页、归档页文章列表的行距和留白 */
.markdown-body .post-list,
.markdown-body .tax-list {
    list-style: none;
    padding-left: 0;
}

.markdown-body .post-list > .post-item,
.markdown-body .tax-list > .tax-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 14px;
    padding: 6px 0;
}

.markdown-body .post-list > .post-item + .post-item {
    margin-top: 0;
}

.markdown-body .post-item a,
.markdown-body .tax-item a {
    color: #111827;
    text-decoration: none;
    min-width: 0;
    transition: color 0.15s ease, opacity 0.15s ease;
}

.markdown-body .post-item a:hover,
.markdown-body .tax-item a:hover {
    color: var(--fgColor-accent);
    text-decoration: underline;
}

html[data-theme="dark"] .markdown-body .post-item a,
html[data-theme="dark"] .markdown-body .tax-item a {
    color: #c9cdd1;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    justify-content: center;
    margin: 24px 0 0;
    font-family: var(--font-family-ui);
}

.pagination-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 2px;
    border: 0;
    border-bottom: 1px solid transparent;
    text-decoration: none;
    color: var(--fgColor-default);
    font-size: 0.92em;
    letter-spacing: 0.02em;
    font-family: var(--font-family-ui);
}

.pagination-link.is-current {
    border-bottom-color: var(--borderColor-muted, #d1d9e0b3);
    color: var(--fgColor-default);
    font-weight: 500;
}

.pagination-link.is-disabled {
    color: var(--fgColor-muted);
    border-bottom-color: transparent;
}

.pagination-link:hover {
    border-bottom-color: var(--borderColor-default, #d1d9e0);
}

.toc-title {
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
    color: var(--fgColor-muted);
    font-family: var(--font-family-ui);
}

.toc-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toc-link,
.toc-link-sub {
    color: var(--fgColor-muted);
    text-decoration: none;
    font-size: var(--font-size-toc);
    font-family: var(--font-family-ui);
}

.toc-link:hover {
    color: var(--fgColor-default);
    text-decoration: underline;
}

.toc-link-sub {
    padding-left: 12px;
    font-size: 13px;
}

.fab,
.theme-toggle {
    position: fixed;
    right: 16px;
    z-index: 10;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--borderColor-default);
    background: var(--bgColor-muted);
    color: var(--fgColor-default);
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.fab:hover,
.theme-toggle:hover {
    border-color: var(--borderColor-muted);
}

.theme-toggle {
    position: fixed;
    bottom: 16px;
}

.theme-toggle::before {
    content: "";
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--borderColor-default);
    background: linear-gradient(90deg, var(--fgColor-default) 0 50%, var(--bgColor-default) 50% 100%);
    box-sizing: border-box;
}

.fab-top {
    bottom: 68px;
    display: none;
}

.fab-top.is-visible {
    display: flex;
}

#themeToggle {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 10;
}

html[data-theme="dark"] .markdown-body h1,
html[data-theme="dark"] .markdown-body h2,
html[data-theme="dark"] .markdown-body h3,
html[data-theme="dark"] .markdown-body h4,
html[data-theme="dark"] .markdown-body h5,
html[data-theme="dark"] .markdown-body h6 {
    color: #f0f6fc;
}

/* ============================================
   友链页面
   - 沿用正文内容宽度和 GitHub 风格变量，避免和文章页割裂
   - 友链卡片只做轻量边框、头像和文字层级，深浅色主题自动适配
   ============================================ */
.markdown-body .friend-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 24px 0 28px;
}

.markdown-body .friend-card {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    min-height: 92px;
    padding: 14px;
    border: 1px solid var(--borderColor-muted);
    border-radius: 8px;
    background: var(--bgColor-default);
    color: var(--fgColor-default);
    text-decoration: none;
    box-sizing: border-box;
    transition: border-color 0.16s ease, background-color 0.16s ease, transform 0.16s ease;
}

.markdown-body .friend-card:hover {
    border-color: var(--fgColor-accent);
    background: var(--bgColor-muted);
    text-decoration: none;
    transform: translateY(-1px);
}

.markdown-body .friend-avatar {
    width: 58px;
    height: 58px;
    margin: 0;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bgColor-muted);
    border: 1px solid var(--borderColor-muted);
    box-sizing: border-box;
}

.markdown-body .friend-info,
.markdown-body .friend-name,
.markdown-body .friend-desc,
.markdown-body .friend-link {
    display: block;
    min-width: 0;
}

.markdown-body .friend-name {
    overflow: hidden;
    color: var(--fgColor-default);
    font-family: var(--font-family-ui);
    font-size: 0.98em;
    font-weight: 650;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.markdown-body .friend-desc {
    display: -webkit-box;
    overflow: hidden;
    margin-top: 4px;
    color: var(--fgColor-muted);
    font-size: 0.86em;
    line-height: 1.5;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.markdown-body .friend-link {
    overflow: hidden;
    margin-top: 5px;
    color: var(--fgColor-accent);
    font-family: var(--font-family-ui);
    font-size: 0.78em;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

html[data-theme="dark"] .markdown-body .friend-card {
    background: #1e1e20;
}

html[data-theme="dark"] .markdown-body .friend-card:hover {
    background: #151b23;
}

/* ============================================
   7. 响应式
   ============================================ */
@media (max-width: 980px) {
    .page-layout {
        padding: 0;
    }

    .page-layout .markdown-body {
        padding: 18px;
    }

    .post-toc {
        display: none;
    }
}

@media (max-width: 767px) {
    :root {
        --font-size-body: 16px;
        --content-padding-x: 18px;
        --content-padding-y: 18px;
    }

    header nav {
        padding: 12px var(--content-padding-x) 0;
    }

    main.markdown-body,
    .page-layout .markdown-body {
        padding: var(--content-padding-y) var(--content-padding-x);
    }

    .markdown-body h1 {
        font-size: 1.82em;
    }

    .markdown-body h2 {
        font-size: 1.42em;
    }

    .markdown-body h3 {
        font-size: 1.18em;
    }

    .markdown-body .friend-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-top: 18px;
    }

    .markdown-body .friend-card {
        grid-template-columns: 52px minmax(0, 1fr);
        min-height: 84px;
        padding: 12px;
    }

    .markdown-body .friend-avatar {
        width: 52px;
        height: 52px;
    }
}
