/* 奇门遁甲 · 主样式（壳层见 ../6yao/css/layout-shell.css） */
.qimen-page {
    background: linear-gradient(180deg, #e8f0ec 0%, #f4f7fb 28%, #f4f7fb 100%);
    min-height: 100vh;
}

.qimen-page .container {
    max-width: 800px;
}

.qimen-main {
    padding: 0;
    max-width: none;
    margin: 0;
}

.qimen-page .mode-selector .mode-btn {
    flex: 1 1 0;
}

html[data-qimen-initial-mode='paipan'] #paipan-mode.mode-content,
html[data-qimen-initial-mode='gua-records'] #gua-records-mode.mode-content {
    display: block !important;
}

html[data-qimen-initial-mode='paipan'] .mode-btn[data-mode='paipan'],
html[data-qimen-initial-mode='gua-records'] .mode-btn[data-mode='gua-records'] {
    color: #2f6b52;
    font-weight: 600;
}

html[data-qimen-initial-mode='paipan'] .mode-btn[data-mode='paipan']::after,
html[data-qimen-initial-mode='gua-records'] .mode-btn[data-mode='gua-records']::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #2f6b52;
}

.qimen-card {
    background: #fff;
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    margin: 12px 8px;
}

.qimen-datetime-row label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.qimen-datetime-display {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #f9fafb;
    font-size: 15px;
}


.qimen-fly-mode-row {
    margin-top: 14px;
}

.qimen-fly-mode-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.qimen-fly-mode-opts {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.qimen-fly-mode-opt {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #f9fafb;
    cursor: pointer;
    font-size: 14px;
    flex: 1;
    min-width: 120px;
    justify-content: center;
}

.qimen-fly-mode-opt:has(input:checked) {
    border-color: #2563eb;
    background: #eff6ff;
    color: #1e40af;
}

.qimen-fly-mode-opt input {
    accent-color: #2563eb;
}

.qimen-matter-row {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 14px;
}

.qimen-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.qimen-btn {
    flex: 1;
    min-width: 120px;
    border: none;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 15px;
    cursor: pointer;
}

.qimen-btn--primary {
    background: #2563eb;
    color: #fff;
}

.qimen-btn--ghost {
    background: #eef2ff;
    color: #1e40af;
}

.qimen-result-head {
    margin-bottom: 12px;
}

.qimen-result-wrap {
    margin: 0 8px 12px;
}

.qimen-result-wrap .qimen-result-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 12px;
}

/* ── 排盘信息（独立区块，参考九宫飞星 pan-info） ── */
.qimen-pan-info-section {
    background: #fff;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 16px;
}

.qimen-pan-meta {
    border-bottom: none;
}

.qimen-meta-row {
    display: grid;
    grid-template-columns: 72px 1fr;
    border-bottom: 1px solid #ececec;
    min-height: 44px;
}

.qimen-meta-row:last-child {
    border-bottom: none;
}

.qimen-meta-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 8px;
    color: #b8860b;
    font-size: 14px;
    font-weight: 600;
    border-right: 1px solid #ececec;
    background: #fff;
}

.qimen-meta-label--empty {
    border-right: 1px solid #ececec;
}

.qimen-meta-value {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.45;
    color: #1a1a1a;
    min-width: 0;
    word-break: break-word;
}

.qimen-meta-row--matter {
    cursor: pointer;
}

.qimen-meta-row--matter:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: -2px;
}

.qimen-meta-value--matter {
    justify-content: space-between;
    gap: 8px;
}

.qimen-meta-matter-placeholder {
    color: #9ca3af;
}

.qimen-meta-matter-edit {
    flex-shrink: 0;
    color: #9ca3af;
    font-size: 15px;
}

.qimen-sizhu-table {
    width: 100%;
}

.qimen-sizhu-table-head,
.qimen-sizhu-table-body {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    text-align: center;
}

.qimen-sizhu-table-head {
    margin-bottom: 6px;
    color: #b8860b;
    font-size: 13px;
    font-weight: 600;
}

.qimen-sizhu-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.15;
    font-size: 18px;
    font-weight: 700;
}

.qimen-sizhu-gan,
.qimen-sizhu-zhi {
    display: block;
}

.qimen-meta-value--cols4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    text-align: center;
    padding-left: 0;
    padding-right: 0;
}

.qimen-kw-pair {
    color: #9ca3af;
    font-size: 14px;
}

.qimen-kw-pair--active {
    color: #dc2626;
    font-weight: 700;
}

.qimen-meta-row--jieqi {
    border-bottom: none;
}

.qimen-meta-params-block {
    display: grid;
    grid-template-columns: 1fr 30% 1fr 1fr 1fr;
    border-top: 1px solid #ececec;
    padding: 10px 6px 12px;
    text-align: center;
}

.qimen-meta-param-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    padding: 0 2px;
}

.qimen-meta-param-head {
    color: #b8860b;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
}

.qimen-meta-param-val {
    color: #1a1a1a;
    font-size: 14px;
    line-height: 1.35;
    word-break: break-word;
}

/* 四柱干支五行色（仅排盘信息区） */
.qimen-pan-meta .sizhu-jin { color: #c9a227; }
.qimen-pan-meta .sizhu-mu { color: #2e7d32; }
.qimen-pan-meta .sizhu-shui { color: #1565c0; }
.qimen-pan-meta .sizhu-huo { color: #c62828; }
.qimen-pan-meta .sizhu-tu { color: #8d6e63; }

/* ── 九宫展示（独立区块） ── */
.qimen-display-section {
    --qimen-color-fushi: #24b7aa;
    --qimen-color-rumu: #ba7d41;
    --qimen-color-jixing: #b968c5;
    --qimen-color-menpo: #d91f2b;
    --qimen-color-xingmu: #47a2cc;
    background: #fff;
    border-radius: 0 0 10px 10px;
    border: 2px solid #e9ecef;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

/* 九宫：时干红字 */
.qimen-display-section .qimen-shi-gan {
    color: #c62828;
}

/* 九宫：符使 */
.qimen-display-section .qimen-mark-fushi {
    color: var(--qimen-color-fushi);
}

/* 九宫：击刑 */
.qimen-display-section .qimen-ji-xing {
    color: var(--qimen-color-jixing);
    font-style: italic;
}

/* 九宫：入墓 */
.qimen-display-section .qimen-ru-mu {
    color: var(--qimen-color-rumu);
}

/* 九宫：刑+墓 */
.qimen-display-section .qimen-ji-xing.qimen-ru-mu {
    color: var(--qimen-color-xingmu);
    font-style: italic;
}

/* 九宫：门迫 */
.qimen-display-section .qimen-men-po {
    color: var(--qimen-color-menpo);
    font-style: italic;
}

.qimen-display-section .qimen-gong-door.qimen-mark-fushi.qimen-men-po {
    color: var(--qimen-color-menpo);
    font-style: italic;
}

.qimen-display-section .qimen-pan-grid.jiu-gong-grid {
    border-radius: 0;
    overflow: hidden;
}

/* 九宫字号：--qimen-gong-font-size 随盘宽缩放；各宫内容统一 inherit */
.qimen-pan-grid.jiu-gong-grid {
    container-type: inline-size;
    --qimen-gong-font-size: clamp(0.8125rem, 3.8cqi, 1.375rem);
    --qimen-sxd-font-size: 1.12em;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    position: relative;
    border: 3px solid #333;
    background: #333;
    font-size: var(--qimen-gong-font-size);
}

.qimen-pan-grid .gong-cell {
    aspect-ratio: 1;
    border: none;
    border-radius: 0;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: #fff;
    position: relative;
    min-width: 0;
    min-height: 0;
    font-size: inherit;
    cursor: pointer;
}

.qimen-pan-grid .gong-cell.is-selected,
.qimen-pan-grid .gong-cell.is-selected.center {
    background: #fde8e8;
}

.qimen-pan-grid.jiu-gong-grid .gong-cell,
.qimen-pan-grid.jiu-gong-grid .gong-cell * {
    font-size: inherit;
}

.qimen-pan-grid.jiu-gong-grid .gong-cell .qimen-gong-god,
.qimen-pan-grid.jiu-gong-grid .gong-cell .qimen-gong-star,
.qimen-pan-grid.jiu-gong-grid .gong-cell .qimen-gong-door {
    font-size: var(--qimen-sxd-font-size);
}

.qimen-gong-index {
    position: absolute;
    top: 4px;
    right: 6px;
    font-weight: 700;
    line-height: 1; 
    pointer-events: none;
    user-select: none;
}

.qimen-gong--maxing.qimen-gong--show-gua-hao .qimen-gong-index {
    right: 22px;
}

.qimen-gong-kongwang {
    position: absolute;
    top: 4px;
    left: 6px;
    font-weight: 400;
    line-height: 1;
    color: #64748b;
    pointer-events: none;
    user-select: none;
}

.qimen-gong-maxing {
    position: absolute;
    top: 4px;
    right: 6px;
    font-weight: 700;
    line-height: 1;
    color: #334155;
    pointer-events: none;
    user-select: none;
}

.qimen-pan-grid .gong-name {
    font-weight: bold;
    margin-bottom: 4px;
    color: #333;
    text-align: center;
    line-height: 1.2;
    flex-shrink: 0;
}

.qimen-gong-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    gap: 4px;
    min-height: 0;
    width: 100%;
}

.qimen-gong-god {
    font-weight: 600;
    color: #0f172a;
}

.qimen-gong-god--empty {
    visibility: hidden;
}

.qimen-gong-mid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: repeat(5, 1.2em);
    row-gap: 3px;
    column-gap: 4px;
    align-items: center;
    min-height: 0;
    flex: 1;
    width: 100%; 
}

.qimen-gong-left-col {
    display: contents;
}

.qimen-gong-feigan-gan,
.qimen-gong-feigan-zhi {
    justify-self: start;
    align-self: center;
    writing-mode: vertical-rl;
    text-orientation: upright;
    line-height: 1;
    color: #475569;
    font-weight: 600;
    min-height: 1.2em;
}

.qimen-gong-feigan-gan {
    grid-column: 1;
    grid-row: 3;
}

.qimen-gong-feigan-zhi {
    grid-column: 1;
    grid-row: 4;
}

.qimen-gong-feigan-gan--empty,
.qimen-gong-feigan-zhi--empty {
    visibility: hidden;
}

.qimen-feigan-plain {
    color: #475569;
}

.qimen-pan-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 10px 12px;
    border-top: 1px solid #e9ecef;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
}

.qimen-pan-legend-label {
    color: #64748b;
    margin-right: 2px;
}

.qimen-pan-legend-items {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.qimen-pan-legend-sep {
    color: #64748b;
}

.qimen-pan-legend-item.qimen-mark-fushi {
    font-weight: 700;
}

.qimen-pan-toolbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 12px 12px;
    border-top: 1px solid #e9ecef;
}

.qimen-pan-toolbar .liuyao-result-meta-toolbar {
    margin: 10px 0 0;
    width: 100%;
}

#qimen-result-meta-actions {
    display: contents;
}

.qimen-result-wrap .gua-result-record-text-card:not(#qimen-result-record-nc-shell) {
    margin: 0 0 12px;
    background: #fff;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 12px 14px;
}

.qimen-result-wrap #qimen-result-record-nc-shell {
    background: #fff;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 0;
    overflow: hidden;
}

.qimen-result-wrap #qimen-result-record-note-card,
.qimen-result-wrap #qimen-result-record-comment-card {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
}

.qimen-result-note-empty {
    margin: 0;
    color: #94a3b8;
    font-size: 14px;
}

.qimen-result-comment-empty {
    margin: 0;
    color: #94a3b8;
    font-size: 14px;
    text-align: center;
}

.qimen-result-comment-add-prompt {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 20px 12px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    color: #64748b;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    cursor: pointer;
}

.qimen-result-comment-add-prompt:hover {
    border-color: #94a3b8;
    color: #475569;
    background: #f1f5f9;
}

.qimen-result-note-add-prompt {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 20px 12px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    color: #64748b;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    cursor: pointer;
}

.qimen-result-note-add-prompt:hover {
    border-color: #94a3b8;
    color: #475569;
    background: #f1f5f9;
}

/* 笔记：标题区上下留白收紧（编辑浮层 + 结果页卡片） */
.qimen-page #ximu-ctx-notes-editor .notes-edit-box:not(.notes-edit-box--inline-dock) {
    padding-top: max(12px, env(safe-area-inset-top, 0px) + 8px);
}

.qimen-page #ximu-ctx-notes-editor .notes-edit-box .notes-edit-header-row .notes-edit-heading,
.qimen-page #ximu-ctx-notes-editor .notes-edit-box .notes-edit-header-row .ximu-ctx-notes-heading {
    margin: 0;
}

.qimen-page #ximu-ctx-notes-editor .notes-edit-box:not(.notes-edit-box--page-zoom-layout) .notes-edit-page-zoom {
    display: none !important;
}

.qimen-page #ximu-ctx-notes-editor .notes-edit-record-context,
.qimen-page #ximu-ctx-notes-editor .ximu-ctx-notes-record-context {
    margin: 0 0 8px;
    padding: 6px 10px;
}

.qimen-page #ximu-ctx-notes-editor .notes-edit-label {
    margin-bottom: 4px;
}

.qimen-page #ximu-ctx-notes-editor .notes-edit-input {
    padding: 8px 10px;
    margin-bottom: 8px;
}

.qimen-result-wrap .qimen-record-nc-tabs {
    display: flex;
    width: 100%;
    border-bottom: 1px solid #e2e8f0;
}

.qimen-result-wrap .qimen-record-nc-tab {
    flex: 1 1 50%;
    width: 50%;
    box-sizing: border-box;
    margin: 0;
    padding: 12px 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: #fff;
    color: #64748b;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.qimen-result-wrap .qimen-record-nc-tab-inner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
}

.qimen-result-wrap .qimen-record-nc-tab-label {
    flex: 0 0 auto;
}

.qimen-result-wrap .qimen-record-nc-tab-badge {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.qimen-result-wrap .qimen-record-nc-tab-badge--note {
    background: #2563eb;
    color: #fff;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.35);
}

.qimen-result-wrap .qimen-record-nc-tab-badge--note.is-zero {
    background: #e2e8f0;
    color: #64748b;
    box-shadow: none;
}

.qimen-result-wrap .qimen-record-nc-tab-badge--comment {
    background: #ea580c;
    color: #fff;
    box-shadow: 0 1px 3px rgba(234, 88, 12, 0.35);
}

.qimen-result-wrap .qimen-record-nc-tab-badge--comment.is-zero {
    background: #e2e8f0;
    color: #64748b;
    box-shadow: none;
}

.qimen-result-wrap .qimen-record-nc-tab.is-active {
    color: #2f6b52;
    border-bottom-color: #7dd3fc;
}

.qimen-result-wrap .qimen-record-nc-tab:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: -2px;
}

.qimen-result-wrap .qimen-record-nc-body {
    padding: 12px 14px;
}

.qimen-result-wrap .qimen-record-nc-panel[hidden] {
    display: none !important;
}

.qimen-result-wrap #qimen-result-record-note-card .gua-result-record-text,
.qimen-result-wrap #qimen-result-record-comment-card .gua-result-record-comment-list {
    margin-top: 0;
}

.qimen-show-gua-hao-btn {
    appearance: none;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #fff;
    color: #475569;
    font-size: 14px;
    line-height: 1.2;
    padding: 6px 16px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.liuyao-result-meta-toolbar .qimen-show-gua-hao-btn {
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1.4;
    background: #f8f9fa;
    border-color: #d0d0d0;
    color: #333;
}

.liuyao-result-meta-toolbar .qimen-show-gua-hao-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.qimen-show-gua-hao-btn.is-active {
    background: #24b7aa;
    border-color: #24b7aa;
    color: #fff;
    font-weight: 600;
}

.qimen-pan-actions {
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding: 0 12px 12px;
    border-top: 1px solid #e9ecef;
}

.qimen-pan-action-btn {
    flex: 1 1 0;
    appearance: none;
    border: none;
    border-radius: 6px;
    background: #24b7aa;
    color: #fff;
    font-size: 14px;
    line-height: 1.2;
    padding: 10px 8px;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
    text-align: center;
    white-space: nowrap;
}

.qimen-pan-action-btn:hover {
    background: #1fa89c;
}

.qimen-pan-action-btn.is-active {
    background: #0f766e;
    font-weight: 600;
}

.qimen-pan-action-btn--nav:active {
    opacity: 0.85;
}

.qimen-pan-nav-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding: 0 12px 12px;
    border-top: 1px solid #e9ecef;
}

.qimen-pan-nav-row .qimen-pan-action-btn {
    flex: 1 1 0;
}

.qimen-palace-detail {
    border-top: 1px solid #e9ecef;
    padding: 10px 12px 14px;
    background: #fff;
}

.qimen-palace-detail.is-empty {
    border-top: none;
    padding: 0;
}

.qimen-palace-detail-body {
    display: block;
}

.qimen-palace-detail-section + .qimen-palace-detail-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
}

.qimen-palace-detail-head {
    margin: 0;
    color: #c62828;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.55;
}

.qimen-palace-detail-item {
    margin: 0;
    color: #334155;
    font-size: 14px;
    line-height: 1.65;
}

.qimen-palace-detail-em {
    color: #c62828;
    font-weight: 700;
}

.qimen-gong-stem-row {
    display: contents;
    line-height: 1.1;
    white-space: nowrap;
}

.qimen-gong-stem-row--empty .qimen-gong-changsheng,
.qimen-gong-stem-row--empty .qimen-gong-stem-main {
    visibility: hidden;
    pointer-events: none;
}

.qimen-gong-stem-main {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
}

.qimen-gong-stem-main--placeholder {
    visibility: hidden;
}

.qimen-gong-changsheng { 
    font-weight: 500;
    color: #94a3b8;
    line-height: 1;
    flex-shrink: 0;
    min-height: 1em;
}

.qimen-gong-changsheng--placeholder {
    visibility: hidden;
}

.qimen-gong-center-col {
    display: contents;
}

.qimen-gong-god,
.qimen-gong-star-line,
.qimen-gong-door-line {
    grid-column: 2;
    width: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    justify-self: center;
    text-align: center;
    line-height: 1.2;
    min-height: 1.2em;
}

.qimen-gong-god,
.qimen-gong-star-line,
.qimen-gong-door-line {
    transform: translateX(-0.5em);
}

.qimen-gong-god {
    grid-row: 1;
}

.qimen-gong-star-line {
    grid-row: 3;
}

.qimen-gong-door-line {
    grid-row: 5;
}

.qimen-gong-door-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
}

.qimen-gong-earth-god-short {
    grid-column: 1;
    grid-row: 5;
    justify-self: start;
    align-self: center;
    color: #475569;
    font-weight: 600;
    line-height: 1.2;
    min-height: 1.2em;
}

.qimen-gong-earth-god-short--placeholder {
    visibility: hidden;
}

.qimen-gong-star {
    flex: 0 0 auto;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
    text-align: center;
}

.qimen-gong-right-col {
    display: contents;
}

.qimen-gong-right-col .qimen-gong-stem-row:nth-child(1) .qimen-gong-changsheng {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
    align-self: center;
}

.qimen-gong-right-col .qimen-gong-stem-row:nth-child(1) .qimen-gong-stem-main {
    grid-column: 3;
    grid-row: 3;
    justify-self: end;
    align-self: center;
}

.qimen-gong-right-col .qimen-gong-stem-row:nth-child(2) .qimen-gong-changsheng {
    grid-column: 3;
    grid-row: 4;
    justify-self: end;
    align-self: center;
}

.qimen-gong-right-col .qimen-gong-stem-row:nth-child(2) .qimen-gong-stem-main {
    grid-column: 3;
    grid-row: 5;
    justify-self: end;
    align-self: center;
}

.qimen-gong-sky {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
}

.qimen-gong-stem-main--multi {
    gap: 3px;
}

.qimen-gong-stem-part {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 1px;
}

.qimen-gong-liuqin {
    font-weight: 600;
    color: #64748b;
    line-height: 1;
    flex-shrink: 0;
}

/* 飞盘：天盘/地盘右列 — 六亲占位在干右侧，开关时干位不动（占位已含一字宽，不再 translateX） */
.qimen-pan-grid--feipan .qimen-gong-stem-part {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 1px;
}

.qimen-pan-grid--feipan .qimen-gong-liuqin {
    display: inline-block;
    min-width: 1em;
    text-align: left;
    flex-shrink: 0;
}

.qimen-pan-grid--feipan .qimen-gong-liuqin--placeholder {
    visibility: hidden;
}

/* 转盘：保留默认三列 1fr/auto/1fr，勿改 grid-template-columns（改 5em 会把神/星/门挤左） */
.qimen-pan-grid--zhuanpan .qimen-gong-mid {
    column-gap: 2px;
}

.qimen-pan-grid--zhuanpan .qimen-gong-god {
    /* 八神为单行 div；星/门为 flex 行且常含「天×」「×门」，同值 translate 时视觉中心略偏左 */
    transform: translateX(-1.28em);
}

.qimen-pan-grid--zhuanpan .qimen-gong-star-line,
.qimen-pan-grid--zhuanpan .qimen-gong-door-line {
    transform: translateX(-1.45em);
}

.qimen-pan-grid--zhuanpan .qimen-gong-right-col .qimen-gong-stem-row:nth-child(1) .qimen-gong-changsheng,
.qimen-pan-grid--zhuanpan .qimen-gong-right-col .qimen-gong-stem-row:nth-child(2) .qimen-gong-changsheng {
    justify-self: end;
    align-self: center; 
    box-sizing: border-box;
    text-align: right;
    /* 比干支少右移，避免长字串（如「冠临」）顶出宫格右缘 */
    transform: translateX(0.05em);
    overflow: hidden;
}

.qimen-pan-grid--zhuanpan .qimen-gong-right-col .qimen-gong-stem-row:nth-child(1) .qimen-gong-stem-main,
.qimen-pan-grid--zhuanpan .qimen-gong-right-col .qimen-gong-stem-row:nth-child(2) .qimen-gong-stem-main {
    justify-self: end;
    align-self: center;
    box-sizing: border-box;
}

.qimen-pan-grid--zhuanpan .qimen-gong-stem-main:not(.qimen-gong-stem-main--multi) {
    width: 4em;
    justify-content: flex-end;
    transform: translateX(0.15em);
}

.qimen-pan-grid--zhuanpan .qimen-gong-stem-main--multi {
    width: 5em;
    gap: 1em;
    justify-content: flex-end;
    transform: translateX(0.2em);
}

/* 双干：第二个干再略右移，避免与星/门交叠 */
.qimen-pan-grid--zhuanpan .qimen-gong-stem-main--multi .qimen-gong-stem-part + .qimen-gong-stem-part {
    margin-left: -0.7em;
}

.qimen-pan-grid--zhuanpan .qimen-gong-stem-part {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    flex: 0 0 auto;
    gap: 0;
}

.qimen-pan-grid--zhuanpan .qimen-gong-heaven,
.qimen-pan-grid--zhuanpan .qimen-gong-earth-stem {
    display: inline-block;
    width: 1em;
    text-align: center;
    flex-shrink: 0;
}

.qimen-pan-grid--zhuanpan .qimen-gong-liuqin {
    display: inline-block;
    min-width: 1em;
    width: 1em;
    text-align: left;
    flex-shrink: 0;
}

.qimen-pan-grid--zhuanpan .qimen-gong-liuqin--placeholder {
    visibility: hidden;
}

.qimen-gong-heaven {
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

.qimen-gong-earth-stem {
    font-weight: 600;
    color: #0f172a;
    line-height: 1.2;
}

.qimen-gong-human {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.qimen-gong-earth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
    text-align: center;
}

.qimen-gong-earth-door {
    font-weight: 500;
    color: #94a3b8;
    line-height: 1.2;
}

.qimen-gong-stem {
    font-weight: 600;
    color: #334155;
}

.qimen-gong-bot {
    text-align: center;
}

.qimen-gong-door {
    font-weight: 600;
    color: #0f172a;
    line-height: 1.2;
}

.qimen-gong-door--empty {
    visibility: hidden;
}

.qimen-mark-fushi {
    font-weight: 700;
}

.qimen-gong--zhifu .qimen-gong-star.qimen-mark-fushi,
.qimen-gong--zhishi .qimen-gong-door.qimen-mark-fushi,
.qimen-gong--zhishi .qimen-gong-human .qimen-mark-fushi {
    font-weight: 700;
}

@media (max-width: 480px) {
    .qimen-fly-mode-opts {
        flex-wrap: nowrap;
    }

    .qimen-fly-mode-opt {
        flex: 1 1 0;
        min-width: 0;
        padding: 8px 6px;
        font-size: 13px;
    }

    .qimen-meta-row {
        grid-template-columns: 58px 1fr;
    }

    .qimen-meta-label {
        font-size: 13px;
        padding: 8px 4px;
    }

    .qimen-meta-value {
        font-size: 13px;
        padding: 8px 10px;
    }

    .qimen-sizhu-stack {
        font-size: 16px;
    }

    .qimen-meta-param-head {
        font-size: 12px;
    }

    .qimen-meta-param-val {
        font-size: 13px;
    }

    .qimen-meta-params-block {
        padding: 8px 2px 10px;
        gap: 2px;
    }

    .qimen-meta-param-col {
        gap: 6px;
    }

    .qimen-pan-grid.jiu-gong-grid {
        --qimen-gong-font-size: clamp(0.75rem, 3.5cqi, 0.9rem);
    /*    --qimen-sxd-font-size: 0.9em;*/
        gap: 2px;
        border-width: 2px;
    }

    .qimen-pan-grid .gong-cell {
        padding: 6px 4px;
    }

    .qimen-gong-index {
        top: 3px;
        right: 4px;
    }

    .qimen-gong-kongwang {
        top: 3px;
        left: 4px;
    }

    .qimen-gong-maxing {
        top: 3px;
        right: 4px;
    } 

    .qimen-gong-center-col,
    .qimen-gong-right-col {
        padding-top: 0;
    }

    .qimen-pan-grid .gong-name {
        margin-bottom: 2px;
    }

    .qimen-pan-legend {
        padding: 8px 8px;
        font-size: 13px;
    }

    .qimen-pan-toolbar {
        padding: 0 8px 10px;
    }

    .qimen-show-gua-hao-btn {
        font-size: 13px;
        padding: 5px 14px;
    }

    .qimen-pan-actions {
        gap: 6px;
        padding: 0 8px 10px;
    }

    .qimen-pan-nav-row {
        gap: 6px;
        padding: 0 8px 10px;
    }

    .qimen-pan-action-btn {
        font-size: 12px;
        padding: 8px 4px;
    }

    .qimen-palace-detail {
        padding: 8px 8px 12px;
    }

    .qimen-palace-detail-head {
        font-size: 14px;
    }

    .qimen-palace-detail-item {
        font-size: 13px;
    }

    .qimen-gong--maxing.qimen-gong--show-gua-hao .qimen-gong-index {
        right: 18px;
    }
}

#qimenToast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.92);
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    z-index: 9999;
    font-size: 14px;
}

.qimen-pan-grid--hide-ren .qimen-gong-human { display: none; }

.qimen-display-section:has(.qimen-yinpan-shell) {
    overflow: visible;
}

/* 阴盘：5×5 网格，九宫居中，引干/马星贴边对齐 */
.qimen-yinpan-shell {
    display: grid;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    container-type: inline-size;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 0.32em 0.28em;
    padding: 0.4em;
    --qimen-yin-shell-font-size: clamp(0.8125rem, 3.5cqi, 1.25rem);
    --qimen-yin-maxing-diag: 0.38em;
    font-size: var(--qimen-yin-shell-font-size);
}

.qimen-yinpan-shell > .jiu-gong-grid.qimen-pan-grid {
    grid-column: 2 / 5;
    grid-row: 2 / 5;
    width: 100%;
    max-width: 100%;
    margin: 0;
}

.qimen-yin-gan-ring {
    display: contents;
}

.qimen-yin-gan {
    color: #475569;
    font-weight: 600;
    line-height: 1;
    font-size: inherit;
    justify-self: center;
    align-self: center;
    white-space: nowrap;
}

.qimen-yin-gan--p9 { grid-column: 3; grid-row: 1; }
.qimen-yin-gan--p1 { grid-column: 3; grid-row: 5; }
.qimen-yin-gan--p4 { grid-column: 1; grid-row: 2; justify-self: end; }
.qimen-yin-gan--p3 { grid-column: 1; grid-row: 3; justify-self: end; }
.qimen-yin-gan--p8 { grid-column: 1; grid-row: 4; justify-self: end; }
.qimen-yin-gan--p2 { grid-column: 5; grid-row: 2; justify-self: start; }
.qimen-yin-gan--p7 { grid-column: 5; grid-row: 3; justify-self: start; }
.qimen-yin-gan--p6 { grid-column: 5; grid-row: 4; justify-self: start; }

/* 阴盘：五行网格（神/长生/天盘/长生/地盘，右列星门对齐天盘地盘行） */
.qimen-pan-grid--yinpan .qimen-yin-cell-body {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: minmax(1.2em, 1fr) 1em minmax(1.2em, 1fr) 1em minmax(1.2em, 1fr);
    width: 100%;
    flex: 1;
    min-height: 0;
    position: relative;
    align-items: center;
}

.qimen-pan-grid--yinpan .qimen-yin-slot {
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 0;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--god {
    grid-column: 1;
    grid-row: 1;
    justify-content: flex-start;
    align-self: center;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--heaven-cs {
    grid-column: 1;
    grid-row: 2;
    justify-content: flex-start;
    align-self: end;
    min-height: 1em;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--heaven {
    grid-column: 1;
    grid-row: 3;
    justify-content: flex-start;
    align-self: center;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--earth-cs {
    grid-column: 1;
    grid-row: 4;
    justify-content: flex-start;
    align-self: end;
    min-height: 1em;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--earth {
    grid-column: 1;
    grid-row: 5;
    justify-content: flex-start;
    align-self: center;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--star {
    grid-column: 2;
    grid-row: 3;
    justify-content: flex-end;
    align-self: center;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--door {
    grid-column: 2;
    grid-row: 5;
    justify-content: flex-end;
    align-self: center;
}

.qimen-pan-grid--yinpan .qimen-yin-slot--heaven-cs .qimen-gong-changsheng,
.qimen-pan-grid--yinpan .qimen-yin-slot--earth-cs .qimen-gong-changsheng {
  
    font-weight: 500;
    color: #94a3b8;
    line-height: 1;
    min-height: 1em;
}

.qimen-pan-grid--yinpan .qimen-yin-slot .qimen-gong-stem-main {
    justify-content: flex-start;
}

.qimen-pan-grid--yinpan .qimen-yin-stem-main--dual {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 0.4em;
    align-items: center;
    justify-content: start;
}

.qimen-pan-grid--yinpan .qimen-gong-stem-part {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 1px;
}

.qimen-pan-grid--yinpan .qimen-gong-stem-part--jigan {
    justify-self: start;
}

.qimen-pan-grid--yinpan .qimen-gong-liuqin {
    display: inline-block;
    min-width: 1em;
    text-align: left;
    font-weight: 600;
    color: #64748b;
    line-height: 1;
    flex-shrink: 0;
}

.qimen-pan-grid--yinpan .qimen-gong-liuqin--placeholder {
    visibility: hidden;
}

.qimen-pan-grid--yinpan .gong-cell .qimen-gong-god,
.qimen-pan-grid--yinpan .gong-cell .qimen-gong-star,
.qimen-pan-grid--yinpan .gong-cell .qimen-gong-door,
.qimen-pan-grid--yinpan .gong-cell .qimen-gong-heaven,
.qimen-pan-grid--yinpan .gong-cell .qimen-gong-earth-stem {
    font-size: var(--qimen-sxd-font-size);
}

.qimen-pan-grid--yinpan .qimen-gong-god {
    transform: none;
}

.qimen-pan-grid--yinpan .qimen-yin-kongwang {
    grid-column: 2;
    grid-row: 1;
    position: static;
    top: auto;
    left: auto;
    right: auto;
    justify-self: end;
    align-self: center;
    pointer-events: none;
    user-select: none;
}

.qimen-pan-grid--yinpan .gong-cell.qimen-gong--time-kw.qimen-gong--show-gua-hao .qimen-gong-index {
    right: 22px;
}

.qimen-yinpan-maxing {
    z-index: 3;
    color: #c62828;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    font-size: inherit;
    justify-self: center;
    align-self: center;
}

/* 角宫：外角对角线外延；边宫：外缘法线外延 */
.qimen-yinpan-maxing--p4 {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
    align-self: start;
    transform: translate(calc(-100% - var(--qimen-yin-maxing-diag)), calc(-100% - var(--qimen-yin-maxing-diag)));
}

.qimen-yinpan-maxing--p9 {
    grid-column: 3;
    grid-row: 2;
    justify-self: center;
    align-self: start;
    transform: translate(-50%, calc(-100% - var(--qimen-yin-maxing-diag)));
}

.qimen-yinpan-maxing--p2 {
    grid-column: 4;
    grid-row: 2;
    justify-self: end;
    align-self: start;
    transform: translate(calc(100% + var(--qimen-yin-maxing-diag)), calc(-100% - var(--qimen-yin-maxing-diag)));
}

.qimen-yinpan-maxing--p3 {
    grid-column: 2;
    grid-row: 3;
    justify-self: start;
    align-self: center;
    transform: translate(calc(-100% - var(--qimen-yin-maxing-diag)), -50%);
}

.qimen-yinpan-maxing--p7 {
    grid-column: 4;
    grid-row: 3;
    justify-self: end;
    align-self: center;
    transform: translate(calc(100% + var(--qimen-yin-maxing-diag)), -50%);
}

.qimen-yinpan-maxing--p8 {
    grid-column: 2;
    grid-row: 4;
    justify-self: start;
    align-self: end;
    transform: translate(calc(-100% - var(--qimen-yin-maxing-diag)), calc(100% + var(--qimen-yin-maxing-diag)));
}

.qimen-yinpan-maxing--p1 {
    grid-column: 3;
    grid-row: 4;
    justify-self: center;
    align-self: end;
    transform: translate(-50%, calc(100% + var(--qimen-yin-maxing-diag)));
}

.qimen-yinpan-maxing--p6 {
    grid-column: 4;
    grid-row: 4;
    justify-self: end;
    align-self: end;
    transform: translate(calc(100% + var(--qimen-yin-maxing-diag)), calc(100% + var(--qimen-yin-maxing-diag)));
}

@media (max-width: 480px) {
    .qimen-yinpan-shell {
        gap: 0.28em 0.22em;
        padding: 0.32em;
    }
}
