/* ========================================
   BOOK READER PAGE STYLES
   Dark theme with comment system
   ======================================== */

/* Override body for book page */
body.book-page {
    background: #1a1a1a;
    padding: 0;
    display: flex;
    min-height: 100vh;
}

body.book-page::before,
body.book-page::after {
    display: none;
}

/* ========================================
   CHAPTER SIDEBAR
   ======================================== */

.chapter-sidebar {
    width: 280px;
    background: #111;
    border-right: 1px solid #333;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s ease;
}

.chapter-sidebar.hidden {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #333;
    position: sticky;
    top: 0;
    background: #111;
    z-index: 10;
}

.back-home {
    color: #d4af37;
    text-decoration: none;
    font-size: 0.9em;
    display: block;
    margin-bottom: 15px;
    transition: color 0.3s ease;
}

.back-home:hover {
    color: #f4cf57;
}

.sidebar-header h3 {
    color: #fff;
    font-size: 1.2em;
    margin: 0;
}

.chapter-list {
    padding: 10px 0;
}

.chapter-item {
    display: block;
    padding: 15px 20px;
    color: #aaa;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
    cursor: pointer;
}

.chapter-item:hover {
    background: #222;
    color: #fff;
    border-left-color: #d4af37;
}

.chapter-item.active {
    background: #222;
    color: #d4af37;
    border-left-color: #d4af37;
}

.chapter-item .chapter-number {
    font-size: 0.8em;
    color: #666;
    display: block;
    margin-bottom: 3px;
}

.chapter-item .chapter-title {
    font-weight: 600;
}

/* ========================================
   MAIN BOOK CONTENT
   ======================================== */

.book-main {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.book-main.sidebar-hidden {
    margin-left: 0;
}

/* ========================================
   BOOK HEADER
   ======================================== */

.book-header {
    background: #111;
    padding: 15px 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #333;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Ensure header actions have proper stacking */
.book-page .header-actions {
    position: relative;
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 15px;
}

.menu-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5em;
    cursor: pointer;
    padding: 5px 10px;
    display: none;
}

.book-title {
    color: #fff;
    font-size: 1.3em;
    font-weight: 600;
    margin: 0;
}

/* Sign In Button */
.sign-in-area {
    position: relative;
    z-index: 199;
}

.sign-in-btn {
    background: linear-gradient(135deg, #d4af37 0%, #c49b2c 100%);
    color: #111;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.sign-in-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.4);
}

/* ========================================
   LANGUAGE SWITCHER - BOOK PAGE OVERRIDE
   Complete standalone styles for dark theme
   ======================================== */

.book-page .language-switcher {
    position: relative;
    z-index: 300;
}

.book-page .language-btn {
    background: #222;
    color: #fff;
    border: 1px solid #444;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.book-page .language-btn:hover {
    background: #333;
    border-color: #555;
}

.book-page .language-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: #222;
    border: 1px solid #444;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 180px;
    max-height: 300px;
    display: none;
    z-index: 301;
}

.book-page .language-dropdown.active {
    display: block;
    animation: bookDropdownSlide 0.3s ease;
}

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

.book-page .language-option {
    padding: 12px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9em;
    color: #ccc;
}

.book-page .language-option:hover {
    background: #333;
    color: #fff;
}

.book-page .language-option.active {
    background: linear-gradient(135deg, #d4af37 0%, #c49b2c 100%);
    color: #111;
}

/* ========================================
   BOOK CONTENT AREA
   ======================================== */

.book-content {
    flex: 1;
    padding: 50px 60px 80px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.chapter-content {
    --chapter-body: 1.1em;
    --chapter-title: 3em;
    --chapter-subtitle: calc(var(--chapter-title) / 2);
    color: #ccc;
    font-size: var(--chapter-body);
    line-height: 1.9;
}

/* Chapter title: 2× body, bold */
.chapter-content h1 {
    color: #fff;
    font-size: var(--chapter-title);
    font-weight: 700;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px solid #d4af37;
}

/* Subtitles: half the chapter title size */
.chapter-content .paragraph.subtitle {
    font-size: var(--chapter-subtitle);
    font-weight: 700;
    color: #f0f0f0;
    text-indent: 0;
    margin-top: 32px;
    margin-bottom: 14px;
    line-height: 1.5;
}

.chapter-content h2 {
    color: #d4af37;
    font-size: 1.5em;
    margin: 30px 0 15px;
}

/* Clickable paragraphs for commenting */
.paragraph {
    margin-bottom: 30px;
    text-indent: 30px;
}

.paragraph.commentable {
    cursor: pointer;
    border-radius: 5px;
    padding: 10px 15px;
    margin-left: -15px;
    margin-right: -15px;
    transition: background 0.2s ease;
}

.paragraph.commentable:hover {
    background: rgba(212, 175, 55, 0.1);
}

/* Comment count bubble - inline at end of paragraph */
.paragraph.commentable.has-comments::after {
    content: attr(data-comment-count);
    background: #d4af37;
    color: #111;
    font-size: 0.7em;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
    margin-left: 8px;
    display: inline;
    vertical-align: middle;
}

.paragraph.commentable.selected {
    background: rgba(212, 175, 55, 0.2);
}

/* Comment icon for paragraphs without comments */
.paragraph.commentable:not(.has-comments)::after {
    content: '💬';
    font-size: 0.8em;
    margin-left: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
    display: inline;
    vertical-align: middle;
}

.paragraph.commentable:not(.has-comments):hover::after {
    opacity: 0.6;
}

/* ========================================
   COMMENTS PANEL
   ======================================== */

.comments-panel {
    width: 350px;
    background: #111;
    border-left: 1px solid #333;
    height: 100vh;
    position: fixed;
    right: -350px;
    top: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: right 0.3s ease;
}

.comments-panel.active {
    right: 0;
}

.comments-header {
    padding: 20px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.comments-header h3 {
    color: #fff;
    margin: 0;
    font-size: 1.1em;
}

.close-comments {
    background: none;
    border: none;
    color: #666;
    font-size: 1.5em;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close-comments:hover {
    color: #fff;
}

/* Comments List */
.comments-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #111;
}

.comment {
    background: transparent;
    border-radius: 0;
    padding: 12px 0;
    margin-bottom: 0;
    border-bottom: 1px solid #222;
}

.comment:last-child {
    border-bottom: none;
}

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

.comment-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #d4af37;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #111;
    font-weight: 600;
    flex-shrink: 0;
}

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

.comment-author {
    flex: 1;
}

.comment-author .name {
    color: #fff;
    font-weight: 600;
    font-size: 0.95em;
}

.comment-author .time {
    color: #666;
    font-size: 0.8em;
}

.comment-text {
    color: #ccc;
    font-size: 0.95em;
    line-height: 1.6;
    margin-bottom: 10px;
}

.comment-actions {
    display: flex;
    gap: 15px;
}

.comment-action {
    background: none;
    border: none;
    color: #666;
    font-size: 0.85em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: color 0.3s ease;
}

.comment-action:hover {
    color: #d4af37;
}

.comment-action.liked {
    color: #e74c3c;
}

/* Comment thread container */
.comment-thread {
    margin-bottom: 15px;
}

/* Reply styling */
.comment.reply {
    margin-left: 45px;
    padding: 10px 0;
    border-left: none;
}

.comment.reply .comment-avatar.small {
    width: 28px;
    height: 28px;
    font-size: 0.8em;
}

/* Replies toggle */
.replies-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 45px;
    padding: 8px 0;
    cursor: pointer;
    color: #888;
    font-size: 0.85em;
}

.replies-toggle:hover {
    color: #d4af37;
}

.toggle-line {
    width: 25px;
    height: 1px;
    background: #444;
}

.toggle-text {
    font-weight: 500;
}

/* Replies container */
.replies-container {
    margin-top: 5px;
}

/* Comment meta inline */
.comment-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 2px;
    font-size: 0.8em;
    color: #888;
}

.comment-meta .time {
    color: #666;
}

.comment-meta .likes-count {
    color: #888;
}

.comment-action-inline {
    background: none;
    border: none;
    color: #888;
    font-size: 0.85em;
    cursor: pointer;
    padding: 0;
    font-weight: 500;
}

.comment-action-inline:hover {
    color: #d4af37;
}

.comment-action-inline.delete-btn {
    margin-left: auto;
}

.comment-action-inline.delete-btn:hover {
    color: #e74c3c;
}

/* Heart like button */
.like-btn-heart {
    background: none;
    border: none;
    font-size: 1.1em;
    cursor: pointer;
    padding: 5px;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.like-btn-heart:hover {
    opacity: 1;
    transform: scale(1.1);
}

.like-btn-heart.liked {
    opacity: 1;
}

/* Mention highlight */
.mention {
    color: #d4af37;
    font-weight: 500;
}

/* Reply indicator */
.reply-indicator {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a1a1a;
    padding: 8px 12px;
    border-radius: 8px 8px 0 0;
    margin-bottom: -1px;
    font-size: 0.85em;
    color: #888;
}

.reply-indicator strong {
    color: #d4af37;
}

.cancel-reply {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1em;
    padding: 2px 6px;
}

.cancel-reply:hover {
    color: #e74c3c;
}

.comment-header {
    position: relative;
}

/* Comment Form */
.comment-form {
    padding: 15px;
    border-top: 1px solid #333;
}

.sign-in-prompt {
    text-align: center;
    padding: 10px;
}

.sign-in-prompt p {
    color: #888;
    margin-bottom: 15px;
    font-size: 0.9em;
}

.google-sign-in {
    background: #fff;
    color: #333;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
}

.google-sign-in:hover {
    background: #f5f5f5;
    transform: translateY(-2px);
}

.google-sign-in.large {
    padding: 15px 30px;
    font-size: 1em;
}

.comment-input-area textarea {
    width: 100%;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 12px;
    color: #fff;
    font-size: 0.95em;
    resize: none;
    height: 80px;
    margin-bottom: 10px;
}

.comment-input-area textarea:focus {
    outline: none;
    border-color: #d4af37;
}

.submit-comment {
    background: #d4af37;
    color: #111;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.3s ease;
}

.submit-comment:hover {
    background: #e5c048;
}

/* See More Comments */
.see-more-comments {
    padding: 15px;
    text-align: center;
    border-top: 1px solid #333;
}

.see-more-comments a {
    color: #d4af37;
    text-decoration: none;
    font-size: 0.9em;
}

.see-more-comments a:hover {
    text-decoration: underline;
}

/* ========================================
   SIGN IN MODAL
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #222;
    border-radius: 15px;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: #666;
    font-size: 1.5em;
    cursor: pointer;
}

.modal-close:hover {
    color: #fff;
}

.modal-content h2 {
    color: #fff;
    margin-bottom: 15px;
}

.modal-content p {
    color: #888;
    margin-bottom: 25px;
}

/* ========================================
   USER SIGNED IN STATE
   ======================================== */

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
}

.user-name {
    color: #fff;
    font-weight: 600;
}

.sign-out-btn {
    background: #333;
    color: #fff;
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.85em;
    cursor: pointer;
}

.sign-out-btn:hover {
    background: #444;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 1200px) {
    .book-main.comments-open {
        margin-right: 350px;
    }
}

@media (max-width: 992px) {
    .chapter-sidebar {
        transform: translateX(-100%);
    }

    .chapter-sidebar.active {
        transform: translateX(0);
    }

    .book-main {
        margin-left: 0;
    }

    .menu-btn {
        display: block;
    }

    .comments-panel {
        width: 100%;
        right: -100%;
    }
}

@media (max-width: 768px) {
    .book-header {
        padding: 10px 15px;
    }

    .book-title {
        font-size: 1em;
    }

    .book-content {
        padding: 20px;
    }

    .chapter-content {
        --chapter-body: 1em;
        --chapter-title: 2.5em;
        --chapter-subtitle: calc(var(--chapter-title) / 2);
        font-size: var(--chapter-body);
    }

    .chapter-content h1 {
        font-weight: 700;
    }

    .chapter-content .paragraph.subtitle {
        font-weight: 700;
    }

    .sign-in-btn span {
        display: none;
    }

    .sign-in-btn::before {
        content: '👤';
    }

    .header-actions {
        gap: 10px;
    }
}

/* RTL Support */
body.rtl.book-page .chapter-sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid #333;
}

body.rtl.book-page .chapter-sidebar.hidden {
    transform: translateX(100%);
}

body.rtl.book-page .book-main {
    margin-left: 0;
    margin-right: 280px;
}

body.rtl.book-page .book-main.sidebar-hidden {
    margin-right: 0;
}

body.rtl.book-page .comments-panel {
    right: auto;
    left: -350px;
    border-left: none;
    border-right: 1px solid #333;
}

body.rtl.book-page .comments-panel.active {
    left: 0;
}

body.rtl.book-page .chapter-item {
    border-left: none;
    border-right: 3px solid transparent;
}

body.rtl.book-page .chapter-item:hover,
body.rtl.book-page .chapter-item.active {
    border-right-color: #d4af37;
}

body.rtl.book-page .paragraph {
    text-indent: 0;
}

/* =========================================================
   FIX v3: Language dropdown layering on Book page
   Problem: dropdown appears but is rendered beneath other
   dark/sticky elements (looks like it's "hiding" under the
   black background). This forces the header + dropdown to
   sit above sidebar/content stacks and prevents clipping.
   ========================================================= */

/* Keep header above sidebar/content stacks */
.book-page .book-header{
  z-index: 600;
  overflow: visible;
}

/* Header actions + switcher should not clip dropdown */
.book-page .header-actions,
.book-page .language-switcher{
  overflow: visible;
}

/* Sidebar should not cover header dropdown */
.book-page .chapter-sidebar{
  z-index: 200;
}

/* Make dropdown always float above everything (except modal) */
.book-page .language-dropdown{
  z-index: 5000;
  max-height: min(70vh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Alignment: keep inline next to Sign In */
.book-page .book-header .language-switcher{
  position: relative;
  top: 0;
  right: auto;
  left: auto;
  margin: 0;
}
