/* ===== 基础变量和重置 ===== */
:root {
    /* 主题变量 - 白天 */
    --bg-color: #f5f5f5;
    --text-color: #333;
    --secondary-text: #666;
    --border-color: #e0e0e0;
    --accent-color: #8b4513;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --content-bg: #fff;
    --toolbar-bg: #fff;
    --sidebar-bg: #fafafa;
    --hover-bg: #f0f0f0;
}

/* 护眼主题 */
[data-theme="sepia"] {
    --bg-color: #f4ecd8;
    --text-color: #5c4b37;
    --secondary-text: #7a6655;
    --border-color: #d4c5a9;
    --accent-color: #8b6914;
    --shadow: 0 2px 8px rgba(92,75,55,0.15);
    --content-bg: #fdf8e8;
    --toolbar-bg: #f4ecd8;
    --sidebar-bg: #efe8d5;
    --hover-bg: #e8dfc8;
}

/* 夜间主题 */
[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #c0c0c0;
    --secondary-text: #888;
    --border-color: #333;
    --accent-color: #d4a574;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --content-bg: #242424;
    --toolbar-bg: #1a1a1a;
    --sidebar-bg: #1a1a1a;
    --hover-bg: #2a2a2a;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.8;
    overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
}

/* ===== 加载界面 ===== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s;
}

.loading-content {
    text-align: center;
    padding: 2rem;
}

.loading-content h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    color: var(--accent-color);
    font-weight: 300;
    letter-spacing: 0.5rem;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

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

.loading-content p {
    color: var(--secondary-text);
    margin-bottom: 1.5rem;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139,69,19,0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

/* ===== 阅读界面 ===== */
.reader {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ===== 工具栏 ===== */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 100;
    box-shadow: var(--shadow);
    transition: background 0.3s, border-color 0.3s;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--hover-bg);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--text-color);
}

.chapter-title {
    font-size: 1rem;
    color: var(--text-color);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== 侧边栏目录 ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    max-width: 85vw;
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}

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

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 500;
}

.sidebar-search {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-search input {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--content-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
}

.sidebar-search input:focus {
    border-color: var(--accent-color);
}

.chapter-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.chapter-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
    font-size: 0.95rem;
}

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

.chapter-item.current {
    background: var(--accent-color);
    color: white;
}

.chapter-item.current:hover {
    background: var(--accent-color);
    opacity: 0.9;
}

.chapter-item.hidden {
    display: none;
}

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

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

/* ===== 设置面板 ===== */
.settings-panel, .bookmark-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    background: var(--content-bg);
    border-radius: 12px;
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
}

.settings-panel.open, .bookmark-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.settings-header, .bookmark-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-header h2, .bookmark-header h2 {
    font-size: 1.1rem;
    font-weight: 500;
}

.settings-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h3 {
    font-size: 0.9rem;
    color: var(--secondary-text);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.theme-options, .line-height-options, .mode-options {
    display: flex;
    gap: 0.5rem;
}

.theme-btn, .line-height-btn, .mode-btn {
    flex: 1;
    padding: 0.6rem 0.5rem;
    border: 1px solid var(--border-color);
    background: var(--content-bg);
    color: var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.theme-btn:hover, .line-height-btn:hover, .mode-btn:hover {
    border-color: var(--accent-color);
}

.theme-btn.active, .line-height-btn.active, .mode-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.font-size-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.btn-small {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background: var(--content-bg);
    color: var(--text-color);
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-small:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

#font-size-display {
    font-size: 1.1rem;
    min-width: 30px;
    text-align: center;
}

/* ===== 书签面板 ===== */
.bookmark-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.empty-text {
    text-align: center;
    color: var(--secondary-text);
    padding: 2rem 0;
}

.bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.bookmark-item:hover {
    background: var(--hover-bg);
}

.bookmark-info {
    flex: 1;
}

.bookmark-title {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.bookmark-time {
    font-size: 0.8rem;
    color: var(--secondary-text);
}

.bookmark-delete {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #dc3545;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.bookmark-delete:hover {
    background: rgba(220,53,69,0.1);
}

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

.progress-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.1s;
}

.progress-text {
    position: fixed;
    top: 60px;
    right: 10px;
    font-size: 0.75rem;
    color: var(--secondary-text);
    background: var(--content-bg);
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 90;
    opacity: 0.8;
}

/* ===== 阅读内容区 ===== */
.content {
    flex: 1;
    padding-top: 56px;
    padding-bottom: 60px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.chapter-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    background: var(--content-bg);
    min-height: calc(100vh - 116px);
}

/* 章节标题 */
.chapter-heading {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 2rem;
    color: var(--accent-color);
    text-align: center;
    line-height: 1.4;
}

/* 章节正文 */
.chapter-body {
    font-size: var(--font-size, 18px);
    line-height: var(--line-height, 1.8);
    text-align: justify;
}

.chapter-body p {
    margin-bottom: 1.5rem;
    text-indent: 2em;
}

.chapter-body p:first-child {
    text-indent: 0;
}

/* 分页模式 */
.content.paginated {
    overflow: hidden;
}

.content.paginated .chapter-container {
    display: flex;
    flex-direction: column;
    min-height: auto;
}

.content.paginated .chapter-body {
    flex: 1;
}

/* ===== 导航按钮 ===== */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.nav-btn {
    flex: 1;
    padding: 1rem;
    border: 1px solid var(--border-color);
    background: var(--content-bg);
    color: var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.nav-btn:hover:not(:disabled) {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

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

/* ===== 滚动加载指示器 ===== */
.scroll-indicator {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--content-bg);
    border-radius: 20px;
    box-shadow: var(--shadow);
    z-index: 80;
}

.scroll-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ===== 底部控制栏 ===== */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: var(--toolbar-bg);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
}

.bottom-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.text-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.text-btn:hover {
    background: var(--hover-bg);
}

.jump-to {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.jump-to span {
    font-size: 0.9rem;
    color: var(--secondary-text);
}

#jump-input {
    width: 60px;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--content-bg);
    color: var(--text-color);
    text-align: center;
    font-size: 0.9rem;
}

#jump-btn {
    padding: 0.4rem 0.75rem;
    border: none;
    background: var(--accent-color);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: opacity 0.2s;
}

#jump-btn:hover {
    opacity: 0.9;
}

/* ===== 触摸区域 ===== */
.touch-zones {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 50px;
    z-index: 50;
    pointer-events: none;
}

.touch-zones.active {
    pointer-events: auto;
}

.touch-zone {
    position: absolute;
    top: 0;
    bottom: 0;
}

.touch-zone.left {
    left: 0;
    width: 20%;
}

.touch-zone.center {
    left: 20%;
    right: 20%;
}

.touch-zone.right {
    right: 0;
    width: 20%;
}

/* ===== 响应式设计 ===== */
@media (max-width: 768px) {
    .loading-content h1 {
        font-size: 2rem;
        letter-spacing: 0.3rem;
    }

    .chapter-title {
        max-width: 150px;
        font-size: 0.9rem;
    }

    .chapter-container {
        padding: 1.5rem 1rem;
    }

    .chapter-heading {
        font-size: 1.5rem;
    }

    .chapter-body {
        font-size: var(--font-size-mobile, 17px);
    }

    .chapter-body p {
        margin-bottom: 1.2rem;
    }

    .nav-btn {
        padding: 0.8rem;
        font-size: 0.9rem;
    }

    .bottom-controls {
        gap: 0.5rem;
    }

    .text-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }

    .jump-to span {
        display: none;
    }
}

@media (max-width: 375px) {
    .toolbar {
        padding: 0 0.5rem;
    }

    .chapter-title {
        max-width: 100px;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
    }
}

/* ===== 打印样式 ===== */
@media print {
    .toolbar, .sidebar, .bottom-bar, .settings-panel, .bookmark-panel, .progress-bar, .progress-text {
        display: none !important;
    }

    .content {
        padding: 0;
    }

    .chapter-container {
        max-width: 100%;
        padding: 1cm;
    }
}
