/* docs/assets/shenlun.css */

/* docs/assets/shenlun.css */

/* ==========================================================================
   1. 基础样式 (全响应式 / Dynamic Fluid Layout)
   ========================================================================== */

.shenlun-wrapper {
    /* --- 核心核心设置 --- */
    /* 1. 启用容器查询：允许内部字体根据容器宽度自动缩放 */
    container-type: inline-size; 
    
    /* 2. 移除固定宽度，改为占满父容器 */
    width: 100%;
    /* 限制最大宽度，防止在大屏幕上格子过大 (可按需修改) */
    max-width: 1000px; 
    
    /* 3. 定义颜色和字体 */
    --grid-color: rgba(255, 82, 82, 0.4); 
    --text-color: #2c3e50;
    --font-face: "LXGW WenKai", "KaiTi", "楷体", "STKaiti", "SimSun", serif;
    
    display: flex;
    flex-direction: column; 
    align-items: center;
    font-family: var(--font-face);
    margin: 20px auto; /* 居中 */
}

.shenlun-wrapper .paper-container {
    width: 100%;
    min-width: 0; /* 允许压缩 */
    
    background-color: #fff;
    /* 内边距使用 cqi (容器宽度百分比)，保持比例 */
    padding: 3cqi 4cqi; 
    
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    box-sizing: border-box; 
    text-align: left;
    line-height: normal;
    margin-bottom: 20px;
    border-radius: 8px; /* 圆角稍微改小一点适配响应式 */
    
    /* 打印与分页设置 */
    break-inside: avoid;
    page-break-after: always;
    
    transition: background-color 0.3s, box-shadow 0.3s;
}

.shenlun-wrapper .paper-container:last-child {
    margin-bottom: 0;
}

/* --- 行样式 --- */
.shenlun-wrapper .grid-row {
    display: flex;
    width: 100%;
    
    /* 【关键】高度不再固定，由格子撑开 */
    height: auto; 
    
    /* 边框 */
    border: 1px solid var(--grid-color);
    
    /* 【关键】行间距：使用 em 单位，随字体大小自动伸缩 */
    margin-bottom: 0.3em; 
    
    box-sizing: border-box;   
    position: relative;
    padding: 0;
}

/* 最后一行也需要边框，不需要下边距 */
.shenlun-wrapper .grid-row:last-child {
    margin-bottom: 0;
}

/* --- 格子样式 --- */
.shenlun-wrapper .grid-cell {
    flex: 1; 
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* 【核心】强制正方形：宽度自动，高度等于宽度 */
    aspect-ratio: 1 / 1;
    
    /* 【核心】动态字体大小计算 */
    /* 解释：25格每格占 4%，字体一般占格子的 55% 左右 -> 2.2cqi */
    /* clamp(最小px, 动态计算值, 最大px) */
    font-size: clamp(9px, 2.2cqi, 40px);
    
    color: var(--text-color);
    border-right: 1px solid var(--grid-color);
    position: relative;
    line-height: 1;
    white-space: nowrap; 
    padding: 0;
    margin: 0;
}

.shenlun-wrapper .grid-cell:nth-child(25) {
    border-right: none;
}

/* --- 特殊内容适配 --- */

/* 数字序号 (1.) */
.shenlun-wrapper .grid-cell.is-number {
    /* font-family: "Times New Roman", serif; */
    /* 稍微缩小一点以免溢出 */
    font-size: 0.9em; 
}

/* 双字符 (xx) / 双数字 (12) */
.shenlun-wrapper .grid-cell.double-x,
.shenlun-wrapper .grid-cell.double-num {
    /* font-family: "Times New Roman", serif; */
    /* 比汉字略大 */
    font-size: 1.1em; 
    /* letter-spacing: -0.05em; */
    color: var(--text-color);
}

/* 纯双标点同格 (”。) */
.shenlun-wrapper .grid-cell.double-punct {
    font-family: var(--font-face);
    letter-spacing: -0.3em; /* 使用 em 替代 px */
    text-indent: -0.15em;   
}

/* 挤压样式 (字，) */
.shenlun-wrapper .grid-cell.squeeze-punct {
    overflow: hidden;
}

.shenlun-wrapper .grid-cell.squeeze-punct .char {
    /* 使用百分比位移，适应不同大小的格子 */
    transform: translateX(-15%); 
    display: inline-block;
}

.shenlun-wrapper .grid-cell.squeeze-punct .punct {
    position: absolute;
    right: -15%; /* 使用百分比 */
    height: 100%;
    display: flex;
    align-items: center; 
    justify-content: center;
    font-family: var(--font-face);
    /* 标点稍微紧凑一点 */
    letter-spacing: -0.1em; 
}

/* 字数标记 */
.shenlun-wrapper .word-count-mark {
    position: absolute;
    /* 放在行间距里 */
    bottom: -0.9em; 
    right: 0;
    /* 字体也要动态 */
    font-size: clamp(8px, 1cqi, 12px); 
    transform: none; /* 移除之前的 scale */
    color: #999;
    font-family: Arial, sans-serif;
    pointer-events: none;
    line-height: 1;
}


/* ==========================================================================
   2. 夜间模式适配 (Dark Mode)
   ========================================================================== */
body[data-md-color-scheme="slate"] .shenlun-wrapper {
    --text-color: #e6e6e6 !important;
    --grid-color: rgba(255, 120, 120, 0.25) !important;
}

body[data-md-color-scheme="slate"] .shenlun-wrapper .paper-container {
    background-color: #1e1e1e !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.8) !important;
}

body[data-md-color-scheme="slate"] .shenlun-wrapper .word-count-mark {
    color: #777 !important;
}

body[data-md-color-scheme="slate"] .shenlun-wrapper .grid-cell::selection,
body[data-md-color-scheme="slate"] .shenlun-wrapper .grid-cell *::selection {
    background-color: rgba(255, 82, 82, 0.4);
    color: #fff;
}


/* ==========================================================================
   4. 打印适配
   ========================================================================== */
@media print {
    body, .shenlun-wrapper {
        background: none !important;
        padding: 0;
        margin: 0;
        width: 100%;
        max-width: none;
    }
    .shenlun-wrapper .paper-container {
        box-shadow: none !important;
        margin-bottom: 0;
        border: none !important;
        background-color: transparent !important;
        /* 打印时通常希望恢复固定大小以确保A4纸效果，但在网页打印中，
           保持流体铺满通常效果更好，或者可以强制指定打印宽度 */
        width: 100%; 
    }
    .shenlun-wrapper {
        --grid-color: rgba(255, 82, 82, 0.6) !important; /* 打印时红线稍微加深 */
        --text-color: #000 !important;
    }
    /* 打印时隐藏字数标记，或者保留看需求 */
    /* .shenlun-wrapper .word-count-mark { display: none; } */
}


/* ==========================================================================
   2. 夜间模式适配 (Dark Mode) - 修复版
   ========================================================================== */

/* 
   核心修复说明：
   不能在 body[...] 选择器后面直接写 .shenlun-wrapper 的嵌套样式。
   必须写完整的选择器路径。
*/

/* 针对 MkDocs Material 主题的 Slate 模式 */
body[data-md-color-scheme="slate"] .shenlun-wrapper {
    /* 1. 变量重写：文字变白，红线变淡 */
    --text-color: #e6e6e6 !important;
    --grid-color: rgba(255, 120, 120, 0.25) !important;
    
    /* 2. 移除最外层的灰色背景，透出网页底色 */
    background-color: transparent !important;
}

/* 针对 MkDocs Material 主题的 Slate 模式 - 纸张容器 */
body[data-md-color-scheme="slate"] .shenlun-wrapper .paper-container {
    /* 3. 纸张变黑 */
    background-color: #1e1e1e !important;
    /* 4. 增加微弱亮边框，防止纸张边缘看不清 */
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    /* 5. 加深阴影 */
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.8) !important;
}

/* 针对 MkDocs Material 主题的 Slate 模式 - 字数标记 */
body[data-md-color-scheme="slate"] .shenlun-wrapper .word-count-mark {
    color: #888 !important;
}

/* 针对 MkDocs Material 主题的 Slate 模式 - 选中效果 */
body[data-md-color-scheme="slate"] .shenlun-wrapper .grid-cell::selection,
body[data-md-color-scheme="slate"] .shenlun-wrapper .grid-cell *::selection {
    background-color: rgba(255, 82, 82, 0.4);
    color: #fff;
}


/* ==========================================================================
   3. 系统深色模式适配 (作为备用，当不使用 Slate 主题但系统是深色时)
   ========================================================================== */
@media (prefers-color-scheme: dark) {
    /* 只有当 body 没有明确指定 data-md-color-scheme="default" (即强制亮色) 时才生效 */
    body:not([data-md-color-scheme="default"]) .shenlun-wrapper {
        --text-color: #e6e6e6 !important;
        --grid-color: rgba(255, 120, 120, 0.25) !important;
        background-color: transparent !important;
    }

    body:not([data-md-color-scheme="default"]) .shenlun-wrapper .paper-container {
        background-color: #1e1e1e !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.8) !important;
    }
    
    body:not([data-md-color-scheme="default"]) .shenlun-wrapper .word-count-mark {
        color: #888 !important;
    }
}


/* ==========================================================================
   移动端适配：全屏铺满 + 特殊字符精细修正
   ========================================================================== */

@media screen and (max-width: 800px) {
    .shenlun-wrapper {
        /* 1. 布局：强制铺满，禁止左右滑动 */
        display: block !important;
        width: auto;
        /* 抵消 MkDocs 默认左右边距，让表格贴边 */
        margin: 15px -16px; 
        overflow-x: hidden; 

        /* 2. 核心计算：基于容器宽度的动态字号 */
        /* 手机竖屏通常很窄，这里设定基准字号 */
        /* clamp(最小9px, 容器宽的2.5%, 最大14px) */
        --mobile-font-size: clamp(9px, 2.5cqi, 14px);
    }

    .shenlun-wrapper .paper-container {
        width: 100% !important;
        min-width: 0 !important;
        /* 左右留极窄白边 (5px 左右) */
        padding: 15px 1.5cqi !important; 
        box-sizing: border-box;
        border-radius: 0; /* 手机端直角更像纸张 */
        
        /* 移除大阴影，改用上下细边框 */
        box-shadow: none;
        border-top: 1px solid rgba(0,0,0,0.05);
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }

    /* 3. 基础网格样式微调 */
    .shenlun-wrapper .grid-row {
        /* 使用 0.5px 极细边框，防止格子看起来像黑框 */
        border-width: 0.5px;
        /* 行间距大幅缩小 */
        margin-bottom: 2px;
    }

    .shenlun-wrapper .grid-cell {
        /* 强制使用动态计算的手机字号 */
        font-size: var(--mobile-font-size);
        /* 右边框也变细 */
        border-right-width: 0.5px;
    }

    /* ==========================================
       4. 特殊内容适配 (关键优化部分)
       使用 em/scale 代替 px，实现完美缩放
       ========================================== */

    /* [A] 双字符/数字 (xx, 12) */
    .shenlun-wrapper .grid-cell.double-x,
    .shenlun-wrapper .grid-cell.double-num {
        /* 继承基准字号后，再缩小到 85% */
        font-size: 0.65em !important; 
        /* font-family: "Times New Roman", serif; */
        /* 稍微收紧字间距 */
        /* letter-spacing: -0.5px; */
        /* 垂直居中修正 */
        transform: translateY(0); 
    }

    /* [B] 纯标点 (” 。) */
    .shenlun-wrapper .grid-cell.double-punct {
        /* 缩小字间距 (相对单位) */
        letter-spacing: -0.15em; 
        text-indent: -0.1em;
    }

    /* [C] 挤压标点 (字，) - 最难处理的部分 */
    .shenlun-wrapper .grid-cell.squeeze-punct {
        /* 允许溢出一点点以放下标点 */
        overflow: visible; 
    }

    .shenlun-wrapper .grid-cell.is-number {
        font-size: 0.65em; 
    }

    .shenlun-wrapper .grid-cell.squeeze-punct .char {
        /* 汉字向左微调 10% */
        transform: translateX(-10%);
        display: inline-block;
    }

    .shenlun-wrapper .grid-cell.squeeze-punct .punct {
        position: absolute;
        /* 标点贴在右侧，使用百分比适应不同宽度的格子 */
        right: -15%; 
        height: 100%;
        display: flex;
        align-items: center; 
        justify-content: center;
        
        /* 标点单独缩小至 75% */
        transform: scale(0.75); 
        /* 修正标点垂直中心 */
        transform-origin: center center;
    }

    /* [D] 字数标记 (100字) */
    .shenlun-wrapper .word-count-mark {
        /* 极小字体，且半透明 */
        font-size: 6px;
        /* 紧贴格子底部 */
        bottom: -6px;
        right: 0px;
        opacity: 0.5;
        /* 防止换行导致布局崩坏 */
        white-space: nowrap;
        transform: scale(0.85);
        transform-origin: right top;
    }
}