/* ============================================================ */
/* 段落评论样式（适配 Site 看书页主题：暖色 / 米黄 / 深色等）         */
/* 主题色用纸张感的暖棕色，深色主题（night/black/brown）做反色覆盖    */
/* ============================================================ */
:root {
    --sn-primary: #8B6F47;
    --sn-primary-dark: #6E5638;
    --sn-primary-light: #F5EDE4;
    --sn-white: #ffffff;
    --sn-text: #2C2C2C;
    --sn-text-secondary: #5A5A5A;
    --sn-text-muted: #9C9388;
    --sn-border: #E4DCC9;
    --sn-gray-bg: #FAF5EB;
    --sn-sheet-bg: #FBF7EE;
    --sn-radius: 16px;
    --sn-radius-sm: 10px;
    --sn-radius-xs: 8px;
}

/* 隐藏所有段评气泡（夜间模式等用户可选关闭） */
.hide-para-bubbles .sn-para-bubble {
    display: none !important;
}

/* ============================================================ */
/* 段落评论：段尾 SVG 对话气泡                                       */
/* 关键约束: 气泡不可让阅读页变长                                    */
/*   1. 缩小盒子(1.1em),放心嵌入任意 line-height>=1.3 的正文不撑高   */
/*   2. empty 默认 display:none,不占行内宽度,避免末行被挤换行         */
/*   3. 空气泡: PC hover 显现; 移动端不显现(改用长按段落直接打开评论) */
/* ============================================================ */
.sn-reader-text p {
    position: relative;
}

.sn-reader-text p .sn-para-bubble {
    position: relative;
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    margin: 0 0 0 3px;
    padding: 0;
    border: none;
    outline: none;
    background: none;
    -webkit-appearance: none;
    appearance: none;
    vertical-align: middle;
    transform: translateY(-0.05em);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    color: #999;
    transition: color 0.15s;
    font-family: inherit;
    font-size: inherit;
    line-height: 1;
    box-sizing: border-box;
}

.sn-reader-text p .sn-para-bubble:active {
    color: #666;
}

.sn-para-bubble .sn-pb-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    display: block;
}

.sn-para-bubble .sn-pb-frame {
    fill: currentColor;
    stroke: none;
}

.sn-para-bubble .sn-pb-plus {
    stroke: currentColor;
    stroke-width: 64;
    stroke-linecap: round;
}

.sn-para-bubble .sn-pb-num {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 78%;
    padding-top: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 600;
    line-height: 1;
    pointer-events: none;
    color: #888;
}

.sn-reader-text p .sn-para-bubble.has {
    color: #999;
}

/* 空气泡默认完全不占空间,避免每段末尾撑出 1em 宽 + 可能换行 */
.sn-reader-text p .sn-para-bubble.empty {
    display: none;
    color: #ccc;
}

/* PC 悬停: 当前段才显现 + */
@media (hover: hover) {
    .sn-reader-text p:hover .sn-para-bubble.empty {
        display: inline-block;
    }
}

/* 移动端: 空气泡不显现,改为长按段落直接打开评论 Sheet。
   长按需禁用文本选择 / 系统选词菜单,否则与原生选词手势冲突。 */
@media (hover: none) {
    .sn-reader-text p {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================================ */
/* 段落评论：底部 Sheet                                              */
/* ============================================================ */
.sn-para-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
}

.sn-para-sheet-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.28s ease;
    touch-action: none;
}

.sn-para-sheet.open .sn-para-sheet-bg {
    opacity: 1;
}

.sn-para-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--sn-sheet-bg);
    color: var(--sn-text);
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(100%);
    transition: transform 0.28s ease;
    overflow: hidden;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
}

/* 移动端默认: 全宽贴底,从下方滑入 */
.sn-para-sheet.open .sn-para-sheet-panel {
    transform: translateY(0);
}

/* PC: 居中固定宽,需要把 translateX(-50%) 配合 translateY 一起写 */
/* 注意: 这块必须放在上面 .open 规则之后,否则会被相同特异度的后置规则覆盖,    */
/* 导致面板丢掉 translateX(-50%) 贴到右半屏。                                  */
@media (min-width: 768px) {
    .sn-para-sheet-panel {
        left: 50%;
        right: auto;
        width: 768px;
        max-width: 100vw;
        transform: translate(-50%, 100%);
    }

    .sn-para-sheet.open .sn-para-sheet-panel {
        transform: translate(-50%, 0);
    }
}

.sn-para-sheet-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

.sn-para-sheet-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--sn-text);
}

.sn-para-sheet-header button {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--sn-text-muted);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.sn-para-sheet-quote-wrap {
    padding: 12px 16px 0;
    flex-shrink: 0;
}

.sn-para-sheet-quote {
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--sn-text-secondary);
    background: rgba(139, 111, 71, 0.08);
    border-left: 3px solid var(--sn-primary);
    border-radius: 4px;
    word-break: break-word;
}

.sn-para-sheet-list {
    flex: 1;
    min-height: 100px;
    padding: 8px 16px 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sn-para-sheet-list .sn-comment-loading {
    padding: 24px 0;
    text-align: center;
    color: var(--sn-text-muted);
    font-size: 13px;
}

.sn-para-sheet-input {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 10px 16px 14px;
    border-top: 1px solid var(--sn-border);
    background: var(--sn-sheet-bg);
    flex-shrink: 0;
}

.sn-para-sheet-textarea {
    flex: 1;
    min-height: 38px;
    max-height: 120px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--sn-text);
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid transparent;
    border-radius: 19px;
    resize: none;
    outline: none;
    box-sizing: border-box;
    font-family: inherit;
}

.sn-para-sheet-textarea:focus {
    background: var(--sn-white);
    border-color: var(--sn-primary);
}

.sn-para-sheet-send {
    flex-shrink: 0;
    padding: 0 18px;
    height: 38px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: var(--sn-primary);
    border: none;
    border-radius: 19px;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.sn-para-sheet-send:active {
    background: var(--sn-primary-dark);
}

.sn-para-sheet-send:disabled {
    background: var(--sn-text-muted);
    cursor: not-allowed;
}

/* ============================================================ */
/* 评论项 / 楼中楼 / 回复框 / 举报弹窗                                */
/* ============================================================ */
.sn-comment-list {
    min-height: 40px;
}

.sn-comment-loading {
    text-align: center;
    padding: 16px 0;
    font-size: 12px;
    color: var(--sn-text-muted);
}

.sn-comment-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
    color: var(--sn-text-muted);
    gap: 8px;
}

.sn-comment-empty svg {
    color: var(--sn-primary-light);
}

.sn-comment-empty p {
    font-size: 13px;
}

.sn-comment-list-inner {
    display: flex;
    flex-direction: column;
}

.sn-comment-item {
    display: flex;
    gap: 10px;
    padding: 12px 0;
    border-top: 1px solid var(--sn-border);
}

.sn-comment-item:first-child {
    border-top: none;
}

.sn-comment-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--sn-gray-bg);
}

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

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

.sn-comment-loadmore {
    text-align: center;
    padding: 12px 0 4px;
}

.sn-comment-loadmore button {
    padding: 8px 20px;
    border-radius: 18px;
    border: 1px solid var(--sn-border);
    background: var(--sn-white);
    color: var(--sn-text-secondary);
    font-size: 12px;
    cursor: pointer;
}

.sn-comment-loadmore button:active {
    background: var(--sn-gray-bg);
}

.sn-comment-line {
    font-size: 13px;
    line-height: 1.6;
    color: var(--sn-text);
    word-wrap: break-word;
}

.sn-comment-line .sn-comment-name {
    color: var(--sn-text);
    font-weight: 600;
    margin-right: 0;
}

.sn-comment-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--sn-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}

.sn-comment-colon {
    color: var(--sn-text-secondary);
    margin-right: 4px;
}

.sn-comment-text {
    font-size: 13px;
    color: var(--sn-text);
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.sn-comment-meta {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 6px;
    font-size: 11px;
    color: var(--sn-text-muted);
}

.sn-comment-time {
    font-size: 11px;
    color: var(--sn-text-muted);
    flex-shrink: 0;
}

.sn-comment-action {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--sn-text-muted);
    font-size: 11px;
    padding: 2px 0;
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
    text-decoration: none;
}

.sn-comment-action:active,
.sn-comment-action.active {
    color: var(--sn-primary);
}

.sn-comment-action.active svg {
    fill: var(--sn-primary);
    fill-opacity: 0.15;
}

.sn-like-count:empty {
    display: none;
}

.sn-comment-reply-btn {
    color: var(--sn-text-muted);
}

.sn-comment-reply-count {
    color: var(--sn-primary);
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
    padding: 2px 10px;
    border: 1px solid var(--sn-primary);
    border-radius: 999px;
    background: var(--sn-white);
    line-height: 1.6;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.sn-comment-reply-count:hover {
    text-decoration: none;
    border-color: var(--sn-primary-dark);
    color: var(--sn-primary-dark);
}

.sn-comment-replies {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--sn-gray-bg);
    border-radius: var(--sn-radius-xs);
}

.sn-comment-reply-item {
    display: flex;
    gap: 8px;
    padding: 8px 0;
}

.sn-comment-reply-item + .sn-comment-reply-item {
    border-top: 1px dashed var(--sn-border);
}

.sn-comment-reply-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--sn-white);
}

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

.sn-comment-reply-body {
    flex: 1;
    min-width: 0;
}

.sn-comment-reply-line {
    font-size: 13px;
    line-height: 1.55;
    color: var(--sn-text);
    word-wrap: break-word;
}

.sn-comment-reply-name {
    color: var(--sn-text);
    font-weight: 600;
}

.sn-comment-reply-verb {
    color: var(--sn-text-muted);
    margin: 0 4px;
}

.sn-comment-reply-target {
    color: var(--sn-primary);
    font-weight: 600;
    text-decoration: none;
}

.sn-comment-reply-target:active {
    opacity: 0.7;
}

.sn-comment-reply-colon {
    color: var(--sn-text-secondary);
    margin-right: 4px;
}

.sn-comment-reply-text {
    color: var(--sn-text);
}

.sn-comment-reply-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--sn-text-muted);
}

.sn-comment-reply-meta .sn-comment-time {
    color: var(--sn-text-muted);
    flex-shrink: 0;
}

.sn-comment-reply-inline-btn {
    color: var(--sn-text-muted);
}

.sn-comment-reply-inline-btn:active {
    color: var(--sn-primary);
}

.sn-comment-view-all-replies {
    display: inline-block;
    margin-top: 8px;
    padding: 2px 10px;
    font-size: 12px;
    color: var(--sn-primary);
    background: #fff;
    border: 1px solid var(--sn-primary);
    border-radius: 999px;
    line-height: 1.6;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.sn-comment-view-all-replies:hover {
    text-decoration: none;
    border-color: var(--sn-primary-dark);
    color: var(--sn-primary-dark);
}

.sn-reply-box {
    margin-top: 10px;
    padding: 10px;
    background: var(--sn-primary-light);
    border-radius: var(--sn-radius-xs);
    border: 1px solid var(--sn-primary);
}

.sn-reply-hint {
    font-size: 12px;
    color: var(--sn-primary-dark);
    margin-bottom: 6px;
    padding: 4px 8px;
    background: rgba(232, 140, 165, 0.12);
    border-radius: 4px;
    font-weight: 600;
}

.sn-reply-textarea {
    width: 100%;
    min-height: 64px;
    padding: 8px 10px;
    border: 1px solid var(--sn-border);
    border-radius: var(--sn-radius-xs);
    background: var(--sn-white);
    font-family: inherit;
    font-size: 13px;
    color: var(--sn-text);
    resize: none;
    outline: none;
    line-height: 1.5;
    box-sizing: border-box;
}

.sn-reply-textarea:focus {
    border-color: var(--sn-primary);
}

.sn-reply-box-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.sn-reply-btn {
    padding: 6px 16px;
    border-radius: 16px;
    border: none;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.sn-reply-btn-cancel {
    background: var(--sn-white);
    color: var(--sn-text-secondary);
    border: 1px solid var(--sn-border);
}

.sn-reply-btn-submit {
    background: var(--sn-primary);
    color: #fff;
}

.sn-reply-btn-submit:disabled {
    background: var(--sn-text-muted);
    cursor: not-allowed;
}

.sn-comment-delete-btn {
    color: #c94a4a;
}

.sn-comment-delete-btn:active {
    color: #8b1a1a;
}

.sn-comment-report-btn {
    color: var(--sn-text-muted);
}

.sn-report-dialog {
    padding: 12px 14px;
    min-width: 240px;
    max-width: 86vw;
    box-sizing: border-box;
}

.sn-report-dialog .sn-report-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--sn-text, #222);
    margin-bottom: 10px;
}

.sn-report-dialog .sn-report-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 2px;
    font-size: 13px;
    color: var(--sn-text, #222);
    cursor: pointer;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.sn-report-dialog .sn-report-item:last-of-type {
    border-bottom: none;
}

.sn-report-dialog .sn-report-item input[type="radio"] {
    margin: 0;
    accent-color: var(--sn-primary);
}

.sn-report-dialog .sn-report-text {
    width: 100%;
    min-height: 64px;
    margin-top: 10px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--sn-text, #222);
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
}

.sn-report-dialog .sn-report-text:focus {
    outline: none;
    border-color: var(--sn-primary);
}

/* ============================================================ */
/* 深色阅读主题适配（HX/ShortNovel 切换主题时整体随之变色）           */
/* 命中 body.theme-night / theme-black / theme-brown 或           */
/* .sn-reader-body[data-theme="dark"]（ShortNovel 用 data-theme） */
/* ============================================================ */
body.theme-night,
body.theme-black,
body.theme-brown,
.sn-reader-body[data-theme="dark"] {
    --sn-text: #E8E1D2;
    --sn-text-secondary: #BFB7A6;
    --sn-text-muted: #8E867A;
    --sn-border: rgba(255, 255, 255, 0.12);
    --sn-gray-bg: rgba(255, 255, 255, 0.05);
    --sn-sheet-bg: #2B2520;
    --sn-white: #3A332C;
    --sn-primary: #D2A56A;
    --sn-primary-dark: #B4884B;
    --sn-primary-light: rgba(210, 165, 106, 0.12);
}

/* 深色主题下面板增加更深的阴影 + 顶部高光分割 */
body.theme-night .sn-para-sheet-panel,
body.theme-black .sn-para-sheet-panel,
body.theme-brown .sn-para-sheet-panel,
.sn-reader-body[data-theme="dark"] .sn-para-sheet-panel {
    box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* 深色主题下输入框 hover/focus 用更深的盒子（避免亮白闪眼） */
body.theme-night .sn-para-sheet-textarea,
body.theme-black .sn-para-sheet-textarea,
body.theme-brown .sn-para-sheet-textarea,
.sn-reader-body[data-theme="dark"] .sn-para-sheet-textarea {
    background: rgba(255, 255, 255, 0.06);
}

body.theme-night .sn-para-sheet-textarea:focus,
body.theme-black .sn-para-sheet-textarea:focus,
body.theme-brown .sn-para-sheet-textarea:focus,
.sn-reader-body[data-theme="dark"] .sn-para-sheet-textarea:focus {
    background: rgba(255, 255, 255, 0.1);
}

body.theme-night .sn-para-sheet-quote,
body.theme-black .sn-para-sheet-quote,
body.theme-brown .sn-para-sheet-quote,
.sn-reader-body[data-theme="dark"] .sn-para-sheet-quote {
    background: rgba(255, 255, 255, 0.05);
}

/* 深色主题下回复框背景用淡金色叠层 */
body.theme-night .sn-reply-box,
body.theme-black .sn-reply-box,
body.theme-brown .sn-reply-box,
.sn-reader-body[data-theme="dark"] .sn-reply-box {
    background: rgba(210, 165, 106, 0.08);
}

body.theme-night .sn-reply-textarea,
body.theme-black .sn-reply-textarea,
body.theme-brown .sn-reply-textarea,
.sn-reader-body[data-theme="dark"] .sn-reply-textarea {
    background: rgba(0, 0, 0, 0.2);
}

/* 深色主题下楼中楼容器更亮一点的灰底 */
body.theme-night .sn-comment-replies,
body.theme-black .sn-comment-replies,
body.theme-brown .sn-comment-replies,
.sn-reader-body[data-theme="dark"] .sn-comment-replies {
    background: rgba(255, 255, 255, 0.04);
}

/* 深色主题下气泡颜色 */
body.theme-night .sn-reader-text p .sn-para-bubble.has,
body.theme-black .sn-reader-text p .sn-para-bubble.has,
body.theme-brown .sn-reader-text p .sn-para-bubble.has,
.sn-reader-body[data-theme="dark"] .sn-reader-text p .sn-para-bubble.has {
    color: rgba(255, 255, 255, 0.5);
}

body.theme-night .sn-para-bubble .sn-pb-num,
body.theme-black .sn-para-bubble .sn-pb-num,
body.theme-brown .sn-para-bubble .sn-pb-num,
.sn-reader-body[data-theme="dark"] .sn-para-bubble .sn-pb-num {
    color: rgba(255, 255, 255, 0.55);
}

body.theme-night .sn-reader-text p .sn-para-bubble.empty,
body.theme-black .sn-reader-text p .sn-para-bubble.empty,
body.theme-brown .sn-reader-text p .sn-para-bubble.empty,
.sn-reader-body[data-theme="dark"] .sn-reader-text p .sn-para-bubble.empty {
    color: rgba(255, 255, 255, 0.25);
}

/* 举报弹窗（layer.js 用全局 z-index 显示，可能在 body 上而不在 sheet 内，
   所以在浅色主题下保持白底原样；深色主题下沿用 body 主题色 */
body.theme-night .sn-report-dialog .sn-report-item,
body.theme-black .sn-report-dialog .sn-report-item,
body.theme-brown .sn-report-dialog .sn-report-item,
.sn-reader-body[data-theme="dark"] .sn-report-dialog .sn-report-item {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

body.theme-night .sn-report-dialog .sn-report-text,
body.theme-black .sn-report-dialog .sn-report-text,
body.theme-brown .sn-report-dialog .sn-report-text,
.sn-reader-body[data-theme="dark"] .sn-report-dialog .sn-report-text {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}
