/* ============================================================
   九宫盘面 · chart-board
   版式对齐 Windows 版 ChartRenderer（DesignCell = 206）：
   行序 4-9-2 / 3-5-7 / 8-1-6，每宫 = 宫名顶栏 + 3x3 内容格。
   取色一律复用 base.css 的设计变量，不另造主色。
   ============================================================ */

.chart-board {
    /* 单宫宽度：默认按 iPhone 390px 版心估算——
       页面左右 24 + 卡片边框 2 + 卡片内边距 20 + 盘面边框 2，再除以 3 */
    --cell: min(calc((100vw - 48px) / 3), 186px);

    width: 100%;
    /* 大屏预览时限制最大宽度，避免盘面撑满整页后文字比例失衡 */
    max-width: 560px;
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 1px;
    background: var(--grid-line);
    border: 1px solid var(--grid-line);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* 支持容器查询时，字号直接随盘面实际宽度缩放（桌面/平板预览更准） */
@supports (container-type: inline-size) {
    .chart-board {
        container-type: inline-size;
    }

    .chart-board > .chart-cell {
        /* 每宫宽 ≈ 盘面内宽的三分之一（1px 网格线的误差不到 1px） */
        --cell: 33.33cqw;
    }
}

/* ---------------- 宫格 ---------------- */

.chart-cell {
    /* 单宫尺寸派生的字号与顶栏高度；全部随 --cell 缩放并夹在可读区间 */
    --cb-head-h: clamp(18px, calc(var(--cell) * 0.192), 30px);
    --cb-fs-palace: clamp(9.5px, calc(var(--cell) * 0.096), 14px);
    --cb-fs-dir: clamp(8px, calc(var(--cell) * 0.080), 11.5px);
    --cb-fs-tag: clamp(7px, calc(var(--cell) * 0.070), 10px);
    --cb-fs-main: clamp(15px, calc(var(--cell) * 0.150), 22px);
    --cb-fs-mf-gan: clamp(13.5px, calc(var(--cell) * 0.138), 20px);
    --cb-fs-ganzhi: clamp(11.5px, calc(var(--cell) * 0.120), 17.5px);
    --cb-fs-an-door: clamp(13px, calc(var(--cell) * 0.132), 19px);
    --cb-fs-an-gz: clamp(10.5px, calc(var(--cell) * 0.102), 15px);
    --cb-fs-di-god: clamp(13px, calc(var(--cell) * 0.137), 20px);
    --cb-fs-wy-gan: clamp(17px, calc(var(--cell) * 0.172), 25px);
    --cb-fs-wy-qin: clamp(8.5px, calc(var(--cell) * 0.088), 12.5px);

    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--card);
    color: var(--ink);
    font-family: inherit;
    font-size: var(--cb-fs-main);
    line-height: 1;
    text-align: left;
    overflow: hidden;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.12s ease;
}

/* 动宫：浅赭底（五元局由 CellClass 不挂 is-dong，不显示动宫底色） */
.chart-cell.is-dong {
    background-color: var(--dong-bg);
}

/* 命宫：浅金叠层，可叠在动宫底色之上 */
.chart-cell.is-ming::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--ming-tint);
    border-radius: inherit;
    pointer-events: none;
}

/* 当前点选宫：2px 金色内框，圆角 3px */
.chart-cell.is-selected {
    border-radius: 3px;
    outline: 2px solid var(--gold);
    outline-offset: -2px;
}

/* 点击反馈 */
.chart-cell:active {
    background-color: var(--paper-mid);
}

.chart-cell.is-dong:active {
    background-color: var(--paper-deep);
}

.chart-cell:focus-visible {
    outline: 2px solid var(--gold-deep);
    outline-offset: -2px;
}

/* ---------------- 宫名顶栏 ---------------- */

.cb-head {
    flex: 0 0 auto;
    height: var(--cb-head-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    padding: 0 4px;
    background: rgba(176, 138, 62, 0.07);
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
}

.cb-palace {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--cb-fs-palace);
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink);
}

.cb-head-right {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.cb-dir {
    font-size: var(--cb-fs-dir);
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--ink-faint);
}

/* 空亡 / 马星小标签（仅括囊局、鸣法局） */
.cb-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 1.6em;
    min-width: 1.4em;
    padding: 0 0.18em;
    border-radius: 2px;
    font-size: var(--cb-fs-tag);
    font-weight: 700;
    line-height: 1;
    color: var(--card);
}

.cb-tag-kong {
    background: var(--ink-faint);
}

.cb-tag-ma {
    background: var(--water);
}

/* ---------------- 宫内容 ---------------- */

.cb-body {
    flex: 1 1 auto;
    min-height: 0;
}

.cb-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    padding: 1px 0;
}

.cb-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    line-height: 1;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* 九神 / 九星 / 明门：主体单字 */
.cb-slot-god,
.cb-slot-star,
.cb-slot-door {
    font-size: var(--cb-fs-main);
    font-weight: 600;
    color: var(--ink);
}

/* 天盘干 / 地盘干：括囊局写干支两字 */
.cb-slot-tian,
.cb-slot-di {
    font-size: var(--cb-fs-ganzhi);
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--ink);
}

/* 鸣法局：天地盘只写一个干，字号略放大（对齐 Windows 版 28/24 的比例） */
.chart-board.is-mingfa .cb-slot-tian,
.chart-board.is-mingfa .cb-slot-di {
    font-size: var(--cb-fs-mf-gan);
}

/* 暗门：细体浅墨，明显比主体虚 */
.cb-slot-an-door {
    font-size: var(--cb-fs-an-door);
    font-weight: 400;
    color: var(--ink-soft);
    opacity: 0.66;
}

/* 暗干支：细体浅墨（鸣法局只有这一处两字浅墨） */
.cb-slot-an-gz {
    font-size: var(--cb-fs-an-gz);
    font-weight: 400;
    letter-spacing: 0.01em;
    color: var(--ink-soft);
    opacity: 0.88;
}

/* 地盘九神：细体浅墨，比主体虚 */
.cb-slot-di-god {
    font-size: var(--cb-fs-di-god);
    font-weight: 400;
    color: var(--ink-soft);
    opacity: 0.62;
}

/* ---------------- 五元局：只留天地盘两干 ---------------- */

.cb-wuyuan {
    position: relative;
    display: block;
    padding: 0;
}

.cb-stem-line {
    position: absolute;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    line-height: 1;
    white-space: nowrap;
}

/* 宫内上下约 30% / 70% 高度处 */
.cb-stem-tian {
    top: 30%;
    transform: translateY(-50%);
}

.cb-stem-di {
    top: 70%;
    transform: translateY(-50%);
}

.cb-wy-stem {
    font-size: var(--cb-fs-wy-gan);
    font-weight: 600;
    color: var(--ink);
}

/* 干右侧小字六亲 */
.cb-wy-qin {
    font-size: var(--cb-fs-wy-qin);
    font-weight: 400;
    letter-spacing: 0.02em;
    color: var(--ink-soft);
}
