* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Times New Roman", "SimSun", "宋体", "Noto Serif SC", "Source Han Serif SC", serif;
    background-color: #f5f5f5;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* 加载状态 */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 50vh;
    color: #666;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #0f4761;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 错误提示 */
.error {
    text-align: center;
    padding: 60px 20px;
}

.error h2 {
    color: #c0392b;
    margin-bottom: 15px;
}

.error p {
    color: #666;
    margin-bottom: 20px;
}

.error a {
    color: #0f4761;
    text-decoration: none;
    padding: 10px 20px;
    border: 1px solid #0f4761;
    border-radius: 4px;
}

.error a:hover {
    background-color: #0f4761;
    color: white;
}

/* 书架 */
.bookshelf {
    padding: 40px 0;
}

.bookshelf h1 {
    color: #0f4761;
    margin-bottom: 20px;
    text-align: center;
}

.bookshelf .hint {
    text-align: center;
    color: #888;
    margin-bottom: 30px;
    font-size: 14px;
}

.bookshelf .hint code {
    background-color: #e8e8e8;
    padding: 2px 8px;
    border-radius: 4px;
}

.book-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
}

.book-item {
    display: block;
    padding: 20px;
    background-color: white;
    border-radius: 8px;
    text-decoration: none;
    color: #333;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.book-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

/* 阅读器 */
.reader {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    min-height: 100vh;
}

.reader-header {
    position: sticky;
    top: 0;
    background-color: white;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 100;
}

.back-btn {
    color: #0f4761;
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
}

.back-btn:hover {
    text-decoration: underline;
}

.book-title {
    flex: 1;
    font-size: 18px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.controls {
    display: flex;
    gap: 8px;
}

.controls button {
    padding: 6px 12px;
    background-color: #0f4761;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.controls button:hover {
    background-color: #0d3a4f;
}

/* 目录侧边栏 */
.toc-sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 300px;
    height: 100vh;
    background-color: white;
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    z-index: 200;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.toc-sidebar.open {
    left: 0;
}

.toc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 199;
    display: none;
}

.toc-overlay.open {
    display: block;
}

.toc-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toc-header h2 {
    color: #0f4761;
    font-size: 18px;
    font-family: "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
    font-weight: normal;
}

.toc-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
}

.toc-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.toc-chapter {
    display: block;
    padding: 12px 20px;
    color: #333;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background-color 0.2s, border-color 0.2s;
}

.toc-chapter:hover {
    background-color: #f5f5f5;
}

.toc-chapter.active {
    background-color: #f0f7fa;
    border-left-color: #0f4761;
    color: #0f4761;
}

.toc-section {
    display: block;
    padding: 8px 20px 8px 35px;
    color: #666;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.2s;
}

.toc-section:hover {
    background-color: #f5f5f5;
    color: #0f4761;
}

/* 章节导航 */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    background-color: #fafafa;
}

.chapter-nav.bottom {
    border-bottom: none;
    border-top: 1px solid #eee;
}

.chapter-nav button {
    padding: 8px 16px;
    background-color: #0f4761;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.chapter-nav button:hover:not(:disabled) {
    background-color: #0d3a4f;
}

.chapter-nav button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.chapter-nav span {
    color: #666;
    font-size: 14px;
}

/* 基准字号，用于缩放 */
.content {
    --base-size: 14.67px;
    --scale: 1;
    padding: 30px 40px;
    font-size: calc(var(--base-size) * var(--scale));
    line-height: 1.5;
    color: #333;
}

.reader-footer {
    padding: 20px;
    text-align: center;
    border-top: 1px solid #eee;
}

.reader-footer button {
    padding: 10px 30px;
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
}

.reader-footer button:hover {
    background-color: #eee;
}

/* 内容样式 */

/* 章标题 - # 固定大小不缩放 */
.chapter-title {
    color: #0f4761;
    font-family: "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
    font-size: 32px;
    line-height: 1.5;
    font-weight: normal;
    margin-top: 24px;
    margin-bottom: 4px;
    break-after: avoid;
}

.chapter-title:first-child {
    margin-top: 0;
}

/* 节编号 - ## 跟随缩放 */
.section-title {
    color: #0f4761;
    font-family: "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
    font-size: calc(16px * var(--scale));
    line-height: 1.5;
    font-weight: normal;
    margin-top: calc(6px * var(--scale));
    margin-bottom: calc(2px * var(--scale));
    break-after: avoid;
}

/* 信息框 - ~...~ 跟随缩放 */
.info-box {
    position: relative;
    margin: calc(8px * var(--scale)) 0;
    padding-left: calc(15px * var(--scale));
    font-family: "Times New Roman", "SimSun", "宋体", "Noto Serif SC", "Source Han Serif SC", serif;
    font-size: calc(var(--base-size) * var(--scale));
    line-height: 1.5;
}

.info-box::before {
    content: '';
    position: absolute;
    left: calc(-5px * var(--scale));
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: #0f4761;
}

.info-box .first-line {
    color: #0f4761;
    font-style: italic;
    margin: 0;
}

.info-box .other-lines {
    color: #333;
    margin: 0;
}

/* 加粗 - **...** */
.bold-text {
    font-family: "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
    font-weight: bold;
}

/* 正文段落 跟随缩放 */
.paragraph {
    margin-top: 0;
    margin-bottom: calc(6px * var(--scale));
    line-height: 1.5;
}

/* 加载中提示 */
.loading-inline {
    text-align: center;
    padding: 40px;
    color: #666;
}

/* 响应式 */
@media (max-width: 600px) {
    .container {
        padding: 10px;
    }
    
    .content {
        padding: 20px 15px;
    }
    
    .reader-header {
        padding: 10px 15px;
    }
    
    .book-title {
        font-size: 14px;
    }

    .toc-sidebar {
        width: 80%;
        left: -85%;
    }

    .chapter-nav {
        padding: 10px 15px;
    }

    .chapter-nav button {
        padding: 6px 12px;
        font-size: 12px;
    }
}