:root {
    --primary-color: #007AFF;
    --bg-color: #FFFFFF;
    --text-color: #000000;
    --sidebar-bg: #F5F5F7;
    --border-color: #E5E5E5;
    --sidebar-width: 300px;
    --content-max-width: 800px;
}

[data-theme="dark"] {
    --bg-color: #000000;
    --text-color: #FFFFFF;
    --sidebar-bg: #1C1C1E;
    --border-color: #38383A;
}

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

/* 自定义滚动条 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
}

#sidebar {
    position: fixed;
    width: var(--sidebar-width);
    height: 100vh;
    left: 0;
    top: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
    transition: background-color 0.3s;
    overflow-y: overlay;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    z-index: 1000;
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.sidebar-header h1 {
    font-size: 24px;
    margin-bottom: 15px;
}

.theme-switch {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

#content {
    margin-left: var(--sidebar-width);
    padding: 40px;
    max-width: calc(var(--content-max-width) + 80px);
    margin-right: auto;
    word-wrap: break-word;
    overflow-x: hidden;
}

.chapter-header {
    margin-bottom: 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    position: sticky;
    top: 0;
    background: var(--bg-color);
    padding: 20px 0;
    z-index: 100;
}

.chapter-title {
    font-size: 24px;
    font-weight: 500;
    margin: 0;
}

.chapter-nav {
    display: flex;
    gap: 10px;
}

.chapter-nav button {
    padding: 8px 16px;
    font-size: 14px;
    border: none;
    border-radius: 6px;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: opacity 0.3s;
}

.chapter-nav button:hover {
    opacity: 0.8;
}

.chapter-nav button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chapter {
    margin-bottom: 40px;
    padding-bottom: 40px;
    border-bottom: 1px solid var(--border-color);
}

.chapter:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.chapter .chapter-title {
    font-size: 24px;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.chapter-content {
    font-size: 18px;
    line-height: 1.8;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.chapter-content p {
    margin-bottom: 1em;
    text-indent: 2em;
    max-width: 100%;
}

.chapter-link {
    display: block;
    padding: 10px 20px;
    color: var(--text-color);
    text-decoration: none;
    transition: background 0.3s;
    &:visited {
        color: var(--text-color);
    }
}

.chapter-link:hover,
.chapter-link.active {
    background: rgba(0, 122, 255, 0.1);
    color: var(--primary-color);
}

#loading,
#error,
#progress {
    position: fixed;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 1000;
}

#loading {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px 40px;
}

#error {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #FF3B30;
    color: white;
}

#progress {
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
}

.show {
    opacity: 1 !important;
}

.infinite-scroll-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-color);
    opacity: 0.7;
    display: none;
}

.infinite-scroll-loading.show {
    display: block;
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 260px;
    }

    #sidebar {
        transform: translateX(-100%);
        z-index: 100;
    }

    #content {
        margin-left: 0;
        padding: 20px;
    }

    .show-sidebar #sidebar {
        transform: translateX(0);
    }

    .chapter-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 0;
    }
}