/* ==========================================================================
   《红颜·史记》阅读页面样式 - 学术排版优化
   ========================================================================== */

/* ==========================================================================
   基础变量
   ========================================================================== */
.reading-mode {
    --color-bg: #FAF8F5;
    --color-text: #2D2D2D;
    --color-text-light: #5A5A5A;
    --color-text-muted: #8A8A8A;
    --color-accent: #8B0000;
    --color-border: #E5E0D8;
    --color-highlight: #F5F0E8;

    --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'SimSun', serif;
    --font-sans: 'Noto Sans SC', 'Source Han Sans SC', 'Microsoft YaHei', sans-serif;

    /* 字号设置 */
    --font-size-sm: 15px;
    --font-size-md: 17px;
    --font-size-lg: 19px;
    --font-size-xl: 22px;

    --line-height: 1.9;
    --max-width: 720px;
}

/* ==========================================================================
   主题配色方案
   ========================================================================== */
.theme-light {
    --color-bg: #FAF8F5;
    --color-text: #2D2D2D;
    --color-text-light: #5A5A5A;
    --color-text-muted: #8A8A8A;
    --color-accent: #8B0000;
    --color-border: #E5E0D8;
    --color-highlight: #F5F0E8;
}

.theme-dark {
    --color-bg: #1A1A1A;
    --color-text: #E5E5E5;
    --color-text-light: #B0B0B0;
    --color-text-muted: #707070;
    --color-accent: #CD5C5C;
    --color-border: #333;
    --color-highlight: #252525;
}

.theme-sepia {
    --color-bg: #F5E6D3;
    --color-text: #5C4B37;
    --color-text-light: #7A6548;
    --color-text-muted: #9A8568;
    --color-accent: #8B4513;
    --color-border: #D4C4A8;
    --color-highlight: #E8D5B7;
}

.theme-paper {
    --color-bg: #F9F4E8;
    --color-text: #3D3D3D;
    --color-text-light: #5A5A5A;
    --color-text-muted: #8A8A8A;
    --color-accent: #6B3E26;
    --color-border: #D9D0BE;
    --color-highlight: #EDE8DC;
}

/* ==========================================================================
   字体方案
   ========================================================================== */
.font-song { --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'SimSun', serif; }
.font-hei { --font-sans: 'Noto Sans SC', 'Source Han Sans SC', 'Microsoft YaHei', sans-serif; }
.font-kai { --font-serif: 'STKaiti', 'KaiTi', '楷体', serif; }

/* ==========================================================================
   阅读导航栏
   ========================================================================== */
.read-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    transition: box-shadow 0.3s ease;
}

.read-nav.scrolled {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.read-nav-left,
.read-nav-right {
    flex: 1;
    display: flex;
    align-items: center;
}

.read-nav-right {
    justify-content: flex-end;
    gap: 8px;
}

.back-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-light);
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--color-accent);
}

.chapter-label {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
}

.nav-logo {
    display: flex;
    align-items: center;
    margin-right: 8px;
}

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

.site-branding {
    font-family: var(--font-sans);
    font-size: 12px;
    color: var(--color-text-light);
    font-weight: 400;
    white-space: nowrap;
}

.read-nav-center {
    display: flex;
    align-items: center;
}

.nav-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text-light);
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--color-highlight);
    border-color: var(--color-accent);
    color: var(--color-accent);
}

/* ==========================================================================
   目录侧边栏
   ========================================================================== */
.toc-sidebar {
    position: fixed;
    top: 0;
    right: -360px;
    width: 360px;
    height: 100vh;
    background: #FFF;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
    z-index: 1002;
    transition: right 0.3s ease;
    overflow-y: auto;
}

.toc-sidebar.active {
    right: 0;
}

.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    background: #FFF;
    z-index: 1;
}

.toc-header h3 {
    font-family: var(--font-serif);
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
}

.close-toc {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: color 0.2s ease;
}

.close-toc:hover {
    color: var(--color-text);
}

.toc-nav {
    padding: 16px 0;
}

.toc-part {
    padding: 8px 0;
}

.toc-part-title {
    display: block;
    padding: 12px 24px;
    font-family: var(--font-serif);
    font-size: 15px;
    font-weight: 600;
    color: var(--color-accent);
    text-decoration: none;
    transition: background 0.2s ease;
}

.toc-part-title:hover {
    background: var(--color-highlight);
}

.toc-chapters {
    margin: 0;
    padding: 0;
}

.toc-chapters li a {
    display: block;
    padding: 10px 24px 10px 40px;
    font-size: 14px;
    color: var(--color-text-light);
    text-decoration: none;
    line-height: 1.5;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.toc-chapters li a:hover {
    background: var(--color-highlight);
    color: var(--color-text);
}

.toc-chapters li a.active {
    background: var(--color-highlight);
    color: var(--color-accent);
    border-left-color: var(--color-accent);
}

/* ==========================================================================
   阅读容器
   ========================================================================== */
.reading-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 80px 24px 60px;
    min-height: 100vh;
}

/* ==========================================================================
   章节内容 - 核心排版
   ========================================================================== */
.chapter-content {
    font-size: var(--font-size-md);
    line-height: var(--line-height);
    color: var(--color-text);
}

.chapter-content h1 {
    font-family: var(--font-serif);
    font-size: 2.2em;
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text);
    margin: 0 0 0.5em;
    text-align: center;
    letter-spacing: 0.02em;
}

.chapter-content h2 {
    font-family: var(--font-serif);
    font-size: 1.5em;
    font-weight: 600;
    line-height: 1.4;
    color: var(--color-text);
    margin: 2em 0 0.8em;
    text-align: center;
    letter-spacing: 0.01em;
}

.chapter-content h3 {
    font-family: var(--font-serif);
    font-size: 1.2em;
    font-weight: 600;
    line-height: 1.4;
    color: var(--color-text);
    margin: 2em 0 0.8em;
}

.chapter-content h4 {
    font-family: var(--font-serif);
    font-size: 1.05em;
    font-weight: 600;
    line-height: 1.5;
    color: var(--color-text-light);
    margin: 1.8em 0 0.6em;
}

.chapter-content p {
    margin: 0 0 1.5em;
    text-align: justify;
    text-justify: inter-word;
    orphans: 3;
    widows: 3;
}

/* 首行缩进 */
.chapter-content p + p {
    text-indent: 2em;
}

/* ==========================================================================
   引用块
   ========================================================================== */
.chapter-content blockquote {
    margin: 1.5em 0;
    padding: 1em 1.5em;
    border-left: 4px solid var(--color-accent);
    background: var(--color-highlight);
    font-family: var(--font-serif);
    font-size: 0.95em;
    line-height: 1.8;
    color: var(--color-text-light);
}

.chapter-content blockquote p {
    margin: 0;
    text-indent: 0;
    text-align: left;
}

/* ==========================================================================
   列表
   ========================================================================== */
.chapter-content ul,
.chapter-content ol {
    margin: 1em 0 1.5em;
    padding-left: 1.5em;
}

.chapter-content li {
    margin-bottom: 0.5em;
    text-align: left;
}

.chapter-content li:last-child {
    margin-bottom: 0;
}

.chapter-content ul {
    list-style-type: disc;
}

.chapter-content ol {
    list-style-type: decimal;
}

/* ==========================================================================
   表格
   ========================================================================== */
.chapter-content table {
    width: 100%;
    margin: 1.5em 0;
    border-collapse: collapse;
    font-size: 0.9em;
    background: #FFF;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chapter-content th,
.chapter-content td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.chapter-content th {
    background: var(--color-highlight);
    font-weight: 600;
    color: var(--color-text);
    font-family: var(--font-serif);
}

.chapter-content td {
    color: var(--color-text-light);
}

.chapter-content tr:last-child td {
    border-bottom: none;
}

.chapter-content tr:hover td {
    background: var(--color-highlight);
}

/* ==========================================================================
   分隔线
   ========================================================================== */
.chapter-content hr {
    margin: 2em auto;
    width: 60%;
    height: 1px;
    background: var(--color-border);
    border: none;
}

/* ==========================================================================
   强调文字
   ========================================================================== */
.chapter-content strong,
.chapter-content b {
    font-weight: 600;
    color: var(--color-text);
}

.chapter-content em,
.chapter-content i {
    font-style: italic;
}

/* ==========================================================================
   链接
   ========================================================================== */
.chapter-content a {
    color: var(--color-accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.chapter-content a:hover {
    border-bottom-color: var(--color-accent);
}

/* ==========================================================================
   占位符页面
   ========================================================================== */
.chapter-placeholder {
    text-align: center;
    padding: 80px 40px;
}

.chapter-placeholder h1 {
    font-size: 2.5em;
    margin-bottom: 0.3em;
}

.chapter-placeholder h2 {
    font-size: 1.3em;
    font-weight: 400;
    color: var(--color-text-light);
    margin-bottom: 2em;
}

.placeholder-info {
    margin-top: 40px;
    padding: 30px;
    background: var(--color-highlight);
    border-radius: 12px;
    display: inline-block;
}

.placeholder-info p {
    margin: 0.5em 0;
    color: var(--color-text-muted);
    text-indent: 0 !important;
    text-align: center !important;
}

/* ==========================================================================
   阅读进度条
   ========================================================================== */
.reading-progress {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--color-border);
    z-index: 999;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-accent), #B8860B);
    width: 0%;
    transition: width 0.1s ease;
}

/* ==========================================================================
   章节导航
   ========================================================================== */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    margin-top: 60px;
    padding-top: 40px;
    border-top: 1px solid var(--color-border);
}

.chapter-nav-btn {
    display: flex;
    flex-direction: column;
    padding: 16px 24px;
    background: #FFF;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.3s ease;
    min-width: 200px;
}

.chapter-nav-btn:hover:not(.disabled) {
    border-color: var(--color-accent);
    box-shadow: 0 4px 12px rgba(139, 0, 0, 0.1);
}

.chapter-nav-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.nav-direction {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 4px;
}

.nav-title {
    font-family: var(--font-serif);
    font-size: 15px;
    color: var(--color-text);
    font-weight: 500;
}

.chapter-nav-btn.prev {
    text-align: left;
}

.chapter-nav-btn.next {
    text-align: right;
    margin-left: auto;
}

/* ==========================================================================
   字体控制面板
   ========================================================================== */
.font-panel {
    position: fixed;
    top: 70px;
    right: 24px;
    background: #FFF;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: none;
    flex-direction: column;
    gap: 16px;
    z-index: 1001;
    min-width: 240px;
}

.font-panel.active {
    display: flex;
}

.font-panel-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.panel-label {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.panel-row {
    display: flex;
    gap: 4px;
}

.font-btn {
    flex: 1;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--color-text-light);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
}

.font-btn:hover {
    background: var(--color-highlight);
    border-color: var(--color-accent);
}

.font-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #FFF;
}

/* 主题按钮样式 */
.theme-btn {
    width: 44px;
    height: 36px;
    padding: 4px;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-btn:hover {
    border-color: var(--color-accent);
    transform: scale(1.05);
}

.theme-btn.active {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(139, 0, 0, 0.1);
}

.theme-preview {
    width: 100%;
    height: 100%;
    border-radius: 4px;
}

.theme-light-preview {
    background: linear-gradient(135deg, #FAF8F5 50%, #E5E0D8 50%);
}

.theme-dark-preview {
    background: linear-gradient(135deg, #1A1A1A 50%, #333 50%);
}

.theme-sepia-preview {
    background: linear-gradient(135deg, #F5E6D3 50%, #D4C4A8 50%);
}

.theme-paper-preview {
    background: linear-gradient(135deg, #F9F4E8 50%, #D9D0BE 50%);
}

/* ==========================================================================
   遮罩层
   ========================================================================== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    z-index: 1001;
    transition: all 0.3s ease;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ==========================================================================
   响应式设计 - 手机优化
   ========================================================================== */
@media (max-width: 768px) {
    /* 导航栏手机优化 */
    .read-nav {
        height: 52px;
        padding: 0 12px;
    }

    .read-nav-center {
        flex: 1;
        justify-content: center;
        min-width: 0;
    }

    .nav-logo {
        margin-right: 6px;
    }

    .nav-logo img {
        height: 36px;
        width: 36px;
        border-radius: 6px;
    }

    .chapter-label {
        font-size: 14px;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .site-branding {
        display: none;
    }

    .nav-btn {
        width: 36px;
        height: 36px;
        border-radius: 6px;
    }

    .nav-btn svg {
        width: 18px;
        height: 18px;
    }

    /* 导航按钮紧凑布局 */
    .read-nav-right {
        gap: 4px;
    }

    /* 目录侧边栏全屏 */
    .toc-sidebar {
        width: 100%;
        right: -100%;
    }

    .reading-container {
        padding: 72px 20px 40px;
    }

    .chapter-content {
        font-size: var(--font-size-md);
    }

    .chapter-content h1 {
        font-size: 1.6em;
    }

    .chapter-content h2 {
        font-size: 1.2em;
    }

    .chapter-content h3 {
        font-size: 1.05em;
    }

    .chapter-nav {
        flex-direction: column;
        gap: 12px;
    }

    .chapter-nav-btn {
        min-width: auto;
        padding: 14px 16px;
        text-align: center !important;
    }

    .nav-direction {
        font-size: 11px;
    }

    .nav-title {
        font-size: 14px;
    }

    .font-panel {
        right: 12px;
        left: 12px;
        top: 66px;
        padding: 12px;
        min-width: auto;
    }

    .font-panel-section {
        gap: 6px;
    }

    .panel-label {
        font-size: 11px;
    }

    .panel-row {
        gap: 6px;
    }

    .font-btn {
        padding: 8px 10px;
        font-size: 12px;
        min-width: 40px;
    }

    .theme-btn {
        width: 40px;
        height: 32px;
    }
}

/* ==========================================================================
   打印样式
   ========================================================================== */
@media print {
    .read-nav,
    .toc-sidebar,
    .reading-progress,
    .chapter-nav,
    .font-panel,
    .overlay {
        display: none !important;
    }

    .reading-container {
        padding: 0;
        max-width: none;
    }

    .chapter-content {
        font-size: 12pt;
        line-height: 1.6;
    }

    .chapter-content p {
        text-indent: 2em;
    }
}

/* ==========================================================================
   暗色模式支持
   ========================================================================== */
/* 自动检测系统暗色模式时，如果用户没有手动选择主题，则应用暗色主题 */
@media (prefers-color-scheme: dark) {
    body:not(.theme-light):not(.theme-sepia):not(.theme-paper) {
        --color-bg: #1A1A1A;
        --color-text: #E5E5E5;
        --color-text-light: #B0B0B0;
        --color-text-muted: #707070;
        --color-accent: #CD5C5C;
        --color-border: #333;
        --color-highlight: #252525;
    }

    .read-nav {
        background: rgba(26, 26, 26, 0.95);
    }

    .toc-sidebar {
        background: #1E1E1E;
    }

    .toc-header,
    .chapter-nav-btn,
    .font-panel {
        background: #1E1E1E;
    }

    .toc-sidebar,
    .chapter-nav-btn {
        box-shadow: none;
    }

    table {
        box-shadow: none !important;
    }
}
