/* ==========================================
   章节阅读页样式 v2.0
   功能：背景切换、夜间模式、听书、滚动、书签、段评
   配色参考起点中文网
========================================== */

/* -------------------- 基础布局 -------------------- */
.chapter-reader-v2 {
    background: #E5E1D6;         /* 外层背景（起点页面背景） */
    min-height: 100vh;
    transition: background 0.3s;
}
.reader-main {
    max-width: 860px;
    margin: 0 auto;
    background: #F5F1E8;         /* 阅读区背景（起点正文背景） */
    border-radius: 12px;
    padding: 2rem 3rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 2rem;
}
.reader-content-wrapper {
    position: relative;
}

/* -------------------- 背景色方案（通过JS动态添加class） -------------------- */
.bg-ivory { background: #fefaf0; }
.bg-green { background: #fef9e8; }            /* 护眼绿（实际为起点米黄） */
.bg-parchment { background: #f9f1e0; }        /* 羊皮纸 */
.bg-gray { background: #2d2d2d; }             /* 深灰 */
.bg-blue { background: #e3f0f9; }             /* 浅蓝 */
.bg-dark { background: #1a1a2e; }             /* 暗夜黑 */

/* 当使用背景色class时，覆盖阅读区背景 */
.bg-ivory .reader-main,
.bg-green .reader-main,
.bg-parchment .reader-main,
.bg-gray .reader-main,
.bg-blue .reader-main,
.bg-dark .reader-main {
    background: transparent;  /* 让阅读区背景与容器一致 */
    box-shadow: none;
    padding: 2rem 3rem;
}

/* 夜间模式（独立于背景色） */
body.reader-dark .chapter-reader-v2 {
    background: #1a1a2e;
}
body.reader-dark .reader-main {
    background: #2a2a3a;
}
body.reader-dark .chapter-content {
    color: #e2e2e2;
}

/* -------------------- 头部导航 -------------------- */
.reader-header {
    position: sticky;
    top: 0;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #e5e7eb;
    padding: 0.8rem 0;
    z-index: 100;
}
body.reader-dark .reader-header {
    background: #16213e;
    border-bottom-color: #2a2a3a;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    max-width: 860px;
    margin: 0 auto;
    padding: 0 1rem;
}
.back-to-novel {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: #8b5a2b;
    text-decoration: none;
    font-size: 0.9rem;
}
.back-to-novel:hover {
    color: #6e451f;
}
.reader-title {
    text-align: center;
}
.reader-title h1 {
    font-size: 1.3rem;
    margin: 0;
    font-weight: 500;
    font-family: var(--font-serif, 'Noto Serif SC', serif);
    color: #1E170E;
}
.novel-name {
    font-size: 0.8rem;
    color: #6c757d;
}
.reader-tools {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.tool-btn {
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}
.tool-btn:hover {
    background: #f3f4f6;
}
body.reader-dark .tool-btn {
    color: #e2e2e2;
    border-color: #4a5568;
}
body.reader-dark .tool-btn:hover {
    background: #2a2a3a;
}

/* 背景选择器下拉菜单 */
.bg-selector {
    position: relative;
}
.bg-options {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 0.5rem;
    z-index: 101;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    min-width: 140px;
}
.bg-options.show {
    display: block;
}
.bg-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.4rem 0.8rem;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.8rem;
}
.bg-option:hover {
    background: #f0f0f0;
}
body.reader-dark .bg-options {
    background: #16213e;
    border-color: #2a2a3a;
}
body.reader-dark .bg-option:hover {
    background: #2a2a3a;
}

/* -------------------- 听书控制栏 -------------------- */
.tts-controls {
    position: sticky;
    top: 70px;
    max-width: 860px;
    margin: 0 auto 1rem auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 40px;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 99;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
body.reader-dark .tts-controls {
    background: #16213e;
    border-color: #2a2a3a;
}
.tts-info {
    font-size: 0.85rem;
    color: #4b5563;
}
body.reader-dark .tts-info {
    color: #9ca3af;
}
.tts-buttons {
    display: flex;
    gap: 0.5rem;
}
.tts-btn {
    background: #f3f4f6;
    border: none;
    border-radius: 20px;
    padding: 0.2rem 0.8rem;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}
.tts-btn:hover {
    background: #e5e7eb;
}
body.reader-dark .tts-btn {
    background: #2a2a3a;
    color: #e2e2e2;
}
body.reader-dark .tts-btn:hover {
    background: #3a3a4a;
}

/* -------------------- 滚动阅读控制栏 -------------------- */
.scroll-controls {
    position: sticky;
    bottom: 20px;
    left: 20px;
    background: rgba(255,255,255,0.95);
    border-radius: 40px;
    padding: 0.4rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    z-index: 99;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 0.8rem;
}
.scroll-controls button {
    background: #2c3e2f;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
}
.scroll-controls button:hover {
    background: #1f2a1f;
}
.speed-control {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.speed-control input {
    width: 60px;
}

/* -------------------- 书签侧边栏 -------------------- */
.bookmark-sidebar {
    position: fixed;
    top: 80px;
    right: 20px;
    width: 300px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    padding: 1rem;
    max-height: 70vh;
    overflow-y: auto;
}
body.reader-dark .bookmark-sidebar {
    background: #2a2a3a;
    color: #e2e2e2;
}
.bookmark-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
}
.bookmark-header h3 {
    margin: 0;
    font-size: 1.1rem;
}
.close-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #6c757d;
}
.bookmark-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.bookmark-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f0f0f0;
}
.bookmark-list li a {
    text-decoration: none;
    color: #2c3e2f;
    flex: 1;
}
.bookmark-list li a:hover {
    color: #8b5a2b;
}
.bookmark-date {
    font-size: 0.7rem;
    color: #9ca3af;
    display: block;
}
.remove-bookmark {
    background: #f0f0f0;
    border: none;
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    font-size: 0.7rem;
}
.bookmark-add {
    margin-top: 1rem;
    text-align: center;
}
.btn-add-bookmark {
    background: #8b5a2b;
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 0.4rem 1rem;
    cursor: pointer;
}

/* -------------------- 正文样式（起点风格） -------------------- */
.chapter-content {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 18px;
    line-height: 1.75;
    color: #1E170E;
}
.paragraph-wrapper {
    margin-bottom: 1.5rem;
}
.paragraph-content p {
    margin-bottom: 1.2em;
    text-indent: 2em;
}
.paragraph-content p:last-child {
    margin-bottom: 0;
}

/* 戏曲特殊标记 */
.chapter-content [外扮], .chapter-content [正旦扮], .chapter-content [正末扮] {
    font-weight: bold;
    color: #8b5a2b;
    display: inline-block;
    margin-top: 0.5rem;
}
.chapter-content .科 {
    color: #6c757d;
    font-style: normal;
}
.chapter-content [唱] {
    font-style: italic;
    color: #8b5a2b;
}

/* -------------------- 段落评论按钮（跟随段落末尾） -------------------- */
.paragraph-comment-btn {
    display: inline-block;
    background: #e9ecef;
    border-radius: 16px;
    padding: 0.1rem 0.6rem;
    font-size: 0.75rem;
    margin-left: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.6;
    vertical-align: middle;
}
.paragraph-wrapper:hover .paragraph-comment-btn {
    opacity: 1;
    background: #e0a800;
    color: #fff;
}

/* 深色背景下的段落评论按钮 */
.bg-gray .paragraph-comment-btn,
.bg-dark .paragraph-comment-btn,
body.reader-dark .paragraph-comment-btn {
    background: #3a3a4a;
    color: #ccc;
}
.bg-gray .paragraph-wrapper:hover .paragraph-comment-btn,
.bg-dark .paragraph-wrapper:hover .paragraph-comment-btn,
body.reader-dark .paragraph-wrapper:hover .paragraph-comment-btn {
    background: #e0a800;
    color: #fff;
}

/* -------------------- 右侧评论侧边栏（段评） -------------------- */
.paragraph-comment-sidebar {
    position: fixed;
    top: 0;
    right: -380px;
    width: 380px;
    height: 100%;
    background: #F5F1E8;
    box-shadow: -2px 0 8px rgba(0,0,0,0.1);
    z-index: 1000;
    transition: right 0.3s;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.paragraph-comment-sidebar.active {
    right: 0;
}
.sidebar-header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.comment-list-container {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}
.comment-form-container {
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}
.comment-form-container textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 8px;
}
.submit-btn {
    margin-top: 0.5rem;
    background: #8b5a2b;
    color: #fff;
    border: none;
    padding: 0.3rem 1rem;
    border-radius: 20px;
    cursor: pointer;
}
/* 评论列表项 */
.comment-item {
    background: #fff;
    border: 1px solid #edf2f7;
    border-radius: 12px;
    padding: 0.8rem;
    margin-bottom: 0.8rem;
}
.comment-avatar img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    float: left;
    margin-right: 0.8rem;
}
.comment-content {
    overflow: hidden;
}
.comment-author {
    font-weight: 600;
    color: #1a202c;
    font-size: 0.9rem;
}
.comment-time {
    font-size: 0.7rem;
    color: #9ca3af;
    margin: 0.2rem 0;
}
.comment-text {
    color: #2d3748;
    line-height: 1.5;
    margin: 0.4rem 0;
}
.comment-actions {
    margin-top: 0.3rem;
}
.comment-like, .comment-reply {
    background: none;
    border: none;
    color: #6c757d;
    font-size: 0.75rem;
    cursor: pointer;
    margin-right: 0.8rem;
}
.comment-like:hover, .comment-reply:hover {
    color: #8b5a2b;
}
.comment-replies {
    margin-top: 0.5rem;
    padding-left: 1rem;
    border-left: 2px solid #e2e8f0;
}
.reply-item {
    margin-top: 0.5rem;
    font-size: 0.85rem;
}
.reply-author {
    font-weight: 500;
    display: inline;
}
.reply-text {
    display: inline;
}
.reply-form {
    margin-top: 0.5rem;
}
.reply-form textarea {
    width: 100%;
    padding: 0.4rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.8rem;
}
.submit-reply {
    margin-top: 0.3rem;
    background: #8b5a2b;
    color: #fff;
    border: none;
    padding: 0.2rem 0.8rem;
    border-radius: 20px;
    cursor: pointer;
}
.no-comments {
    color: #9ca3af;
    text-align: center;
    padding: 1rem;
}

/* -------------------- 阅读进度 -------------------- */
.reading-progress {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(255,255,255,0.9);
    border-radius: 30px;
    padding: 0.3rem 0.8rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 99;
}
body.reader-dark .reading-progress {
    background: #2a2a3a;
    color: #e2e2e2;
}
.progress-bar {
    width: 60px;
    height: 3px;
    background: #8b5a2b;
    border-radius: 2px;
}
/* 深色背景下的进度条 */
.bg-gray .progress-bar,
.bg-dark .progress-bar {
    background: #e0a800;
}

/* -------------------- 章节导航 -------------------- */
.chapter-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e5e7eb;
    flex-wrap: wrap;
}
.chapter-navigation a {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: #f5f0e6;
    border-radius: 40px;
    text-decoration: none;
    color: #2c3e2f;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.chapter-navigation a:hover {
    background: #e8e0d0;
    transform: translateY(-1px);
}
body.reader-dark .chapter-navigation a {
    background: #2a2a3a;
    color: #e2e2e2;
}
body.reader-dark .chapter-navigation a:hover {
    background: #3a3a4a;
}
.nav-disabled {
    padding: 0.6rem 1.2rem;
    background: #f0f0f0;
    border-radius: 40px;
    color: #aaa;
    font-size: 0.85rem;
}

/* -------------------- 返回顶部按钮 -------------------- */
.back-to-top {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: #2c3e2f;
    color: #fff;
    border: none;
    border-radius: 40px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.8rem;
    z-index: 99;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.2s;
}
.back-to-top:hover {
    background: #1f2a1f;
    transform: translateY(-2px);
}
body.reader-dark .back-to-top {
    background: #2a2a3a;
}
body.reader-dark .back-to-top:hover {
    background: #3a3a4a;
}

/* -------------------- 移动端适配 -------------------- */
@media (max-width: 768px) {
    .reader-main {
        padding: 1rem 1.5rem !important;
        max-width: 100% !important;
    }
    .chapter-content {
        font-size: 16px;
    }
    .paragraph-comment-btn {
        margin-left: 0.3rem;
        font-size: 0.7rem;
        padding: 0.05rem 0.4rem;
    }
    .paragraph-comment-sidebar {
        width: 100%;
        right: -100%;
    }
    .bookmark-sidebar {
        width: 260px;
        right: 10px;
        top: 70px;
    }
    .scroll-controls {
        left: 10px;
        bottom: 10px;
        padding: 0.3rem 0.8rem;
    }
    .scroll-controls .speed-control {
        display: none;
    }
    .scroll-controls .speed-control.active {
        display: flex;
    }
    .tts-controls {
        top: 70px;
        margin: 0 1rem 1rem 1rem;
    }
}

/* 段落内的评论按钮（行内显示） */
.paragraph-content .inline-comment {
    display: inline-block;
    margin-left: 8px;
    font-size: 0.75rem;
    background: #e9ecef;
    border-radius: 16px;
    padding: 0 6px;
    line-height: 1.4;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    vertical-align: middle;
}
.paragraph-content .inline-comment:hover {
    opacity: 1;
    background: #e0a800;
    color: #fff;
}
/* 移除原来的绝对定位样式 */
.paragraph-comment-btn {
    /* 原来的绝对定位样式已失效，不再需要 */
}
/* 调整段落包装器，移除之前预留的右侧内边距 */
.paragraph-wrapper {
    position: relative;
    margin-bottom: 1.2rem;
    /* 移除 padding-right，因为按钮在内容内部 */
    padding-right: 0;
}

/* 评分样式 */
.novel-rating {
    margin: 1rem 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.rating-stars {
    position: relative;
    display: inline-block;
    font-size: 1.2rem;
    letter-spacing: 2px;
    color: #ddd;
    cursor: pointer;
}
.stars-display {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--width, 0%);
    overflow: hidden;
    white-space: nowrap;
    color: #ffc107;
    pointer-events: none;
}
.star-selector span {
    display: inline-block;
    transition: color 0.1s;
}
.star-selector span.active {
    color: #ffc107;
}
.rating-info {
    font-size: 0.85rem;
    color: #6c757d;
}
.rating-tip {
    margin-left: 0.5rem;
    font-size: 0.75rem;
    color: #999;
}
.rating-tip a {
    color: #8b5a2b;
}

.chapter-images {
    margin-top: 2rem;
    text-align: center;
}
.chapter-image {
    max-width: 100%;
    height: auto;
    margin: 1rem auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}