:root {
    --primary-color: #4a6fa5;
    --secondary-color: #6c757d;
    --text-color: #333;
    --light-bg: #f8f9fa;
    --white: #ffffff;
    --border-radius: 8px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
    --code-font: "Consolas", "Menlo", "Ubuntu Mono", "DejaVu Sans Mono", "Monaco", "Roboto Mono", "Courier New", monospace;

    /* 代码高亮特定颜色 */
    --code-bg: #000a2008;
    --code-text: #333333;
    --code-border: #444c56;
    --code-line-number: #768390;
    --code-line-highlight: rgba(99, 110, 123, 0.4);

    /* 语法高亮颜色 */
    --code-keyword: #0077aa;
    --code-type: #0077aa;
    --code-string: #dd1144;
    --code-number: #990073;
    --code-comment: #999999;
    --code-function: #0086b3;
    --code-constant: #990073;
    --code-tag: #22863a;
    --code-attribute: #6f42c1;
    --code-regex: #d16965;
    --code-title: #6f42c1;
    --code-section: #005cc5;
    --code-builtin: #d73a49;
    --code-meta: #555555;
    --code-addition: #22863a;
    --code-deletion: #b31d28;
}

/* 暗黑模式变量 */
[data-theme="dark"] {
    --primary-color: #6d8cc7;
    --secondary-color: #adb5bd;
    --text-color: #f8f9fa;
    --light-bg: #212529;
    --white: #343a40;

    /* 代码高亮特定颜色 */
    --code-bg: #282c34;
    --code-text: #abb2bf;
    --code-border: #444c56;
    --code-line-number: #768390;
    --code-line-highlight: rgba(99, 110, 123, 0.4);

    /* 语法高亮颜色 */
    --code-keyword: #c678dd;
    --code-type: #e5c07b;
    --code-string: #98c379;
    --code-number: #d19a66;
    --code-comment: #5c6370;
    --code-function: #61afef;
    --code-constant: #56b6c2;
    --code-tag: #e06c75;
    --code-attribute: #d19a66;
    --code-regex: #f69d50;
    --code-title: #e5c07b;
    --code-section: #e06c75;
    --code-builtin: #56b6c2;
    --code-meta: #7f848e;
    --code-addition: #98c379;
    --code-deletion: #e06c75;
}

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

html,
body {
    height: 100%;
    margin: 0;
}

body {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    min-height: 100vh;
    font-family: 'Times New Roman', '宋体', sans-serif;
    color: var(--text-color);
    background-color: var(--light-bg);
    line-height: 1.6;
    transition: var(--transition);
}

/* 导航栏样式 */
.navbar {
    grid-row: 1;
    background-color: var(--white);
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 1rem 0;
    transition: var(--transition);
}

.navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.avatar-link {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    transition: var(--transition);
}

.avatar-link:hover {
    transform: scale(1.1);
}

.avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.navbar-info {
    display: flex;
    flex-direction: column;
}

.name {
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 1.1rem;
}

.subject {
    font-size: 0.9rem;
    color: var(--secondary-color);
    text-decoration: none;
}

.brand-home-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-color);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
}

.brand-home-link:hover {
    color: var(--primary-color);
}

.navbar-actions {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.nav-link:hover {
    color: var(--primary-color);
}

.nav-link i {
    font-size: 1.1rem;
}

/* 标题区域 */
.title-section {
    grid-row: 2;
    background-color: var(--primary-color);
    color: white;
    padding: 2rem 0;
    margin-bottom: 2rem;
    height: auto;
}

.title-container {
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
    padding: 0 2rem;
}

.chapter-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    line-height: 1.3;
    white-space: pre-line;
}

.chapter-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    font-size: 0.95rem;
    opacity: 0.9;
}

.chapter-meta i {
    margin-right: 0.3rem;
}

.chapter-tags {
    display: flex;
    gap: 0.5rem;
}

.tag {
    background-color: rgba(255, 255, 255, 0.2);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
}

/* 内容区域 */
.content-section {
    grid-row: 3;
    grid-column: 1;
    max-width: 80vw;
    min-width: 70vw;
    margin: 0 auto 3rem;
    padding: 0 2rem;
}

.chapter-content {
    background-color: var(--white);
    padding: 3rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    transition: var(--transition);
    min-width: 90%;
    min-height: 0;
    line-break: strict;
    /* 严格的换行规则 */
    word-break: normal;
    hyphens: manual;
    overflow-wrap: break-word;
}

/* 添加H1样式 */
.chapter-content h1 {
    color: var(--primary-color);
    margin: 2.5rem 0 1.5rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.7rem;
}

/* 调整现有的H2样式，确保层级正确 */
.chapter-content h2 {
    color: var(--primary-color);
    margin: 2rem 0 1rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
}

.chapter-content h3 {
    color: var(--primary-color);
    margin: 1.5rem 0 0.8rem;
}

.chapter-content h4 {
    color: var(--primary-color);
    margin: 1.2rem 0 0.6rem;
}

.chapter-content h5 {
    color: var(--primary-color);
    margin: 1rem 0 0.5rem;
}

.chapter-content h6 {
    color: var(--primary-color);
    margin: 0.8rem 0 0.4rem;
}

.chapter-content p {
    line-height: 1.8;
    display: block;
}

.chapter-content p:lang(zh) {
    line-break: normal;
    /* 中文使用更宽松的换行规则 */
    hanging-punctuation: none;
    /* 禁用悬挂标点 */
}

.chapter-content a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dotted var(--primary-color);
    transition: var(--transition);
}

.chapter-content a:hover {
    color: #3a5a8f;
    border-bottom-style: solid;
}

.chapter-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2rem auto;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chapter-content ul,ol{
    margin-left: 1.2em;
}

code,
pre {
    font-family: var(--code-font);
}

code {
    white-space: pre-wrap;
    /* 保留空白符，但允许必要时的换行 */
    word-break: normal;
    display: inline-block;
    /* 防止代码片段被分割 */
    color: #245bad;
}

[data-theme="dark"] code {
    white-space: pre-wrap;
    /* 保留空白符，但允许必要时的换行 */
    word-break: normal;
    display: inline-block;
    /* 防止代码片段被分割 */
    color: #6d8cc7;
}

/* ===== 代码块核心样式 ===== */
figure.highlight {
    background: var(--light-bg);
    color: var(--text-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    /* margin: 1.5em 0; */
    /* overflow: hidden; */
    transition: var(--transition);
    margin: 1em 0;
    max-width: 100%;
    overflow-x: auto;
}

/* figure.highlight::before {
    content: var("--lang-name");
    top: 0;
    right: 0;
    background: #e0e0e0;
    color: #555;
    padding: 0.2em 0.5em;
    font-family: monospace;
} */

/* ===== 表格核心样式 ===== */
table {
    width: 100%;
    border-collapse: separate;
    /* 关键改动：分离边框模式 */
    border-spacing: 0;
    margin: 1.5em 0;
    background: var(--white);
    color: var(--text-color);
    box-shadow: var(--box-shadow);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: var(--transition);
}

/* 单元格统一边框样式 */
table th:not(:has(pre)),
table td:not(:has(pre)) {
    padding: 12px 16px;
    text-align: center;
    vertical-align: middle;
    border-right: 1px solid var(--primary-color);
    /* 垂直分割线 */
    border-bottom: 1px solid var(--primary-color);
    /* 水平分割线 */
    transition: background-color 0.2s;
}

/* 最后一列去掉右边框 */
table th:last-child,
table td:last-child {
    border-right: none;
}

/* 表头特殊样式 */
table th {
    background: var(--light-bg);
    font-weight: 600;
    border-bottom: 2px solid var(--primary-color);
    /* 加粗表头底部线 */
    letter-spacing: 0.5px;
}

/* 最后一行去掉底部边框 */
table tr:last-child td {
    border-bottom: none;
}


/* 深色模式适配 */
[data-theme="dark"] table {
    background: var(--white);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] table th,
[data-theme="dark"] table td {
    border-right-color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

[data-theme="dark"] table th {
    background: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* 响应式优化 */
@media (max-width: 768px) {

    table th,
    table td {
        padding: 10px 12px;
        font-size: 0.9em;
    }
}

/* ===== 行号列 ===== */
figure.highlight .gutter {
    width: 2.5em;
    padding: 0.75em 0.5em;
    text-align: right;
    color: var(--secondary-color);
    background: rgba(0, 0, 0, 0.03);
    border-right: 1px solid;
    border-color: color-mix(in srgb, var(--secondary-color) 15%, transparent);
    user-select: none;
    vertical-align: top;
}

[data-theme="dark"] figure.highlight .gutter {
    background: rgba(255, 255, 255, 0.05);
}

/* ===== 代码列 ===== */
figure.highlight .code {
    padding: 0.75em 1em;
    vertical-align: top;
    overflow-x: auto;
    max-width: 100%;
    white-space: pre;
}

figure.highlight br {
    content: "";
    /* 清除默认换行行为 */
    display: none;
    /* 完全隐藏 */
    line-height: 0;
    /* 或设置高度为0 */
}

/* ===== 代码行 ===== */
figure.highlight .line {
    line-height: 1.6em;
    font-size: 14px;
    display: block;
    min-height: 1.6em;
}

figure.highlight table {
    margin: 0;
    width: 100%;
    border-collapse: collapse;
}

figure.highlight tr {
    background: transparent !important;
}

figure.highlight td {
    padding: 0;
    border: none;
}

/* figure.highlight td.gutter {
    width: 2.5em;
    padding: 0.75em 1em;
    text-align: right;
    color: var(--code-line-number);
    background-color: var(--code-bg);
    border-right: 1px solid var(--code-border);
    user-select: none;
} */

figure.highlight td.code {
    padding: 0.75em 1em;
    vertical-align: top;
}

figure.highlight pre {
    margin: 0;
    overflow: auto;
}

/* 行高亮样式 */
figure.highlight .line.marked {
    background-color: var(--code-line-highlight);
}

/* ===== 语法高亮样式 ===== */
figure.highlight .keyword,
figure.highlight .keyword.function {
    color: var(--code-keyword);
    font-weight: bold;
}

figure.highlight .type {
    color: var(--code-type);
}

figure.highlight .string,
figure.highlight .string .value {
    color: var(--code-string);
}

figure.highlight .number {
    color: var(--code-number);
}

figure.highlight .comment {
    color: var(--code-comment);
    font-style: italic;
}

figure.highlight .function {
    color: var(--code-function);
}

figure.highlight .title.function {
    color: var(--code-function);
}

figure.highlight .params {
    color: var(--code-text);
}

figure.highlight .built_in {
    color: var(--code-builtin);
}

figure.highlight .literal {
    color: var(--code-constant);
}

figure.highlight .tag,
figure.highlight .selector-tag {
    color: var(--code-tag);
}

figure.highlight .attribute {
    color: var(--code-attribute);
}

figure.highlight .regexp {
    color: var(--code-regex);
}

figure.highlight .title.class_ {
    color: var(--code-title);
}

figure.highlight .section {
    color: var(--code-section);
}

figure.highlight .meta {
    color: var(--code-meta);
}

figure.highlight .addition {
    color: var(--code-addition);
    background-color: rgba(70, 149, 74, 0.15);
}

figure.highlight .deletion {
    color: var(--code-deletion);
    background-color: rgba(203, 36, 49, 0.15);
}

/* ===== Katex 相关样式调整 ===== */
.katex {
    font-size: 1.05em !important;
}

.katex-display {
    overflow: auto hidden;
    padding: 0.5em 0;
}

/* 确保代码块和 Katex 公式在暗黑模式下协调 */
[data-theme="dark"] .katex {
    color: var(--text-color);
}

/* ===== 行内代码样式 ===== */
code:not([class*="language-"]) {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 0.85em;
    background-color: var(--code-bg);
    border-radius: 3px;
    color: var(--code-text);
    /* font-family: var(--code-font); */
    /* border: 1px solid var(--code-border); */
}

/* ===== 代码块标题样式 ===== */
figure.highlight figcaption {
    padding: 0.5em 1em;
    background-color: var(--code-border);
    color: var(--code-line-number);
    font-family: var(--code-font);
    font-size: 0.85em;
    border-bottom: 1px solid var(--code-border);
}

figure.highlight figcaption a {
    color: inherit;
    text-decoration: none;
}

figure.highlight figcaption a:hover {
    text-decoration: underline;
}

/* ===== 滚动条样式 ===== */
figure.highlight pre::-webkit-scrollbar {
    height: 6px;
}

figure.highlight pre::-webkit-scrollbar-thumb {
    background-color: var(--code-line-number);
    border-radius: 3px;
}

figure.highlight pre::-webkit-scrollbar-track {
    background-color: var(--code-border);
}

/* ===== 响应式优化 ===== */
@media (max-width: 768px) {
    .content-section .chapter-content figure.highlight {
        border-radius: calc(var(--border-radius) / 2);
        font-size: 0.85em;
    }
}



/* 笔记工具条 */
.note-tools {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.95rem;
}

.tool-btn:hover {
    background-color: #3a5a8f;
    transform: translateY(-2px);
}

.tool-btn i {
    font-size: 1rem;
}

/* 页脚样式 */
.footer {
    font-family: sans-serif;
    grid-row: 4;
    background-color: var(--white);
    padding: 1rem 0;
    text-align: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
    transition: var(--transition);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

.footer p {
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

.footer-links a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: var(--transition);
}

.footer-links a:hover {
    color: var(--primary-color);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .navbar-container {
        padding: 0 1rem;
        align-items: flex-start;
        flex-direction: column;
        gap: 1rem;
    }

    .navbar-actions {
        justify-content: flex-start;
        gap: 1rem;
    }

    .chapter-title {
        font-size: 2rem;
    }

    .chapter-meta {
        flex-direction: column;
        gap: 0.5rem;
    }

    .content-section,
    .title-container {
        padding: 0 1rem;
    }

    .chapter-content {
        padding: 2rem 1.5rem;
    }

    .note-tools {
        justify-content: flex-start;
    }
}

@media print {
    body * {
        visibility: hidden;
        /* 隐藏所有元素 */
    }

    /* h1.chapter-title, */
    .chapter-content,
    .chapter-content * {
        visibility: visible;
        /* 仅显示目标区域 */
    }

    /* h1.chapter-title, */
    .chapter-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

/* Astro compatibility: keep the old note.css as the baseline and only map Astro output to it. */
.chapter-content pre.astro-code {
    background: var(--code-bg) !important;
    color: var(--code-text) !important;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin: 1.5em 0;
    max-width: 100%;
    overflow-x: auto;
    padding: 2rem 1em 0.75em 3.9em;
    position: relative;
    transition: var(--transition);
}

.chapter-content pre.astro-code .code-lang-label,
.chapter-content pre.astro-code .copy-code-btn {
    position: absolute;
    top: 0;
    padding: 0.2em 0.5em;
    background: #eee;
    color: #333;
    font-family: var(--code-font);
    font-size: 0.8em;
    line-height: 1.4;
}

.chapter-content pre.astro-code .code-lang-label {
    right: 0;
    border-radius: 0 4px 0 4px;
    text-transform: lowercase;
}

.chapter-content pre.astro-code .copy-code-btn {
    right: 4.2rem;
    border: 0;
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    transition: var(--transition);
}

.chapter-content pre.astro-code .copy-code-btn:hover {
    color: var(--primary-color);
}

.chapter-content pre.astro-code code,
.chapter-content pre.astro-code code:not([class*="language-"]) {
    background: transparent;
    border-radius: 0;
    color: inherit;
    display: block;
    font-family: var(--code-font);
    font-size: 14px;
    line-height: 1.6em;
    margin: 0;
    padding: 0;
    white-space: pre;
}

.chapter-content pre.astro-code .line {
    display: inline;
    min-height: 0;
    position: relative;
}

.chapter-content pre.astro-code .line-number {
    position: absolute;
    left: -3.2em;
    width: 2.4em;
    padding-right: 0.7em;
    color: var(--secondary-color);
    text-align: right;
    user-select: none;
}

.chapter-content pre.astro-code::-webkit-scrollbar {
    height: 6px;
}

.chapter-content pre.astro-code::-webkit-scrollbar-thumb {
    background-color: var(--code-line-number);
    border-radius: 3px;
}

.chapter-content pre.astro-code::-webkit-scrollbar-track {
    background-color: var(--code-border);
}

[data-theme="dark"] .chapter-content pre.astro-code {
    background: var(--code-bg) !important;
    color: var(--code-text) !important;
}

[data-theme="dark"] .chapter-content pre.astro-code .code-lang-label,
[data-theme="dark"] .chapter-content pre.astro-code .copy-code-btn {
    background: #444;
    color: #ddd;
}

.chapter-content .katex-display {
    overflow: auto hidden;
    padding: 0.5em 0;
}

.code-lang-label {
    position: absolute;
    top: 0;
    right: 0;
    padding: 0.2em 0.5em;
    border-radius: 0 4px 0 4px;
    background: #eee;
    color: #333;
    font-family: var(--code-font);
    font-size: 0.8em;
    line-height: 1.4;
    z-index: 1;
}

.note-code-language {
    display: none !important;
}

[data-theme="dark"] .code-lang-label {
    background: #444;
    color: #ddd;
}
