/* ============================================================
   维汉自动方向对齐插件 - 样式表
   功能：维语RTL + 精美字体，汉语LTR，混合文本智能处理
   ============================================================ */

/* ---------- 引入维语精美字体（Google Fonts） ---------- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Naskh+Arabic:wght@400;500;600;700&family=Amiri:wght@400;700&family=Scheherazade+New:wght@400;700&display=swap');

/* ---------- 维语字体栈定义 ---------- */
:root {
    --uyghur-font: 'Noto Naskh Arabic', 'Scheherazade New', 'Amiri',
                   'UKIJ Tuz Tom', 'UKIJ Ekran', 'UKIJ Tuz',
                   'Tahoma', 'Arial', sans-serif;
    --uyghur-font-size-base: 1.12em;   /* 维语字体略大，更清晰 */
    --uyghur-line-height: 2;           /* 维语行高更宽松 */
    --uyghur-letter-spacing: 0.02em;
}

/* ---------- 维语内容通用样式 ---------- */
.ug-text,
[dir="rtl"].ug-content {
    font-family: var(--uyghur-font) !important;
    font-size: var(--uyghur-font-size-base);
    line-height: var(--uyghur-line-height);
    letter-spacing: var(--uyghur-letter-spacing);
    direction: rtl;
    unicode-bidi: plaintext;
    text-align: right;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 维语段落 */
p.ug-text,
.ug-content p {
    text-align: right;
    margin: 0.8em 0;
}

/* 维语标题 */
h1.ug-text, h2.ug-text, h3.ug-text,
h4.ug-text, h5.ug-text, h6.ug-text,
.ug-content h1, .ug-content h2, .ug-content h3,
.ug-content h4, .ug-content h5, .ug-content h6 {
    text-align: right;
    font-family: var(--uyghur-font) !important;
    line-height: 1.8;
}

/* 维语列表 */
.ug-text ul, .ug-text ol,
.ug-content ul, .ug-content ol {
    padding-right: 2em;
    padding-left: 0;
    text-align: right;
}

.ug-text li, .ug-content li {
    margin: 0.4em 0;
}

/* 维语引用块 */
.ug-text blockquote,
.ug-content blockquote {
    border-right: 4px solid #c9a96e;
    border-left: none;
    padding: 0.8em 1em 0.8em 0.5em;
    margin: 1em 0;
    background: linear-gradient(to left, rgba(201,169,110,0.08), transparent);
    font-style: normal;
}

/* 维语代码块（保持LTR） */
.ug-text pre, .ug-text code,
.ug-content pre, .ug-content code {
    direction: ltr;
    unicode-bidi: embed;
    text-align: left;
    font-family: 'Courier New', Consolas, monospace !important;
    font-size: 0.9em;
}

/* 维语链接 */
.ug-text a, .ug-content a {
    color: #1a73e8;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.ug-text a:hover, .ug-content a:hover {
    border-bottom-color: #1a73e8;
}

/* ---------- 汉语内容样式（保持默认LTR） ---------- */
.zh-text,
[dir="ltr"].zh-content {
    direction: ltr;
    unicode-bidi: plaintext;
    text-align: left;
}

/* ---------- 混合文本处理 ---------- */
/* 段落内同时包含汉维时，按段落主语言方向对齐 */
.mixed-text {
    unicode-bidi: plaintext;
}

/* 行内维语片段（在汉语段落中出现的维语） */
.ug-inline {
    font-family: var(--uyghur-font);
    font-size: 1.08em;
    direction: rtl;
    unicode-bidi: embed;
    display: inline-block;
    margin: 0 2px;
    padding: 0 3px;
    background: rgba(201,169,110,0.06);
    border-radius: 3px;
}

/* 行内汉语片段（在维语段落中出现的汉语） */
.zh-inline {
    direction: ltr;
    unicode-bidi: embed;
    display: inline-block;
    margin: 0 2px;
}

/* ---------- 防止布局混乱的关键样式 ---------- */
/* 表格单元格内的维语 */
.ug-text table, .ug-content table {
    direction: rtl;
}

.ug-text th, .ug-text td,
.ug-content th, .ug-content td {
    text-align: right;
    vertical-align: top;
}

/* 表单元素 */
.ug-text input[type="text"],
.ug-text input[type="search"],
.ug-text textarea,
.ug-content input[type="text"],
.ug-content input[type="search"],
.ug-content textarea {
    direction: rtl;
    text-align: right;
    font-family: var(--uyghur-font);
}

/* 图片和多媒体保持正常流 */
.ug-text img, .ug-content img,
.ug-text video, .ug-content video,
.ug-text iframe, .ug-content iframe {
    max-width: 100%;
    height: auto;
}

/* 浮动元素在RTL下的修正 */
.ug-text .alignleft,
.ug-content .alignleft {
    float: right;
    margin: 0 0 1em 1em;
}

.ug-text .alignright,
.ug-content .alignright {
    float: left;
    margin: 0 1em 1em 0;
}

/* 清除浮动 */
.ug-text::after,
.ug-content::after {
    content: '';
    display: table;
    clear: both;
}

/* ---------- 文章内容区域特殊适配 ---------- */
/* Emlog 默认文章内容容器 */
.log-content .ug-text,
.article-content .ug-text,
.post-content .ug-text,
.entry-content .ug-text {
    margin: 0.6em 0;
}

/* 评论区维语 */
.comment-content .ug-text {
    font-size: 1.05em;
}

/* ---------- 加载动画（字体加载前的占位） ---------- */
.ug-text.font-loading {
    opacity: 0.85;
    transition: opacity 0.3s;
}

.ug-text.font-loaded {
    opacity: 1;
}

/* ---------- 响应式适配 ---------- */
@media screen and (max-width: 768px) {
    :root {
        --uyghur-font-size-base: 1.08em;
        --uyghur-line-height: 1.9;
    }

    .ug-text blockquote,
    .ug-content blockquote {
        padding: 0.6em 0.8em 0.6em 0.4em;
    }
}

@media screen and (max-width: 480px) {
    :root {
        --uyghur-font-size-base: 1.05em;
    }
}

/* ---------- 打印样式 ---------- */
@media print {
    .ug-text, .ug-content {
        font-size: 12pt;
        line-height: 1.8;
    }
}
