/*
 * Chapter reader page styles — Enhanced Reader UX/UI
 */

/* Reading Progress Bar at the top of the viewport */
.reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #27ae60, #2ecc71, #3498db);
    width: 0%;
    z-index: 9999;
    transition: width 0.1s ease-out;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
}

/* Chapter Container & Background Themes */
#chapter-theme-container {
    transition: background-color 0.25s ease, color 0.25s ease;
    min-height: calc(100vh - 120px);
}

#chapter-theme-container.chapter-theme-FFF {
    background-color: #ffffff;
    color: #2b2b2b;
}

#chapter-theme-container.chapter-theme-EAE4D3 {
    background-color: #eae4d3;
    color: #3a2e22;
}

#chapter-theme-container.chapter-theme-E9EBEE {
    background-color: #e9ebee;
    color: #27313a;
}

#chapter-theme-container.chapter-theme-F4F4F4 {
    background-color: #f4f4f4;
    color: #333333;
}

#chapter-theme-container.chapter-theme-232323 {
    background-color: #232323;
    color: rgba(255, 255, 255, 0.85);
}

.chapter-container {
    max-width: 1050px;
    margin: 0 auto;
    padding: 30px 20px 60px;
    min-height: 80vh;
}

/* Header */
.chapter-header {
    text-align: center;
    margin-bottom: 20px;
}

.story-title {
    font-size: 26px;
    margin: 0 auto 8px;
    text-transform: uppercase;
    font-weight: 800;
    color: #4b8b3b;
    letter-spacing: 0.5px;
    line-height: 1.3;
}

.story-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.story-title a:hover {
    color: #2c5e8a;
}

.chapter-title {
    color: #666;
    font-size: 18px;
    font-weight: 600;
    margin: 8px 0 0;
    line-height: 1.4;
}

/* Reader Quick Customizer Toolbar */
.reader-quick-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 20px auto 25px;
    padding: 8px 16px;
    background-color: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 25px;
    max-width: fit-content;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* Theme Palette Pills */
.theme-palette {
    display: flex;
    align-items: center;
    gap: 6px;
}

.theme-pill {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid #bbb;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.theme-pill.theme-pill-white { background-color: #ffffff; }
.theme-pill.theme-pill-sepia { background-color: #eae4d3; }
.theme-pill.theme-pill-green { background-color: #e9ebee; }
.theme-pill.theme-pill-gray  { background-color: #f4f4f4; }
.theme-pill.theme-pill-dark  { background-color: #232323; border-color: #555; }

.theme-pill:hover {
    transform: scale(1.18);
}

.theme-pill.active {
    box-shadow: 0 0 0 2px #27ae60;
    transform: scale(1.12);
}

/* Font Size Controls */
.font-size-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 15px;
    padding: 2px 6px;
}

.btn-tool {
    background: transparent;
    border: none;
    font-size: 13px;
    font-weight: 700;
    color: #555;
    padding: 2px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-tool:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #111;
}

.font-size-badge {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    min-width: 34px;
    text-align: center;
    user-select: none;
}

/* Font Family Select */
.font-family-controls .form-select {
    font-size: 12px;
    padding: 3px 24px 3px 8px;
    height: 28px;
    border-radius: 14px;
    border-color: #ccc;
    background-color: #fff;
    cursor: pointer;
}

/* Focus Mode Button */
.btn-focus {
    display: flex;
    align-items: center;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.04);
}

.btn-focus.active {
    background: #27ae60;
    color: #fff;
}

/* Chapter Navigation Buttons */
.chapter-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
}

.btn-chapter-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    background-color: #27ae60;
    border: 1px solid #27ae60;
    color: #fff;
}

.btn-chapter-nav:hover {
    background-color: #219653;
    border-color: #219653;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(39, 174, 96, 0.25);
}

.btn-chapter-nav.btn-toc {
    background-color: #34495e;
    border-color: #34495e;
}

.btn-chapter-nav.btn-toc:hover {
    background-color: #2c3e50;
    border-color: #2c3e50;
    box-shadow: 0 4px 8px rgba(44, 62, 80, 0.25);
}

.btn-chapter-nav.disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: not-allowed;
}

/* Chapter Content Typography */
.chapter-content {
    font-family: var(--chapter-font-family, "Palatino Linotype", "Arial", "Times New Roman", sans-serif);
    line-height: var(--chapter-line-height, 1.85);
    font-size: var(--chapter-font-size, 20px);
    color: inherit;
    text-align: left;
    word-wrap: break-word;
    margin: 30px auto;
    max-width: 100%;
}

.chapter-content p {
    margin-bottom: 18px;
    text-indent: 0;
}

.chapter-content p:empty {
    display: none;
}

hr.chapter-divider {
    border: 0;
    height: 1px;
    background: #e4e4e4;
    margin: 25px auto;
}

/* Next Big Chapter Callout */
.next-chapter-box .btn-next-big {
    font-size: 16px;
    font-weight: 700;
    padding: 12px 28px;
    border-radius: 30px;
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    border: none;
    color: #fff;
    transition: all 0.25s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.next-chapter-box .btn-next-big:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(46, 204, 113, 0.35) !important;
    color: #fff;
}

/* Floating Bottom Smart Navigation Bar */
.floating-chapter-nav {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 30px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 999;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease;
}

.floating-chapter-nav.is-visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.btn-float-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #444;
    background: transparent;
    border: none;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-float-nav:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #111;
}

.btn-float-nav.disabled {
    opacity: 0.25;
    pointer-events: none;
}

/* Chapter Selector Modal / Drawer */
.chapter-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.chapter-modal-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.chapter-modal-drawer {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -46%) scale(0.96);
    width: 92%;
    max-width: 850px;
    height: 82vh;
    max-height: 720px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.15), opacity 0.25s ease, visibility 0.25s ease;
    overflow: hidden;
}

.chapter-modal-drawer.is-open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    visibility: visible;
}

.chapter-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eaeaea;
    background: #f8f9fa;
}

.modal-header-titles .modal-story-title {
    font-size: 17px;
    font-weight: 700;
    color: #2c5e8a;
    margin: 0 0 4px;
    max-width: 600px;
}

.modal-header-titles .modal-subtitle {
    font-size: 13px;
    color: #666;
}

.modal-header-titles .view-story-link {
    color: #27ae60;
    text-decoration: none;
    font-weight: 500;
}

.modal-header-titles .view-story-link:hover {
    text-decoration: underline;
}

.btn-close-modal {
    background: transparent;
    border: none;
    font-size: 18px;
    color: #888;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.btn-close-modal:hover {
    background: #e9ecef;
    color: #111;
}

.chapter-modal-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: #ffffff;
    border-bottom: 1px solid #f0f0f0;
}

.modal-search-box {
    flex: 1;
    position: relative;
}

.modal-search-box input {
    padding-left: 32px;
    border-radius: 16px;
    font-size: 13px;
    height: 34px;
}

.modal-search-box .search-icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    font-size: 13px;
    pointer-events: none;
}

.chapter-modal-toolbar #btnModalSort {
    font-size: 12px;
    border-radius: 16px;
    padding: 5px 12px;
    white-space: nowrap;
}

.chapter-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px 20px 25px;
}

.modal-chapter-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 16px;
    list-style: none;
    padding: 0;
    margin: 0;
}

@media (max-width: 767px) {
    .modal-chapter-list {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .chapter-modal-drawer {
        width: 100%;
        height: 88vh;
        max-height: 88vh;
        top: auto;
        bottom: 0;
        left: 0;
        transform: translateY(100%);
        border-radius: 20px 20px 0 0;
    }

    .chapter-modal-drawer.is-open {
        transform: translateY(0);
    }
}

.modal-chapter-item {
    border-radius: 6px;
    transition: background 0.15s ease, transform 0.15s ease;
    border-bottom: 1px dashed #eee;
    padding: 6px 10px;
}

.modal-chapter-item:hover {
    background: #f0f4f8;
    border-bottom-color: transparent;
    transform: translateX(3px);
}

.modal-chapter-item a {
    display: flex;
    align-items: center;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    line-height: 1.4;
    width: 100%;
}

.modal-chapter-item.is-current {
    background-color: #e8f5e9 !important;
    border: 1px solid #c8e6c9 !important;
}

.modal-chapter-item.is-current a {
    color: #1b5e20 !important;
    font-weight: 700;
}

.modal-chapter-item .chapter-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.modal-chapter-item .chapter-item-icon {
    color: #9ab0c5;
    font-size: 13px;
    flex-shrink: 0;
}

.modal-chapter-item .chapter-read-badge {
    color: #27ae60;
    font-size: 12px;
}

.modal-chapter-item.is-read:not(.is-current) a {
    color: #888;
}

.modal-chapter-item.is-read:not(.is-current) .chapter-read-badge {
    display: inline-block !important;
}

/* Dark Theme for Modal */
.dark-theme .chapter-modal-drawer {
    background: #1a222a;
    color: #eee;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
}

.dark-theme .chapter-modal-header {
    background: #141b22;
    border-bottom-color: #263340;
}

.dark-theme .modal-header-titles .modal-story-title {
    color: #92bb35;
}

.dark-theme .btn-close-modal {
    color: #aaa;
}

.dark-theme .btn-close-modal:hover {
    background: #242f39;
    color: #fff;
}

.dark-theme .chapter-modal-toolbar {
    background: #1a222a;
    border-bottom-color: #263340;
}

.dark-theme .modal-search-box input {
    background: #141b22;
    border-color: #2b3846;
    color: #fff;
}

.dark-theme .modal-chapter-item {
    border-bottom-color: #242f39;
}

.dark-theme .modal-chapter-item:hover {
    background: #242f39;
}

.dark-theme .modal-chapter-item a {
    color: #bbb;
}

.dark-theme .modal-chapter-item.is-current {
    background: #1c3325 !important;
    border-color: #27ae60 !important;
}

.dark-theme .modal-chapter-item.is-current a {
    color: #a3e9a4 !important;
}

.dark-theme #modalNoChapter {
    background: #141b22;
    border-color: #263340;
    color: #888;
}

/* Focus Mode (Fullscreen Reader) */
body.reader-focus-mode #nav,
body.reader-focus-mode .navbar-breadcrumb,
body.reader-focus-mode #footer,
body.reader-focus-mode .reader-footer-tips {
    display: none !important;
}

body.reader-focus-mode #wrap {
    padding-top: 0 !important;
}

body.reader-focus-mode .chapter-container {
    max-width: 950px;
    padding-top: 40px;
}

/* Responsive */
@media (max-width: 768px) {
    .chapter-container {
        padding: 15px 12px 50px;
    }

    .story-title {
        font-size: 20px;
    }

    .chapter-title {
        font-size: 15px;
    }

    .chapter-content {
        margin: 20px auto;
    }

    .reader-quick-toolbar {
        gap: 8px;
        padding: 6px 10px;
        border-radius: 20px;
    }

    .btn-chapter-nav {
        padding: 7px 14px;
        font-size: 13px;
    }

    .floating-chapter-nav {
        bottom: 12px;
        padding: 4px 8px;
        gap: 4px;
    }

    .btn-float-nav {
        padding: 5px 8px;
        font-size: 12px;
    }
}

/* Dark Theme Adjustments */
.dark-theme .chapter-container {
    background-color: transparent;
    color: rgba(255, 255, 255, 0.85);
}

.dark-theme .story-title {
    color: #92bb35;
}

.dark-theme .chapter-title {
    color: #aaa;
}

.dark-theme .reader-quick-toolbar {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.12);
}

.dark-theme .btn-tool {
    color: #bbb;
}

.dark-theme .btn-tool:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.dark-theme .font-size-badge {
    color: #aaa;
}

.dark-theme .font-family-controls .form-select {
    background-color: #1e262f;
    border-color: #333;
    color: #eee;
}

.dark-theme .floating-chapter-nav {
    background: rgba(30, 38, 47, 0.92);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.dark-theme .btn-float-nav {
    color: #ccc;
}

.dark-theme .btn-float-nav:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.dark-theme hr.chapter-divider {
    background: #333;
}

