:root {
    --primary-color: #3b82f6;
    --bg-color: #ffffff;
    --text-color: #1f2937;
    --sidebar-bg: #f9fafb;
    --border-color: #e5e7eb;
    --sidebar-width: 280px;
    --toc-width: 240px;
    --content-max-width: 720px;
    --base-font-size: 16px;
    --heading-font-family: system-ui, sans-serif;
    --app-max-width: 1380px;
    --code-bg: #f3f4f6;
    --code-lang-bg: #e5e7eb;
}

.dark {
    --primary-color: #60a5fa;
    --bg-color: #111827;
    --text-color: #f3f4f6;
    --sidebar-bg: #111827;
    --border-color: #374151;
    --code-bg: #000000;
    --code-lang-bg: #374151;
}

body {
    background: linear-gradient(135deg, #f0f2f5 0%, #e2e8f0 100%);
    color: var(--text-color);
    font-size: var(--base-font-size);
    transition: background-color 0.3s, color 0.3s;
    overflow: hidden;
    display: flex;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    position: relative;
}

.dark body {
    background: linear-gradient(135deg, #0f172a 0%, #000000 100%);
}

#background-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
}

#app-container {
    width: 100%;
    height: 100%;
    max-width: var(--app-max-width);
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

#sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    transition: width 0.3s ease;
}

#toc-sidebar {
    width: var(--toc-width);
    background-color: var(--bg-color);
    border-left: none;
}

.markdown-body {
    max-width: var(--content-max-width);
    margin: 0 auto;
    line-height: 1.75;
    font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    font-family: var(--heading-font-family);
    margin-top: 1.5em;
    margin-bottom: 0.6em;
    font-weight: 700;
    color: var(--text-color);
    scroll-margin-top: 80px;
}

.markdown-body h1 {
    font-size: 2.2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

.markdown-body h2 {
    font-size: 1.7em;
}

.markdown-body h3 {
    font-size: 1.4em;
}

.markdown-body p {
    margin-bottom: 1.2em;
}

.markdown-body ul {
    list-style-type: disc;
    padding-left: 1.5em;
    margin-bottom: 1.2em;
}

.markdown-body ol {
    list-style-type: decimal;
    padding-left: 1.5em;
    margin-bottom: 1.2em;
}

.markdown-body pre {
    background-color: var(--code-bg) !important;
    padding: 1.2rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: 1.5em;
    line-height: 1.6;

    position: relative;
}

.markdown-body pre code.hljs {
    background: transparent !important;
    padding: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
}

.markdown-body p code,
.markdown-body li code,
.markdown-body h1 code,
.markdown-body h2 code,
.markdown-body h3 code {
    background: rgba(125, 125, 125, 0.15);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.85em;
    color: var(--primary-color);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.markdown-body pre[data-lang]::after {
    content: attr(data-lang);
    position: absolute;
    top: 0;
    right: 0;
    background-color: var(--code-lang-bg);
    color: var(--text-color);
    font-size: 0.75rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    padding: 0.2rem 0.6rem;
    border-bottom-left-radius: 0.5rem;
    border-top-right-radius: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    font-weight: 600;
}

.markdown-body pre:hover[data-lang]::after {
    opacity: 1;
}

.markdown-body a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.markdown-body a:hover {
    opacity: 0.8;
    border-bottom-color: var(--primary-color);
}

.markdown-body blockquote {
    border-left: 4px solid var(--primary-color);
    background: rgba(125, 125, 125, 0.05);
    padding: 1em;
    margin-bottom: 1.5em;
    color: #6b7280;
    border-radius: 0 0.5rem 0.5rem 0;
}

.dark .markdown-body blockquote {
    color: #9ca3af;
}

.markdown-body img {
    max-width: 100%;
    border-radius: 0.5rem;
    margin: 1.5rem 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.markdown-body hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

.markdown-body details {
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin-bottom: 1.5em;
    background-color: var(--bg-color);
    overflow: hidden;
    transition: all 0.2s;
}

.markdown-body summary {
    cursor: pointer;
    padding: 0.75rem 1rem;
    background-color: rgba(0, 0, 0, 0.03);
    font-weight: 600;
    color: var(--text-color);
    outline: none;
    transition: background-color 0.2s;
    user-select: none;
}

.dark .markdown-body summary {
    background-color: rgba(255, 255, 255, 0.05);
}

.markdown-body summary:hover {
    background-color: rgba(0, 0, 0, 0.06);
}

.dark .markdown-body summary:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.markdown-body details[open] summary {
    border-bottom: 1px solid var(--border-color);
}

.markdown-body details > *:not(summary) {
    margin: 1rem;
}

.markdown-body details pre {
    margin: 0;
    border-radius: 0;
    border: none;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.dark ::-webkit-scrollbar-thumb {
    background: #4b5563;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.folder-content {
    display: none;
    padding-left: 0.5rem;
}

.folder-content.open {
    display: block;
}

.tree-item {
    cursor: pointer;
    padding: 0.5rem;
    margin: 0.05rem 0;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #4b5563;
    transition: all 0.15s;
    font-size: 0.9rem;
}

.dark .tree-item {
    color: #d1d5db;
}

.tree-item:hover {
    background-color: #f3f4f6;
    color: var(--primary-color);
}

.dark .tree-item:hover {
    background-color: #374151;
}

.folder-header {
    font-weight: 600;
    opacity: 0.9;
    justify-content: space-between;
}

.tree-item.active {
    background-color: #eff6ff;
    color: #2563eb;
    font-weight: 600;
}

.dark .tree-item.active {
    background-color: #1e3a8a;
    color: #60a5fa;
}

.folder-arrow {
    transition: transform 0.2s;
    font-size: 0.7em;
    opacity: 0.5;
}

.folder-arrow.rotated {
    transform: rotate(90deg);
}

.toc-link {
    display: block;
    padding: 0.3rem 0.6rem;
    color: var(--text-color);
    opacity: 0.7;
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-link:hover {
    background-color: rgba(0, 0, 0, 0.05);
    opacity: 1;
    color: var(--primary-color);
}

.dark .toc-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.toc-h1 {
    font-weight: bold;
    margin-top: 0.5rem;
}

.toc-h2 {
    padding-left: 1rem;
}

.toc-h3 {
    padding-left: 2rem;
    font-size: 0.85rem;
}

@media (max-width: 1024px) {
    #toc-sidebar {
        display: none;
    }
}

#user-custom-style-container {
    display: block;
}

.tab-btn {
    position: relative;
    padding-bottom: 2px;
    color: #6b7280;
    transition: all 0.2s;
    border-bottom: 1px solid transparent;
    margin-bottom: -1px;
    z-index: 1;
}

.dark .tab-btn {
    color: #9ca3af;
}

.tab-btn:hover {
    color: #4b5563;
}

.dark .tab-btn:hover {
    color: #d1d5db;
}

.tab-btn.active-tab {
    background-color: var(--bg-color);
    color: var(--primary-color);
    border-color: var(--border-color);
    border-bottom-color: var(--bg-color);
    border-top: 2px solid var(--primary-color);
    font-weight: 600;
    z-index: 10;
}

.dark .tab-btn.active-tab {
    background-color: var(--bg-color);
    border-color: var(--border-color);
    border-bottom-color: transparent;
    border-top: 2px solid var(--primary-color);
}

.tab-btn::after {
    display: none;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s;
}

.role-ttr { color: #ffc000; }
.role-ch { color: #ff027f; }
.role-sl { color: #00b0f0; }
.role-gk { color: #30c0b4; }
.role-wv { color: #767171; }
.role-ls { color: #ef939e; }
.role-fe { color: #0b0dbd; }
.dialogue-line { text-align: center; }

@media (max-width: 768px) {
    #sidebar {
        position: absolute;
        height: 100%;
    }
}

#secondary-nav {
    max-height: 3rem;
    opacity: 1;
    transform: translateY(0);
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s ease-out,
    transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    border-width 0.1s linear 0.3s;
}

.nav-hidden {
    max-height: 0 !important;
    opacity: 0;
    transform: translateY(-10px);
    border-bottom-width: 0 !important;
    pointer-events: none;
}

#back-to-top {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -200%);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 40;
    backdrop-filter: blur(10px);
    background-color: rgba(255, 255, 255, 0.8);
    color: var(--primary-color);
}

.dark #back-to-top {
    background-color: rgba(31, 41, 55, 0.8);
    color: var(--primary-color);
}

#back-to-top.show-btn {
    transform: translate(-50%, 5rem);
    opacity: 1;
    pointer-events: auto;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

@media (min-width: 1024px) {
    #back-to-top {
        left: calc(50% - (var(--toc-width) / 2));
    }
}

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

/* style.css */

/* 搜索下拉列表中的高亮 */
.search-highlight {
    color: var(--primary-color);
    font-weight: 800;
    background: rgba(59, 130, 246, 0.1);
    padding: 0 2px;
    border-radius: 2px;
}

/* 打开文件后的定位高亮 (Mark 标签) */
mark.active-highlight {
    background-color: rgba(255, 235, 59, 0.5); /* 黄色背景 */
    color: inherit;
    padding: 2px 0;
    border-radius: 2px;
    border-bottom: 2px solid #f59e0b;
    animation: highlight-pulse 2s infinite;
}

.dark mark.active-highlight {
    background-color: rgba(251, 191, 36, 0.3); /* 深色模式下的黄色 */
    color: white;
    border-bottom-color: #fbbf24;
}

@keyframes highlight-pulse {
    0% { background-color: rgba(255, 235, 59, 0.5); }
    50% { background-color: rgba(255, 235, 59, 0.1); }
    100% { background-color: rgba(255, 235, 59, 0.5); }
}

/* style.css */

/* 受保护的搜索结果容器 */
.search-item-protected {
    position: relative;
    overflow: hidden;
}

/* 模糊层：模糊文字并禁止选中 */
.search-item-protected .protected-content {
    filter: blur(4px);
    opacity: 0.5;
    user-select: none;
    pointer-events: none;
}

/* 遮罩层：显示锁图标 */
.search-item-protected .protected-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    color: var(--text-color);
}

.search-item-protected .protected-overlay i {
    font-size: 1.2rem;
    margin-bottom: 0.2rem;
    color: var(--primary-color);
}

.search-item-protected .protected-overlay span {
    font-size: 0.75rem;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.8);
    padding: 2px 8px;
    border-radius: 99px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.dark .search-item-protected .protected-overlay span {
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
}

/* 搜索结果内部 Markdown 样式重置 */
.search-result-content {
    font-size: 0.85rem; /* text-xs */
    color: #6b7280; /* text-gray-500 */
    line-height: 1.5;
}
.dark .search-result-content {
    color: #9ca3af; /* dark:text-gray-400 */
}

/* 去除段落间距，使其紧凑 */
.search-result-content p {
    margin: 0;
    display: inline; /* 让多段落显示为连贯文本 */
}

/* 重置标题样式，使其像普通文本一样显示，但保留加粗 */
.search-result-content h1,
.search-result-content h2,
.search-result-content h3,
.search-result-content h4 {
    font-size: 1em;
    font-weight: bold;
    margin: 0;
    display: inline;
}

/* 隐藏搜索结果中的图片，防止撑破布局 */
.search-result-content img {
    display: none;
}

/* 优化代码块显示 */
.search-result-content code {
    background: rgba(125, 125, 125, 0.1);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    font-family: monospace;
    color: var(--primary-color);
}

.search-result-content pre {
    display: none; /* 或者是 inline-block，通常长代码块在搜索里隐藏体验更好 */
}

/* === 单行公式 (inline) === */
.math-inline {
    display: inline-block;
    vertical-align: middle; /* 修正单行公式和文字的对齐 */
    padding: 0 4px;
}

/* === 多行公式 (block) === */
.math-block {
    display: block;
    width: 100%;
    text-align: center;      /* 让容器内的内容居中 */
    margin: 1.5rem 0;        /* 上下留出更多呼吸空间 */
    overflow-x: auto;        /* 移动端防溢出 */
    overflow-y: hidden;
}

/* 修正 math-block 内部 KaTeX 元素的行为 */
.math-block > .katex-display {
    display: inline-block !important; /* 必须是 inline-block 才能被父级 text-align: center 居中 */
    text-align: center;
    margin: 0 !important;    /* 去除 KaTeX 默认的大边距，由 .math-block 控制 */
}

.markdown-body table {
    /* 必须：改为独立边框模式 */
    border-collapse: separate;
    border-spacing: 0;

    border: 1px solid rgba(125,125,125,0.75);
    border-radius: 8px; /* 整体圆角 */
    overflow: hidden;   /* 确保子元素不超出圆角范围 */
}

.markdown-body table th,
.markdown-body table td {
    /* 注意：此时由于边框不再合并，为了避免边框变粗，
       我们通常只给右边和下边加框线 */
    border-bottom: 1px solid rgba(125,125,125,0.75);
    border-right: 1px solid rgba(125,125,125,0.75);
    padding: 6px 13px;
}

/* 去掉最后一行和最后一列的多余边框 */
.markdown-body table tr:last-child td {
    border-bottom: none;
}

.markdown-body table th:last-child,
.markdown-body table td:last-child {
    border-right: none;
}

.markdown-body img {
    display: block !important;
    margin-left: auto !important;
    margin-right: auto !important;
    max-width: 100%; /* 防止大图撑破容器 */
}