/* 图文卡片单张下载按钮样式 */
.it-page-card-wrapper {
    position: relative;
    width: 750px; 
    min-width: 750px; /* 锁定宽度，确保定位坐标系稳定 */
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* PC 端：添加透明桥接区，解决鼠标移向按钮时的“悬停死区”问题 */
@media (min-width: 768px) {
    .it-page-card-wrapper::after {
        content: "";
        position: absolute;
        top: -40px;
        bottom: 0;
        left: 100%;
        width: 100px; /* 扩大感应区 */
        pointer-events: auto;
        z-index: 10;
    }
}

.it-card-download-btn {
    position: absolute;
    top: 0;
    right: 0;
    left: auto;
    margin: 0;
    width: 36px;
    height: 36px;
    background-color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.03);
    color: #4b5563; /* gray-600 */
    cursor: pointer;
    z-index: 20;
    opacity: 0;
    
    /* 使用变量解耦位移与缩放，解决抖动问题 */
    --it-btn-tx: calc(100% + 12px);
    --it-btn-ty: -12px;
    --it-btn-scale: 0.8;
    transform: translate(var(--it-btn-tx), var(--it-btn-ty)) scale(var(--it-btn-scale));
    
    transform-origin: center center;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease;
    will-change: transform, opacity;
    backface-visibility: hidden;
}

/* PC 端位置微调 */
@media (min-width: 768px) {
    .it-card-download-btn {
        --it-btn-tx: calc(100% + 16px);
        --it-btn-ty: -8px;
    }
}

/* 移动端尺寸与位置优化 */
@media (max-width: 767px) {
    .it-page-card-wrapper {
        width: 750px;
    }
    .it-card-download-btn {
        width: 72px; 
        height: 72px;
        font-size: 24px;
        --it-btn-tx: calc(100% + 10px);
        --it-btn-ty: -10px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2), 0 4px 8px rgba(0, 0, 0, 0.1);
    }
}

.it-card-download-btn:hover {
    background-color: #fef2f2; /* red-50 */
    color: #ef4444; /* red-500 */
    --it-btn-scale: 1.1 !important;
}

.it-card-download-btn:active {
    --it-btn-scale: 0.95 !important;
}

/* PC 端悬停逻辑 */
@media (hover: hover) {
    .it-page-card-wrapper:hover:not(.is-downloaded) .it-card-download-btn {
        opacity: 1;
        pointer-events: auto;
        --it-btn-scale: 1;
    }
}

/* 移动端/通用显示逻辑 */
.it-page-card-wrapper.show-download:not(.is-downloaded) .it-card-download-btn {
    opacity: 1;
    pointer-events: auto;
    --it-btn-scale: 1;
}

/* 强制隐藏逻辑：点击下载后或导出模式中 */
.it-page-card-wrapper.is-downloaded .it-card-download-btn,
body.is-exporting .it-card-download-btn {
    opacity: 0 !important;
    --it-btn-scale: 0 !important; /* 统一使用变量，严禁直接写 transform 属性 */
    pointer-events: none !important;
}

/* 图文编辑器专用：固定基准画布与缩放适配 */
.it-preview-scale-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 40px 0;
    background-color: transparent;
}

/* 固定宽度的卡片基准 */
.it-page-card, #cover-canvas.it-fixed-canvas {
    width: 750px !important; /* 固定基准宽度 */
    min-width: 750px !important;
    max-width: 750px !important;
    margin-bottom: 32px;
    transform-origin: top center;
    transition: transform 0.2s ease;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    background-color: white;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 预览缩放容器：由 JS 动态设置 --it-scale 变量 */
.it-preview-container-scaled {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 750px; /* 内部容器保持固定宽度 */
    padding: 60px 80px; /* 增加内边距，为卡片外部的下载按钮留出空间 */
    transform: scale(var(--it-scale, 1));
    transform-origin: top center;
    transition: transform 0.2s ease;
    box-sizing: content-box; /* 确保 padding 增加在 750px 之外 */
}

/* 响应式调整：确保外层容器能包裹缩放后的内容 */
#it-preview-content-list, #cover-preview-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 导出模式：全局强制还原 1:1 比例并禁用过渡 */
body.is-exporting .it-preview-scale-wrapper,
body.is-exporting .it-preview-container-scaled,
body.is-exporting #preview-container,
body.is-exporting #cover-canvas {
    transform: none !important;
    transition: none !important;
    animation: none !important;
}

/* 导出时禁用小组件的过渡动画，但保留其位移（translate） */
body.is-exporting .draggable-element {
    transition: none !important;
    animation: none !important;
}

body.is-exporting .it-preview-scale-wrapper {
    overflow: visible !important;
    height: auto !important;
    padding: 0 !important;
}

body.is-exporting #cover-canvas.it-fixed-canvas,
body.is-exporting .it-page-card {
    width: 750px !important;
    min-width: 750px !important;
    max-width: 750px !important;
    margin: 0 0 20px 0 !important;
    position: relative !important;
    left: 0 !important;
    top: 0 !important;
    transform: none !important;
    flex-shrink: 0 !important;
}

body.is-exporting .it-page-card {
    box-shadow: none !important;
}

/* 选中态样式：使用 outline 确保不影响尺寸计算 */
.selected-element {
    outline: 2px solid #3b82f6 !important; /* blue-500 */
    outline-offset: 2px;
    z-index: 60 !important; /* 提升选中目标的层级 */
}

/* 导出模式下隐藏选中态和对齐线 */
body.is-exporting .selected-element {
    outline: none !important;
}

body.is-exporting #guide-v,
body.is-exporting #guide-h {
    display: none !important;
}

/* 导出模式下禁用所有指针事件，防止干扰 */
body.is-exporting .draggable-element {
    pointer-events: none !important;
}

/* 导出时特殊处理：那些靠 transform: translate(-50%, -50%) 定位的元素 */
body.is-exporting .draggable-element[style*="transform"] {
    /* 这里不能简单 none，因为很多元素靠这个居中。
       但在 CanvasDragManager 中我们已经把位置改成了百分比，
       且 CanvasDragManager 的 handleDragStart 会确保 transform 包含 translate(-50%, -50%)。
       我们需要确保在导出时不应用预览缩放的 scale，但保留平移。
    */
}

/* 溢出警告状态：底部红色边框 */
.it-page-card.has-overflow {
    border-bottom: 4px solid #ef4444 !important;
}

/* 溢出提示信息：底部悬浮显示 */
.overflow-warning {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(254, 242, 242, 0.85); /* red-50 with 85% opacity */
    color: #ef4444; /* red-500 */
    text-align: center;
    padding: 8px 0;
    font-size: 14px;
    font-weight: 600;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    backdrop-filter: blur(8px); /* 增加模糊度 */
    pointer-events: none; /* 允许点击穿透 */
}

/* 导出/下载时隐藏警告信息并移除红框 */
body.is-exporting .it-page-card.has-overflow {
    border-bottom: none !important;
}

body.is-exporting .overflow-warning {
    display: none !important;
}
