/**
 * 结果区与预览模块（result-and-preview.css）
 * - 包含结果区基础壳、AI 解卦加载态、卦象全屏预览与横版预览浮层基础样式。
 * - 不包含六亲强弱明细、飞伏/动爻业务色等深层规则。
 * - 建议在模块基础样式之后、style.css 之前加载。
 */
.result-section {
    padding: 14px 2px;
    background: #f9f9f9;
    border-top: 2px solid #e0e0e0;
}

.result-section #paipan-yingqi-ref-container,
.result-section #paipan-gua-diagnosis-ref-container {
    padding: 16px 12px;
    min-width: 0;
    box-sizing: border-box;
}

/* AI 解卦等待：#gua-result-loading 由 liuyaoAiJieguaUi 控制；卦录延迟展开时整区先显示仅加载态 */
#result-section.liuyao-result-section--ai-loading > *:not(#gua-result-loading) {
    display: none !important;
}

#result-section.liuyao-result-section--ai-loading #gua-result-loading {
    display: flex !important;
}

/* AI 解卦：全屏悬浮层，视口水平垂直居中（仍挂在 #result-section 内以便卦录延迟时父级非 none） */
.gua-result-loading {
    position: fixed;
    inset: 0;
    z-index: 100000;
    box-sizing: border-box;
    margin: 0;
    padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
        max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.38);
    border: none;
    border-radius: 0;
    box-shadow: none;
    pointer-events: auto;
}

.gua-result-loading__inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    max-width: min(360px, 100%);
    padding: 28px 24px 32px;
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

.gua-result-loading__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #64748b;
    border-radius: 50%;
    animation: liuyao-jiegua-loading-spin 0.85s linear infinite;
    box-sizing: border-box;
    display: inline-block;
}

.gua-result-loading__text {
    margin: 0;
    font-size: 0.95rem;
    color: #475569;
    letter-spacing: 0.02em;
}

@keyframes liuyao-jiegua-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

/* 横版预览入口：与复制/重置同排，略作区分 */
.gua-preview-top-btn {
    border-color: #64748b;
    color: #475569;
}

.gua-preview-top-btn:hover {
    background: #475569;
    color: #fff;
    border-color: #475569;
}

/* 卦象全屏预览：与导出同源的竖版位图，铺满视口（object-fit: contain） */
.liuyao-gua-preview-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    box-sizing: border-box;
}

.liuyao-gua-preview-overlay.is-open {
    display: flex;
}

.liuyao-gua-preview-backdrop {
    position: absolute;
    inset: 0;
    background: #0f172a;
    cursor: pointer;
    z-index: 0;
}

/* 右下角：关闭 */
.liuyao-gua-preview-corner-actions {
    position: absolute;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    top: auto;
    left: auto;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.liuyao-gua-preview-corner-actions .liuyao-gua-preview-close {
    pointer-events: auto;
}

.liuyao-gua-preview-close {
    position: static;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    flex-shrink: 0;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: #334155;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.22);
    transition: background 0.15s ease, transform 0.15s ease;
    pointer-events: auto;
}

.liuyao-gua-preview-close:hover {
    background: #fff;
    transform: scale(1.04);
}

.liuyao-gua-preview-panel {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    overflow: hidden;
    box-sizing: border-box;
    pointer-events: none;
}

.liuyao-gua-preview-stage {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 0;
    box-sizing: border-box;
    position: relative;
}

.liuyao-gua-preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: #e2e8f0;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
    z-index: 1;
}

.liuyao-gua-preview-img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    background: #f9f9f9;
    pointer-events: auto;
    box-sizing: border-box;
}

/* 横版 DOM 排版浮层：结构对齐 .liuyao-gua-preview-overlay，内容区可滚动，内嵌与离屏生图同源的 .liuyao-gua-export-host */
.liuyao-gua-layout-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99998;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    box-sizing: border-box;
}

.liuyao-gua-layout-overlay.is-open {
    display: flex;
    /* 减轻部分浏览器在浮层内的双击缩放误触 */
    touch-action: manipulation;
}

.liuyao-gua-layout-backdrop {
    position: absolute;
    inset: 0;
    background: #0f172a;
    cursor: pointer;
    z-index: 0;
}

.liuyao-gua-layout-top-actions {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    z-index: 4;
    display: none;
    pointer-events: none;
}

.liuyao-gua-layout-close {
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: #334155;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.22);
    transition: background 0.15s ease, transform 0.15s ease;
    pointer-events: auto;
}

.liuyao-gua-layout-close:hover {
    background: #fff;
    transform: scale(1.04);
}

/* 左下角操作菜单：不拦截点击（点击由整层 overlay 统一关闭） */
.liuyao-gua-layout-corner-actions {
    position: absolute;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    right: auto;
    top: auto;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

/* 菜单容器 */
.liuyao-gua-layout-menu {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: auto;
}

/* 菜单项容器（窄屏：相对图片按钮居中展开；bottom=上下间距，translateX=左右间距） */
.liuyao-gua-layout-menu-items {
    position: absolute;
    bottom: calc(100% + 15px);
    left: 50%;
    right: auto;
    transform: translate(calc(-50% + 25px), 0) rotate(90deg);
    transform-origin: center bottom;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
}

.liuyao-gua-layout-menu.is-open .liuyao-gua-layout-menu-items {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* 菜单项按钮 */
.liuyao-gua-layout-menu-item {
    min-width: 64px;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    background: #f3f4f6;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    white-space: nowrap;
}

.liuyao-gua-layout-menu-item:hover {
    background: #f3f4f6;
}

.liuyao-gua-layout-menu-item:active {
    transform: translateY(0);
}

.liuyao-gua-layout-menu-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 菜单切换按钮（原LOGO位置） */
.liuyao-gua-layout-menu-toggle {
    position: static;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    flex-shrink: 0;
    border: none;
    border-radius: 5px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    pointer-events: auto;
}

.liuyao-gua-layout-menu-toggle:hover {
    background: #fff;
    transform: scale(1.04);
}

.liuyao-gua-layout-logo-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    vertical-align: top;
    pointer-events: none;
    transform: rotate(90deg);
    transform-origin: center center;
}

@media (min-width: 768px) {
    .liuyao-gua-layout-top-actions {
        display: flex;
    }

    .liuyao-gua-layout-corner-actions {
        left: auto;
        right: max(12px, env(safe-area-inset-right, 0px));
        bottom: max(12px, env(safe-area-inset-bottom, 0px));
    }

    .liuyao-gua-layout-logo-img {
        transform: none;
    }

    /* 横屏宽屏布局：菜单在按钮上方、右对齐 */
    .liuyao-gua-layout-menu-items {
        left: auto;
        right: 0;
        bottom: calc(100% + 12px);
        transform: none;
        transform-origin: center bottom;
    }
}

/* 窄屏旋转横版：点击图片按钮圆心 150px 半径圆内可隐藏/再次点击显示角标图片菜单（默认显示） */
.liuyao-gua-layout-overlay.liuyao-gua-layout-overlay--narrow-rotated.liuyao-gua-layout-corner-actions-hidden
    .liuyao-gua-layout-corner-actions {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* 暂时隐藏生图按钮（恢复时去掉 HTML 上的 liuyao-gua-export-img-btn--hidden） */
.liuyao-gua-export-img-btn--hidden {
    display: none !important;
}

/* 与生图 html2canvas backgroundColor、.liuyao-gua-preview-img 一致，避免 contain 留白处透出深色遮罩像黑边 */
.liuyao-gua-layout-panel {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    overflow: hidden;
    box-sizing: border-box;
    pointer-events: auto;
    background: #f9f9f9;
    /* 抑制移动端双击缩放整页，避免与切换代表爻等点击冲突 */
    touch-action: manipulation;
}

/* 与 .liuyao-gua-preview-stage 对齐：无 padding，contain 参照区 = 整块 panel（与生图预览 img 的 100%×100%+object-fit 一致）
 * 纵轴勿对 stage 使用 align-items:center：内容高于视口时会「滚不到宿主顶部」。改用列 flex + 宿主 margin 上下 auto：
 * 短时垂直居中；溢出时 auto 边距按规范坍为 0，宿主贴顶，scrollTop=0 即可见卦象信息顶。 */
.liuyao-gua-layout-stage {
    width: 100%;
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    background: #f9f9f9;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
    .liuyao-gua-layout-overlay.liuyao-gua-layout-fill-mode .liuyao-gua-layout-stage {
        overflow-y: auto;
        overflow-x: hidden;
        display: block;
    }

    /* stage 改 block 后纵向 auto margin 不再居中；清零以免异常占位，横向仍居中 */
    .liuyao-gua-layout-overlay.liuyao-gua-layout-fill-mode .liuyao-gua-export-host {
        transform-origin: top left !important;
        margin-top: 0;
        margin-bottom: 0;
        margin-left: auto;
        margin-right: auto;
    }
}

/* 浮层内取消离屏定位；旋转与缩放由 liuyaoGuaLayoutOverlay.applyLayoutRotationFit 写入 transform */
.liuyao-gua-layout-overlay .liuyao-gua-export-host {
    position: relative;
    left: auto;
    top: auto;
    width: max-content;
    max-width: none;
    margin-top: auto;
    margin-bottom: auto;
    margin-left: 0;
    margin-right: 0;
    min-width: 0;
    flex-shrink: 0;
    will-change: transform;
    touch-action: manipulation;
}

/*
 * 主页 #liuyao-gua-visual-stack（≤767）迷你排盘会藏原忌仇/旺衰/六兽等；横版与预览宿主不在该栈内，
 * 但旧规则放在 max-width:767 内会导致手机横屏（视口宽度常 >767）浮层收不到恢复声明。此处不限定宽度。
 * 变卦非变爻仍由 result-export .yao-bian-static-line 收列；应期「详情」展开见 gua-layout。
 */
#liuyao-gua-layout-overlay:not(.liuyao-layout-yingqi-detail-open) .liuyao-gua-export-host .liuyao-gua-export-ben-card .gua-display .yao-yuanjichou,
#liuyao-gua-preview-overlay .liuyao-gua-export-host .liuyao-gua-export-ben-card .gua-display .yao-yuanjichou {
    display: inline-flex !important;
}

#liuyao-gua-layout-overlay:not(.liuyao-layout-yingqi-detail-open) .liuyao-gua-export-host .liuyao-gua-export-ben-card .yao-wangshuai,
#liuyao-gua-layout-overlay:not(.liuyao-layout-yingqi-detail-open) .liuyao-gua-export-host .liuyao-gua-export-ben-card .yao-liushou,
#liuyao-gua-layout-overlay:not(.liuyao-layout-yingqi-detail-open) .liuyao-gua-export-host .liuyao-gua-export-ben-card .yao-kongwang,
#liuyao-gua-preview-overlay .liuyao-gua-export-host .liuyao-gua-export-ben-card .yao-wangshuai,
#liuyao-gua-preview-overlay .liuyao-gua-export-host .liuyao-gua-export-ben-card .yao-liushou,
#liuyao-gua-preview-overlay .liuyao-gua-export-host .liuyao-gua-export-ben-card .yao-kongwang {
    display: inline-flex !important;
}

.liuyao-gua-layout-overlay .liuyao-gua-export-host .dongyao-item {
    word-break: break-word;
    overflow-wrap: break-word;
}

 

.liuyao-gua-layout-overlay .liuyao-gua-export-host .ben-gua-fushen-block {
    max-width: 100%;
}

/* 页面横版浮层：爻槽按行高定高并拉伸 PNG，加粗爻线；离屏生图仍用 .liuyao-gua-export-host .yao-symbol 细爻规则 */
.liuyao-gua-layout-overlay .liuyao-gua-export-host .yao-symbol-wrap:not(.yao-fushen-symbol-wrap) {
    flex: 0 0 38px;
    width: 38px;
    min-width: 38px;
    font-size: 17px;
    height: 0.9em;
    min-height: 15px;
    box-sizing: border-box;
    align-items: stretch;
    justify-content: center;
}

.liuyao-gua-layout-overlay .liuyao-gua-export-host .yao-symbol {
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: fill;
    object-position: center;
    display: block;
}
