/* =====================================================
   SAGANEST — READER
   Reading page, progress bar, reader controls
   ===================================================== */

.reader-page {
    background: #f7f4ed;
    color: #222;
    min-height: 100vh;
    font-family: Georgia, 'Times New Roman', serif;
    overflow-x: clip;
}

.reader-page.dark-theme {
    background: #0d0d12;
    color: #e8e8e8;
}

/* ================= HEADER ================= */
.reader-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: rgba(247, 244, 237, 0.97);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.reader-page.dark-theme .reader-header {
    background: rgba(13, 13, 18, 0.97);
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

.reader-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1;
}

.reader-back {
    color: #555;
    font-size: 28px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background var(--transition);
    flex-shrink: 0;
    line-height: 1;
}

.reader-back:hover { background: rgba(0, 0, 0, 0.06); }

.reader-page.dark-theme .reader-back { color: #888; }
.reader-page.dark-theme .reader-back:hover { background: rgba(255, 255, 255, 0.06); }

.reader-header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.reader-header-info strong {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #222;
    min-width: 0;
    max-width: 100%;
}

.reader-page.dark-theme .reader-header-info strong { color: #e8e8e8; }

.reader-header-info span {
    font-size: 13px;
    color: #888;
}

/* ================= ACTIONS ================= */
.reader-actions {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.reader-menu-btn {
    border: 0;
    background: rgba(0, 0, 0, 0.06);
    color: #333;
    border-radius: 24px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 20px;
    transition: background var(--transition);
    line-height: 1;
}

.reader-menu-btn:hover { background: rgba(0, 0, 0, 0.1); }

.reader-page.dark-theme .reader-menu-btn {
    background: rgba(255, 255, 255, 0.06);
    color: #ddd;
}

.reader-page.dark-theme .reader-menu-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.reader-dropdown {
    position: absolute;
    top: 50px;
    right: 0;
    min-width: 180px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-md);
    padding: 6px;
    display: none;
    z-index: 200;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.reader-dropdown.active {
    display: block;
    animation: dropdownFade 0.2s ease;
}

@keyframes dropdownFade {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.reader-dropdown a {
    display: block;
    padding: 10px 14px;
    color: #333;
    border-radius: 8px;
    font-size: 14px;
    transition: background var(--transition);
}

.reader-dropdown a:hover { background: rgba(155, 92, 255, 0.08); }

.reader-page.dark-theme .reader-dropdown {
    background: #1a1a2e;
    border-color: #2a2a4a;
}

.reader-page.dark-theme .reader-dropdown a { color: #d0d0d0; }
.reader-page.dark-theme .reader-dropdown a:hover { background: rgba(155, 92, 255, 0.15); }

/* ================= PROGRESS ================= */
.reading-progress {
    position: fixed;
    top: 64px;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-dark));
    z-index: 999;
    transition: width 0.15s ease;
    box-shadow: 0 0 8px rgba(155, 92, 255, 0.5);
}

/* ================= CONTENT ================= */
.reader-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 88px 24px 120px;
}

.reader-page-content {
    width: 100%;
    font-size: 18px;
    line-height: 1.75;
    color: #333;
    touch-action: pan-y;
}

.reader-page.dark-theme .reader-page-content { color: #d0d0d0; }

.reader-page-content h1,
.page-chapter-title {
    margin: 0 0 24px;
    padding: 0;
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1.25;
    color: #222;
    font-weight: 700;
}

.reader-page.dark-theme .reader-page-content h1,
.reader-page.dark-theme .page-chapter-title { color: #e8e8e8; }

.reader-page-content p,
.reader-page-content .story p {
    margin: 0 0 1.2em;
    font-size: 18px;
    line-height: 1.75;
    color: #333;
}

.reader-page.dark-theme .reader-page-content p,
.reader-page.dark-theme .reader-page-content .story p { color: #d0d0d0; }

/* ================= RESPONSIVE ================= */
@media (max-width: 800px) {
    .reader-header { height: 56px; padding: 0 14px; }
    .reading-progress { top: 56px; }
    .reader-container { padding: 76px 16px 90px; }
    .reader-page-content { font-size: 17px; }
    .reader-page-content h1,
    .page-chapter-title { font-size: 22px; margin-bottom: 16px; }
    .reader-page-content p,
    .reader-page-content .story p { font-size: 17px; line-height: 1.7; }
    .reader-header-info strong { font-size: 14px; }
    .reader-header-info span { font-size: 12px; }
    .reader-back { font-size: 24px; }
    .reader-menu-btn { padding: 7px 12px; font-size: 18px; }
    .reader-dropdown { min-width: 160px; top: 44px; right: -4px; }
    .reader-dropdown a { font-size: 13px; padding: 8px 12px; }
}

@media (max-width: 650px) {
    .reader-page-content p { font-size: 17px; line-height: 1.75; }
    .reader-page-content h1,
    .page-chapter-title { font-size: 22px; margin-bottom: 16px; }
    .reader-header-info strong { font-size: 14px; }
    .reader-header-info span { font-size: 12px; }
}

@media (max-width: 480px) {
    .reader-container { padding: 68px 12px 84px; }
    .reader-page-content h1,
    .page-chapter-title { font-size: 20px; margin-bottom: 14px; }
    .reader-page-content p { font-size: 16px; line-height: 1.7; }
    .reader-header { padding: 0 10px; height: 50px; }
    .reading-progress { top: 50px; }
    .reader-header-info strong { font-size: 13px; }
    .reader-header-info span { font-size: 11px; }
    .reader-back { font-size: 22px; }
    .reader-menu-btn { padding: 6px 10px; font-size: 16px; }
    .reader-dropdown { min-width: 140px; top: 40px; padding: 4px; }
    .reader-dropdown a { font-size: 12px; padding: 7px 10px; }
}

@media (min-width: 1100px) {
    .reader-container { padding: 96px 40px 130px; }
    .reader-page-content { font-size: 19px; }
    .reader-page-content p,
    .reader-page-content .story p { font-size: 19px; line-height: 1.8; }
    .reader-page-content h1,
    .page-chapter-title { font-size: 36px; margin-bottom: 28px; }
}






/* ================= CHAPTER COMMENTS TRIGGER ================= */
.chapter-comments-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #2a2a2f; /* Matches the dark grey in screenshot */
    padding: 16px 20px;
    border-radius: 12px;
    margin: 40px 0 60px;
    cursor: pointer;
    transition: background 0.2s ease;
    color: #e8e8e8;
    border: 1px solid rgba(255,255,255,0.05);
}

.reader-page.dark-theme .chapter-comments-trigger {
    background: #1a1a20;
}

.chapter-comments-trigger:hover {
    background: #333338;
}

.reader-page.dark-theme .chapter-comments-trigger:hover {
    background: #22222a;
}

.comments-trigger-left {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    font-size: 15px;
}

.comments-trigger-left svg {
    width: 20px;
    height: 20px;
    opacity: 0.8;
}

.comments-trigger-right {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #a0a0a5;
    font-size: 14px;
}

/* ================= COMMENTS MODAL DRAWER ================= */
.comments-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.comments-modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.comments-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75vh; /* Slides up from bottom */
    background: #1e1e24;
    z-index: 2001;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
    color: #e8e8e8;
}

.reader-page:not(.dark-theme) .comments-modal {
    background: #ffffff;
    color: #222;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.15);
}

.comments-modal.active {
    transform: translateY(0);
}

.comments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.reader-page:not(.dark-theme) .comments-header {
    border-bottom-color: rgba(0,0,0,0.08);
}

.comments-header h2 {
    font-size: 18px;
    margin: 0;
    font-family: inherit;
}

.modal-comment-count {
    color: #a0a0a5;
    font-weight: 400;
}

.close-comments-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: #e8e8e8;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}

.reader-page:not(.dark-theme) .close-comments-btn {
    background: rgba(0,0,0,0.05);
    color: #222;
}

.close-comments-btn:hover { background: rgba(255,255,255,0.2); }
.reader-page:not(.dark-theme) .close-comments-btn:hover { background: rgba(0,0,0,0.1); }

.comments-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Comment Item */
.comment-item {
    display: flex;
    gap: 14px;
}

.comment-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.comment-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.comment-avatar-fallback {
    width: 100%;
    height: 100%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 15px;
}

.comment-content {
    flex: 1;
    min-width: 0;
}

.comment-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.comment-header strong {
    font-size: 14px;
    color: inherit;
}

.comment-date {
    font-size: 12px;
    color: #888;
}

.comment-content p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: #d0d0d5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; /* Override serif for UI */
}

.reader-page:not(.dark-theme) .comment-content p { color: #444; }

/* Input Area */
.comments-input-area {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: inherit;
    flex-shrink: 0;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.reader-page:not(.dark-theme) .comments-input-area { border-top-color: rgba(0,0,0,0.08); }

.comment-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 8px 8px 8px 16px;
}

.reader-page:not(.dark-theme) .comment-input-wrapper {
    background: #f4f4f5;
    border-color: rgba(0,0,0,0.1);
}

#commentInput {
    flex: 1;
    background: transparent;
    border: none;
    color: #e8e8e8;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    min-height: 24px;
    padding: 4px 0;
    outline: none;
}

.reader-page:not(.dark-theme) #commentInput { color: #222; }

.submit-comment-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: opacity 0.2s;
}

.submit-comment-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.comment-auth-message {
    text-align: center;
    font-size: 14px;
    color: #888;
    padding: 10px;
}

.comment-auth-message a {
    color: var(--accent);
    text-decoration: underline;
}

.comments-empty, .comments-loading {
    text-align: center;
    color: #888;
    font-size: 14px;
    padding: 40px 0;
}

/* Desktop adjustments */
@media (min-width: 768px) {
    .comments-modal {
        width: 500px;
        left: auto;
        right: 0;
        height: 100vh;
        border-radius: 0;
        transform: translateX(100%);
    }
    .comments-modal.active { transform: translateX(0); }
}








/* ================= LISTEN BUTTON ================= */
.reader-listen-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.06);
    color: #333;
    border: none;
    border-radius: 24px;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all var(--transition);
    margin-right: 8px;
}

.reader-listen-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

.reader-page.dark-theme .reader-listen-btn {
    background: rgba(255, 255, 255, 0.06);
    color: #ddd;
}

.reader-page.dark-theme .reader-listen-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Active (Playing) State */
.reader-listen-btn.active {
    background: var(--accent);
    color: #fff;
    animation: pulseListen 2s infinite;
}

@keyframes pulseListen {
    0% { box-shadow: 0 0 0 0 rgba(155, 92, 255, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(155, 92, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(155, 92, 255, 0); }
}

/* Responsive adjustments for mobile */
@media (max-width: 480px) {
    .reader-listen-btn {
        padding: 8px 12px;
        font-size: 13px;
    }
    /* Hide the word "Listen" on very small screens to save space, just show the icon */
    .reader-listen-btn span {
        display: none;
    }
    .reader-listen-btn.active span {
        display: inline; /* Show "Stop" when active so they know how to turn it off */
    }
}