/* 核心变量 */
:root {
    --bg-color: #f2e9d2; --text-color: #3e2e1e; --accent-color: #8b572a;
    --card-bg: rgba(255, 255, 255, 0.9); --border-color: rgba(62, 46, 30, 0.1);
}
body.theme-white { --bg-color: #f5f5f5; --text-color: #444; --accent-color: #555; --card-bg: #fff; --border-color: #ddd; }
body.theme-green { --bg-color: #d8e6d8; --text-color: #2c3e2c; --accent-color: #4a7c4a; --card-bg: rgba(255, 255, 255, 0.8); --border-color: rgba(0, 0, 0, 0.05); }
body.theme-night { --bg-color: #1e2327; --text-color: #a0aab5; --accent-color: #d4a76a; --card-bg: #2a3137; --border-color: #38424a; }

*{
    box-sizing: border-box;
}

html, body {
    /* 禁用某些浏览器的触控缩放手势 */
    touch-action: manipulation;
    overflow-x: hidden;
}

body, html { margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden; background-color: var(--bg-color); color: var(--text-color); font-family: "PingFang SC", serif; transition: background 0.3s; }

#reader-viewport { width: 100%; height: 100%; position: relative; overflow: hidden; }


/* 修改内容层边距，给顶部标题留出空间 */
#content-layer {
    height: calc(100% - 80px); /* 稍微调高底部，留出更多呼吸感 */
    margin: 40px 0 20px 0; /* 增加顶部 margin (40px) 避开固定标题 */
    /* 其他保持不变 */
    padding: 0 20px;
    box-sizing: border-box;
    column-width: calc(100vw - 40px);
    column-gap: 40px;
    column-fill: auto;
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    text-align: justify;
    max-height: 100%;
}

#reader-viewport, .read-container {
    background-color: var(--bg-color); /* 确保背景色显现 */
}

#content-layer h1 { font-size: 24px; margin: 0 0 20px 0; column-span: all; color: var(--accent-color); }
#content-layer p { margin: 0 0 1.2em 0; text-indent: 2em; line-height: 1.8; font-size: 19px; }

#touch-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; z-index: 10; }
.touch-zone { position: absolute; height: 100%; top: 0; z-index: 10; }
.prev-zone { left: 0; width: 30%; }
.menu-zone { left: 30%; width: 40%; }
.next-zone { left: 70%; width: 30%; }

.ui-panel { position: fixed; background: var(--card-bg); backdrop-filter: blur(15px); transition: all 0.3s ease; z-index: 100; border: 1px solid var(--border-color); }

/* 激活状态 */
.ui-panel.active {
    transform: translateY(0);
}

/* 专门针对目录列表的滚动容器 */
.toc-list {
    /*height: 80vh; !* 给一个固定高度 *!*/
    overflow-y: auto;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.toc-item.active {
    color: var(--accent-color, #d32f2f); /* 使用你的主题色 */
    background-color: rgba(0,0,0,0.05);  /* 淡淡的背景色 */
    font-weight: bold;
}

#top-nav { top: -60px;  width: 100%; height: 50px; display: flex; align-items: center; padding: 0 15px; box-sizing: border-box; border-radius: 0; }
#top-nav.active { top: 0; }
.back-btn { text-decoration: none; color: var(--accent-color); font-size: 14px; font-weight: bold; }

#settings-menu { bottom: -1500px;  width: 100%; padding: 25px 20px 40px; box-sizing: border-box; border-radius: 24px 24px 0 0; }
#settings-menu.active { bottom: 0; }

.menu-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.row-label { font-size: 15px; opacity: 0.8; min-width: 70px; }

.theme-dots { display: flex; flex-direction: row; gap: 12px; }
.dot { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-color); cursor: pointer; box-sizing: border-box; }

.btn-group { display: flex; gap: 8px; flex: 1; margin-left: 10px; justify-content: flex-end; }
.action-btn {
    padding: 5px 0; border-radius: 8px; border: 1px solid var(--border-color);
    background: rgba(255,255,255,0.5); color: var(--text-color);
    cursor: pointer; font-size: 13px; white-space: nowrap; flex: 1; text-align: center;
}
.action-btn.active { background: var(--accent-color); color: #fff; border-color: var(--accent-color); }
body.theme-night .action-btn { background: #252a2f; color: #a0aab5; }

/* 自动翻页滑块 */
.auto-config { display: flex; align-items: center; gap: 10px; flex: 1; margin-left: 10px; }
input[type=range] { flex: 1; accent-color: var(--accent-color); cursor: pointer; }


.toc-header { font-size: 18px; font-weight: bold; margin-bottom: 20px; color: var(--accent-color); display: flex; justify-content: space-between; }
.toc-item { padding: 15px 0; border-bottom: 1px solid var(--border-color); font-size: 15px; color: var(--text-color); cursor: pointer; display: block; text-decoration: none; }

#page-info { position: absolute; bottom: 10px; width: 100%; text-align: center; font-size: 11px; opacity: 0.4; z-index: 5; pointer-events: none; }

@media screen and (min-width: 800px) {
    #reader-viewport, #settings-menu, #top-nav,#toc-panel { max-width: 800px; left: 50%; transform: translateX(-50%); }
    #content-layer { column-width: 760px; }
}

/* 固定标题样式 */
/* 固定标题样式 - 溢出处理 */
#fixed-book-title {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 40px;
    line-height: 40px;  /* 改为40px与高度一致 */
    text-align: center;
    font-size: 12px;
    opacity: 0.5;
    z-index: 5;
    pointer-events: none;
    letter-spacing: 1px;
    /* 新增溢出处理 */
    white-space: nowrap;      /* 强制单行显示 */
    overflow: hidden;         /* 隐藏溢出内容 */
    text-overflow: ellipsis;  /* 显示省略号 */
    padding: 0 20px;          /* 左右留白，避免贴边 */
    box-sizing: border-box;
}

/* 针对没有章节时的长标题链接样式 */
.btn-group-vertical {
    display: flex;
    flex-direction: column; /* 强制上下排列 */
    gap: 12px;
    width: 100%;
}

.page-a {
    display: block; /* 块级化 */
    width: 100%;
    height: auto;   /* 高度自适应，允许长标题折行或单行 */
    min-height: 40px;
    line-height: 1.5; /* 调整行高，适合多行标题 */
    padding: 10px 15px; /* 增加内边距 */
    text-align: left;  /* 标题长，靠左对齐更好看 */
    background: var(--card-bg); /* 使用已有的变量 */
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    text-decoration: none;
    box-sizing: border-box;
    transition: opacity 0.2s;
}

.page-a:active {
    opacity: 0.7;
    background: var(--accent-color);
    color: #fff;
}

/* 高亮遮罩层 */
#read-highlight-sync {
    position: absolute;
    background-color: var(--accent-color); /* 使用你主题的强调色 */
    opacity: 0.15; /* 极低透明度，只是一层淡淡的背景 */
    pointer-events: none; /* 确保不影响点击翻页 */
    z-index: 1;
    border-radius: 4px;
    transition: all 0.2s ease; /* 让高亮切换时有个小动画 */

    mix-blend-mode: multiply; /* 推荐：这样可以让高亮颜色与文字背景融合，不遮挡文字 */
}

/* 如果你想让不同主题的高亮颜色不同，可以在你的主题样式里定义变量 */
.theme-night #read-highlight-sync { background-color: #ff9800; opacity: 0.1; }
.theme-green #read-highlight-sync { background-color: #2e7d32; opacity: 0.2; }

/* 章节导航支持多行 */
.chapter-nav {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

/* 左右按钮：允许换行 */
.chapter-nav .action-btn {
    flex: 1;
    min-width: 0;

    white-space: normal;        /* ✅ 允许换行 */
    word-break: break-all;      /* ✅ 中文长句强制换行 */
    line-height: 1.4;

    padding: 8px 10px;
}

/* 中间目录按钮 */
.chapter-nav .action-btn:nth-child(2) {
    flex: 0 0 70px;
    white-space: nowrap;        /* 目录保持单行 */
}

.no-transition {
    transition: none !important;
}

/* 美化速度下拉框 */
#voice-speed {
    appearance: none;       /* 移除原生样式 */
    -webkit-appearance: none;

    flex: 1;
    padding: 8px 35px 8px 15px; /* 右侧留出空间放箭头 */
    font-size: 14px;
    color: var(--text-color);
    background-color: var(--card-bg);

    border: 1px solid var(--border-color);
    border-radius: 12px;     /* 与按钮一致的圆角 */

    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;

    /* 自定义下拉箭头图标 (SVG) */

    background-repeat: no-repeat;
    background-position: calc(100% - 12px) center;

    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

#voice-speed:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(139, 87, 42, 0.1);
}

/* --- 阅读页设置菜单书架按钮增量 --- */
.shelf-bar-mini {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.03);
    padding: 12px 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.shelf-book-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 60%;
}

.shelf-label {
    font-size: 10px;
    opacity: 0.5;
    letter-spacing: 1px;
}

.shelf-title {
    font-size: 14px;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-color);
}

.shelf-action-btn {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    outline: none;
    white-space: nowrap;
}

/* 激活状态：实心主题色 */
.shelf-action-btn.active {
    background: var(--accent-color);
    color: #fff !important;
    border-color: transparent;
}

/* 点击反馈 */
.shelf-action-btn:active {
    transform: scale(0.95);
}

/* 夜间模式适配：让背景稍微亮一点突出层次 */
body.theme-night .shelf-bar-mini {
    background: rgba(255, 255, 255, 0.04);
}

/* 兼容性修复：确保设置菜单不会因为内容增多而被底部遮挡 */
#settings-menu {
    /*max-height: 90vh;*/
    overflow-y: auto;
}

/* 确保内容层使用平滑过渡（可选） */
#content-layer p {
    /* 移除固定的 19px，或者将其作为初始值 */
    transition: font-size 0.2s ease;
}

/* 针对移动端的微调：确保字号改变后分栏依然准确 */
#content-layer {
    column-fill: auto;
}

.action-btn {
    min-width: 40px; /* 保证 A- A+ 是正方形感 */
    width: auto;     /* 允许按钮根据文字撑开 */
    /* 其他现有样式保持不变 */
}

/* 进度条整行容器 */
.setting-row-progress {
    display: flex;
    align-items: flex-start; /* 顶部对齐，给多行文字留空间 */
    gap: 15px;
    margin-bottom: 25px;
}

/* 左侧“进度”标签 */
.setting-row-progress .row-label {
    font-size: 14px;
    opacity: 0.8;
    padding-top: 5px; /* 对齐滑块中心 */
    min-width: 35px;
}

/* 右侧内容区：包含进度条和文字 */
.progress-main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 滑块包装器：控制轨道样式 */
.progress-slider-wrapper {
    width: 100%;
    display: flex;
    align-items: center;
}

/* 进度条本体 */
#reader-progress {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 10px;
    background: var(--border-color); /* 随主题变色 */
    outline: none;
    /* 进度条已填充部分颜色：随主题强调色 */
    background-image: linear-gradient(var(--accent-color), var(--accent-color));
    background-repeat: no-repeat;
    background-size: 0% 100%;
}

/* 进度条滑块按钮 (Thumb) */
#reader-progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-color);
    border: 2px solid var(--card-bg); /* 白色描边感 */
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: transform 0.1s;
}

#reader-progress::-webkit-slider-thumb:active {
    transform: scale(1.2);
}

/* 页码和百分比文字区域 */
.progress-info-text {
    display: flex;
    flex-direction: row;
    justify-content: space-between; /* 关键：让子元素一个靠左，一个靠右 */
    align-items: center;
    width: 100%; /* 确保撑满父容器宽度 */
    margin-top: 4px;
}

#progress-pages {
    font-size: 10px;
    color: var(--text-color);
    opacity: 0.6;
}

#progress-percent {
    font-size: 14px;
    color: var(--text-color);
    opacity: 0.6;
}

/* 夜间模式微调 */
body.theme-night #progress-pages,
body.theme-night #progress-percent {
    color: var(--text-color);
}

/* 关闭设置按钮的动效 */
.close-settings-btn {
    transition: transform 0.2s, opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.close-settings-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* 如果想加个图标感，可以在文字前加个符号，例如 ✓ */
.close-settings-btn::before {
    content: "✓";
    font-size: 16px;
}

/* 1. 面板容器：强制设为 flex 布局，禁止自身滚动 */
#toc-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 85vh; /* 必须给固定高度 */
    background: var(--bg-color);
    z-index: 1000;
    display: flex;
    flex-direction: column; /* 纵向排列子元素 */
    overflow: hidden !important; /* 关键：面板本身绝对不允许滚动 */
    border-radius: 20px 20px 0 0;
    transition: transform 0.3s ease;
    transform: translateY(100%);
    padding: 10px;
}

#toc-panel.active {
    transform: translateY(0);
}

/* 2. 固定头部：包裹了标题和按钮 */
.toc-fixed-header {
    flex-shrink: 0; /* 禁止被压缩 */
    position: relative;
    padding: 15px 0;
    background: var(--bg-color); /* 确保背景不透明，挡住下方的文字 */
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

/* 3. 按钮定位 */
.toc-close-fixed {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent-color);
    color: #fff;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

/* 4. 滚动视口：这是唯一允许滚动的地方 */
.toc-list-viewport {
    flex: 1; /* 自动撑满剩下的屏幕高度 */
    overflow-y: auto; /* 允许纵向滚动 */
    -webkit-overflow-scrolling: touch; /* iOS 丝滑滚动 */
}

.toc-list {
    padding: 10px 15px 50px; /* 底部留白多一点，方便最后一章点到 */
}

#bookmark-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
}

#bookmark-btn:active {
    transform: scale(0.95);
}

#bookmark-icon {
    font-size: 18px;
}




/* 段落容器 */
/*#content-layer p {*/
/*    position: relative;*/
/*    padding-right: 40px !important; !* 预留右侧按钮位 *!*/
/*    cursor: pointer;*/
/*}*/

/* 消息按钮容器 */
.para-comment-btn {
    position: absolute;
    right: 0;
    bottom: 2px;
    width: 26px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.3; /* 默认浅色，不干扰阅读 */
    transition: all 0.2s ease;
}

/* 激活状态（有评论或悬停） */
.para-comment-btn.has-count, .para-comment-btn:hover {
    opacity: 0.9;
}

/* 图标颜色跟随主题 */
.para-comment-btn svg {
    width: 18px;
    height: 18px;
    fill: var(--accent-color); /* 关键：使用你主题定义的强调色 */
}

/* 消息数字气泡 */
.comment-badge {
    position: absolute;
    top: -4px;
    right: -2px;
    background: var(--accent-color);
    color: #fff; /* 气泡文字通常固定白色 */
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 10px;
    min-width: 14px;
    text-align: center;
    font-style: normal;
    font-family: Arial, sans-serif;
    transform: scale(0.9);
}

.para-comment-tag{
    position: relative;
}

.p-count {
    color: #fff;
    font-size: 9px !important;
    font-weight: bold;
    font-style: normal;

    /* 气泡尺寸控制 */
    min-width: 12px;
    height: 12px;
    border-radius: 6px;

    /* 关键：定位与偏移 */
    position: absolute;
    top: -6px;
    right: -12px;

    /* 关键：让文字偏上的核心设置 */
    display: flex;
    align-items: flex-start; /* 居顶对齐 */
    justify-content: center; /* 水平居中 */
    line-height: 1;          /* 强制行高为1 */
    padding-top: 0px;        /* 如果还不够上，可以设为 0 */

    /* 备选方案：如果 flex 不好使，用下面这两行 */
    /* line-height: 8px; */  /* 行高小于字体大小，字就会往上挤 */
}