/* 小说框架子主题 - 章节段评（起点式「本章说」气泡 + popover / 底部抽屉）
   仅在小说章节页加载，依赖 reader.css；暗色变体复用 body.dark-theme */

/* 段落容器：默认无需 relative（气泡走文档流而非绝对定位） */

.novel-frame-chapter-body.is-novel .novel-frame-chapter-content p.nf-pc-p-active {
    background: rgba(4, 105, 208, .05);
    transition: background-color .2s ease;
    border-radius: 4px;
}

/* 气泡按钮：
   桌面 inline-flex 紧跟段末文字，默认隐藏；段落 hover / 气泡自身 hover/focus / has-comments 时显现。
   hover 自身 → 实心蓝 pill；has-comments → 蓝渐变 pill + 阴影常显。
   移动 / 中窄屏：去 pill 化，仅保留小图标 + 数字（has-comments 时蓝色加粗）。 */

.nf-pc-bubble {
    /* 默认隐藏：避免段末出现"占位空白"；段落 hover 或 has-comments 时切换为 inline-flex */
    display: none;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 22px;
    padding: 0 10px;
    margin-left: 8px;
    vertical-align: middle;
    font-size: 11.5px;
    line-height: 1;
    font-weight: 500;
    color: #0469d0;
    background: #eaf3fc;
    border: 1px solid #d0e3f7;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .18s ease, color .18s ease, box-shadow .18s ease, border-color .18s ease, transform .18s ease;
    white-space: nowrap;
    /* 防止 chapter-content 里 p 的字体样式串进来 */
    font-family: inherit;
    letter-spacing: 0;
    text-indent: 0; /* 阻止父段落 text-indent: 2em 影响 inline-flex 内排版 */
    -webkit-font-smoothing: antialiased;
}

.nf-pc-bubble i {
    font-size: 13px;
    line-height: 1;
}

.nf-pc-bubble-count {
    font-weight: 600;
    min-width: 8px;
    text-align: center;
}

/* 空 count（无评论且移动端无 "+" 文案）时不渲染，避免 padding 不对称 */
.nf-pc-bubble-count:empty {
    display: none;
}

/* 段落 hover / 气泡自身 hover:focus / 已有评论 三种情况让气泡浮现 */
.novel-frame-chapter-body.is-novel .novel-frame-chapter-content p.nf-pc-p-mounted:hover .nf-pc-bubble,
.nf-pc-bubble:hover,
.nf-pc-bubble:focus-visible,
.nf-pc-bubble.has-comments {
    display: inline-flex;
}

/* 无评论 hover 自身 → 整个 pill 变实心蓝（强可点反馈） */
.nf-pc-bubble:hover,
.nf-pc-bubble:focus-visible {
    color: #fff;
    background: #0469d0;
    border-color: #0469d0;
    box-shadow: 0 4px 12px rgba(4, 105, 208, .28);
    outline: none;
}

/* 有评论常显态：蓝色渐变 pill + 白字 + 阴影 */
.nf-pc-bubble.has-comments {
    color: #fff;
    background: linear-gradient(135deg, #1f7fe0 0%, #0469d0 100%);
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(4, 105, 208, .22);
}

.nf-pc-bubble.has-comments:hover,
.nf-pc-bubble.has-comments:focus-visible {
    background: linear-gradient(135deg, #2a8aec 0%, #0a72d8 100%);
    box-shadow: 0 4px 14px rgba(4, 105, 208, .36);
    transform: translateY(-1px);
}

/* Popover（桌面端） */

.nf-pc-panel {
    z-index: 9998;
    background: #fff;
    box-shadow: 0 12px 32px rgba(17, 24, 39, .18);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.nf-pc-panel.is-popover {
    position: absolute;
    width: 320px;
    max-height: 70vh;
}

/* 头部 */
.nf-pc-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px 10px;
    border-bottom: 1px solid rgba(0, 0, 0, .06);
}

.nf-pc-header-preview {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nf-pc-header-label {
    font-size: 13px;
    font-weight: 700;
    color: #111827;
}

.nf-pc-header-quote {
    font-size: 12px;
    color: rgba(17, 24, 39, .5);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.nf-pc-close {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border: 0;
    background: transparent;
    color: rgba(17, 24, 39, .4);
    font-size: 20px;
    line-height: 20px;
    border-radius: 50%;
    cursor: pointer;
}

.nf-pc-close:hover {
    color: #0469d0;
    background: rgba(0, 0, 0, .04);
}

/* 列表 */
.nf-pc-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 14px;
    min-height: 80px;
    max-height: 280px;
}

.nf-pc-list-loading,
.nf-pc-list-error,
.nf-pc-empty {
    padding: 24px 0;
    text-align: center;
    color: rgba(17, 24, 39, .45);
    font-size: 13px;
}

.nf-pc-list-error {
    color: #d93025;
}

.nf-pc-item {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(0, 0, 0, .05);
}

.nf-pc-item:last-child {
    border-bottom: 0;
}

.nf-pc-item-avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(0, 0, 0, .06);
}

.nf-pc-item-body {
    flex: 1;
    min-width: 0;
}

.nf-pc-item-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.nf-pc-item-author {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

.nf-pc-item-time {
    font-size: 11px;
    color: rgba(17, 24, 39, .4);
}

.nf-pc-item-content {
    font-size: 13px;
    line-height: 1.6;
    color: rgba(17, 24, 39, .85);
    word-break: break-word;
    white-space: pre-wrap; /* 保留服务端原文里的换行（textContent 赋值默认折叠换行） */
}

.nf-pc-more {
    display: block;
    width: 100%;
    margin: 8px 0 0;
    padding: 8px;
    border: 1px dashed rgba(0, 0, 0, .12);
    background: transparent;
    color: rgba(17, 24, 39, .6);
    font-size: 12.5px;
    border-radius: 6px;
    cursor: pointer;
}

.nf-pc-more:hover {
    color: #0469d0;
    border-color: rgba(4, 105, 208, .4);
}

/* 编辑器 */
.nf-pc-editor {
    padding: 10px 14px 14px;
    border-top: 1px solid rgba(0, 0, 0, .06);
    background: rgba(0, 0, 0, .015);
}

.nf-pc-login-tip {
    margin: 4px 0;
    padding: 10px;
    text-align: center;
    font-size: 13px;
    color: rgba(17, 24, 39, .6);
    background: rgba(0, 0, 0, .03);
    border-radius: 6px;
}

.nf-pc-input-name,
.nf-pc-input-email {
    width: 100%;
    padding: 6px 10px;
    margin-bottom: 6px;
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    color: #111827;
    box-sizing: border-box;
}

.nf-pc-textarea {
    width: 100%;
    min-height: 64px;
    padding: 8px 10px;
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    background: #fff;
    color: #111827;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
}

.nf-pc-textarea:focus,
.nf-pc-input-name:focus,
.nf-pc-input-email:focus {
    outline: none;
    border-color: #0469d0;
    box-shadow: 0 0 0 2px rgba(4, 105, 208, .15);
}

.nf-pc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

.nf-pc-counter {
    font-size: 11px;
    color: rgba(17, 24, 39, .4);
}

.nf-pc-submit {
    padding: 6px 16px;
    background: #0469d0;
    color: #fff;
    border: 0;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease;
}

.nf-pc-submit:hover {
    background: #0357ac;
}

.nf-pc-submit:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* 中窄屏 / 移动端：气泡极简化（去 pill 背景），仅保留小图标 + 数字。
   桌面 hover 浮现 pill 不抢眼；中窄屏 / 移动无 hover，pill 会常驻段末抢视觉 → 主动去 pill。
   默认始终可见：浅灰图标 + 浅灰数字；has-comments 仅文字与图标变蓝加粗，不加 pill 背景。 */

@media (max-width: 768px) {
    /* 强制覆盖桌面隐藏规则：中窄屏始终可见 */
    .nf-pc-bubble,
    .novel-frame-chapter-body.is-novel .novel-frame-chapter-content p.nf-pc-p-mounted:hover .nf-pc-bubble,
    .nf-pc-bubble.has-comments {
        display: inline-flex;
        height: auto;
        padding: 1px 4px;
        margin-left: 4px;
        vertical-align: middle;
        font-size: 12px;
        font-weight: 400;
        color: rgba(0, 0, 0, .35);
        background: transparent;
        border: 0;
        border-radius: 4px;
        box-shadow: none;
        transform: none;
    }

    .nf-pc-bubble i {
        font-size: 12px;
    }

    /* 触摸设备 :hover 不可靠；点击瞬间触发的 :hover 也用 transparent 不变，避免按下闪烁 */
    .nf-pc-bubble:hover,
    .nf-pc-bubble:focus-visible {
        color: #0469d0;
        background: transparent;
        border: 0;
        box-shadow: none;
        transform: none;
    }

    /* has-comments：仅文字 + 图标变蓝加粗；无 pill */
    .nf-pc-bubble.has-comments {
        color: #0469d0;
        background: transparent;
        border: 0;
        box-shadow: none;
        font-weight: 600;
    }

    .nf-pc-bubble.has-comments:hover,
    .nf-pc-bubble.has-comments:focus-visible {
        color: #0a72d8;
        background: transparent;
        box-shadow: none;
        transform: none;
    }

    /* 遮罩 */
    .nf-pc-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .45);
        opacity: 0;
        transition: opacity .24s ease;
        z-index: 9997;
    }

    .nf-pc-overlay.is-open {
        opacity: 1;
    }

    /* 底部抽屉 */
    .nf-pc-panel.is-mobile {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 75vh;
        height: 75vh;
        border-radius: 14px 14px 0 0;
        transform: translateY(100%);
        transition: transform .28s cubic-bezier(.2,.8,.2,1);
        z-index: 9998;
        box-shadow: 0 -12px 32px rgba(0, 0, 0, .25);
    }

    .nf-pc-panel.is-mobile.is-open {
        transform: translateY(0);
    }

    .nf-pc-list {
        max-height: none;
    }

    /* 面板打开时禁止 body 滚动，避免背景联动滚动 */
    body.nf-pc-panel-open {
        overflow: hidden;
    }
}

/* 暗色主题 */

/* 暗色：无评论默认态用深色描边 pill，hover 变实心亮蓝；有评论常显实心亮蓝 */
body.dark-theme .nf-pc-bubble {
    color: #9ec5ff;
    background: rgba(94, 168, 255, .12);
    border-color: rgba(94, 168, 255, .28);
}

body.dark-theme .nf-pc-bubble:hover,
body.dark-theme .nf-pc-bubble:focus-visible {
    color: #fff;
    background: #2a8aec;
    border-color: #2a8aec;
    box-shadow: 0 4px 12px rgba(42, 138, 236, .4);
}

body.dark-theme .nf-pc-bubble.has-comments {
    color: #fff;
    background: linear-gradient(135deg, #2a8aec 0%, #1f7fe0 100%);
    border-color: transparent;
    box-shadow: 0 2px 10px rgba(42, 138, 236, .35);
}

body.dark-theme .nf-pc-bubble.has-comments:hover,
body.dark-theme .nf-pc-bubble.has-comments:focus-visible {
    background: linear-gradient(135deg, #3a9aff 0%, #2a8aec 100%);
    box-shadow: 0 4px 16px rgba(42, 138, 236, .5);
}

/* 中窄屏 / 移动暗色：跟桌面相反，无 pill；浅白图标，has-comments 仅蓝字蓝图标 */
@media (max-width: 768px) {
    body.dark-theme .nf-pc-bubble {
        color: rgba(255, 255, 255, .35);
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    body.dark-theme .nf-pc-bubble:hover,
    body.dark-theme .nf-pc-bubble:focus-visible {
        color: #9ec5ff;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    body.dark-theme .nf-pc-bubble.has-comments {
        color: #9ec5ff;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    body.dark-theme .nf-pc-bubble.has-comments:hover,
    body.dark-theme .nf-pc-bubble.has-comments:focus-visible {
        color: #c0d8ff;
        background: transparent;
        box-shadow: none;
    }
}

body.dark-theme .nf-pc-panel {
    background: #1e2025;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .6);
}

body.dark-theme .nf-pc-header {
    border-bottom-color: rgba(255, 255, 255, .08);
}

body.dark-theme .nf-pc-header-label {
    color: rgba(255, 255, 255, .9);
}

body.dark-theme .nf-pc-header-quote {
    color: rgba(255, 255, 255, .5);
}

body.dark-theme .nf-pc-close {
    color: rgba(255, 255, 255, .4);
}

body.dark-theme .nf-pc-close:hover {
    color: #9ec5ff;
    background: rgba(255, 255, 255, .06);
}

body.dark-theme .nf-pc-item {
    border-bottom-color: rgba(255, 255, 255, .06);
}

body.dark-theme .nf-pc-item-author {
    color: rgba(255, 255, 255, .9);
}

body.dark-theme .nf-pc-item-time {
    color: rgba(255, 255, 255, .4);
}

body.dark-theme .nf-pc-item-content {
    color: rgba(255, 255, 255, .82);
}

body.dark-theme .nf-pc-editor {
    border-top-color: rgba(255, 255, 255, .08);
    background: rgba(255, 255, 255, .03);
}

body.dark-theme .nf-pc-textarea,
body.dark-theme .nf-pc-input-name,
body.dark-theme .nf-pc-input-email {
    background: #15171b;
    color: rgba(255, 255, 255, .9);
    border-color: rgba(255, 255, 255, .1);
}

body.dark-theme .nf-pc-textarea:focus,
body.dark-theme .nf-pc-input-name:focus,
body.dark-theme .nf-pc-input-email:focus {
    border-color: #5ea8ff;
    box-shadow: 0 0 0 2px rgba(94, 168, 255, .2);
}

body.dark-theme .nf-pc-counter {
    color: rgba(255, 255, 255, .4);
}

body.dark-theme .nf-pc-login-tip {
    color: rgba(255, 255, 255, .6);
    background: rgba(255, 255, 255, .04);
}

body.dark-theme .nf-pc-more {
    color: rgba(255, 255, 255, .5);
    border-color: rgba(255, 255, 255, .12);
}

body.dark-theme .nf-pc-more:hover {
    color: #9ec5ff;
    border-color: rgba(94, 168, 255, .4);
}

body.dark-theme .novel-frame-chapter-body.is-novel .novel-frame-chapter-content p.nf-pc-p-active {
    background: rgba(94, 168, 255, .08);
}

body.dark-theme .nf-pc-submit {
    background: #1f6fd8;
}

body.dark-theme .nf-pc-submit:hover {
    background: #2a7be6;
}

/* 沉浸阅读：降低气泡存在感 */

body.novel-frame-immersive .nf-pc-bubble:not(.has-comments):not(:hover) {
    opacity: 0;
}

body.novel-frame-immersive .nf-pc-bubble.has-comments {
    opacity: .5;
}

body.novel-frame-immersive .nf-pc-bubble:hover,
body.novel-frame-immersive .nf-pc-bubble:focus {
    opacity: 1;
}
