/* 六爻排盘盘面：神煞表、干支时间、藏/本/变三卦列布局、爻图形与动爻配色 */
/* 本文件同时被六爻页、案例页与小灵儿排盘复用，类名与 DOM 结构由
   liuyao_case_paipan_renderer.js 及 _paipan_display.html 固定，勿随意改名 */

/* ─── 设计变量 ─────────────────────────────────────────────── */
:root {
    /* 动爻（老阴/老阳）与藏卦伏神强调色：两个主题各自需要固定色值，
       与 --accent-* / --primary-color-hover 的主题取值不同，故不做令牌映射 */
    --ly-yao-moving: #ff7c5e;
    --ly-canggua-fushen: #c59e77;
    --ly-canggua-fushen-light: #ff7c5e;
    --ly-canggua-muted: #4a4a4a;
    --ly-canggua-muted-light: #a8a8a8;
}

/* ─── 神煞表 ───────────────────────────────────────────────── */
.shensha-grid {
    color: var(--text-primary);
}

.shensha-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
}

/* 每行 6 组「地支时间 + 神煞」列：auto 给时间格，1fr 均分剩余空间，
   使上下两行同位置的列宽完全一致 */
.shensha-list-row1,
.shensha-list-row2 {
    display: grid;
    grid-template-columns: repeat(6, auto 1fr);
    width: 100%;
}

.shensha-list-shen {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0; /* 允许 grid 子项收缩，溢出时才出省略号 */
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
    border: 0.5px solid var(--border-primary);
}

.shensha-list-time {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    min-height: 25px;
    padding: 2px;
    font-size: 1rem;
    border: 0.5px solid var(--border-primary);
}

/* 外框由 .shensha-list 提供，单元格只保留行间分隔线 */
.shensha-list-row1 > * {
    border-top: none;
}

.shensha-list-row2 > * {
    border-bottom: none;
}

.shensha-list-row1 > *:first-child,
.shensha-list-row2 > *:first-child {
    border-left: none;
}

.shensha-list-row1 > *:last-child,
.shensha-list-row2 > *:last-child {
    border-right: none;
}

/* ─── 干支时间 ─────────────────────────────────────────────── */
.gz-time {
    display: flex;
    align-items: center;
    color: var(--text-primary);
}

.liuyao-gztime-layout {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: 100%;
    font-size: 0.8rem;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
}

.gz-show {
    padding: 4px;
    text-align: center;
    border-right: 1px solid var(--border-primary);
}

.liuyao-gztime-layout > *:last-child {
    border-right: none;
}

/* ─── 盘面布局：三卦列 ─────────────────────────────────────── */
.paipan {
    display: grid;
    grid-template-columns: 5fr 15fr 10fr;
    gap: 5px;
    margin: 0;
    padding: 10px;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
}

/* 左藏卦、中本卦、右变卦 */
.canggua-wai {
    grid-column: 1;
}

.bengua-wai {
    grid-column: 2;
}

.biangua-wai {
    grid-column: 3;
}

/* 藏卦/本卦的爻自上而下竖排 */
.cg,
.bengua {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* 世应/动爻标记列：只占位撑住行高 */
.shiying,
.dongyao {
    display: block;
    min-width: 5px;
    min-height: 10px;
    text-align: center;
}

.biangua {
    display: grid;
    grid-template-columns: 1fr;
    height: 1rem;
    gap: 1rem;
}

/* 卦名列：固定 30px 高保证三列卦名基线对齐，长卦名由 .gua-name-text 缩放 */
.cg-guaming,
.biangua-guaming,
.bengua-guaming {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 30px;
    min-height: 30px;
    margin-bottom: 10px;
    padding: 0;
    overflow: hidden;
    font-size: 0.8rem;
    text-align: center;
    white-space: nowrap;
}

.gua-name-text {
    white-space: nowrap;
}

/* ─── 卦象符号 ─────────────────────────────────────────────── */
.cg-symbol {
    display: grid;
    width: 100%;
    height: 1rem;
}

.bengua-symbol:focus {
    outline: none;
}

/* 键盘焦点环画在爻图形上，避免整行 outline 撑破布局 */
.bengua-symbol:focus-visible .symbol-img {
    outline: 2px solid var(--accent-color-1);
    outline-offset: 2px;
}

/* 六神列只有一个值，占满首列，避免被三列模板压窄 */
.bengua-symbol > .fill-symbol:first-child {
    grid-template-columns: 1fr;
}

/* 本卦每爻四段：六神 / 六亲纳甲五行 / 爻图形 / 世应动爻 */
.bengua-symbol {
    display: grid;
    grid-template-columns: 2fr 5fr 5fr 3fr;
    height: 1rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.biangua-symbol {
    display: grid;
    grid-template-columns: 1fr 1fr;
    height: 1rem;
    font-size: min(14px, 2vw);
    white-space: nowrap;
}

/* 小灵儿/案例页复用：分组容器不参与布局，爻行直接进入父 grid */
.xiaolinger-gua-group {
    display: contents;
}

/* 六亲/纳甲/五行三列 */
.fill-symbol {
    display: grid;
    grid-template-columns: 2fr 2fr 1fr;
    width: 100%;
    align-items: center;
    justify-items: center;
    font-size: 0.8rem;
    line-height: 0.8rem;
    white-space: nowrap;
    animation: liuyaoFadeIn 0.6s ease-in-out forwards;
}

.cg-symbol span,
.biangua-symbol span {
    /* 收缩到文字宽度并停在单元格起点：文字位置不变，
       标注高亮框（outline 画在元素盒上）才能居中贴合文字而非整格。 */
    width: fit-content;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
    align-items: center;
    justify-self: start;
    animation: liuyaoFadeIn 0.6s ease-in-out forwards;
}

/* ─── 藏卦伏神与六神/六亲配色 ──────────────────────────────── */
:root.light .canggua-yao--highlight {
    color: var(--ly-canggua-fushen-light);
}

.canggua-yao--highlight {
    color: var(--ly-canggua-fushen);
}

:root.light .canggua-yao--muted {
    color: var(--ly-canggua-muted-light);
}

.canggua-yao--muted {
    color: var(--ly-canggua-muted);
}

.liuyao-shen {
    color: var(--accent-color-2);
}

.liuyao-liuqin {
    color: var(--accent-color-1);
}

:root.light .liuyao-shen,
:root.light .liuyao-liuqin {
    color: var(--text-primary);
}

/* ─── 爻图形 ───────────────────────────────────────────────── */
.symbol-img {
    display: block;
    position: relative;
    width: 100%;
    height: 1rem;
    cursor: pointer;
    transition: all 0.3s ease-in-out;
    transform-style: preserve-3d; /* 让翻转动画落在 3D 空间 */
    animation: flipShrinkFade 0.6s ease-in-out forwards;
}

/* 起卦完成或开始解读后，爻位不可再点击修改 */
.bengua-symbol.symbol-locked .symbol-img {
    cursor: default;
}

/* 阳爻一整条、阴爻两段（各 40%）；75% 高让爻与爻之间留缝。
   10px 圆角在 --radius-* 令牌里没有等值项，保留字面值 */
.symbol-img.yang::before,
.symbol-img.yin::before,
.symbol-img.yin::after {
    content: '';
    position: absolute;
    /* 75% 高的爻条用 top 12.5% 在 1rem 行高内垂直居中，与两侧文字中线对齐；
       不能用 transform 居中，flipShrinkFade 动画会覆盖 transform。 */
    top: 12.5%;
    display: block;
    height: 75%;
    background: var(--text-primary);
    border-radius: 10px;
    transition: all 0.3s ease-in-out;
    transform-style: preserve-3d;
    animation: flipShrinkFade 0.6s ease-in-out forwards;
}

.symbol-img.yang::before {
    width: 100%;
}

.symbol-img.yin::before {
    left: 0;
    width: 40%;
}

.symbol-img.yin::after {
    right: 0;
    width: 40%;
}

/* 老阳/老阴＝动爻，用动爻色覆盖爻条底色 */
.symbol-img.yang.lao-yang::before,
.symbol-img.yin.lao-yin::before,
.symbol-img.yin.lao-yin::after {
    background: var(--ly-yao-moving);
}

/* ─── 动画 ─────────────────────────────────────────────────── */
/* 爻位切换：缩小 + 翻转 + 淡出淡入 */
@keyframes flipShrinkFade {
    0% {
        transform: scale(1) rotateX(0deg);
        opacity: 1;
    }

    50% {
        transform: scale(0.8) rotateX(180deg);
        opacity: 0.5;
    }

    100% {
        transform: scale(1) rotateX(0deg);
        opacity: 1;
    }
}

/* 排盘数据落盘：内容自下轻轻淡入 */
@keyframes liuyaoFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── 响应式：移动端收窄神煞与卦名 ────────────────────────── */
@media (max-width: 768px) {
    .shensha-list-time {
        width: 20px;
        font-size: 0.8rem;
    }

    .shensha-list-shen {
        font-size: 0.5rem;
    }

    .fill-symbol {
        font-size: 0.6rem;
    }

    .cg-guaming,
    .biangua-guaming,
    .bengua-guaming {
        height: 20px;
        min-height: 20px;
        font-size: 0.6rem;
    }
}
