/* Blog 列表与正文（含 TOC）。颜色用 colors.css 变量。 */

.blog-list,
.blog-post,
.blog-body {
    font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei",
        "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
}

.blog-list .post-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.blog-list .post-list li {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--color-border);
}

.blog-list .post-list a {
    font-size: 1.1rem;
    color: var(--color-blog-link);
}

.blog-list .post-list .meta {
    display: block;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* ---------- 正文布局 ---------- */

/* 外框透明：卡片分别落在 toc / body 上 */
main.markdown-stage.blog-post {
    background: transparent;
    box-shadow: none;
    padding: 0;
    margin: 1rem;
    max-width: none;
    min-width: 0;
    overflow: visible;
}

.blog-post {
    display: grid;
    /* 适中：两列按内容宽度合起来居中；全宽见 :has(.is-wide) */
    grid-template-columns: minmax(180px, 240px) minmax(0, 46rem);
    justify-content: center;
    gap: 1.25rem 1.75rem;
    max-width: 1120px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    align-items: start;
    box-sizing: border-box;
}

.blog-post:has(.blog-body.is-wide) {
    grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
    justify-content: stretch;
}

.blog-toc {
    position: sticky;
    top: 0.5rem;
    max-height: calc(100vh - 1.5rem);
    align-self: start;
    z-index: 2;
}

.blog-toc-toggle {
    display: none;
    width: 100%;
    margin: 0 0 0.5rem;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--color-border-medium);
    border-radius: 8px;
    background: var(--color-surface-hover);
    color: var(--color-text);
    font: inherit;
    cursor: pointer;
    text-align: left;
}

.blog-toc-panel {
    max-height: calc(100vh - 1.5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--color-accent-transparent);
    border-radius: 14px;
    padding: 0.85rem 1rem;
    box-sizing: border-box;
    /* 滚动条不可见；悬停在 TOC 上滚轮仍可滚动面板 */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.blog-toc-panel::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.blog-toc-panel .toc {
    margin: 0;
    background: transparent;
    padding: 0;
}

.blog-toc-panel .toc::before {
    content: "目录";
    display: block;
    font-weight: 700;
    color: var(--color-bar-text);
    margin-bottom: 0.5rem;
}

.blog-toc-panel .toc ul {
    list-style: none;
    margin: 0.25rem 0 0;
    padding: 0 0 0 0.75rem;
}

.blog-toc-panel .toc > ul {
    padding-left: 0;
}

.blog-toc-panel .toc li {
    margin: 0.2rem 0;
    line-height: 1.35;
}

.blog-toc-panel .toc a {
    display: block;
    color: var(--color-bar-text);
    text-decoration: none;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    border-left: 3px solid transparent;
    opacity: 0.9;
    font-size: 0.88rem;
}

.blog-toc-panel .toc a:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.12);
}

.blog-toc-panel .toc a.is-active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.18);
    border-left-color: var(--color-accent-light);
    font-weight: 600;
}

.blog-body {
    position: relative;
    min-width: 0;
    width: 100%;
    max-width: none;
    color: var(--color-text-secondary);
    line-height: 1.6;
    background: var(--color-blog-body-bg);
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    padding: 2rem 3rem;
    box-sizing: border-box;
}

.blog-body-toolbar {
    display: flex;
    justify-content: flex-end;
    margin: -0.35rem 0 0.75rem;
}

.blog-width-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.65rem;
    border: 1px solid var(--color-border-medium);
    border-radius: 8px;
    background: var(--color-surface-hover);
    color: var(--color-text-secondary);
    font: inherit;
    font-size: 0.82rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
}

.blog-width-toggle:hover {
    color: var(--color-text);
    border-color: var(--color-border-dark);
}

.blog-width-toggle[aria-pressed="true"] {
    background: var(--color-accent-light);
    border-color: var(--color-accent-solid);
    color: var(--color-text);
}

.blog-width-toggle svg {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}

.blog-body-inner {
    max-width: none;
}

.blog-body .math-display {
    margin: 1.1em 0;
    overflow-x: auto;
    text-align: center;
}

.blog-body .math-inline {
    padding: 0 0.05em;
}

/* 普通段落：行距正常、段间距偏紧；列表行距另见下方 ul/ol */
.blog-body > p,
.blog-body p {
    line-height: 1.65;
    margin: 0.65em 0;
}

.blog-body table {
    line-height: 1.6em;
    margin: 1.1em 0;
}

.blog-body h1,
.blog-body h2,
.blog-body h3,
.blog-body h4,
.blog-body h5,
.blog-body h6 {
    position: relative;
    font-weight: bold;
    line-height: 1.1em;
    margin: 1.1em 0;
    color: var(--color-text);
}

.blog-body h1 { font-size: 2em; }
.blog-body h2 { font-size: 1.5em; }
.blog-body h3 { font-size: 1.3em; }
.blog-body h4 { font-size: 1.2em; }
.blog-body h5 { font-size: 1em; }
.blog-body h6 {
    font-size: 1em;
    color: var(--color-text-subtle);
}

.blog-body a:not(.headerlink) {
    color: var(--color-blog-link);
}

.blog-body .headerlink {
    margin-left: 0.35em;
    font-size: 0.85em;
    color: var(--color-blog-anchor);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.blog-body h1:hover .headerlink,
.blog-body h2:hover .headerlink,
.blog-body h3:hover .headerlink,
.blog-body h4:hover .headerlink,
.blog-body h5:hover .headerlink,
.blog-body h6:hover .headerlink,
.blog-body .headerlink:focus {
    opacity: 1;
    text-decoration: none;
}

.blog-body ul,
.blog-body ol,
.blog-body dl {
    margin: 1.2em 0 1.2em 0.25em;
    padding-left: 0.35em;
}

/* 顶级列表约 2.2 倍行距；嵌套逐级收紧。
   Markdown 会给「含嵌套/空行」的 li 包 <p>，统一清掉 p 外边距以免视觉间距不齐。 */
.blog-body ul {
    list-style: none;
    line-height: 2.2;
}

.blog-body ol {
    list-style: decimal;
    padding-left: 1.4em;
    line-height: 2.2;
}

.blog-body ul ul,
.blog-body ol ul {
    list-style: none;
    margin-top: 0.15em;
    margin-bottom: 0.15em;
    line-height: 1.85;
}

.blog-body ul ul ul,
.blog-body ol ul ul,
.blog-body ul ol ul {
    line-height: 1.6;
}

.blog-body ul ol,
.blog-body ol ol {
    margin-top: 0.15em;
    margin-bottom: 0.15em;
    line-height: 1.85;
    padding-left: 1.4em;
}

.blog-body ul > li,
.blog-body ol > li {
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.blog-body ul > li {
    position: relative;
    padding-left: 1.45em;
}

.blog-body ul > li::before {
    content: "";
    position: absolute;
    left: 0.15em;
    top: 0.85em;
    width: 0.55em;
    height: 0.55em;
    box-sizing: border-box;
    border-radius: 50%;
    border: 2.5px solid var(--color-blog-list-marker);
    background: transparent;
    pointer-events: none;
}

.blog-body ul ul > li::before {
    top: 0.7em;
    width: 0.48em;
    height: 0.48em;
    border-width: 2px;
}

.blog-body li > p {
    margin: 0;
    line-height: inherit;
}

.blog-body li > p + ul,
.blog-body li > p + ol {
    margin-top: 0.1em;
}

.blog-body ol > li::marker {
    color: var(--color-blog-list-marker);
}

.blog-body blockquote {
    position: relative;
    margin: 1.6em 0;
    padding: 1.75rem 2.25rem 1.75rem 2.25rem;
    text-align: left;
    color: var(--color-text-secondary);
    font-family: inherit;
    font-size: inherit;
    font-style: italic;
    line-height: 1.6em;
    background: var(--color-blog-quote-bg);
    border: 1px solid var(--color-blog-quote-border);
    border-radius: 14px;
    quotes: none;
    box-sizing: border-box;
    /* Markdown 软换行会留在 <p> 文本里；默认 HTML 会收成空格，这里保留换行 */
    white-space: pre-line;
}

.blog-body blockquote p {
    white-space: pre-line;
    margin: 0.25em 0;
}

.blog-body blockquote::before,
.blog-body blockquote::after {
    position: absolute;
    font-family: Georgia, "Times New Roman", serif;
    font-style: normal;
    font-weight: 700;
    font-size: 3.2rem;
    line-height: 1;
    color: var(--color-blog-quote-mark);
    opacity: 0.9;
    pointer-events: none;
}

.blog-body blockquote::before {
    content: "\201C";
    top: 0.35rem;
    left: 0.7rem;
}

.blog-body blockquote::after {
    content: "\201D";
    right: 0.7rem;
    bottom: 0.1rem;
}

.blog-body blockquote > *:first-child {
    margin-top: 0;
}

.blog-body blockquote > *:last-child {
    margin-bottom: 0;
}

.blog-body hr {
    border: none;
    border-top: 1px dashed var(--color-border-medium);
    margin: 2em 0;
}

.blog-body table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
}

.blog-body th {
    font-weight: bold;
    border-bottom: 3px solid var(--color-border-medium);
    padding-bottom: 0.5em;
    text-align: left;
}

.blog-body td {
    border-bottom: 1px solid var(--color-border-medium);
    padding: 10px 0;
}

.blog-body img,
.blog-body video {
    max-width: 100%;
    height: auto;
    display: block;
    margin: auto;
}

.blog-mark-red {
    color: var(--color-blog-mark-red);
}

.blog-mark-blue {
    color: var(--color-blog-mark-blue);
}

.blog-mark-gold {
    color: var(--color-blog-mark-gold);
}

.blog-mark-purple {
    color: var(--color-blog-mark-purple);
}

@media (max-width: 900px) {
    main.markdown-stage.blog-post {
        margin: 0.75rem;
    }

    .blog-post,
    .blog-post:has(.blog-body.is-wide) {
        grid-template-columns: 1fr;
        justify-content: stretch;
        gap: 0.85rem;
    }

    .blog-body {
        padding: 1.35rem 1.25rem;
        max-width: none;
    }

    .blog-body-toolbar {
        display: none;
    }

    .blog-toc {
        position: static;
        max-height: none;
        order: -1;
    }

    .blog-toc-toggle {
        display: block;
    }

    .blog-toc.is-collapsed .blog-toc-panel {
        display: none;
    }

    .blog-toc:not(.is-collapsed) .blog-toc-panel {
        display: block;
        max-height: min(50vh, 320px);
    }

    .blog-toc-panel .toc::before {
        display: none;
    }
}

@media (min-width: 901px) {
    .blog-toc-toggle {
        display: none;
    }

    .blog-toc.is-collapsed .blog-toc-panel {
        display: block;
    }
}
