/* ==========================================================================
   1. 变量定义 (Variables)
   ========================================================================== */
:root {
  /* --- 基础定义 --- */
  --siteFont: "PT Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --codeFontFamily: "Roboto Mono", Monaco, courier, monospace;
  --bodyFontSize: 16px;
  --sidebarWidth: 300px;

  /* 引入间距系统，消除魔法数字 */
  --spacing-s: 8px;
  --spacing-m: 16px;
  --spacing-l: 24px;
  --spacing-xl: 32px;
  --spacing-xxl: 40px;

  /* --- 亮色主题变量 --- */
  --accent: #42b983;
  --background: #ffffff;
  --textColor: #34495e;
  --codeTextColor: #525252;
  --codeBackgroundColor: #f8f8f8;
  --borderColor: rgba(0, 0, 0, 0.07);
  --blockQuoteColor: #858585;
  --highlightColor: #d22778;
  --sidebarSublink: #505d6b;
  --codeTypeColor: #091a28;
  --coverBackground: linear-gradient(to left bottom, hsl(118, 100%, 85%) 0%, hsl(181, 100%, 85%) 100%);

  /* 统一使用 color-mix 定义带透明度的颜色，移除 --accent-rgb 和 @supports */
  --scrollbar-thumb: color-mix(in srgb, var(--accent) 30%, transparent);
  --scrollbar-thumb-hover: color-mix(in srgb, var(--accent) 50%, transparent);
  --sidebar-level1-border: color-mix(in srgb, var(--accent) 20%, transparent);
  --sidebar-level2-border: color-mix(in srgb, var(--accent) 40%, transparent);
  --sidebar-level3-border: color-mix(in srgb, var(--accent) 60%, transparent);
  --sidebar-active-child-border: color-mix(in srgb, var(--accent) 60%, transparent);
  --hover-bg: color-mix(in srgb, var(--accent) 8%, transparent);
  --active-bg: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* --- 暗色主题变量覆盖 --- */
body.dark {
  --background: #091a28;
  --textColor: #d0d0d0;
  --codeTextColor: #ffffff;
  --codeBackgroundColor: #0e2233;
  --borderColor: #0d2538;
  --sidebarSublink: #d0d0d0;
  --codeTypeColor: #ffffff;
  --coverBackground: linear-gradient(to left bottom, hsl(215, 30%, 25%) 0%, hsl(220, 30%, 10%) 100%);
}

/* ==========================================================================
   2. 全局重置与基础样式 (Global Reset & Base Styles)
   ========================================================================== */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
}
* {
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    box-sizing: border-box;
}

body:not(.ready) {
    overflow: hidden;
}

body:not(.ready) .app-nav,
body:not(.ready)>nav,
body:not(.ready) [data-cloak] {
    display: none;
}

div#app {
  font-size: 30px;
  font-weight: lighter;
  margin: 40vh auto;
  text-align: center;
}
div#app:empty::before {
  content: 'Loading...';
}

.progress {
    background-color: var(--accent);
    height: 2px;
    position: fixed;
    inset-inline-start: 0; /* 使用逻辑属性 */
    inset-inline-end: 0;   /* 使用逻辑属性 */
    top: 0;
    transition: width .2s,opacity .4s;
    width: 0;
    z-index: 999999;
}

body, html {
    height: 100%;
}

body {
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    color: var(--textColor);
    font-family: var(--siteFont);
    font-size: var(--bodyFontSize);
    letter-spacing: 0;
    overflow-x: hidden;
    background-color: var(--background);
}

.emoji {
    height: 1.2rem;
    vertical-align: middle;
}

a[disabled] {
    cursor: not-allowed;
    opacity: .6;
}

kbd {
    border: 1px solid #ccc;
    border-radius: 3px;
    display: inline-block;
    font-size: 12px!important;
    line-height: 12px;
    margin-bottom: 3px;
    padding: 3px 5px;
    vertical-align: middle;
}

li input[type=checkbox] {
    margin: 0 .2em .25em 0;
    vertical-align: middle;
}

/* ==========================================================================
   3. 组件样式 (Components)
   ========================================================================== */

/* --- 搜索框 --- */
.search {
    border-bottom: none;
}

body.dark .search {
    border-bottom-color: var(--borderColor);
}

.search .input-wrap {
    margin-top: var(--spacing-l); /* 使用间距变量 */
}

.search input {
    border: 1px solid var(--borderColor);
    background-color: var(--background);
    width: 90%;
    margin: 0 auto;
    color: var(--textColor);
    border-radius: 15px;
    text-indent: 15px;
}

.search .search-keyword,
.search a:hover {
    color: var(--accent);
}

.search .search-keyword {
    font-style: normal;
    font-weight: 700;
}

/* --- 顶部导航 --- */
.app-nav {
    margin: var(--spacing-l) 60px 0 0; /* 使用间距变量 */
    position: absolute;
    inset-inline-end: 0; /* 使用逻辑属性 */
    text-align: end;     /* 使用逻辑属性 */
    z-index: 10;
}

.app-nav.no-badge {
    margin-inline-end: var(--spacing-l); /* 使用逻辑属性和间距变量 */
}

.app-nav p {
    margin: 0;
}

.app-nav>a {
    margin: 0 1rem;
    padding: 5px 0;
}

.app-nav li, .app-nav ul {
    display: inline-block;
    list-style: none;
    margin: 0;
    padding: 0;
}

.app-nav a {
    color: inherit;
    font-size: 16px;
    text-decoration: none;
}

.app-nav a.active,
.app-nav a:hover {
    color: var(--accent);
}

.app-nav a.active {
    border-bottom: 2px solid var(--accent);
}

.app-nav li {
    display: inline-block;
    margin: 0 1rem;
    padding: 5px 0;
    position: relative;
    cursor: pointer;
}

.app-nav li ul {
    background-color: var(--background);
    border: 1px solid var(--borderColor);
    border-radius: 4px;
    box-sizing: border-box;
    display: none;
    max-height: calc(100vh - 61px);
    overflow-y: auto;
    padding: 10px 0;
    position: absolute;
    inset-inline-end: -15px; /* 使用逻辑属性 */
    text-align: start;       /* 使用逻辑属性 */
    top: 100%;
    white-space: nowrap;
}

.app-nav li ul li {
    display: block;
    font-size: 14px;
    line-height: 1rem;
    margin: 8px 14px;
    white-space: nowrap;
}

.app-nav li ul a {
    display: block;
    font-size: inherit;
    margin: 0;
    padding: 0;
}

.app-nav li ul a.active {
    border-bottom: 0;
}

.app-nav li:hover ul {
    display: block;
}

/* --- GitHub 角标 --- */
.github-corner {
    border-bottom: 0;
    position: fixed;
    inset-inline-end: 0; /* 使用逻辑属性 */
    text-decoration: none;
    top: 0;
    z-index: 1;
}

.github-corner:hover .octo-arm {
    animation: octocat-wave .56s ease-in-out;
}

.github-corner svg {
    color: #fff;
    fill: var(--accent);
    height: 70px;
    width: 70px;
}

@keyframes octocat-wave {
    0%, to { transform: rotate(0); }
    20%, 60% { transform: rotate(-25deg); }
    40%, 80% { transform: rotate(10deg); }
}

/* ==========================================================================
   4. 布局 (Layout)
   ========================================================================== */
main {
    display: block;
    position: relative;
    width: 100vw;
    height: 100%;
    z-index: 0;
}

main.hidden {
    display: none;
}

.anchor {
    display: inline-block;
    text-decoration: none;
}

.anchor span {
    color: var(--textColor);
}

.anchor:hover {
    text-decoration: underline;
}

/* --- 侧边栏 --- */
.sidebar {
    border-inline-end: 1px solid var(--borderColor); /* 使用逻辑属性 */
    overflow-y: auto;
    padding-block-start: var(--spacing-xxl); /* 使用逻辑属性和间距变量 */
    padding-inline: 0;
    position: absolute;
    top: 0;
    bottom: 0;
    inset-inline-start: 0; /* 使用逻辑属性 */
    transition: inset-inline-start .25s ease-out; /* 修改为对布局属性进行过渡 */
    width: var(--sidebarWidth);
    z-index: 20;
    color: var(--textColor);
    background-color: var(--background); /* 关键: 保持组件独立性 */
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.sidebar > h1 {
    margin: 0 auto 1rem;
    font-size: 1.5rem;
    font-weight: 300;
    text-align: center;
}

.sidebar > h1 a {
    color: inherit;
    text-decoration: none;
}

.sidebar > h1 .app-nav {
    display: block;
    position: static;
}

.sidebar .sidebar-nav {
    line-height: 2em;
    padding-bottom: var(--spacing-xxl); /* 使用间距变量 */
}

.sidebar li.collapse .app-sub-sidebar {
    display: none;
}

.sidebar li > p {
    font-weight: 700;
    margin: 6px 0;
}

.sidebar ul {
    list-style: none;
    padding-inline-start: var(--spacing-m); /* 使用逻辑属性和间距变量 */
    margin: 0;
}

.sidebar li {
    margin: 6px 0;
}

.sidebar ul li a {
    color: var(--sidebarSublink);
    font-size: 14px;
    font-weight: 400;
    text-decoration: none;
    display: block;
    padding: 6px var(--spacing-m); /* 使用间距变量 */
    border-inline-end: 3px solid transparent; /* 使用逻辑属性 */
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar ul li a:hover {
    color: var(--accent);
    background-color: var(--hover-bg);
}

.sidebar ul li ul {
    padding-inline-start: var(--spacing-l); /* 使用逻辑属性和间距变量 */
    margin-inline-start: 12px;
    border-inline-start: 1px solid var(--sidebar-level1-border); /* 使用逻辑属性 */
}

.sidebar ul li ul li ul {
    border-inline-start-color: var(--sidebar-level2-border);
}

.sidebar ul li ul li ul li ul {
    border-inline-start-color: var(--sidebar-level3-border);
}

.sidebar ul li.active > a {
    color: var(--accent);
    font-weight: 600;
    background-color: var(--active-bg);
    border-inline-end-color: var(--accent); /* 使用逻辑属性 */
}

.sidebar ul li.active > ul {
  border-inline-start-color: var(--sidebar-active-child-border);
}

.sidebar li.has-children > a::after {
    content: '›';
    position: absolute;
    inset-inline-end: var(--spacing-l); /* 使用逻辑属性和间距变量 */
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    font-size: 20px;
    line-height: 1;
    font-weight: bold;
    color: currentColor;
    opacity: 0.5;
    transition: transform 0.3s ease;
}

.sidebar li.has-children.expanded > a::after {
    transform: translateY(-50%) rotate(90deg);
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
.sidebar:hover::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb-hover); }

/* --- 侧边栏开关 --- */
.sidebar-toggle {
    background-color: transparent;
    border: 0;
    outline: none;
    padding: 10px;
    position: absolute;
    bottom: 0;
    inset-inline-start: 0; /* 使用逻辑属性 */
    text-align: center;
    width: calc(var(--sidebarWidth) - 16px);
    z-index: 30;
    cursor: pointer;
}

.sidebar-toggle:hover .sidebar-toggle-button { opacity: .4; }
.sidebar-toggle span {
    background-color: var(--accent);
    display: block;
    margin-bottom: 4px;
    width: 16px;
    height: 2px;
}

body.sticky .sidebar, body.sticky .sidebar-toggle { position: fixed; }

/* --- 内容区域 --- */
.content {
    padding-top: 60px;
    position: absolute;
    top: 0;
    inset-inline-end: 0; /* 使用逻辑属性 */
    bottom: 0;
    inset-inline-start: var(--sidebarWidth); /* 使用逻辑属性 */
    background-color: var(--background); /* 关键: 保持组件独立性 */
    color: var(--textColor);
    transition: inset-inline-start .25s ease-out;
}

/* ==========================================================================
   5. Markdown 内容样式 (Markdown Content)
   ========================================================================== */
.markdown-section {
    margin: 0 auto;
    max-width: min(90%, 100ch); /* 使用min()函数保证最佳阅读行长 */
    padding: var(--spacing-xl) var(--spacing-m) var(--spacing-xxl); /* 使用间距变量 */
    position: relative;
}

.markdown-section>* {
    box-sizing: border-box;
    font-size: inherit;
}

.markdown-section>:first-child { margin-top: 0!important; }

.markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section strong {
    color: var(--textColor);
    font-weight: 600;
}

.markdown-section a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.markdown-section h1 { font-size: 2rem; margin: 0 0 1rem; }
.markdown-section h2 { font-size: 1.75rem; margin: 45px 0 .8rem; border-bottom: 1px solid var(--borderColor); padding-bottom: .3rem; }
.markdown-section h3 { font-size: 1.5rem; margin: 40px 0 .6rem; }
.markdown-section h4 { font-size: 1.25rem; }
.markdown-section h5 { font-size: 1rem; }
.markdown-section h6 { color: #777; font-size: 1rem; }
.markdown-section figure, .markdown-section p { margin: 1.2em 0; }
.markdown-section ol, .markdown-section p, .markdown-section ul {
    line-height: 1.6rem;
    word-spacing: .05rem;
}

.markdown-section ol, .markdown-section ul {
    padding-inline-start: 1.5rem; /* 使用逻辑属性 */
}

.markdown-section hr { border: none; border-bottom: 1px solid var(--borderColor); margin: 2em 0; }
.markdown-section iframe { border: 1px solid var(--borderColor); width: 1px; min-width: 100%; margin: 1em 0; }

.markdown-section table {
    border-collapse: collapse;
    border-spacing: 0;
    display: block;
    margin-bottom: 1rem;
    overflow: auto;
    width: 100%;
}
.markdown-section th { font-weight: 700; }
.markdown-section td, .markdown-section th { border: 1px solid var(--borderColor); padding: 6px 13px; }
.markdown-section tr { border-top: 1px solid var(--borderColor); }
.markdown-section tr:nth-child(2n) { background-color: var(--codeBackgroundColor); }

.markdown-section p.tip {
    border-radius: 0 2px 2px 0;
    border-inline-start: 4px solid #f66; /* 使用逻辑属性 */
    margin: 2em 0;
    padding: 12px 24px 12px 30px;
    position: relative;
    background-color: var(--codeBackgroundColor);
}
.markdown-section p.tip:before {
    background-color: #f66;
    border-radius: 100%;
    color: #fff;
    content: "!";
    font-family: Dosis, Source Sans Pro, Helvetica Neue, Arial, sans-serif;
    font-size: 14px;
    font-weight: 700;
    inset-inline-start: -12px; /* 使用逻辑属性 */
    line-height: 20px;
    position: absolute;
    height: 20px;
    width: 20px;
    text-align: center;
    top: 14px;
}
.markdown-section p.tip code { background-color: rgba(0,0,0,0.05); }
.markdown-section p.tip em { color: var(--textColor); }

.markdown-section p.warn { background: rgba(66,185,131,.1); border-radius: 2px; padding: 1rem; }
.markdown-section ul.task-list>li { list-style-type: none; }

.markdown-section blockquote {
    border-inline-start: 4px solid var(--accent); /* 使用逻辑属性 */
    color: var(--blockQuoteColor);
    margin: 2em 0;
    padding-inline-start: 20px; /* 使用逻辑属性 */
}
.markdown-section blockquote p { font-weight: 600; margin-inline-start: 0; }
.markdown-section em { color: #7f8c8d; }

.markdown-section code {
    border-radius: 2px;
    color: var(--highlightColor);
    background-color: var(--codeBackgroundColor);
    font-family: var(--codeFontFamily);
    font-size: .9rem;
    margin: 0 2px;
    padding: 3px 5px;
    white-space: pre-wrap;
    font-weight: 700;
}

.markdown-section pre {
    -moz-osx-font-smoothing: initial;
    -webkit-font-smoothing: initial;
    line-height: 1.5rem;
    margin: 1.2em 0;
    overflow: auto;
    padding: 0 1.4rem;
    position: relative;
    word-wrap: normal;
    background-color: var(--codeBackgroundColor);
}
.markdown-section pre>code {
    -moz-osx-font-smoothing: initial;
    -webkit-font-smoothing: initial;
    background-color: transparent;
    border-radius: 2px;
    color: var(--codeTextColor);
    display: block;
    font-size: .8rem;
    line-height: inherit;
    margin: 0 2px;
    max-width: inherit;
    overflow: inherit;
    padding: 2.2em 5px;
    white-space: inherit;
}

.markdown-section code:after, .markdown-section code:before { letter-spacing: .05rem; }

pre:after {
    color: var(--codeTypeColor);
    content: attr(data-lang);
    font-size: .6rem;
    font-weight: 600;
    height: 15px;
    line-height: 15px;
    padding: 5px 10px 0;
    position: absolute;
    inset-inline-end: 0; /* 使用逻辑属性 */
    text-align: end;     /* 使用逻辑属性 */
    top: 0;
}

/* ==========================================================================
   6. 语法高亮 (Syntax Highlighting)
   ========================================================================== */
code .token { -moz-osx-font-smoothing: initial; -webkit-font-smoothing: initial; min-height: 1.5rem; position: relative; left: auto; }
.token.cdata, .token.comment, .token.doctype, .token.prolog { color: #8e908c; }
.token.namespace { opacity: .7; }
.token.boolean, .token.number { color: #c76b29; }
.token.punctuation { color: #525252; }
.token.property { color: #c08b30; }
.token.tag { color: #2973b7; }
.token.string { color: var(--accent); }
.token.selector { color: #6679cc; }
.token.attr-name { color: #2973b7; }
.language-css .token.string, .style .token.string, .token.entity, .token.url { color: #22a2c9; }
.token.attr-value, .token.control, .token.directive, .token.unit { color: var(--accent); }
.token.function, .token.keyword { color: #e96900; }
.token.atrule, .token.regex, .token.statement { color: #22a2c9; }
.token.placeholder, .token.variable { color: #3d8fd1; }
.token.deleted { text-decoration: line-through; }
.token.inserted { border-bottom: 1px dotted #202746; text-decoration: none; }
.token.italic { font-style: italic; }
.token.bold, .token.important { font-weight: 700; }
.token.important { color: #c94922; }
.token.entity { cursor: help; }

/* ==========================================================================
   7. 封面页 (Cover Page)
   ========================================================================== */
section.cover {
    align-items: center;
    background-position: 50%;
    background-repeat: no-repeat;
    background-size: cover;
    height: 100vh;
    display: none;
    background: var(--coverBackground);
}
section.cover.show { display: flex; }
section.cover.has-mask .mask { background-color: #fff; opacity: .8; position: absolute; top: 0; height: 100%; width: 100%; }
section.cover .cover-main { flex: 1; margin: -20px 16px 0; text-align: center; z-index: 1; }
section.cover a { color: inherit; text-decoration: none; }
section.cover p { line-height: 1.5rem; margin: 1em 0; }
section.cover h1 { color: inherit; font-size: 2.5rem; font-weight: 300; margin: .625rem 0 2.5rem; position: relative; text-align: center; }
section.cover h1 a { display: block; }
section.cover h1 small { bottom: -.4375rem; font-size: 1rem; position: absolute; }
section.cover blockquote { font-size: 1.5rem; text-align: center; margin: 1em 0; }
section.cover ul { line-height: 1.8; list-style-type: none; margin: 1em auto; max-width: 500px; padding: 0; }

section.cover .cover-main>p:last-child a {
    border-radius: 2rem;
    border: 1px solid var(--accent);
    box-sizing: border-box;
    color: var(--accent);
    display: inline-block;
    font-size: 1.05rem;
    letter-spacing: .1rem;
    margin: .5rem 1rem;
    padding: .75em 2rem;
    text-decoration: none;
}
section.cover .cover-main>p:last-child a:last-child { background-color: var(--accent); color: #fff; }
section.cover .cover-main>p:last-child a:last-child:hover { color: #fff; opacity: .8; }
section.cover .cover-main>p:last-child a:hover { color: var(--accent); background-color: var(--hover-bg); transition: color .15s ease, background-color .15s ease; }
section.cover blockquote>p>a { border-bottom: 2px solid var(--accent); transition: color .3s; }
section.cover blockquote>p>a:hover { color: var(--accent); }

/* ==========================================================================
   8. 响应式与特定状态 (Responsive & States)
   ========================================================================== */
body.close .sidebar {
    inset-inline-start: calc(var(--sidebarWidth) * -1);
}

body.close .sidebar-toggle {
    width: auto;
}

body.close .content {
    inset-inline-start: 0; /* 使用逻辑属性 */
}

@media print {
    .app-nav, .github-corner, .sidebar, .sidebar-toggle {
        display: none;
    }
}

@media screen and (max-width: 768px) {
    .sidebar {
        inset-inline-start: calc(var(--sidebarWidth) * -1); /* 使用逻辑属性 */
        transition: transform .25s ease-out;
    }

    body.close .sidebar {
        transform: translateX(var(--sidebarWidth));
    }
    
    .sidebar-toggle { z-index: 101; }
    
    .content {
        position: static;
        inset-inline-start: 0; /* 使用逻辑属性 */
        max-width: 100vw;
        transition: none;
    }

    body.close .content { transform: none; }
    .app-nav, .github-corner { display: none; }
}

/* ==========================================================================
   9. 主题切换按钮 (Theme Toggle Button)
   ========================================================================== */
#theme-toggle {
    /* position: fixed; */
    position: absolute;
    top: 25px;
    inset-inline-end: 30px; /* 使用逻辑属性 */
    z-index: 102;
    background: transparent;
    border: none;
    padding: 5px;
    cursor: pointer;
    user-select: none;
    border-radius: 50%;
    line-height: 0;
}

#theme-toggle svg {
    width: 25px;
    height: 25px;
    fill: var(--accent);
    transition: opacity 0.3s ease, transform 0.3s ease, fill 0.2s ease;
    display: block;
}

#theme-toggle:hover svg {
    opacity: 0.7;
    transform: scale(1.15) rotate(5deg);
}

/* ==========================================================================
   10. 移动端体验优化 (Mobile Experience Enhancements)
   ========================================================================== */
@media screen and (max-width: 768px) {
  #theme-toggle {
    padding: 10px;
    top: 10px;
    inset-inline-end: 10px; /* 使用逻辑属性 */
  }
  
  #theme-toggle svg {
    width: 30px;
    height: 30px;
  }
}

/* ==========================================================================
   11. 插件回退样式 (Plugin Fallback Styles)
   ========================================================================== */
.math-fallback {
  background-color: var(--codeBackgroundColor);
  color: var(--highlightColor);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: var(--codeFontFamily);
  font-weight: 600;
  border: 1px solid var(--borderColor);
}