/* =========================================
   全局重置与基础样式
   ========================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 120px; /* 为固定顶部导航栏留出空间 */
}

body {
    font-family: "Noto Sans SC";
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: #333;
    transition: color 0.2s;
}

a:hover {
    color: #555;
}

ul, ol {
    list-style: none;
}

/* =========================================
   顶部导航栏 (Top Navigation)
   ========================================= */
.top-nav {
    background: #f8f9fa;
    border-bottom: 1px solid #e3f2fd;
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
}

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

.logo a {
    font-size: 1.5rem;
    font-weight: 700;
    color: #333;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.logo-img {
    height: 32px;
    width: auto;
}

.logo-text {
    font-family: 'Audiowide';
    color: #64b5f6;
    font-size: 1.5rem;
    font-weight: 400;
}

/* 搜索框触发按钮 */
.search-box {
    flex: 1;
    max-width: 400px;
    margin: 0 2rem;
}

.search-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border: 2px solid #bbdefb;
    border-radius: 15px;
    background-color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.search-trigger:hover {
    background-color: #fff;
    border-color: #64b5f6;
}

.search-trigger-text {
    font-size: 0.9rem;
    color: #666;
}

.search-trigger-kbd {
    font-size: 0.75rem;
    color: #666;
    border: 1px solid #bbdefb;
    padding: 2px 6px;
    border-radius: 4px;
    background: #fff;
    font-family: inherit;
}

/* 搜索悬浮窗遮罩 */
.search-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    justify-content: center;
    padding-top: 15vh;
}

.search-modal-overlay.active {
    display: flex;
}

/* 搜索悬浮窗 */
.search-modal {
    width: 560px;
    max-width: 90vw;
    max-height: 70vh;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e3f2fd;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: search-modal-in 0.15s ease-out;
}

@keyframes search-modal-in {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(-8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.search-modal-input-wrap {
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid #e3f2fd;
}

.search-modal-icon {
    flex-shrink: 0;
    color: #666;
    margin-right: 0.75rem;
}

.search-modal-input-wrap input {
    flex: 1;
    border: none;
    outline: none;
    padding: 1rem 0;
    font-size: 1rem;
    background: transparent;
    color: #333;
}

.search-modal-input-wrap input::placeholder {
    color: #666;
}

/* 搜索结果列表 */
.search-results {
    overflow-y: auto;
    max-height: calc(70vh - 56px);
}

.search-result-item {
    display: block;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e3f2fd;
    transition: background-color 0.2s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover,
.search-result-item.active {
    background-color: #e3f2fd;
}

.search-result-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
}

.search-result-preview {
    font-size: 0.85rem;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-no-results {
    padding: 2rem 1rem;
    text-align: center;
    color: #666;
}

/* =========================================
   二级导航栏 (Secondary Navigation)
   ========================================= */
.secondary-nav {
    background: #f8f9fa;
    height: 50px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 60px; /* 顶部导航高度 */
    z-index: 999;
}

.secondary-nav .nav-container {
    padding: 0 2rem;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none; /* Firefox */
    justify-content: flex-start;
}

.secondary-nav .nav-container::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.nav-item {
    display: inline-block;
    position: relative;
    margin-right: 0.5rem;
}

.nav-link {
    display: block;
    padding: 0.75rem 0;
    color: #555;
    font-weight: bold;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.nav-item:hover .nav-link {
    color: #333;
    border-bottom-color: #64b5f6;
}

.nav-item.active .nav-link {
    color: #333;
    border-bottom-color: #64b5f6;
}

/* 下拉菜单 */
.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: -10px;
    background: #f8f9fa;
    border: 1px solid #e3f2fd;
    border-radius: 0px;
    min-width: 220px;
    z-index: 1001;
    padding: 5px;
}

.nav-item:hover .dropdown-content {
    display: block;
}

.dropdown-content a {
    display: block;
    padding: 8px 15px;
    color: #333;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 0px;
}

.dropdown-content a:hover {
    background-color: #e3f2fd;
    color: #333;
}

/* 分标题样式 */
.dropdown-submenu {
    padding: 0.25rem 0;
}

.submenu-title {
    display: block;
    padding: 0.5rem 1rem;
    font-weight: bold;
    color: #333;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: default;
}

.submenu-items {
    padding-left: 0.5rem;
}

.submenu-items a {
    display: block;
    padding: 8px 15px;
    color: #333;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 0px;
}

.submenu-items a:hover {
    background-color: #e3f2fd;
    color: #333;
}

/* =========================================
   主布局容器 (Main Layout)
   ========================================= */
.main-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    justify-content: center;
}

/* =========================================
   左侧侧边栏 (Sidebar)
   ========================================= */
.sidebar {
    position: fixed;
    top: 120px; /* 顶部导航60px + 二级导航50px + 10px间距 */
    left: calc((100vw - 1440px) / 2 + 2rem); /* 根据主容器计算左侧位置 */
    width: 260px; /* 280px - padding */
    height: calc(100vh - 140px);
    overflow-y: auto;
    padding-right: 1rem;
}

.sidebar-nav {
    padding-bottom: 2rem;
}

.nav-section {
    margin-bottom: 2rem;
}

.nav-section-title {
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    color: #666;
    margin-bottom: 0.75rem;
    letter-spacing: 0.5px;
}

.sidebar-subsection {
    margin-bottom: 1rem;
}

.sidebar-subsection-title {
    font-size: 1rem;
    font-weight: bold;
    color: #333;
    padding: 0.5rem 0.75rem;
    padding-left: 0.5rem;
    margin-top: 0.5rem;
}

.nav-list li {
    margin-bottom: 0.25rem;
    padding-left: 0.5rem;
}

.nav-list a {
    display: block;
    padding: 8px 15px;
    color: #555;
    font-size: 0.85rem;
    font-weight: bold;
    border-radius: 0px;
    transition: all 0.2s;
}

.nav-list a:hover {
    background-color: #e3f2fd;
    color: #1565c0;
}

.nav-list a.active {
    background-color: #64b5f6;
    color: white;
    font-weight: bold;
}

/* =========================================
   主要内容区 (Content Area)
   ========================================= */
.content {
    min-height: calc(100vh - 200px);
    max-width: 800px; /* 限制阅读宽度 */
    width: 100%;
    margin: 0 280px; /* 为左右固定侧边栏留出空间 */
}

/* =========================================
   Markdown 内容样式 (Markdown Body)
   ========================================= */
.markdown-body {
    font-size: 16px;
    line-height: 1.8;
    color: #333;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-weight: bold;
    line-height: 1.25;
    color: #333;
}

.markdown-body h1 {
    font-size: 2.5rem;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #e3f2fd;
    margin-top: 0;
}

.markdown-body h2 {
    font-size: 2rem;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #e3f2fd;
}

.markdown-body h3 {
    font-size: 1.5rem;
}

.markdown-body h4 {
    font-size: 1.25rem;
}

.markdown-body p {
    margin-bottom: 1.25rem;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 2rem;
    margin-bottom: 1.25rem;
    list-style: disc;
}

.markdown-body ol {
    list-style: decimal;
}

.markdown-body li {
    margin-bottom: 0.5rem;
}

.markdown-body blockquote {
    padding: 0 1rem;
    color: #666;
    border-left: 0.25rem solid #64b5f6;
    margin-bottom: 1.25rem;
    background-color: #f8f9fa;
}

.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: #e3f2fd;
    border-radius: 0px;
    font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
    color: #333;
}

.markdown-body pre {
    padding: 1rem;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: #f8f9fa;
    border-radius: 0px;
    border: 1px solid #bbdefb;
    margin-bottom: 1.25rem;
}

.markdown-body pre code {
    padding: 0;
    margin: 0;
    background-color: transparent;
    border: 0;
    font-size: 100%;
    word-break: normal;
    white-space: pre;
}

.markdown-body img {
    max-width: 100%;
    box-sizing: content-box;
    background-color: #fff;
    border-radius: 0px;
    border: 1px solid #bbdefb;
    margin: 1.5rem 0;
}

.markdown-body table {
    display: table;
    width: 100%;
    table-layout: fixed; /* 列宽平分 */
    overflow: auto;
    margin-bottom: 1.25rem;
    border-spacing: 0;
    border-collapse: collapse;
    border: 1px solid #bbdefb;
    border-radius: 0px;
}

.markdown-body table th,
.markdown-body table td {
    padding: 0.75rem 1rem;
    border: 1px solid #bbdefb;
    text-align: center; /* 文本居中 */
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.markdown-body table th {
    font-weight: bold;
    background-color: #e3f2fd;
}

.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 2rem 0;
    background-color: #e3f2fd;
    border: 0;
}

.markdown-body a {
    color: #1565c0;
    text-decoration: none;
}

.markdown-body a:hover {
    color: #64b5f6;
    text-decoration: underline;
}

/* 搜索结果中高亮样式 */
.search-highlight {
    font-weight: bold;
    color: #333;
}

.markdown-body mark {
    font-weight: bold;
    background: #bbdefb;
    color: #333;
}

/* =========================================
   右侧目录 (Table of Contents)
   ========================================= */
.toc-sidebar {
    position: fixed;
    top: 120px; /* 顶部导航60px + 二级导航50px + 10px间距 */
    right: calc((100vw - 1440px) / 2 + 2rem); /* 根据主容器计算右侧位置 */
    width: 220px; /* 240px - padding */
    height: calc(100vh - 140px);
    overflow-y: auto;
    padding-left: 1rem;
    padding-right: 0.5rem; /* 调整右边距 */
}

.toc-title {
    font-size: 0.85rem;
    font-weight: bold;
    text-transform: uppercase;
    color: #333;
    margin-bottom: 1rem;
}

.toc-list ul {
    border-left: 2px solid #e3f2fd;
    padding-left: 1rem;
}

.toc-list li {
    margin-bottom: 0.75rem;
}

.toc-list a {
    display: block;
    font-size: 0.85rem;
    color: #666;
    line-height: 1.4;
}

.toc-list a:hover {
    color: #333;
}

.toc-list a.active {
    color: #333;
    font-weight: bold;
    border-left: 2px solid #64b5f6;
    margin-left: -1.1rem; /* 对齐边框 */
    padding-left: 1.1rem;
}

/* 不同级别标题的缩进 */
.toc-level-1 {
    margin-left: 0;
    font-weight: bold;
}

.toc-level-2 {
    margin-left: 1.5rem;
}

.toc-level-3 {
    margin-left: 3rem;
    margin-top: 0.5rem;
}

.toc-level-4 {
    margin-left: 4.5rem;
}

.toc-level-5 {
    margin-left: 6rem;
}

.toc-level-6 {
    margin-left: 7.5rem;
}

/* =========================================
   按钮样式 (Buttons)
   ========================================= */
.btn-primary {
    background-color: #64b5f6;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    color: white;
    font-weight: bold;
    font-family: "Noto Sans SC";
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: #42a5f5;
}

.btn-primary:active {
    background-color: #1e88e5;
}

.btn-secondary {
    background-color: #66bb6a;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    color: white;
    font-weight: bold;
    font-family: "Noto Sans SC";
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background-color: #4caf50;
}

.btn-secondary:active {
    background-color: #388e3c;
}

/* =========================================
   404 错误页
   ========================================= */
.error-page {
    text-align: center;
    padding: 5rem 2rem;
    max-width: 600px;
    margin: 0 auto;
}

.error-page h1 {
    font-size: 8rem;
    font-weight: 800;
    color: #bbdefb;
    line-height: 1;
    margin-bottom: 1rem;
    border: none;
}

.error-page h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.error-page p {
    color: #666;
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.back-home {
    display: inline-block;
    padding: 8px 12px;
    background-color: #64b5f6;
    color: #fff;
    border-radius: 8px;
    font-weight: bold;
    transition: background-color 0.2s;
}

.back-home:hover {
    background-color: #42a5f5;
    color: #fff;
    text-decoration: none;
}

/* =========================================
   响应式设计 (Responsive)
   ========================================= */

/* 平板尺寸 (< 1200px) */
@media (max-width: 1200px) {
    .main-container {
        padding: 2rem;
    }

    .toc-sidebar {
        display: none;
    }
    
    .sidebar {
        left: 2rem;
        width: 220px;
    }
    
    .content {
        max-width: 100%;
        margin: 0 0 0 260px; /* 只给左侧边栏留空间 */
    }
}

/* =========================================
   移动端菜单下拉框
   ========================================= */
.mobile-menu-dropdown {
    display: none;
    position: relative;
}

.mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    color: #333;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.mobile-menu-btn:hover {
    background-color: #e3f2fd;
}

.mobile-menu-content {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border: 1px solid #e3f2fd;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    min-width: 160px;
    z-index: 2000;
    overflow: hidden;
}

.mobile-menu-content.active {
    display: block;
    animation: dropdownIn 0.2s ease;
}

@keyframes dropdownIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mobile-menu-content a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: #333;
    font-size: 0.9rem;
    font-weight: bold;
    transition: background-color 0.2s;
}

.mobile-menu-content a:hover {
    background-color: #e3f2fd;
}

.mobile-menu-content svg {
    color: #64b5f6;
}

/* 移动端侧边栏遮罩 */
.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

.mobile-sidebar-overlay.active {
    display: block;
}

/* 手机尺寸 (< 768px) */
@media (max-width: 768px) {
    .nav-container {
        padding: 0 1rem;
    }

    .search-box {
        display: none; /* 移动端隐藏搜索框 */
    }

    .mobile-menu-dropdown {
        display: block; /* 显示移动端菜单下拉框 */
    }

    .secondary-nav .nav-container {
        padding: 0 1rem;
    }

    .main-container {
        padding: 1rem;
    }

    /* 移动端侧边栏样式 */
    .sidebar {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        background: white;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        padding: 1rem;
        padding-top: 80px;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-content {
        height: 100%;
        overflow-y: auto;
    }
    
    .content {
        margin: 0; /* 移动端不需要留空间 */
    }

    /* 移动端搜索框宽度调整 */
    .search-modal {
        width: calc(100vw - 32px);
        max-width: calc(100vw - 32px);
        margin: 0 16px;
    }

    .search-modal-overlay {
        padding-top: 10vh;
    }

    /* 移动端搜索输入框占满宽度 */
    .search-modal-input-wrap {
        width: 100%;
    }

    .search-modal-input-wrap input {
        width: 100%;
        min-width: 0;
    }

    .markdown-body h1 {
        font-size: 2rem;
    }

    .markdown-body h2 {
        font-size: 1.5rem;
    }
}