/* ============================================================
   资治通鉴结构化知识工程 — 主样式表
   参照：史记知识图谱 (baojie.github.io/shiji-kb)
   基于 shiji-styles.css v5.7 对齐
   ============================================================ */

/* --- 基础重置 --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* --- CSS 变量 --- */
:root {
    --bg-primary: #fdfdf8;
    --bg-secondary: #f8f6f0;
    --text-primary: #2c2c2c;
    --text-secondary: #666;
    --accent-red: #8B0000;
    --accent-brown: #8B4513;
    --accent-gold: #d4af37;
    --color-person: #8B4513;
    --color-place: #B8860B;
    --color-official: #8B0000;
    --color-time: #008B8B;
    --color-dynasty: #9370DB;
    --color-institution: #4682B4;
    --color-tribe: #2F4F4F;
    --color-artifact: #CD853F;
    --color-astro: #483D8B;
    --color-myth: #8B008B;
    --color-purple-num: #C8A8FF;
    --max-width: 900px;
    --font-serif: "Noto Serif SC", "Source Han Serif SC", serif;
    --font-sans: "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* --- 全局排版 --- */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition-duration: 0.01ms !important; }
}

body {
    font-family: var(--font-serif);
    line-height: 2.0;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 20px;
}

p {
    margin: 1.5em 0;
}

/* ============================================================
   首页样式
   ============================================================ */

.site-header {
    text-align: center;
    padding: 40px 0 20px;
    border-bottom: 2px solid var(--accent-gold);
    margin-bottom: 30px;
}

.site-header h1 {
    font-size: 2rem;
    color: var(--accent-red);
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}

.site-header .subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* --- 搜索框 --- */
.search-box {
    position: relative;
    margin-bottom: 30px;
}

#search-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    font-family: var(--font-sans);
    border: 1px solid #ddd;
    border-radius: 8px;
    background: var(--bg-secondary);
    outline: none;
    transition: border-color 0.2s;
}

#search-input:focus {
    border-color: var(--accent-brown);
}

.search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 0 0 8px 8px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.search-results.active {
    display: block;
}

/* --- 导航栏 --- */
.main-nav {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.nav-link {
    color: var(--accent-brown);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--accent-red);
    text-decoration: underline;
}

.nav-separator {
    color: #ddd;
}

/* 搜索结果摘要行 */
.ss-summary {
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid #eee;
    font-family: var(--font-sans);
}

/* 搜索结果项 */
.search-result-item,
.ss-hit {
    display: block;
    padding: 10px 16px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.1s;
}

.search-result-item:hover,
.ss-hit:hover {
    background: var(--bg-secondary);
}

.sr-chapter,
.ss-ch {
    display: block;
    font-size: 0.8rem;
    color: var(--accent-brown);
    margin-bottom: 2px;
    font-family: var(--font-sans);
}

.sr-snippet,
.ss-snip {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.6;
}

.sr-snippet mark,
.ss-snip mark {
    background: #fff3b0;
    color: #8B0000;
    padding: 1px 2px;
    border-radius: 2px;
}

/* 无结果提示 */
.ss-hint {
    padding: 10px 16px;
    color: #999;
    font-size: 0.9rem;
    text-align: center;
}

/* 查看更多 */
.ss-more {
    display: block;
    padding: 10px 16px;
    text-align: center;
    color: var(--accent-brown);
    font-size: 0.9rem;
    text-decoration: none;
    border-bottom: none;
}

.ss-more:hover {
    background: var(--bg-secondary);
}

/* --- 辑/卷分组 --- */
.volume-section {
    margin-bottom: 40px;
}

.volume-heading {
    font-size: 1.3rem;
    color: var(--accent-red);
    border-left: 4px solid var(--accent-gold);
    padding-left: 12px;
    margin-bottom: 4px;
}

.volume-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-left: 16px;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chapter-card {
    display: block;
    padding: 10px 16px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.15s;
}

.chapter-card:hover {
    background: var(--bg-secondary);
}

/* --- 页脚 --- */
.site-footer {
    text-align: center;
    padding: 30px 0;
    border-top: 1px solid #eee;
    margin-top: 40px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.site-footer a {
    color: var(--accent-brown);
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

/* ============================================================
   章节页样式
   ============================================================ */

.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.chapter-nav a {
    color: var(--accent-brown);
    text-decoration: none;
    font-size: 0.9rem;
}

.chapter-nav a:hover {
    text-decoration: underline;
}

.chapter-nav .nav-home {
    color: var(--text-secondary);
}

.chapter-header {
    margin-bottom: 30px;
}

.chapter-meta {
    margin-bottom: 8px;
}

.volume-badge {
    display: inline-block;
    background: var(--accent-red);
    color: white;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-sans);
}

.volume-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 8px;
}

.chapter-header h1 {
    font-size: 1.6rem;
    color: var(--accent-red);
    line-height: 1.6;
}

/* --- 文章内容 --- */
article {
    line-height: 2.0;
    font-size: 16px;
}

article p {
    margin: 1.5em 0;
    text-align: justify;
}

/* --- Purple Numbers --- */
.para-num {
    color: var(--color-purple-num);
    font-family: Helvetica, Arial, sans-serif;
    font-size: 0.75em;
    font-weight: bold;
    margin-right: 0.5em;
    text-decoration: none;
    vertical-align: baseline;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: color 0.2s ease;
    scroll-margin-top: 80px;
}

.para-num:hover {
    color: #9370DB;
    text-decoration: underline;
}

.para-num:focus {
    outline: 2px solid #9370DB;
    outline-offset: 2px;
}

/* --- 标题 --- */
article h1 {
    font-size: 1.6em;
    color: var(--accent-red);
    border-bottom: 3px solid var(--accent-red);
    padding-bottom: 10px;
    margin: 30px 0 15px;
}

article h2 {
    font-size: 1.4em;
    color: var(--accent-brown);
    border-left: 5px solid var(--accent-brown);
    padding-left: 15px;
    margin: 40px 0 15px;
}

article h3 {
    font-size: 1.2em;
    color: #B8860B;
    margin-top: 30px;
    margin-bottom: 10px;
}

article h4 {
    font-size: 1em;
    color: var(--text-primary);
    margin: 20px 0 8px;
    font-style: italic;
}

/* --- 水平线 --- */
hr {
    border: none;
    border-top: 2px solid #ddd;
    margin: 40px 0;
}

/* --- 列表 --- */
ul, ol {
    line-height: 2;
    list-style: none;
    padding-left: 2em;
    margin: 1em 0;
}

ul li, ol li {
    margin: 0;
}

/* --- 引用块 --- */
blockquote {
    border: none;
    margin: 0.5em 0;
    padding: 0;
    padding-left: 2em;
    background: none;
}

p:has(+ blockquote) {
    margin-bottom: 0.5em;
}

/* ============================================================
    实体高亮样式（12种）— 参照 shiji-styles.css v5.7
    ============================================================ */

.person, .place, .official, .time, .dynasty,
.institution, .tribe, .artifact, .astro, .myth {
    cursor: default;
    font-weight: 500;
}

/* 人名：棕色 + 单下划线（半透明） */
.person {
    color: var(--color-person);
    text-decoration: underline;
    text-decoration-color: #8B451380;
    text-underline-offset: 3px;
}

/* 地名：金色 + 双下划线（半透明） */
.place {
    color: var(--color-place);
    text-decoration: underline double;
    text-decoration-color: #B8860B80;
    text-underline-offset: 3px;
}

/* 官职：深红 */
.official {
    color: var(--color-official);
}

/* 时间：青色 + 斜体 */
.time {
    color: var(--color-time);
    font-style: italic;
}

/* 朝代：紫色 + 粗实线下划线 */
.dynasty {
    color: var(--color-dynasty);
    text-decoration: underline solid #9370DB80;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

/* 制度：钢蓝 */
.institution {
    color: var(--color-institution);
}

/* 族群：深灰 */
.tribe {
    color: var(--color-tribe);
}

/* 器物：秘鲁棕 */
.artifact {
    color: var(--color-artifact);
}

/* 天文：深蓝紫 + 斜体 */
.astro {
    color: var(--color-astro);
    font-style: italic;
}

/* 神话：深洋红 + 双下划线 */
.myth {
    color: var(--color-myth);
    text-decoration: underline double #8B008B80;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

/* --- 语法高亮关闭 --- */
body.syntax-off .person, body.syntax-off .place, body.syntax-off .official,
body.syntax-off .time, body.syntax-off .dynasty, body.syntax-off .institution,
body.syntax-off .tribe, body.syntax-off .artifact, body.syntax-off .astro,
body.syntax-off .myth {
    color: inherit !important;
    background-color: transparent !important;
    text-decoration: none !important;
    font-weight: inherit !important;
    font-style: inherit !important;
}

/* ============================================================
   对话与评论
   ============================================================ */

/* 对话「」— 参照 shiji .quoted 样式 */
.dialogue {
    background-color: rgba(139, 69, 19, 0.05);
    border-bottom: 1px dashed rgba(139, 69, 19, 0.4);
    padding: 0 3px;
}

/* 长对话块级缩进 */
.dialogue-block {
    display: block;
    padding-left: 2em;
}

/* --- 评论框 --- */
.commentary {
    margin: 20px 0;
    padding: 16px 20px;
    border-left: 4px solid;
    border-radius: 0 6px 6px 0;
    font-size: 0.95rem;
}

.commentary.baiyang {
    border-color: var(--accent-brown);
    background-color: rgba(139, 69, 19, 0.04);
}

.commentary.sima-guang {
    border-color: var(--accent-red);
    background-color: rgba(139, 0, 0, 0.03);
}

.commentary-label {
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--accent-brown);
}

/* ============================================================
   表格（年表）
   ============================================================ */

.table-wrapper {
    overflow-x: auto;
    margin: 2em 0;
}

.zztj-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

.zztj-table th, .zztj-table td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    text-align: left;
    white-space: nowrap;
}

.zztj-table th {
    background: var(--bg-secondary);
    font-weight: bold;
}

.zztj-table tr:hover td {
    background: rgba(139, 69, 19, 0.02);
}

/* ============================================================
   设置面板
   ============================================================ */

.settings-toggle {
    position: fixed;
    top: 60px;
    right: 20px;
    width: 36px;
    height: 36px;
    background: var(--bg-secondary);
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    z-index: 1000;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    padding: 0;
}

.settings-toggle:hover {
    opacity: 1;
    background: white;
    border-color: var(--accent-brown);
    transform: scale(1.1);
}

.settings-panel {
    display: none;
    position: fixed;
    top: 104px;
    right: 20px;
    width: 280px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 20px;
    z-index: 999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

.settings-panel.open {
    display: block;
    animation: slideIn 0.2s ease-out;
}

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

.settings-panel label {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
}

.settings-panel input[type="range"] {
    width: 100%;
    margin-top: 4px;
}

/* 搜索高亮标记 */
.search-highlight {
    background: #ffeb3b;
    padding: 1px 2px;
    border-radius: 2px;
    animation: highlightFade 3s ease-out;
}

@keyframes highlightFade {
    0% { background: #ffeb3b; }
    100% { background: transparent; }
}

/* ============================================================
   实体索引侧边栏
   ============================================================ */

.entity-sidebar {
    margin-top: 40px;
    padding: 20px;
    background: var(--bg-secondary);
    border: 1px solid #e8e4d8;
    border-radius: 8px;
}

.entity-sidebar-title {
    font-size: 1rem;
    font-weight: bold;
    color: var(--accent-red);
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ddd;
}

.entity-group {
    margin-bottom: 12px;
}

.entity-group-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--accent-brown);
    margin-bottom: 6px;
}

.entity-count {
    font-weight: normal;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.entity-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
}

.entity-tag {
    font-size: 0.85rem;
    cursor: default;
    padding: 1px 4px;
    border-radius: 3px;
    transition: background 0.15s;
}

.entity-tag:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* ============================================================
   响应式
   ============================================================ */

@media (max-width: 960px) {
    body { line-height: 1.9; }
    .settings-toggle { right: 15px; }
    .settings-panel { right: 15px; width: 260px; }
}

@media (max-width: 768px) {
    body { padding: 15px; font-size: 16px; line-height: 1.8; }
    .site-header h1 { font-size: 1.6rem; }
    article h1 { font-size: 1.4em; }
    article h2 { font-size: 1.2em; margin-top: 30px; }
    p { margin: 1.2em 0; }
}

@media (max-width: 480px) {
    body { padding: 10px; font-size: 15px; }
    .site-header h1 { font-size: 1.4rem; }
    .chapter-header h1 { font-size: 1.3rem; }
    .chapter-nav { font-size: 0.8rem; }
}

/* --- 打印样式 --- */
@media print {
    .settings-toggle, .settings-panel, .chapter-nav, .search-box {
        display: none !important;
    }
    body { background: white; max-width: 100%; padding: 1cm; }
    .para-num { color: #999; font-size: 8pt; }
    p { page-break-inside: avoid; }
}

/* --- Logo 样式 --- */

/* --- Logo 样式 --- */
.site-logo {
    display: block;
    height: 80px;
    width: auto;
    margin: 0 auto 10px;
}
