:root {
    --bg-color: #fcfcfc;
    --text-color: #333;
    --toolbar-bg: #fff;
    --border-color: #eaeaea;
    --accent: #2563eb;
}
html.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --toolbar-bg: #1e1e1e;
    --border-color: #333;
}
body.read-mode-active {
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    font-family: 'Georgia', serif;
    transition: background 0.3s, color 0.3s;
}
.read-mode-toolbar {
    position: sticky;
    top: 0;
    display: flex;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    font-family: sans-serif;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 15px; }
.btn-back { text-decoration: none; color: var(--accent); font-weight: bold; }
.read-title { font-size: 1.1rem; margin: 0; font-weight: 600; }
button { background: none; border: 1px solid var(--border-color); color: var(--text-color); padding: 5px 10px; cursor: pointer; border-radius: 4px; }
button:hover { background: var(--border-color); }
.read-progress-container { width: 100%; height: 4px; background: var(--border-color); position: sticky; top: 48px; z-index: 99; }
.read-progress-bar { height: 100%; background: var(--accent); width: 0%; transition: width 0.1s; }
.read-layout { display: flex; max-width: 1200px; margin: 0 auto; position: relative; }


.read-sidebar ul { list-style: none; padding: 0; }
.read-sidebar li { margin-bottom: 10px; }
.read-sidebar a { color: var(--text-color); text-decoration: none; font-family: sans-serif; font-size: 0.95rem; display: block; padding: 8px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.read-sidebar a:hover, .read-sidebar a.active-toc { color: var(--accent); font-weight: bold; }



/* Single Chapter Logic */
.book-chapter { display: none; margin-bottom: 80px; animation: fadeIn 0.3s; }
.book-chapter.active { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.book-chapter h2 { font-size: 2rem; margin-bottom: 30px; font-family: sans-serif; border-bottom: 1px solid var(--border-color); padding-bottom: 10px;}

/* Chapter Navigation Buttons */
.toolbar-center { display: flex; gap: 10px; }
.btn-chapter-nav { background: #007bff; color: #fff; border: none; padding: 8px 16px; border-radius: 4px; font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: background 0.2s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn-chapter-nav:hover:not(:disabled) { background: #0056b3; }
.btn-chapter-nav:disabled { background: #cccccc; color: #666666; cursor: not-allowed; opacity: 0.7; }
.chapter-nav-bottom { display: flex; justify-content: space-between; margin-top: 50px; padding-top: 20px; border-top: 1px dashed var(--border-color); }

/* Mobile Overlay */
.toc-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1001;
    display: none;
    opacity: 0;
    transition: opacity 0.3s;
}
body.toc-open .toc-overlay { display: block; opacity: 1; }




.read-sidebar {
    position: fixed;
    top: 52px;
    left: 0;
    width: fit-content;
    min-width: 200px;
    max-width: 85vw;
    height: calc(100vh - 52px);
    z-index: 1002;
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    padding: 20px 40px 20px 20px; /* 40px right padding provides a fair gap between text and border */
    background: var(--bg-color);
    border-right: 1px solid var(--border-color);
    transition: transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}
body.toc-open .read-sidebar {
    transform: translateX(0);
}
.read-content {
    flex: 1;
    padding: 40px 60px;
    max-width: 800px;
    margin: 0 auto; /* Center content when sidebar is fixed */
    font-size: 18px;
    line-height: 1.8;
}

@media(max-width: 768px) {
    .read-mode-toolbar { flex-wrap: wrap; }
    .toolbar-center { order: 3; width: 100%; justify-content: space-between; margin-top: 10px; }
    .read-progress-container { top: 90px; }
    
    .read-content { 
        padding: 20px 12px !important; 
        font-size: 17px; 
    }
    
    .book-chapter h2 {
        font-size: 1.5rem;
    }
}
