html {
    font-size: 10.5pt;
}

/* 设置段落两端对齐 */
p {
    text-align: justify;
    text-justify: inter-ideograph; /* 针对中文优化，改善标点和汉字间距 */
}

/* 增加段落行高，原为 2rem */
p,
ul,
ol,
dl {
    line-height: 2.2rem;
}

/* 标题样式调整：默认（中文）不倾斜，加粗 */
h1,
h2,
h3,
h4,
h5 {
    font-style: normal;
    font-weight: bold;
    color: #111;
}

h2 {
    font-size: 2.3rem;
    line-height: 1.2;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

h3 {
    font-size: 2rem;
    line-height: 1.2;
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
}

h4 {
    font-size: 1.75rem;
    line-height: 1.2;
    margin-top: 1.2rem;
    margin-bottom: 0.5rem;
}

h5 {
    font-size: 1.5rem;
    line-height: 1.2;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* 英文/数字部分：倾斜、加粗 */
.heading-en {
    font-style: italic;
}

/* 覆盖 Tufte CSS 的默认代码块样式 */
pre > code {
    width: 95%;
    /* 原为 52.5%，改为 100% 以适应父容器 */
    font-size: 1.2rem;
    /* 原为 0.9rem，增大字体 */
    line-height: 1.5; /* 显式设置行高以对齐行号 */
    margin-left: 0%;
    background-color: transparent;
    /* 避免代码块内重复背景 */
    padding: 0;
    border: none;
}

/* 行号样式 */
pre.has-line-numbers {
    display: flex;
    align-items: flex-start;
}

.line-numbers-rows {
    display: flex;
    flex-direction: column;
    padding-right: 0.4em;
    margin-right: 0.4em;
    border-right: 1px solid #ddd;
    color: #aaa;
    user-select: none;
    text-align: right;
    min-width: 1.2em;
    font-size: 1.2rem; /* 匹配代码字体大小 */
    line-height: 1.5; /* 匹配代码行高 */
    font-family: monospace; /* 确保字体一致 */
}

/* 调整行内代码大小及样式 */
code {
    font-size: 1.2rem;
    background-color: #f7f7f7;
    /* 浅灰背景 */
    padding: 0.1em 0.3em;
    /* 内边距 */
    border-radius: 3px;
    /* 圆角 */
    border: 1px solid #e7e7e7;
    /* 浅色边框 */
}

/* 代码块容器样式 */
pre {
    position: relative;
    /* 为复制按钮定位 */
    background-color: #f7f7f7;
    /* 浅灰背景 */
    border: 1px solid #e0e0e0;
    /* 边框 */
    border-radius: 5px;
    /* 圆角 */
    padding: 1em;
    /* 内边距 */
    overflow-x: auto;
    /* 横向滚动 */
    margin-bottom: 1.5em;

    /* 布局修复 */
    width: 55%;
    margin-left: 0;
    margin-right: 0;
    float: none;
    clear: none;
    box-sizing: border-box;
    /* 包含内边距和边框 */
    left: 0;
}

/* 列表中的代码块需要占满列表项宽度 */
li pre,
ul pre,
ol pre,
dl pre {
    width: 100%;
}

/* Figure 中的代码块需要占满 Figure 宽度 */
figure pre {
    width: 100%;
}

/* 修复引用块 (Quote Box) 样式 */
/* 针对 theorion 包生成的带左边框的 div */
div[style*="border-inline-start"] {
    width: 55% !important;
    /* 强制宽度为 55%，与正文一致 */
    font-size: 1.4rem;
    /* 统一字体大小，匹配正文 p 标签 */
    line-height: 2.2rem;
    /* 统一行高 */
    clear: none;
    /* 清除浮动 */
    margin: 1.5em 0;
    /* 垂直间距 */
    padding-right: 0 !important;
    /* 移除右内边距，确保侧边注与正文侧边注对齐 */
}

/* 确保内部 p 标签样式一致 */
div[style*="border-inline-start"] p {
    font-size: 1.4rem;
    /* 确保 p 标签也是 1.4rem */
    margin: 0.5em 0;
    /* 调整内部段落间距 */
    width: 100%;
    /* 内部 p 占满 div */
}

/* 修复引用块内的脚注和侧边注样式 */
div[style*="border-inline-start"] .footnote-ref,
div[style*="border-inline-start"] .marginnote,
div[style*="border-inline-start"] .footnote-ref a {
    color: #111 !important;
}

/* 复制按钮样式 */
.copy-button {
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    padding: 0.3em 0.6em;
    font-size: 0.8rem;
    color: #666;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    /* 默认隐藏 */
    transition:
        opacity 0.2s,
        background-color 0.2s;
}

/* 鼠标悬停在代码块上时显示按钮 */
pre:hover .copy-button {
    opacity: 1;
}

/* 修复脚注导致的行距不一致问题 */
sup.footnote-ref {
    line-height: 0;
    position: relative;
    vertical-align: baseline;
    top: -0.5em;
}

.copy-button:hover {
    background-color: #f0f0f0;
    color: #333;
}

.copy-button.copied {
    background-color: #e6fffa;
    color: #008000;
    border-color: #008000;
}

/* 深色模式适配 */
/* 优先使用手动设置的主题，其次使用系统偏好 */
[data-theme="dark"],
@media (prefers-color-scheme: dark) {
    /* 如果没有手动设置为浅色，则应用深色主题 */
    :root:not([data-theme="light"]) {
        /* 标题颜色 */
        h1,
        h2,
        h3,
        h4,
        h5 {
            color: #eee;
        }

        /* 正文颜色 */
        body,
        p {
            color: #e0e0e0;
        }

        /* 链接颜色 */
        a {
            color: #64b5f6;
        }

        a:hover {
            color: #90caf9;
        }

        /* 行内代码样式 */
        code {
            background-color: #2d2d2d;
            color: #e8e8e8;
            border-color: #3d3d3d;
        }

        /* 代码块容器样式 */
        pre {
            background-color: #2d2d2d;
            border-color: #3d3d3d;
        }

        /* 代码块中的代码文本 */
        pre > code {
            color: #e8e8e8;
        }

        /* 行号边框和颜色 */
        .line-numbers-rows {
            border-right-color: #555;
            color: #666;
        }

        /* 复制按钮 */
        .copy-button {
            background-color: #333;
            color: #ccc;
            border-color: #555;
        }

        .copy-button:hover {
            background-color: #444;
            color: #eee;
        }

        .copy-button.copied {
            background-color: #1a4d3a;
            color: #5fda9d;
            border-color: #5fda9d;
        }

        /* 引用块样式 */
        div[style*="border-inline-start"] .footnote-ref,
        div[style*="border-inline-start"] .marginnote,
        div[style*="border-inline-start"] .footnote-ref a {
            color: #eee !important;
        }

        /* 背景颜色 */
        body {
            background-color: #1a1a1a;
        }

        /* 侧边注和脚注 */
        .marginnote,
        .footnote {
            color: #e0e0e0;
        }
    }
}
