/* ============================================================
single-poetry.css - 诗词详情页专属样式
版本：重构版 v4.0 - 无 !important 版本
单位使用规范：
• 字体大小：使用 rem（随用户字号缩放）
• 容器尺寸（宽/高/边距）：使用 rem（保持比例）
• 边框宽度：使用 px（保持 1px 清晰）
• 圆角：使用 px（保持精致度）
• 阴影：使用 px（保持质感）
• 固定布局：使用 px（不随字体缩放）
更新内容：
1. 彻底移除所有 !important
2. 采用级联优先级策略
3. 统一选择器权重
4. 优化移动端适配
============================================================ */

/* ========== 详情页主题变量 ========== */
/* 明亮模式 */
body.light-mode {
    --poetry-header-bg: linear-gradient(135deg, rgba(124, 77, 255, 0.15), rgba(0, 145, 234, 0.15));
    --poetry-card-bg: rgba(255, 255, 255, 0.4);
    --poetry-line-border: 1px solid rgba(0, 0, 0, 0.05);
    --poetry-highlight-bg: rgba(3, 105, 161, 0.15);
    --poetry-translate-bg: rgba(0, 0, 0, 0.03);
    --poetry-note-bg: #f1f5f9;
    --poetry-text-primary: #1a1a2e;
    --poetry-text-secondary: #475569;
    --poetry-meta-color: #666;
    --poetry-btn-bg: #f0f0f0;
    --poetry-btn-t-color: #0984e3;
    --poetry-btn-n-color: #00b894;
}

/* 黑暗模式 */
body.dark-mode {
    --poetry-header-bg: linear-gradient(135deg, rgba(124, 77, 255, 0.25), rgba(0, 145, 234, 0.25));
    --poetry-card-bg: rgba(30, 20, 50, 0.6);
    --poetry-line-border: 1px solid rgba(255, 255, 255, 0.1);
    --poetry-highlight-bg: rgba(124, 77, 255, 0.25);
    --poetry-translate-bg: rgba(255, 255, 255, 0.05);
    --poetry-note-bg: #1e293b;
    --poetry-text-primary: #e0e6ed;
    --poetry-text-secondary: #cbd5e1;
    --poetry-meta-color: #94a3b8;
    --poetry-btn-bg: #2d3748;
    --poetry-btn-t-color: #60a5fa;
    --poetry-btn-n-color: #34d399;
}

/* 默认主题 */
body:not(.light-mode):not(.dark-mode) {
    --poetry-header-bg: linear-gradient(135deg, rgba(124, 77, 255, 0.2), rgba(0, 145, 234, 0.2));
    --poetry-card-bg: rgba(255, 255, 255, 0.4);
    --poetry-line-border: 1px solid rgba(0, 0, 0, 0.05);
    --poetry-highlight-bg: rgba(3, 105, 161, 0.15);
    --poetry-translate-bg: rgba(0, 0, 0, 0.03);
    --poetry-note-bg: #f1f5f9;
    --poetry-text-primary: #1a1a2e;
    --poetry-text-secondary: #475569;
    --poetry-meta-color: #666;
    --poetry-btn-bg: #f0f0f0;
    --poetry-btn-t-color: #0984e3;
    --poetry-btn-n-color: #00b894;
}

/* ========== 详情页布局 ========== */
/* 容器 */
.poetry-layout-v4 .inside-article {
    background: transparent;
    box-shadow: none;
    padding: 0;
}

/* 头卡片 */
.poetry-header-card {
    background: var(--poetry-header-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    padding: 0.3125rem;
    margin-bottom: 0.3125rem;
    text-align: center;
}

/* 主标题 - 2rem（32px） */
.poetry-header-card .entry-title {
    color: var(--poetry-text-primary);
    font-size: 2rem;
    margin-bottom: 0.3125rem;
}

/* 作者朝代 - 0.9375rem（15px） */
.poetry-header-card .poetry-meta {
    color: var(--poetry-meta-color);
    font-size: 0.9375rem;
}

/* 卡片容器 */
.poetry-card {
    background: var(--poetry-card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    padding: 0.625rem;
    margin-bottom: 1.5625rem;
    overflow: hidden;
}

/* 诗词行 */
.poetry-line-item {
    margin-bottom: 0.15rem;
    border-bottom: var(--poetry-line-border);
}

.poetry-line-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* 诗词正文 - 1rem（16px） */
.line-q {
    font-size: 1rem;
    line-height: 2;
    color: var(--poetry-text-primary);
}

/* ========== 拼音样式（旧版 ruby 兼容） ========== */
ruby {
    ruby-position: over;
    margin: 0 1px;
    display: inline-flex;
    flex-direction: column-reverse;
    align-items: center;
    vertical-align: middle;
}

rt.line-p {
    font-size: 0.75rem;
    color: var(--poetry-text-secondary);
    letter-spacing: 0.5px;
    padding-bottom: 0.25rem;
    line-height: 1.2;
}

/* 移动端拼音稍小 */
@media (max-width: 768px) {
    rt.line-p {
        font-size: 0.65rem;
    }
    .line-q {
        font-size: 0.9375rem;
        line-height: 1.8;
    }
}

/* ========== 高亮词：默认完全透明，无气泡 ========== */
.poetry-word-highlight {
    display: inline;
    padding: 0;
    margin: 0;
    background: transparent;
    transition: background-color 0.2s;
    cursor: default;
}

/* 角标：默认隐藏 */
.note-ref,
.note-ref-absolute {
    display: none;
}

/* ========== 开启注释后的样式（.show-notes 类由 JS 添加） ========== */
.show-notes .poetry-word-highlight {
    cursor: pointer;
    background-color: var(--poetry-highlight-bg);
    border-radius: 8px;
    padding: 0.125rem 0.375rem;
    margin: 0 0.125rem;
    display: inline-block;
}

.show-notes .poetry-word-highlight:hover {
    background-color: rgba(3, 105, 161, 0.28);
}

.show-notes .note-ref,
.show-notes .note-ref-absolute {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: bold;
    color: #7c4dff;
    margin-left: 0.125rem;
    vertical-align: super;
}

/* 译文区域 - 0.9375rem（15px） */
.line-t {
    display: none;
    color: var(--poetry-text-secondary);
    background: var(--poetry-translate-bg);
    padding: 0.25rem 1rem;
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.line-t b {
    color: var(--poetry-btn-t-color);
    margin-right: 0.3125rem;
}

.line-t p {
    margin-bottom: 0;
}

/* 注释列表区域 - 0.875rem（14px） */
.line-n {
    display: none;
    margin-top: 0.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.line-n span {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
    background: var(--poetry-note-bg);
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    color: var(--poetry-text-secondary);
    border: 1px solid rgba(0, 0, 0, 0.1);
    gap: 0.25rem;
}

.line-n span b {
    font-weight: 600;
    color: var(--poetry-text-primary);
    margin-right: 0.25rem;
}

.note-num {
    font-weight: bold;
    color: #7c4dff;
    margin-right: 0.25rem;
}

/* 鉴赏区 */
.poetry-jianshang-section {
    line-height: 1.8;
    color: var(--poetry-text-secondary);
    margin-top: 1.875rem;
}

/* 鉴赏区小标题 - 1.25rem（20px） */
.poetry-jianshang-section .section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--poetry-text-primary);
    border-left: 4px solid #7c4dff;
    padding-left: 0.9375rem;
    margin: 1.875rem 0 0.9375rem;
}

/* 悬浮气泡弹窗 */
#p-popover {
    display: none;
    position: absolute;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    color: #fff;
    padding: 0.625rem 0.875rem;
    border-radius: 8px;
    font-size: 0.8125rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    max-width: 260px;
    line-height: 1.4;
    pointer-events: none;
}

/* 移动端调整 */
@media (max-width: 768px) {
    .poetry-card,
    .poetry-header-card {
        padding: 0.25rem;
    }
    .poetry-header-card .entry-title {
        font-size: 1.5rem;
    }
    #p-popover {
        max-width: 200px;
        font-size: 0.6875rem;
        padding: 0.5rem 0.75rem;
    }
}

/* ========== 独立控制栏样式 ========== */
.poetry-control-bar-wrapper {
    margin: 0.625rem 0;
    padding: 0;
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.poetry-control-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.9375rem;
    background: var(--poetry-card-bg, rgba(255,255,255,0.3));
    backdrop-filter: blur(8px);
    padding: 0.35rem 0.25rem;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.3);
}

.control-buttons-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.font-selector-group {
    display: flex;
    align-items: center;
}

/* 按钮 - 1rem（16px） */
.btn-toggle {
    padding: 0.5rem 1.25rem;
    border-radius: 40px;
    font-size: 1rem;
    font-weight: 500;
    background: var(--poetry-btn-bg);
    cursor: pointer;
    transition: all 0.25s;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--poetry-text-primary);
}

.btn-toggle.active {
    background: linear-gradient(135deg, #7832ff, #0091ea);
    color: #fff;
    border-color: transparent;
}

/* ========== 字体选择器样式 ========== */
.font-selector-wrapper {
    position: relative;
    display: inline-block;
}

/* 字体选择器按钮 - 1rem（16px） */
.btn-font-selector {
    padding: 0.5rem 1.25rem;
    border-radius: 40px;
    font-size: 1rem;
    font-weight: 500;
    background: var(--poetry-btn-bg, #f0f0f0);
    cursor: pointer;
    transition: all 0.25s;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: var(--poetry-text-primary, #1a1a2e);
}

.btn-font-selector:hover {
    background: #e0e0e0;
}

.font-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    left: auto;
    margin-top: 0.5rem;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    z-index: 9999;
    display: none;
    overflow: hidden;
}

.font-dropdown.show {
    display: block;
}

/* 字体下拉选项 - 0.875rem（14px） */
.font-option {
    padding: 0.625rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.875rem;
    white-space: nowrap;
}

.font-option:hover {
    background: #f5f5f5;
}

.font-option.active {
    background: linear-gradient(135deg, #7832ff, #0091ea);
    color: #fff;
}

/* ========== 独立翻译+注释模块 ========== */
.trans-notes-module {
    margin: 1.5625rem 0;
    background: var(--poetry-card-bg, rgba(255,255,255,0.4));
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    overflow: hidden;
}

.trans-notes-header {
    padding: 0.9375rem 1.25rem;
    background: var(--poetry-btn-bg, #f0f0f0);
    font-weight: 600;
    font-size: 0.9375rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.trans-notes-header .toggle-icon {
    margin-right: 0.5rem;
}

.trans-notes-body {
    padding: 1.25rem;
    max-height: 300px;
    overflow-y: hidden;
    transition: max-height 0.3s ease;
}

.trans-notes-body.expanded {
    max-height: none;
    overflow-y: visible;
}

.trans-notes-footer {
    padding: 0.75rem 1.25rem;
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.btn-expand {
    background: transparent;
    border: none;
    color: #7c4dff;
    cursor: pointer;
    font-size: 0.8125rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    transition: all 0.2s;
}

.btn-expand:hover {
    background: rgba(124, 77, 255, 0.1);
}

.tn-item {
    margin-bottom: 1.25rem;
    padding-bottom: 0.9375rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.tn-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* 翻译模块 - 0.875rem（14px） */
.tn-translate {
    color: #2c7a4d;
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.tn-notes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
}

/* 注释模块 - 0.8125rem（13px） */
.tn-note {
    background: rgba(124, 77, 255, 0.08);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8125rem;
    color: #6c757d;
}

.tn-note strong {
    color: #7c4dff;
    margin-right: 0.25rem;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .poetry-control-bar {
        flex-direction: column;
        align-items: stretch;
        border-radius: 20px;
    }
    .control-buttons-group {
        justify-content: center;
    }
    .font-selector-group {
        justify-content: center;
    }
    .btn-toggle,
    .btn-font-selector {
        padding: 0.375rem 1rem;
        font-size: 0.875rem;
    }
    .font-dropdown {
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* 黑暗模式适配 */
body.dark-mode .font-dropdown {
    background: #2d3748;
    border-color: #4a5568;
}

body.dark-mode .font-option {
    color: #e0e6ed;
}

body.dark-mode .font-option:hover {
    background: #4a5568;
}

body.dark-mode .trans-notes-module {
    background: var(--poetry-card-bg, rgba(30,20,50,0.6));
    border-color: rgba(255,255,255,0.1);
}

body.dark-mode .trans-notes-header {
    background: var(--poetry-btn-bg, #2d3748);
}

body.dark-mode .tn-translate {
    color: #60a5fa;
}

body.dark-mode .tn-note {
    background: rgba(96, 165, 250, 0.15);
}

/* ============================================================
田字格样式（div 方案）- 无 !important 重构版
采用级联优先级策略，彻底移除 !important
============================================================ */

/* 基础样式层 - 定义所有元素的默认行为 */
.char-with-pinyin {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 0.1rem 0.25rem;
}

.char-grid {
    width: 2rem;
    height: 2rem;
    font-size: 1.2rem;
    color: var(--poetry-text-primary, #1a1a2e);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border: 1px solid #ebdcb9;
    border-radius: 3px;
    background-color: #fdfbf7;
    background-image: 
        linear-gradient(to right, #ebdcb9 50%, transparent 50%),
        linear-gradient(to bottom, #ebdcb9 50%, transparent 50%);
    background-position: center center;
    background-size: 0.375rem 0.0625rem, 0.0625rem 0.375rem;
    background-repeat: repeat-x, repeat-y;
    transition: transform 0.2s, background-color 0.2s;
}

.poetry-card .pinyin-top {
    display: none;
    position: relative;
    width: 100%;
    min-width: 2.2rem;
    font-size: 0.75rem;
    font-family: "Lucida Sans Unicode", "Palatino Linotype", "Palatino", "Book Antiqua", "Georgia", sans-serif;
    color: var(--poetry-text-secondary, #475569);
    white-space: nowrap;
    text-align: center;
    background-image: 
        linear-gradient(to bottom, 
            #cbd5e1 0%, #cbd5e1 1px, transparent 1px,
            transparent 33%, #cbd5e1 33%, #cbd5e1 calc(33% + 1px), transparent calc(33% + 1px),
            transparent 66%, #cbd5e1 66%, #cbd5e1 calc(66% + 1px), transparent calc(66% + 1px),
            transparent calc(100% - 1px), #cbd5e1 calc(100% - 1px), #cbd5e1 100%
        );
    background-size: 100% 100%;
    background-repeat: no-repeat;
    height: 1.5rem;
    line-height: 1.25rem;
    padding-top: 0.08rem;
    margin-bottom: 0.25rem;
    box-sizing: border-box;
}

/* 正文区域布局 - 覆盖行高 */
.poetry-card .line-q {
    line-height: normal;
    text-align: left;
    word-break: break-all;
    display: block;
}

/* 拼音显示控制 */
.pinyin-visible .pinyin-top {
    display: block;
}

/* ========== 非田字格模式（样式覆盖层） ========== */
/* 通过更高的选择器优先级来覆盖基础样式 */
:is(.poetry-card, #poetry-main-area, .inside-article):not(.tian-grid-mode) .char-with-pinyin {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    margin: 0 0.125rem;
    vertical-align: middle;
}

:is(.poetry-card, #poetry-main-area, .inside-article):not(.tian-grid-mode) .char-grid {
    display: inline-block;
    width: auto;
    height: auto;
    min-width: 1.2rem;
    border: none;
    background: none;
    background-image: none;
    font-size: 1.2rem;
    padding: 0;
    margin: 0;
    text-align: center;
    box-shadow: none;
}

:is(.poetry-card, #poetry-main-area, .inside-article):not(.tian-grid-mode) .pinyin-top {
    display: none;
    background-image: none;
    text-align: center;
    font-size: 0.7rem;
    padding: 0;
    margin: 0;
    min-width: auto;
    width: auto;
}

/* 非田字格模式下显示拼音 */
:is(.poetry-card, #poetry-main-area, .inside-article):not(.tian-grid-mode).pinyin-visible .pinyin-top {
    display: block;
}

/* 标点符号样式 */
:is(.poetry-card, #poetry-main-area, .inside-article):not(.tian-grid-mode) .punctuation {
    display: inline-block;
    min-width: 1rem;
    text-align: center;
}

/* ========== 田字格模式特有样式（无需覆盖，使用基础样式即可） ========== */
/* 如需田字格特有样式，在此添加 */
.tian-grid-mode .char-with-pinyin {
    position: relative;
}

/* ========== 移动端适配 ========== */
@media (max-width: 768px) {
    .char-grid {
        width: 2rem;
        height: 2rem;
        font-size: 1rem;
    }
    
    .poetry-card .pinyin-top {
        min-width: 2rem;
        font-size: 0.65rem;
        height: 1.2rem;
        line-height: 1.05rem;
        padding-top: 0.04rem;
    }
    
    .poetry-card .line-q {
        line-height: 2.8;
    }
}

/* ========== 黑暗模式适配 ========== */
.dark-mode .char-grid {
    border-color: #64748b;
    background-image: 
        linear-gradient(to right, #475569 1px, transparent 1px),
        linear-gradient(to bottom, #475569 1px, transparent 1px);
}

.dark-mode .pinyin-top {
    background-image: 
        linear-gradient(to bottom, 
            #475569 0%, #475569 1px, transparent 1px,
            transparent 33%, #475569 33%, #475569 calc(33% + 1px), transparent calc(33% + 1px),
            transparent 66%, #475569 66%, #475569 calc(66% + 1px), transparent calc(66% + 1px),
            transparent calc(100% - 1px), #475569 calc(100% - 1px), #475569 100%
        );
}

/* ========== PDF 工作台专用适配 ========== */
#pdf-render-area {
    font-size: 16px; /* 默认值，会被 JS 覆盖 */
}

#pdf-render-area .char-grid {
    width: 2em;
    height: 2em;
    font-size: 1.2em;
}

#pdf-render-area .pinyin-top {
    font-size: 0.75em;
}

#pdf-render-area .line-q {
    font-size: 1em;
}

#pdf-render-area .line-t {
    font-size: 0.9375em;
}

#pdf-render-area .line-n span {
    font-size: 0.875em;
}

/* PDF 工作台拼音显示 */
#pdf-render-area.pinyin-visible .pinyin-top,
#pdf-preview-pages.pinyin-visible .pinyin-top,
.pdf-global-portal.pinyin-visible .pinyin-top {
    display: block;
}

/* PDF 工作台田字格模式 */
#pdf-render-area.tian-grid-mode .char-with-pinyin,
#pdf-preview-pages.tian-grid-mode .char-with-pinyin,
.pdf-global-portal.tian-grid-mode .char-with-pinyin {
    display: inline-flex;
    width: 48px;
    height: 48px;
    border: 1px solid #ebdcb9;
    margin: 0 0.1rem 0.25rem;
    position: relative;
}

#pdf-render-area.tian-grid-mode .pinyin-top,
#pdf-preview-pages.tian-grid-mode .pinyin-top,
.pdf-global-portal.tian-grid-mode .pinyin-top {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.65rem;
    background: none;
}

/* PDF 工作台非田字格模式 */
#pdf-render-area:not(.tian-grid-mode) .char-grid,
#pdf-render-area .inside-article:not(.tian-grid-mode) .char-grid {
    position: static;
    background: none;
    border: none;
    box-shadow: none;
}

/* PDF 工作台非田字格模式下的拼音 */
#pdf-render-area:not(.tian-grid-mode) .pinyin-top {
    position: static;
    background: none;
}