.qm-page { max-width:1040px; --qm-line:#d8cab2; --qm-gold:#785722; --qm-ink:#322c23 }
.qm-hero { padding:1.5rem 1rem; margin-bottom:0 }
.qm-hero h1 { margin-bottom:.35rem }
.qm-hero p { margin-bottom:0; color:#756349 }
.qm-page .zw-fields [hidden] { display:none }
.qm-modes { margin-top:.9rem; min-width:0 }
.qm-modes legend { font-weight:600; margin-bottom:.5rem }
.qm-modes > div { display:grid; grid-template-columns:repeat(3,1fr); gap:4px; padding:4px; background:#f0ebe1; border-radius:10px }
.qm-modes label { position:relative; cursor:pointer }
.qm-modes input { position:absolute; opacity:0; width:1px; height:1px }
.qm-modes span { display:block; text-align:center; padding:10px 2px; border-radius:7px; font-size:.95rem }
.qm-modes input:checked + span { background:#55442c; color:#fffaf1 }
.qm-modes input:focus-visible + span,.qm-cell:focus-visible { outline:3px solid #987328; outline-offset:-3px }
.qm-now { margin-left:10px; padding:10px 14px; color:var(--qm-gold); text-decoration:underline; text-underline-offset:4px }
.qm-chart-head { display:flex; align-items:end; justify-content:space-between; flex-wrap:wrap; gap:5px; padding-bottom:14px; border-bottom:1px solid var(--qm-line); margin-bottom:16px }
.qm-school,.qm-chart-head time,.qm-key { font-size:.82rem; color:#73644f }
.qm-chart-head h2 { font:700 clamp(1.45rem,3vw,2rem) 'Noto Serif SC',serif; margin:2px 0 0 }
.qm-reading { display:grid; grid-template-columns:minmax(200px,.85fr) minmax(0,1.45fr); gap:clamp(16px,3vw,36px); align-items:start }
.qm-pillars { display:grid; grid-template-columns:repeat(4,1fr); border-block:1px solid var(--qm-line); background:#f6f0e6; text-align:center }
.qm-pillars > div { padding:6px; border-right:1px solid var(--qm-line) }
.qm-pillars > div:last-child { border:0 }
.qm-pillars dt,.qm-summary dt,.qm-cell-head small,.qm-hidden-gan { color:#75634c; font-size:.75rem }
.qm-pillars dd { font:700 1.45rem/1.1 'Noto Serif SC',serif; margin:4px 0 0 }
.qm-pillars span { display:block }
.qm-pillars :is([data-char="甲"],[data-char="乙"],[data-char="寅"],[data-char="卯"]) { color:#416c47 }
.qm-pillars :is([data-char="丙"],[data-char="丁"],[data-char="午"],[data-char="巳"]) { color:#a24937 }
.qm-pillars :is([data-char="庚"],[data-char="辛"],[data-char="酉"],[data-char="申"]) { color:#886519 }
.qm-pillars :is([data-char="壬"],[data-char="癸"],[data-char="子"],[data-char="亥"]) { color:#345c80 }
.qm-pillars dd { color:#80583b }
.qm-summary { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px 12px; margin:12px 0 }
.qm-summary dd { margin:1px 0; font-weight:550 }
.qm-board { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); border:1px solid #9e8d70; gap:1px; background:#b7a78e; overflow:hidden; border-radius:5px }
.qm-board article { display:flex; background:#fffdf8; min-width:0 }
.qm-board article:nth-child(5) { background:#f4eee3 }
.qm-cell { display:flex; flex-flow:column; gap:4px; width:100%; min-height:110px; padding:clamp(6px,1vw,14px); color:var(--qm-ink); text-align:left; line-height:1.3 }
.qm-cell:hover,.qm-cell:focus-visible { background:#f2ead9 }
.qm-cell-head,.qm-pair { display:flex; align-items:baseline; justify-content:space-between; gap:2px }
.qm-cell-head { border-bottom:1px solid #eee5d6; padding-bottom:3px }
.qm-cell-head b { color:var(--qm-gold); font-size:.88rem }
.qm-pair { font:500 clamp(1rem,2vw,1.28rem)/1.25 'Noto Serif SC',serif }
.qm-tags { display:flex; gap:3px; flex-wrap:wrap }
.qm-tags i { font-size:.68rem; font-style:normal; color:#41645e; background:#edf2ec; border-radius:3px; padding:1px 3px }
.qm-tags .qm-tomb { color:#854f21; background:#f6ead6 }
.qm-tags .qm-strike { color:#74436b; background:#f3e6ee }
.qm-tags .qm-door { color:#943b34; background:#fae8e2 }
.qm-key { margin-top:8px }
.qm-dialog { width:min(420px,92vw); margin:auto; border:1px solid var(--qm-line); border-radius:12px; padding:22px; background:#fffdf8; color:var(--qm-ink); max-height:80dvh; overflow:auto }
.qm-dialog::backdrop { background:#29241c75 }
.qm-dialog h2 { font:700 1.5rem 'Noto Serif SC',serif }
.qm-dialog form { margin-top:18px; text-align:right }
@media (max-width:700px) {
    .qm-page { padding-inline:8px }
    .qm-page .qm-chart { padding:12px 9px }
    .qm-reading { grid-template-columns:minmax(0,1fr); gap:6px }
    .qm-summary { grid-template-columns:repeat(3,minmax(0,1fr)); font-size:.86rem }
    .qm-cell { min-height:98px }
    .qm-chart-head { margin-bottom:10px; padding-bottom:8px }
    .qm-page .zw-fields { grid-template-columns:minmax(0,1fr); gap:9px }
    .qm-page .zw-primary,.qm-now { min-height:44px }
    .qm-dialog .qm-summary { grid-template-columns:repeat(2,1fr) }
}

/* 宫内以位置、字号区分神门星仪，字色对应五行。 */
.qm-board { background:#aaa9a3; border-color:#9d9b95; border-radius:2px }
.qm-board article { background:#fff }
.qm-board article:nth-child(5) { background:#f7f7f3 }
.qm-cell { font-family:'Noto Sans SC','PingFang SC','Microsoft YaHei',sans-serif; gap:6px }
.qm-cell-head { border:0 }
.qm-cell-head b { font-size:clamp(.94rem,2vw,1.17rem); font-weight:500 }
.qm-cell-head small,.qm-hidden-gan { color:#6d7073 }
.qm-pair { font:500 clamp(1.08rem,2.3vw,1.46rem)/1.25 'PingFang SC','Microsoft YaHei',sans-serif }
.qm-pair strong { font-weight:550 }
.qm-pair:nth-child(3) strong { font-weight:700 }
.qm-wood { color:#15712b }
.qm-fire { color:#c52822 }
.qm-earth { color:#854c18 }
.qm-metal { color:#ab5500 }
.qm-water { color:#2346aa }
.qm-tags i:not([class]),.qm-tags i[class=""] { background:#ffea80; color:#463900 }
.qm-dialog .qm-meaning { border-block-end:1px solid #ddd9cf; padding:12px 0 }
.qm-meaning small,.qm-subtitle small { color:#6c6559; font-size:.76rem; font-weight:400 }
.qm-meaning h3,.qm-subtitle { margin:4px 0; font-size:1.08rem; font-weight:650 }
.qm-gloss > div { display:grid; grid-template-columns:6em 1fr; gap:8px; padding:6px 0; border-bottom:1px solid #eeeae3 }
.qm-gloss dt { color:#695539 }
.qm-dialog form { position:sticky; bottom:0; background:#fffdf8; padding-top:6px }
.qm-layer-controls { display:flex; flex-wrap:wrap; gap:6px; margin-top:12px }
.qm-layer-controls button { padding:8px 12px; min-height:42px; border:1px solid #cbbda8; border-radius:6px }
.qm-layer-controls [aria-pressed="true"] { color:white; background:#59472f }
.qm-ring,.qm-rotations,.qm-state { display:none }
.show-rotate .qm-rotations,.show-states .qm-state { display:block }
.qm-state { color:#746954; font:500 .72rem/1.3 sans-serif; text-align:right }
.qm-rotations h3 { font-size:1rem; margin:18px 0 6px }
.qm-rotated,.qm-rotated:hover { background:white; cursor:default }
.show-ring .qm-frame { display:grid; grid-template-columns:auto minmax(0,1fr) auto; grid-template-areas:". top ." "left board right" ". bottom ."; gap:3px }
.show-ring .qm-frame > .qm-board { grid-area:board }
.show-ring .qm-ring { display:grid; align-items:center; text-align:center; font-size:clamp(.65rem,2vw,.8rem) }
.qm-ring-top,.qm-ring-bottom { grid-template-columns:repeat(3,1fr) }
.qm-ring-top { grid-area:top }
.qm-ring-bottom { grid-area:bottom }
.qm-ring-left,.qm-ring-right { grid-template-rows:repeat(3,1fr) }
.qm-ring-left { grid-area:left }
.qm-ring-right { grid-area:right }
.qm-ring-left span,.qm-ring-right span { writing-mode:vertical-rl }
.qm-ring b { color:#9d392d }

.show-ring .qm-frame > .qm-stem-frame { grid-area:board }
.qm-stem-frame { display:grid; grid-template-columns:auto minmax(0,1fr) auto; grid-template-areas:". top ." "left board right" ". bottom ."; gap:2px }
.qm-stem-frame > .qm-board { grid-area:board }
.qm-stems { display:grid; place-items:center; font-size:clamp(.72rem,2vw,.96rem) }
.qm-stems-top { grid-area:top }
.qm-stems-bottom { grid-area:bottom }
.qm-stems-left,.qm-stems-right { grid-template-rows:repeat(3,minmax(0,1fr)) }
.qm-stems-left { grid-area:left }
.qm-stems-right { grid-area:right }
.qm-stems-left > span,.qm-stems-right > span { writing-mode:vertical-rl }
.qm-stem-frame > .qm-board { grid-template-rows:repeat(3,1fr) }
.qm-ring [hidden] { display:none }

.qm-patterns { margin-top:14px }
.qm-patterns summary { cursor:pointer; font-weight:600 }
.qm-patterns p { margin:.6em 0; line-height:1.6 }
.qm-patterns h3 { font-weight:600; margin-top:.8em }

.qm-save-panel { display:flex; align-items:center; justify-content:space-between; gap:1rem }
.qm-save-panel a { color:var(--qm-gold); white-space:nowrap }
.qm-save-panel p,.qm-record-note { white-space:pre-wrap; overflow-wrap:anywhere }
.qm-note-field { grid-column:1 / -1 }

.qm-adjacent { display:flex; align-items:center; justify-content:center; gap:clamp(.6rem,3vw,1.6rem); margin-block:1rem }
.qm-adjacent small { color:var(--qm-ink); text-align:center }
.qm-adjacent button { min-height:44px; white-space:nowrap }
.qm-adjacent button:disabled { opacity:.45; cursor:not-allowed }
#qimen-result { scroll-margin-top:5rem }
.qm-adjacent { position:relative; padding-bottom:.9rem }
.qm-nav-status { position:absolute; bottom:-.25rem; font-size:.75rem; color:var(--qm-ink) }
.qm-adjacent[aria-busy="true"] button { cursor:wait; opacity:.6 }
