.home-header nav, .app-nav, .suite-nav, .qm-suite-nav, .ly-wrap header nav {
    align-items: center;
}
.home-header nav > a, .app-nav > a, .suite-nav > a, .qm-suite-nav > a, .ly-wrap header nav > a {
    height: 30px; display: inline-flex; align-items: center; line-height: 1;
}

/* 功能页共用页头：固定宽度、基线和导航节奏，跨页面切换不跳位。 */
.app-header {
    width: min(1100px, calc(100% - 40px));
    min-height: 78px;
    margin: 0 auto !important;
    padding: 0 !important;
    display: flex;
    align-items: center !important;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid #594b34 !important;
}
.app-title {
    flex: 0 1 auto;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    color: #d4af37;
    font: 500 28px/1.2 "STSong", "SimSun", "Noto Serif SC", serif !important;
    letter-spacing: 6px !important;
    white-space: nowrap;
}
.app-title small {
    color: #ad9d82;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 2px;
}
.app-nav {
    flex: 0 0 auto;
    margin: 0 !important;
    padding: 0 !important;
    display: flex;
    justify-content: flex-end;
    gap: 18px !important;
}
.app-nav > a {
    margin: 0 !important;
    color: #92866f;
    text-decoration: none;
    font-size: 13px !important;
    letter-spacing: 1px !important;
}
.app-nav > a:hover, .app-nav > a.active { color: #d4af37; }
.theme-toggle {
    box-sizing: border-box !important; width: auto !important; height: 30px !important;
    min-width: 62px; margin: 0 !important; padding: 0 9px !important;
    border: 1px solid currentColor !important; border-radius: 999px !important;
    background: transparent !important; box-shadow: none !important;
    color: #a8997f !important; font: 12px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif !important;
    display: inline-flex !important; align-items: center; justify-content: center;
    letter-spacing: 1px !important; white-space: nowrap; cursor: pointer;
}
.theme-toggle:hover, .theme-toggle:focus-visible { color: #d4af37 !important; outline: 2px solid transparent; }
.theme-toggle-fixed { position: fixed; z-index: 3000; top: 18px; right: 18px; }

/* 四个术数入口共用的历史栏、记录卡片与按钮规格。 */
.bazi-body #sidebar.history-sidebar,
.qm-sidebar.history-sidebar,
.ly-layout > aside.history-sidebar {
    box-sizing: border-box;
    position: sticky;
    top: 20px;
    width: 100%;
    height: auto;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 16px;
    background: rgba(26, 26, 26, .9);
    border: 1px solid #4a4234;
    border-radius: 6px;
    box-shadow: none;
}
.bazi-body #sidebar .history-title,
.qm-sidebar .history-title,
.ly-layout > aside .history-title {
    margin: 0 0 12px;
    padding: 0;
    color: #d4af37;
    background: transparent;
    font: 500 15px/1.4 "STSong", "SimSun", "Noto Serif SC", serif;
    letter-spacing: 3px;
    text-align: left;
}
.bazi-body #sidebar ul { margin: 0; padding: 0; }
.history-card,
.bazi-body #sidebar ul li.history-card {
    position: relative;
    margin: 0 0 10px;
    padding: 10px 12px !important;
    background: #171410;
    border: 1px solid #3a332a !important;
    border-radius: 4px;
    box-shadow: none;
    color: #e6d5b8;
}
.history-card:last-child,
.bazi-body #sidebar ul li.history-card:last-child { margin-bottom: 0; }
.history-card::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 4px;
    border-radius: 3px 0 0 3px;
    background: #d4af37;
}
.history-card.is-completed::before { background: #8b0000; }
.history-card.is-pending::before { background: #d4af37; }
.history-card:hover,
.bazi-body #sidebar ul li.history-card:hover { background: #211d17; border-color: #705c3b !important; }
.history-card.active { border-color: #8c734a !important; box-shadow: 0 0 10px rgba(212, 175, 55, .15); }
.history-card .qm-hist-q,
.history-card .hist-q { margin: 0 0 6px; font-size: 13.5px; line-height: 1.5; }
.history-card .qm-hist-meta,
.history-card .hist-meta { margin: 0; font-size: 11.5px; line-height: 1.5; }
.history-empty {
    margin: 0; padding: 18px 0; color: #887c68;
    font-size: 12px !important; line-height: 1.7; text-align: center;
}
.bazi-body #sidebar ul li.history-empty {
    margin: 0; padding: 18px 0 !important; background: transparent;
    border: 0 !important; color: #887c68; text-align: center;
}
.bazi-history-card { display: flex; align-items: center; cursor: pointer; }
.bazi-history-content { flex: 1; min-width: 0; }
.bazi-history-title { margin: 0 0 6px; color: #d4af37; font-size: 13.5px; font-weight: 600; line-height: 1.5; }
.bazi-history-meta { margin: 0; color: #8a7d66; font-size: 11.5px; line-height: 1.5; }
.history-ops { display: flex; gap: 8px; margin-top: 8px; }

.primary-action {
    box-sizing: border-box !important;
    height: 44px !important;
    min-height: 44px;
    padding: 0 24px !important;
    background: linear-gradient(135deg, #8b0000, #5a0000) !important;
    color: #e6d5b8 !important;
    border: 1px solid #8c734a !important;
    border-radius: 4px !important;
    box-shadow: none !important;
    font: 500 15px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif !important;
    letter-spacing: 3px !important;
    cursor: pointer;
}
.primary-action:hover { filter: brightness(1.16); box-shadow: 0 0 12px rgba(139, 0, 0, .28) !important; }
.primary-action:disabled { background: #333 !important; color: #777 !important; border-color: #555 !important; filter: none; cursor: wait; }
.secondary-action {
    box-sizing: border-box !important;
    width: auto;
    height: 30px !important;
    min-height: 30px;
    padding: 0 12px !important;
    background: #1f1c17 !important;
    color: #c0b298 !important;
    border: 1px solid #5a4b31 !important;
    border-radius: 4px !important;
    box-shadow: none !important;
    font: 400 12px/1 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif !important;
    letter-spacing: 1px !important;
}
.secondary-action:hover { background: #29241d !important; color: #d4af37 !important; border-color: #8c734a !important; }
.history-ops .secondary-action { flex: 1; }

/* 功能页通用面板与表单节奏。 */
.bazi-body .flex-container,
.qm-main .qm-panel,
.qm-main .qm-analyze-result,
.ly-layout main .panel,
.ly-layout main .chart,
.ly-layout main .report {
    box-sizing: border-box;
    padding: 20px;
    background: rgba(26, 24, 20, .94);
    border: 1px solid #78623e;
    border-radius: 7px;
    box-shadow: 0 0 24px rgba(122, 97, 56, .1);
}
.bazi-body .input-group > label,
.qm-main .qm-field > label,
.ly-layout main label {
    color: #baa98b;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
    letter-spacing: 1px;
}
.bazi-body input:not([type="checkbox"]):not([type="radio"]),
.bazi-body select,
.bazi-body textarea,
.qm-main input[type="datetime-local"],
.qm-main select,
.qm-main textarea,
.ly-layout main input[type="datetime-local"],
.ly-layout main select,
.ly-layout main textarea {
    box-sizing: border-box;
    min-height: 42px;
    padding: 9px 12px !important;
    background: #121212 !important;
    color: #eadfc9 !important;
    border: 1px solid #584a35 !important;
    border-radius: 4px;
    font: 400 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.ly-layout main label > input[type="datetime-local"],
.ly-layout main label > select,
.ly-layout main label > textarea { margin-top: 8px; }
.bazi-body textarea,
.qm-main textarea,
.ly-layout main textarea { line-height: 1.6; resize: vertical; }
.bazi-body textarea { margin-top: 0 !important; }
.note,
.ui-hint {
    font-size: 12px !important;
    line-height: 1.7 !important;
    letter-spacing: 1px;
}
.qm-radio-item { font-size: 14px !important; line-height: 1.5; }
.qm-analyze-hint,
.ly-layout .analyze > .ui-hint { margin: 12px 0 0; }
.qm-analyze-title,
.ly-layout .analyze h2 {
    font-size: 16px;
    line-height: 1.5;
    letter-spacing: 3px;
}
.qm-err,
.ly-layout .error { font-size: 13px; line-height: 1.5; }
.bazi-body .result-container,
.qm-main .qm-markdown,
.ly-layout .report article {
    font-size: 14.5px;
    line-height: 1.95;
}
.bazi-body .result-container h2,
.qm-main .qm-markdown h2,
.ly-layout .report article h2 { font-size: 17px; line-height: 1.5; }
.bazi-body .result-container h3,
.qm-main .qm-markdown h3,
.ly-layout .report article h3 { font-size: 15.5px; line-height: 1.5; }
.markdown-output h1,
.markdown-output h2,
.markdown-output h3 {
    color: #d4af37;
    font-family: "STSong", "SimSun", "Noto Serif SC", serif;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 2px;
}
.markdown-output h1 {
    margin: 20px 0 10px;
    padding-bottom: 7px;
    border-bottom: 1px solid #5a4b31;
    font-size: 19px !important;
}
.markdown-output h2 { margin: 18px 0 8px; font-size: 17px !important; }
.markdown-output h3 { margin: 16px 0 7px; font-size: 15.5px !important; }
.markdown-output p { margin: 8px 0; }
.markdown-output strong { color: #f0e3c2; }
.markdown-output ul,
.markdown-output ol { margin: 8px 0; padding-left: 22px; }
.markdown-output li { margin: 4px 0; }
.markdown-output hr { margin: 14px 0; border: 0; border-top: 1px solid #3a3328; }
.markdown-output blockquote {
    margin: 10px 0;
    padding: 6px 14px;
    background: rgba(40, 34, 25, .5);
    color: #c9b98f;
    border-left: 3px solid #8c734a;
}
.markdown-output table { max-width: 100%; margin: 10px 0; border-collapse: collapse; font-size: 13px; }
.markdown-output th,
.markdown-output td { padding: 6px 10px; border: 1px solid #4a4234; }
.markdown-output th { background: #221e18; color: #d4af37; }

/* 全屏/面板加载与后台运行状态统一。 */
@keyframes ui-spin { to { transform: rotate(360deg); } }
#loadingOverlay,
.qm-loading,
.loading {
    position: fixed;
    inset: 0;
    z-index: 999;
    margin: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(10, 10, 10, .84);
}
.loading-spinner {
    box-sizing: border-box !important;
    width: 46px !important;
    height: 46px !important;
    flex: 0 0 46px;
    position: relative;
    margin: 0 !important;
    background: transparent !important;
    border: 3px solid transparent !important;
    border-top-color: #d4af37 !important;
    border-bottom-color: #8b0000 !important;
    border-radius: 50% !important;
    animation: ui-spin 1s linear infinite !important;
}
.loading-spinner::before,
.loading-spinner::after { display: none !important; content: none !important; }
.loading-message {
    margin: 0 !important;
    color: #d4af37 !important;
    font: 500 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif !important;
    letter-spacing: 2px !important;
    text-align: center;
}
.loading-submessage {
    min-height: 0;
    margin: 0 !important;
    color: #a8997f !important;
    font-size: 12px !important;
    line-height: 1.6;
    letter-spacing: 1px !important;
}
.run-status {
    min-height: 24px;
    margin: 0 0 12px !important;
    display: flex !important;
    align-items: center;
    gap: 8px !important;
    color: #d4af37 !important;
    font: 500 13px/1.7 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif !important;
    letter-spacing: 1px !important;
}
.inline-loading-spinner {
    box-sizing: border-box;
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    border: 2px solid rgba(212, 175, 55, .25);
    border-top-color: #d4af37;
    border-radius: 50%;
    animation: ui-spin .9s linear infinite;
}

html[data-theme="light"] body {
    background-color: #f4efe6 !important;
    background-image: radial-gradient(circle at 50% 15%, #fffdf8 0%, #eee4d4 78%) !important;
    color: #3c3225 !important;
}
html[data-theme="light"] body,
html[data-theme="light"] .home-shell { --bg:#f4efe6; --surface:#fffaf1; --surface-hover:#f2e5d2; --text:#3c3225; --muted:#776a57; --gold:#896712; --line:#cbb78f; }

html[data-theme="light"] .method-card,
html[data-theme="light"] .choice-guide,
html[data-theme="light"] .flex-container,
html[data-theme="light"] .bazi-body #sidebar,
html[data-theme="light"] .bazi-body #sidebar ul li,
html[data-theme="light"] .qm-sidebar,
html[data-theme="light"] .qm-panel,
html[data-theme="light"] .qm-meta,
html[data-theme="light"] .qm-cell,
html[data-theme="light"] .qm-analyze-result,
html[data-theme="light"] .ly-layout aside,
html[data-theme="light"] .panel,
html[data-theme="light"] .chart,
html[data-theme="light"] .report,
html[data-theme="light"] .hist,
html[data-theme="light"] .bazi-card,
html[data-theme="light"] .person-section {
    background: rgba(255, 250, 241, .96) !important;
    border-color: #c8ae7a !important;
    color: #3c3225 !important;
    box-shadow: 0 8px 24px rgba(91, 65, 28, .08) !important;
}
html[data-theme="light"] .method-card:hover,
html[data-theme="light"] .bazi-body #sidebar ul li:hover { background: #f3e6d2 !important; }

/* 奇门历史记录的内层卡片原本使用固定深色，浅色主题需逐层覆盖。 */
html[data-theme="light"] .qm-hist-item {
    background: #fffdf8 !important;
    border-color: #d7c6a4 !important;
    box-shadow: none !important;
}
html[data-theme="light"] .qm-hist-item.active {
    background: #fbf2e3 !important;
    border-color: #a98542 !important;
    box-shadow: 0 0 0 2px rgba(137, 103, 18, .08) !important;
}
html[data-theme="light"] .qm-hist-q { color: #3c3225 !important; }
html[data-theme="light"] .qm-hist-empty { color: #8a7b64 !important; }
html[data-theme="light"] .qm-hist-view,
html[data-theme="light"] .qm-hist-del {
    background: #f5ead8 !important;
    color: #665842 !important;
    border-color: #cbb78f !important;
}
html[data-theme="light"] .qm-hist-view:hover {
    background: #eee0c8 !important;
    color: #896712 !important;
    border-color: #a98542 !important;
}
html[data-theme="light"] .qm-hist-del:hover {
    background: #f6e2dc !important;
    color: #9b3e31 !important;
    border-color: #bd7767 !important;
}
html[data-theme="light"] .qm-hist-status { border-color: #cbb78f !important; }

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea,
html[data-theme="light"] .qm-field input[type="datetime-local"],
html[data-theme="light"] .qm-analyze-panel textarea {
    background: #fffdf8 !important; color: #3c3225 !important; border-color: #bda36f !important;
}
html[data-theme="light"] input::placeholder,
html[data-theme="light"] textarea::placeholder { color: #9a8b73 !important; }

html[data-theme="light"] .suite-nav a,
html[data-theme="light"] .qm-suite-nav a,
html[data-theme="light"] .ly-wrap header nav a,
html[data-theme="light"] .home-header nav a,
html[data-theme="light"] label,
html[data-theme="light"] .hint,
html[data-theme="light"] .muted,
html[data-theme="light"] .qm-field label,
html[data-theme="light"] .qm-hist-meta,
html[data-theme="light"] .hist-meta,
html[data-theme="light"] .qm-analyze-hint,
html[data-theme="light"] .qm-markdown,
html[data-theme="light"] .report article,
html[data-theme="light"] .result-container,
html[data-theme="light"] .bazi-card,
html[data-theme="light"] .bazi-card-header { color: #766954 !important; }

html[data-theme="light"] h1,
html[data-theme="light"] h2,
html[data-theme="light"] h3,
html[data-theme="light"] .brand,
html[data-theme="light"] .hero-kicker,
html[data-theme="light"] .method-number,
html[data-theme="light"] .method-action,
html[data-theme="light"] .choice-guide strong,
html[data-theme="light"] .qm-header h1,
html[data-theme="light"] .qm-sidebar-title,
html[data-theme="light"] .qm-analyze-title,
html[data-theme="light"] .qm-markdown h1,
html[data-theme="light"] .qm-markdown h2,
html[data-theme="light"] .qm-markdown h3,
html[data-theme="light"] .ly-wrap h1,
html[data-theme="light"] .ly-wrap aside h2,
html[data-theme="light"] .analyze h2,
html[data-theme="light"] .tag,
html[data-theme="light"] .tab-btn.active { color: #896712 !important; }

html[data-theme="light"] .home-header,
html[data-theme="light"] .app-header,
html[data-theme="light"] .qm-header,
html[data-theme="light"] .ly-wrap header,
html[data-theme="light"] .tab-container,
html[data-theme="light"] .meta,
html[data-theme="light"] .yao-row { border-color: #cbb78f !important; }

html[data-theme="light"] .note { background: #f9eadf !important; color: #7c371f !important; border-color: #c9876d !important; }
html[data-theme="light"] .qm-grid { background: #eadcc4 !important; border-color: #a98542 !important; }
html[data-theme="light"] .qm-cell.center { background: repeating-linear-gradient(45deg,#f4ead9,#f4ead9 6px,#eadcc5 6px,#eadcc5 12px) !important; }
html[data-theme="light"] .qm-shen,
html[data-theme="light"] .qm-xing,
html[data-theme="light"] .qm-badge,
html[data-theme="light"] .dayun-tag { background: #f5ead8 !important; color: #5b4a35 !important; }
html[data-theme="light"] .qm-stem { color: #4b3824 !important; }
html[data-theme="light"] .bar { background: #896712 !important; }
html[data-theme="light"] .bar.yin { background: linear-gradient(to right,#896712 0 42%,transparent 42% 58%,#896712 58%) !important; }
html[data-theme="light"] pre,
html[data-theme="light"] .qm-raw { background: #f5ead8 !important; color: #5f523f !important; border-color: #cbb78f !important; }
html[data-theme="light"] .modal { background: rgba(69, 53, 32, .35) !important; }
html[data-theme="light"] .modal-content { background: #fffaf1 !important; color: #3c3225 !important; border-color: #b99349 !important; }
html[data-theme="light"] .theme-toggle { color: #75664f !important; }
html[data-theme="light"] .theme-toggle:hover { color: #896712 !important; }
html[data-theme="light"] #loadingOverlay,
html[data-theme="light"] .qm-loading,
html[data-theme="light"] .loading { background: rgba(244, 239, 230, .92) !important; }
html[data-theme="light"] .loading-message,
html[data-theme="light"] .run-status { color: #896712 !important; }
html[data-theme="light"] .loading-submessage { color: #776a57 !important; }
html[data-theme="light"] .inline-loading-spinner {
    border-color: rgba(137, 103, 18, .2);
    border-top-color: #896712;
}
html[data-theme="light"] .markdown-output strong { color: #4b3824 !important; }
html[data-theme="light"] .markdown-output hr { border-color: #cbb78f !important; }
html[data-theme="light"] .markdown-output blockquote {
    background: #f5ead8 !important;
    color: #665842 !important;
    border-color: #a98542 !important;
}
html[data-theme="light"] .markdown-output th,
html[data-theme="light"] .markdown-output td { border-color: #cbb78f !important; }
html[data-theme="light"] .markdown-output th { background: #f0e2ca !important; color: #896712 !important; }

html[data-theme="light"] .history-sidebar {
    background: rgba(255, 250, 241, .96) !important;
    border-color: #c8ae7a !important;
    box-shadow: 0 8px 24px rgba(91, 65, 28, .08) !important;
}
html[data-theme="light"] .history-card,
html[data-theme="light"] .bazi-body #sidebar ul li.history-card {
    background: #fffdf8 !important;
    color: #3c3225 !important;
    border-color: #d7c6a4 !important;
    box-shadow: none !important;
}
html[data-theme="light"] .history-card:hover,
html[data-theme="light"] .history-card.active,
html[data-theme="light"] .bazi-body #sidebar ul li.history-card:hover {
    background: #fbf2e3 !important;
    border-color: #a98542 !important;
}
html[data-theme="light"] .bazi-history-title { color: #896712 !important; }
html[data-theme="light"] .bazi-history-meta { color: #776a57 !important; }
html[data-theme="light"] .secondary-action {
    background: #f5ead8 !important;
    color: #665842 !important;
    border-color: #cbb78f !important;
}
html[data-theme="light"] .secondary-action:hover {
    background: #eee0c8 !important;
    color: #896712 !important;
    border-color: #a98542 !important;
}

@media (max-width: 860px) {
    .bazi-body #sidebar.history-sidebar {
        position: fixed; top: 0; left: 0; width: 260px; height: 100%; max-height: none;
        transform: translateX(-260px); border-width: 0 1px 0 0; border-radius: 0;
    }
    .bazi-body #sidebar.history-sidebar.open { transform: translateX(0); }
    .qm-sidebar.history-sidebar { position: static; max-height: none; }
}
@media (max-width: 800px) {
    .ly-layout > aside.history-sidebar { position: static; max-height: 260px; }
}

@media (max-width: 700px) {
    .home-header nav > a, .app-nav > a, .suite-nav > a, .qm-suite-nav > a, .ly-wrap header nav > a { height: 28px; }
    .app-header {
        width: calc(100% - 36px);
        min-height: 0;
        padding: 18px 0 14px !important;
        align-items: flex-start !important;
        flex-direction: column;
        gap: 8px;
    }
    .app-title { font-size: 23px !important; letter-spacing: 4px !important; }
    .app-title small { display: inline; font-size: 12px; }
    .app-nav { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 6px 14px !important; }
    .theme-toggle { height: 28px !important; min-width: 0; padding: 0 7px !important; font-size: 11px !important; }
    .theme-toggle-fixed { top: 12px; right: 12px; }
}
