/* 弹幕评论功能样式 */

/* 段落容器 - 需要相对定位以放置 badge */
#chapter-content p {
    position: relative;
}

/* 段落右侧评论数量徽标 */
.danmaku-badge {
    display: inline-block;
    vertical-align: middle;
    margin-left: 4px;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    background: #ff4757;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    padding: 0 5px;
    cursor: pointer;
    z-index: 10;
    user-select: none;
    box-shadow: 0 1px 3px rgba(255, 71, 87, 0.4);
    transition: transform 0.2s;
}

.danmaku-badge:active {
    transform: scale(1.15);
}

/* hover 时段落末尾出现的添加按钮（inline） */
.danmaku-add-btn {
    display: inline-block;
    vertical-align: middle;
    margin-left: 4px;
    width: 22px;
    height: 22px;
    line-height: 20px;
    text-align: center;
    background: rgba(100, 100, 100, 0.15);
    color: #999;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    z-index: 9;
    opacity: 0;
    transition: opacity 0.2s;
    user-select: none;
}

#chapter-content p:hover .danmaku-add-btn {
    opacity: 1;
}

.danmaku-add-btn:active {
    background: rgba(100, 100, 100, 0.3);
}

/* 有 badge 时隐藏 add 按钮 */
#chapter-content p .danmaku-badge ~ .danmaku-add-btn {
    display: none;
}

/* ============ 遮罩层 ============ */
.danmaku-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 999;
    animation: danmaku-fade-in 0.25s ease;
}

@keyframes danmaku-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ============ 评论列表面板（PC 端 inline） ============ */
.danmaku-panel {
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    margin: 8px 0 12px 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    animation: danmaku-slide-down 0.2s ease;
}

@keyframes danmaku-slide-down {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============ 底部面板 Bottom Sheet（移动端） ============ */
.danmaku-panel.danmaku-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50vh;
    max-height: 50vh;
    margin: 0;
    border: none;
    border-radius: 16px 16px 0 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    animation: danmaku-slide-up 0.3s ease;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
}

@keyframes danmaku-slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.danmaku-sheet-handle {
    width: 36px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    margin: 8px auto 0;
    flex-shrink: 0;
}

.danmaku-bottom-sheet .danmaku-panel-body {
    flex: 1;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* body 锁定（防止底部面板打开时页面滚动） */
body.danmaku-body-locked {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* ============ 面板通用子元素 ============ */
.danmaku-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    color: #666;
    flex-shrink: 0;
}

.danmaku-panel-header .danmaku-close {
    cursor: pointer;
    font-size: 18px;
    color: #999;
    line-height: 1;
    padding: 2px 4px;
}

.danmaku-panel-body {
    max-height: 240px;
    overflow-y: auto;
    padding: 6px 0;
}

.danmaku-panel-body:empty::after {
    content: "暫無評論，快來搶沙發~";
    display: block;
    text-align: center;
    padding: 20px 0;
    color: #ccc;
    font-size: 13px;
}

/* 加载指示器 & 无更多 */
.danmaku-loading,
.danmaku-no-more {
    text-align: center;
    padding: 12px 0;
    color: #999;
    font-size: 12px;
}

/* 单条评论 */
.danmaku-item {
    display: flex;
    align-items: flex-start;
    padding: 8px 14px;
    gap: 8px;
}

.danmaku-item-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e8e8e8;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #999;
}

.danmaku-item-body {
    flex: 1;
    min-width: 0;
}

.danmaku-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #999;
    margin-bottom: 3px;
}

.danmaku-item-meta .nickname {
    color: #666;
    font-weight: 500;
}

.danmaku-item-content {
    font-size: 13px;
    color: #333;
    line-height: 1.5;
    word-break: break-word;
}

/* 输入区 */
.danmaku-panel-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.danmaku-panel-input input {
    flex: 1;
    height: 34px;
    border: 1px solid #e0e0e0;
    border-radius: 17px;
    padding: 0 14px;
    font-size: 13px;
    outline: none;
    background: #f8f8f8;
    color: #333;
}

.danmaku-panel-input input:focus {
    border-color: #409eff;
    background: #fff;
}

.danmaku-panel-input input::placeholder {
    color: #bbb;
}

.danmaku-panel-input .danmaku-send-btn {
    height: 34px;
    padding: 0 16px;
    border: none;
    border-radius: 17px;
    background: #409eff;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.danmaku-panel-input .danmaku-send-btn:active {
    background: #3a8ee6;
}

.danmaku-panel-input .danmaku-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 弹幕隐藏状态 */
.danmaku-hidden .danmaku-badge,
.danmaku-hidden .danmaku-add-btn {
    display: none !important;
}

/* ============ 夜间模式适配 ============ */
body.theme-dark .danmaku-panel {
    background: #1e1e1e;
    border-color: #333;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

body.theme-dark .danmaku-panel.danmaku-bottom-sheet {
    background: #1e1e1e;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

body.theme-dark .danmaku-overlay {
    background: rgba(0, 0, 0, 0.55);
}

body.theme-dark .danmaku-sheet-handle {
    background: #444;
}

body.theme-dark .danmaku-panel-header {
    border-bottom-color: #333;
    color: #aaa;
}

body.theme-dark .danmaku-panel-header .danmaku-close {
    color: #777;
}

body.theme-dark .danmaku-panel-body:empty::after {
    color: #555;
}

body.theme-dark .danmaku-item-content {
    color: #ccc;
}

body.theme-dark .danmaku-item-meta .nickname {
    color: #aaa;
}

body.theme-dark .danmaku-panel-input {
    border-top-color: #333;
}

body.theme-dark .danmaku-panel-input input {
    background: #2a2a2a;
    border-color: #444;
    color: #ddd;
}

body.theme-dark .danmaku-panel-input input:focus {
    border-color: #409eff;
    background: #2a2a2a;
}

body.theme-dark .danmaku-panel-input input::placeholder {
    color: #555;
}

body.theme-dark .danmaku-add-btn {
    background: rgba(200, 200, 200, 0.1);
    color: #666;
}

body.theme-dark .danmaku-loading,
body.theme-dark .danmaku-no-more {
    color: #555;
}

body.theme-dark .danmaku-item-avatar {
    background: #333;
    color: #777;
}

/* ============ 其他主题适配 ============ */
body.theme-beige2 .danmaku-panel {
    background: #f5f0e8;
    border-color: #e0d8c8;
}

body.theme-beige2 .danmaku-panel-header {
    border-bottom-color: #e0d8c8;
}

body.theme-beige2 .danmaku-panel-input {
    border-top-color: #e0d8c8;
}

body.theme-beige2 .danmaku-panel-input input {
    background: #ebe5da;
    border-color: #d8d0c0;
}

body.theme-green .danmaku-panel {
    background: #e8f0e0;
    border-color: #d0e0c0;
}

body.theme-green .danmaku-panel-header {
    border-bottom-color: #d0e0c0;
}

body.theme-green .danmaku-panel-input {
    border-top-color: #d0e0c0;
}

body.theme-green .danmaku-panel-input input {
    background: #dfe8d8;
    border-color: #c8d8b8;
}

/* ============ 移动端响应式 ============ */
@media (max-width: 768px) {
    .danmaku-badge {
        min-width: 18px;
        height: 18px;
        line-height: 18px;
        font-size: 10px;
        padding: 0 4px;
    }

    .danmaku-add-btn {
        width: 20px;
        height: 20px;
        line-height: 18px;
        font-size: 14px;
        /* 移动端默认隐藏，点击段落后通过 JS 添加 active 类显示 */
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.15s;
    }

    /* 点击段落后显示 "+" 按钮 */
    .danmaku-add-btn.danmaku-add-btn-active {
        opacity: 0.7;
        pointer-events: auto;
    }

    #chapter-content p:hover .danmaku-add-btn {
        /* 移动端不靠 hover */
        opacity: 0;
        pointer-events: none;
    }

    #chapter-content p:hover .danmaku-add-btn.danmaku-add-btn-active {
        opacity: 0.7;
        pointer-events: auto;
    }

    .danmaku-item {
        padding: 6px 12px;
    }

    .danmaku-panel-input {
        padding: 8px 12px;
    }

    /* 底部面板安全区域适配（iPhone 等） */
    .danmaku-bottom-sheet .danmaku-panel-input {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
}
