/* ============================================
   拼音标注系统样式
   汉字上方固定显示拼音
   ============================================ */

/* 拼音标注行（居左对齐，用于古文） */
.annotated-line {
    line-height: 2.2;
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-end;
    gap: 0;
}

/* 诗句行样式（居中对齐，用于诗词） */
.poem-line {
    padding: 2px 0;
    text-align: center;
}

.poem-line-text {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

/* 字组容器（一个汉字+拼音） - 用于古文居左 */
.char-group {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: 1.8em;
    min-height: 2.4em;
    flex-shrink: 0;
    justify-content: flex-end;
    margin: 0;
}

/* 字组容器（一个汉字+拼音） - 用于诗词居中 */
.char-container {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: 1.6em;
    flex-shrink: 0;
    justify-content: flex-end;
}

/* 字组容器（古文观止等使用） */
.char {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: 1.8em;
    flex-shrink: 0;
    justify-content: flex-end;
}

/* 拼音（上方） */
.pinyin, .char-pinyin {
    font-size: 0.6em;
    color: var(--highlight-pinyin);
    font-family: "微软雅黑", "Microsoft YaHei", sans-serif !important;
    line-height: 1.2;
    margin-bottom: 1px;
    min-height: 0;
    white-space: nowrap;
    letter-spacing: 0;
    text-align: center;
    width: auto;
}

/* 汉字（下方） */
.hanzi, .char-text {
    font-size: 1.1em;
    color: var(--text-mohei);
    font-family: "微软雅黑", "Microsoft YaHei", sans-serif !important;
    line-height: 1.2;
    font-weight: 400;
    letter-spacing: 0;
    text-align: center;
    width: auto;
    display: inline-block;
}

/* 标点符号样式 - char-group */
.char-group.punctuation {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    min-width: auto;
    margin: 0 1px;
}

.char-group.punctuation .pinyin {
    display: none;
    height: 0;
}

.char-group.punctuation .hanzi {
    font-size: 1.1em;
    color: var(--text-gray);
    display: inline;
}

/* 标点符号样式 - char-container */
.char-container.punctuation {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: auto;
    margin: 0;
}

.char-container.punctuation .char-pinyin {
    display: none;
    height: 0;
    min-height: 0;
    margin: 0;
}

.char-container.punctuation .char-text {
    font-size: 1.1em;
    color: var(--text-gray);
    letter-spacing: 0;
    width: auto;
}

/* 标点符号样式 - char (古文观止) */
.char.punctuation {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    min-width: auto;
    margin: 0;
}

.char.punctuation .pinyin {
    display: none;
    height: 0;
    min-height: 0;
    margin: 0;
}

.char.punctuation .hanzi {
    font-size: 1.1em;
    color: var(--text-gray);
    letter-spacing: 0;
    width: auto;
}

/* 原文区域样式 */
.original-text {
    background: var(--bg-xuanzhi);
    padding: 2rem;
    border-radius: var(--radius-md);
    font-family: "微软雅黑", "Microsoft YaHei", sans-serif !important;
    text-align: justify;
    text-justify: inter-ideograph;
    -webkit-text-align: justify;
}

.original-text p {
    text-align: justify;
    text-justify: inter-ideograph;
    -webkit-text-align: justify;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.original-text .annotated-line {
    color: var(--text-shenhe);
    line-height: 2.8 !important;
}

.original-text p.annotated-line {
    line-height: 2.8 !important;
}

/* 白话文区域样式 */
.modern-text {
    background: var(--bg-huiben);
    padding: 2rem;
    border-radius: var(--radius-md);
}

.kids-version {
    font-size: 1.1rem;
    line-height: 2;
    color: var(--text-mohei);
    margin-bottom: 1rem;
    font-family: var(--font-sans);
}

/* 对照阅读容器 */
.parallel-unit {
    margin-bottom: 2rem;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-white);
    box-shadow: var(--shadow-sm);
}

.unit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: linear-gradient(90deg, var(--bg-nav) 0%, var(--bg-white) 100%);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.unit-number {
    font-family: var(--font-serif);
    font-size: 0.9rem;
    color: var(--text-gray);
    font-weight: 600;
}

.audio-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--color-zhusha);
    color: white;
    border: none;
    border-radius: var(--radius-xl);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.audio-btn:hover {
    background: #b82d28;
    transform: translateY(-1px);
}

.audio-btn.playing {
    background: var(--color-zhuqing);
}

.audio-btn .icon {
    font-size: 1.1rem;
}

/* 内容区域 */
.content-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

.content-wrapper .original-text,
.content-wrapper .modern-text {
    border-radius: 0;
}

.content-wrapper .original-text {
    border-right: 1px dashed rgba(0,0,0,0.1);
}

/* 插图区域 */
.illustration-area {
    display: none;
    padding: 1rem;
    text-align: center;
    background: var(--bg-white);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.unit-image {
    max-width: 200px;
    max-height: 150px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    margin: 0 auto;
}

.image-credit {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

/* 双向高亮效果 */
.sentence {
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    margin: -0.25rem -0.5rem;
}

.sentence:hover {
    background: rgba(255, 241, 118, 0.3);
}

.sentence.active {
    background: var(--highlight-yellow);
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* 非高亮内容淡化 */
.parallel-unit.has-highlight .sentence:not(.active) {
    opacity: 0.5;
}

/* 篇旨导读 */
.chapter-guide {
    background: linear-gradient(135deg, var(--bg-huiben) 0%, var(--bg-xuanzhi) 100%);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    border-left: 4px solid var(--color-zhusha);
}

.chapter-guide h3 {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    color: var(--color-zhusha);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.kids-summary {
    font-size: 1rem;
    color: var(--text-gray);
    line-height: 1.8;
}

/* 小问号注释 */
.note-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--color-liuli);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    cursor: help;
    margin-left: 0.25rem;
    vertical-align: middle;
    position: relative;
}

.note-trigger:hover .note-popup {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.note-popup {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--text-mohei);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    white-space: nowrap;
    opacity: 0;
    display: none;
    transition: all 0.3s ease;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.note-popup::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--text-mohei);
}

/* 对话体样式 */
.dialogue-speaker {
    font-weight: 600;
    color: var(--color-zhusha);
    margin-bottom: 0.5rem;
}

.dialogue-content {
    padding-left: 1.5rem;
    border-left: 2px solid var(--color-zhusha);
    margin-bottom: 1rem;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .content-wrapper {
        grid-template-columns: 1fr;
    }
    
    .content-wrapper .original-text {
        border-right: none;
        border-bottom: 1px dashed rgba(0,0,0,0.1);
    }
    
    .original-text,
    .modern-text {
        padding: 1.5rem;
    }
    
    .annotated-line {
        line-height: 2.8;
    }
    
    .char-group {
        margin: 0 4px;
    }
    
    .pinyin {
        font-size: 10px;
        min-height: 12px;
    }
    
    .hanzi {
        font-size: 18px;
        letter-spacing: 1px;
    }
    
    .kids-version {
        font-size: 1rem;
    }
    
    .unit-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }
    
    .audio-btn {
        align-self: stretch;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .original-text,
    .modern-text {
        padding: 1rem;
    }
    
    .char-group {
        margin: 0 3px;
    }
    
    .pinyin {
        font-size: 9px;
    }
    
    .hanzi {
        font-size: 16px;
        letter-spacing: 1px;
    }
}

/* 打印样式 */
@media print {
    .audio-btn,
    .note-trigger {
        display: none;
    }
    
    .parallel-unit {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .content-wrapper {
        grid-template-columns: 1fr;
    }
    
    .original-text {
        border-right: none;
        border-bottom: 1px dashed #ccc;
    }
}

/* 引号样式 - 确保显示 */
.char-group.punctuation .hanzi,
.char.punctuation .hanzi,
.char-container.punctuation .char-text {
    color: var(--text-gray);
    font-size: 1.2em;
    line-height: 1;
}

/* 引号区分样式 - 左引号蓝色，右引号红色 */
/* ASCII 双引号 " */
.hanzi:contains("\"") {
    /* 左双引号 " - 蓝色 */
}
.hanzi:contains("'"):matches(::before:first-child) {
    /* 测试样式 */
}

/* 使用伪元素区分左右引号 */
/* 由于 :contains 是实验特性，用 JS 添加 class 更可靠 */
/* 暂时用颜色区分 - 左引号蓝色调，右引号红色调 */
.char .hanzi:has(+ .char .hanzi:not([class])), /* 简化逻辑 */
.hanzi-quote-left {
    color: #2563eb !important; /* 蓝色 */
}

.hanzi-quote-right {
    color: #dc2626 !important; /* 红色 */
}
