/* 🔧 v1.2.0 - 修復 z-index 堆疊問題 */
.gasp-scroll-trigger-wrapper {
    position: relative;
    width: 100%;
    isolation: isolate;
    /* 創建新的堆疊上下文 */
    z-index: 1;
}

/* 🔧 核心修復：pin-spacer z-index 管理 */
.pin-spacer:has(.gasp-scroll-trigger-wrapper),
.pin-spacer:has(.gasp-fixed-container),
.elementor-widget-gasp-scroll-trigger .pin-spacer {
    z-index: 1 !important;
    isolation: isolate !important;
}

/* 🔧 核心修復：後續 section 必須顯示在 pin-spacer 之上 */
.pin-spacer+.elementor-section,
.pin-spacer+.elementor-element,
.pin-spacer+.e-con,
.pin-spacer~.elementor-section,
.pin-spacer~.elementor-element,
.pin-spacer~.e-con,
.elementor-widget-gasp-scroll-trigger+.elementor-section,
.elementor-widget-gasp-scroll-trigger~.elementor-section,
.elementor-widget-gasp-scroll-trigger~.e-con {
    position: relative !important;
    z-index: 100 !important;
}

.gasp-fixed-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.gasp-fixed-container.gasp-three-column {
    --text-width: 0.8fr;
    --middle-width: 1.2fr;
    --scroll-width: 0.6fr;
    display: grid;
    grid-template-columns: var(--text-width) var(--middle-width) var(--scroll-width);
    gap: 0;
    position: sticky;
    top: 0;
    width: 100%;
    height: 100vh;
    min-height: 671px;
    max-height: 100vh;
    z-index: 10;
    /* 🔧 降低 z-index，避免蓋住後續 section */
    overflow: hidden;
    box-sizing: border-box;
    /* 關鍵修復 v3.0.1：移除 contain: layout，因為它會破壞 position: fixed */
    contain: none;
    background: #ffffff;
    /* Safari 修復 */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.gasp-pinned-container {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 三欄佈局樣式 */
.gasp-three-column .gasp-text-area {
    padding: 60px 40px;
    position: relative;
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
}

.gasp-three-column .gasp-image-area {
    padding: 20px;
    position: relative;
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    background-color: #f8f8f8;
    min-height: 400px;
}

.gasp-three-column .gasp-scroll-area {
    position: relative;
    height: 100vh;
    min-height: 671px;
    width: 100%;
    overflow-y: auto;
    /* 允許內容在 Safari/Chrome 都能同步滾動 */
    overflow-x: hidden;
    padding: 20px;
    /* 隱藏 scrollbar 但保持可滾動 */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE and Edge */
    -webkit-overflow-scrolling: touch;
    /* Safari 平滑滾動 */
}

/* Chrome, Safari and Opera */
.gasp-three-column .gasp-scroll-area::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* 右側滾動圖片容器 */
.gasp-scroll-image-container {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    min-height: 400px;
}

.gasp-scroll-image-container img {
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* 滾動觸發整體容器 */
.gasp-scroll-trigger-wrapper {
    position: relative;
    width: 100%;
    min-height: 671px;
}

/* 固定三欄內容在視窗中 */
.gasp-scroll-trigger-wrapper.pinned {
    height: auto;
}

/* 兩欄佈局（向下相容） */
.gasp-content-area,
.gasp-text-container {
    width: 50%;
    padding: 40px;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gasp-image-area:not(.gasp-three-column .gasp-image-area),
.gasp-image-container {
    width: 50%;
    padding: 40px;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gasp-text-step,
.gasp-external-text-step {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
}

.gasp-text-step h2,
.gasp-external-text-step h2 {
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: #333;
}

.gasp-step-content {
    font-size: 1.125rem;
    line-height: 1.7;
    color: #555;
    max-width: 90%;
}

.gasp-image-step,
.gasp-external-image-step {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gasp-image-step img,
.gasp-external-image-step img {
    width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
}

/* Elementor 範本在中間區域的特殊處理 */
.gasp-image-step .elementor,
.gasp-external-image-step .elementor {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gasp-image-step .elementor-widget-container,
.gasp-external-image-step .elementor-widget-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Image Comparison Widget 特殊處理 */
.gasp-image-step .elementor-widget-image-comparison,
.gasp-external-image-step .elementor-widget-image-comparison {
    width: 100%;
    height: 100%;
}

.gasp-image-step .elementor-widget-image-comparison .elementor-widget-container,
.gasp-external-image-step .elementor-widget-image-comparison .elementor-widget-container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* 三欄佈局中間區域的 Elementor 範本對齊修正 */
.gasp-three-column .gasp-image-area .gasp-image-step {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    transform: none;
    display: block;
    padding: 20px;
    box-sizing: border-box;
}

/* 隱藏非當前步驟 */
.gasp-three-column .gasp-image-area .gasp-image-step {
    display: none;
}

.gasp-three-column .gasp-image-area .gasp-image-step[style*="display: block"],
.gasp-three-column .gasp-image-area .gasp-image-step[style*="display: flex"] {
    display: block !important;
}

.gasp-three-column .gasp-image-area .elementor {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.gasp-three-column .gasp-image-area .elementor-section {
    width: 100%;
    min-height: auto !important;
    height: auto !important;
}

.gasp-three-column .gasp-image-area .elementor-section-wrap>.elementor-section {
    display: block !important;
}

.gasp-three-column .gasp-image-area .elementor-widget {
    width: 100%;
}

.gasp-three-column .gasp-image-area .elementor-element {
    width: 100%;
}

/* 確保只顯示一個 widget 容器 */
.gasp-three-column .gasp-image-area .elementor-widget-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.gasp-three-column .gasp-image-area .elementor-column {
    width: 100%;
}

/* 確保 Image Comparison 在三欄佈局中正確顯示 */
.gasp-three-column .gasp-image-area .elementor-widget-image-comparison {
    max-width: 100%;
    margin: 0 auto;
}

.gasp-three-column .gasp-image-area .elementor-widget-image-comparison img {
    max-width: 100%;
    height: auto;
}

/* Image Comparison 滑塊對齊修正 */
.gasp-image-area .twentytwenty-container,
.gasp-image-area .eae-image-comp-wrapper,
.gasp-image-area .elementor-widget-image-comparison {
    width: 100% !important;
    max-width: 500px !important;
    margin: 0 auto !important;
    position: relative !important;
}

/* 如果 Elementor 範本包含多個 sections，確保它們垂直排列而不是並排 */
.gasp-image-area .elementor>.elementor-section-wrap,
.gasp-image-area .elementor>.elementor-inner {
    display: block !important;
    width: 100% !important;
}

/* 如果範本包含兩個 widgets，優化並排顯示 */
.gasp-image-area .elementor-section {
    display: inline-block !important;
    width: auto !important;
    max-width: 50% !important;
    vertical-align: middle !important;
}

/* 調整兩個 Image Comparison widgets 的佈局 */
.gasp-image-area .elementor-widget-image-comparison {
    display: inline-block !important;
    width: auto !important;
    max-width: 300px !important;
    margin: 0 15px !important;
}

/* 讓兩個 widgets 居中對齊 */
.gasp-three-column .gasp-image-area .elementor {
    text-align: center;
}

/* ========== 預設：只顯示一個 widget ========== */
.gasp-image-area .elementor-section:nth-child(2),
.gasp-image-area .elementor-section:nth-child(3) {
    display: none !important;
}

.gasp-image-area .elementor-widget-image-comparison {
    max-width: 500px !important;
    margin: 0 auto !important;
    display: block !important;
}

/* 覆蓋之前的並排設定 */
.gasp-image-area .elementor-section:first-child {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
}

/* ========== 選項：如果要顯示兩個 widgets ========== */
/* 如果您想顯示兩個 Image Comparison，請取消註釋以下代碼： */
/*
.gasp-image-area .elementor-section:nth-child(2) {
    display: inline-block !important;
}

.gasp-image-area .elementor-section {
    max-width: 50% !important;
}

.gasp-image-area .elementor-widget-image-comparison {
    max-width: 300px !important;
}
*/

.gasp-image-area .twentytwenty-wrapper,
.gasp-image-area .eae-ic-container {
    width: 100% !important;
    height: auto !important;
}

.gasp-image-area .twentytwenty-before,
.gasp-image-area .twentytwenty-after,
.gasp-image-area .eae-ic-before-image,
.gasp-image-area .eae-ic-after-image {
    position: absolute !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

.gasp-image-area .twentytwenty-handle,
.gasp-image-area .eae-ic-slider {
    z-index: 40 !important;
}

/* Elementor Pro Image Comparison 支援 */
.gasp-image-area .elementor-image-comparison {
    width: 100% !important;
    max-width: 500px !important;
    margin: 0 auto !important;
}

.gasp-image-area .elementor-image-comparison__wrapper {
    width: 100% !important;
    position: relative !important;
}

/* 防止內容溢出 - v3.0.1 修復：移除 contain: layout style，改用其他方式 */
.gasp-three-column .gasp-image-area {
    /* contain: layout style 會破壞 position: fixed，使用 overflow 替代 */
    overflow: hidden;
}

/* 確保切換動畫時維持尺寸 */
.gasp-image-step[style*="display: block"] .elementor-widget-image-comparison,
.gasp-image-step[style*="display: block"] .twentytwenty-container {
    visibility: visible !important;
    opacity: 1 !important;
}

.gasp-scroll-sections {
    position: relative;
    width: 100%;
}

.gasp-scroll-section {
    position: relative;
    width: 100%;
    min-height: 100vh;
}

.gasp-scroll-trigger {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
}

/* Overlay 版面樣式 */
.gasp-scroll-trigger-wrapper[data-layout="overlay"] .gasp-fixed-container {
    position: relative;
}

.gasp-scroll-trigger-wrapper[data-layout="overlay"] .gasp-content-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
}

.gasp-scroll-trigger-wrapper[data-layout="overlay"] .gasp-image-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* 外部 Widget 模式的滾動圖片 */
.gasp-scroll-section .gasp-scroll-image {
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    object-fit: contain;
}

/* 為了更好的用戶體驗，可選擇性地添加自訂滾動指示器 */
.gasp-scroll-area-indicator {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.gasp-scroll-area:hover .gasp-scroll-area-indicator {
    opacity: 1;
}

.gasp-scroll-area-indicator-thumb {
    position: absolute;
    width: 100%;
    height: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    top: 0;
    transition: background 0.3s ease;
}

.gasp-scroll-area:hover .gasp-scroll-area-indicator-thumb {
    background: rgba(0, 0, 0, 0.5);
}

/* 響應式設計 */
@media (max-width: 991px) {

    .gasp-fixed-container,
    .gasp-pinned-container {
        flex-direction: column;
    }

    .gasp-fixed-container.gasp-three-column {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr 2fr;
    }

    .gasp-three-column .gasp-scroll-area {
        height: auto;
        min-height: 50vh;
    }

    .gasp-content-area,
    .gasp-text-container,
    .gasp-image-area,
    .gasp-image-container {
        width: 100%;
        height: 50%;
        padding: 20px;
    }

    .gasp-text-step h2,
    .gasp-external-text-step h2 {
        font-size: 2rem;
    }

    .gasp-step-content {
        font-size: 1rem;
    }
}

@media (max-width: 767px) {

    .gasp-text-step h2,
    .gasp-external-text-step h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .gasp-step-content {
        font-size: 0.9rem;
    }

    .gasp-content-area,
    .gasp-text-container,
    .gasp-image-area,
    .gasp-image-container {
        padding: 15px;
    }
}

/* 動畫過渡效果 */
.gasp-text-step,
.gasp-image-step,
.gasp-external-text-step,
.gasp-external-image-step {
    will-change: transform, opacity;
}

/* 除錯模式標記樣式 */
.gasp-scroll-trigger-wrapper[data-debug="yes"] .gasp-scroll-section {
    border: 2px dashed rgba(255, 0, 0, 0.3);
    position: relative;
}

.gasp-scroll-trigger-wrapper[data-debug="yes"] .gasp-scroll-section::before {
    content: attr(data-step);
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    font-weight: bold;
    z-index: 9999;
}

/* Elementor 編輯器樣式 */
.elementor-editor-active .gasp-scroll-trigger-wrapper {
    min-height: 500px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.elementor-editor-active .gasp-scroll-sections {
    display: none;
}

.elementor-editor-active .gasp-fixed-container {
    height: auto;
    min-height: 500px;
}

/* ========== Safari 專用修復 ========== */
@supports (-webkit-touch-callout: none) {

    /* 只針對 Safari */
    .gasp-fixed-container.gasp-three-column {
        position: fixed !important;
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
        will-change: transform;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    .gasp-three-column .gasp-scroll-area {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y;
        overscroll-behavior-y: contain;
    }

    /* 防止 Safari 的彈性滾動 */
    .gasp-scroll-trigger-wrapper {
        -webkit-overflow-scrolling: auto;
        overscroll-behavior: none;
        overflow-anchor: none;
        /* 防止滾動錨定 */
    }

    /* 防止 pin-spacer 衝突 */
    .pin-spacer {
        -webkit-transform: translateZ(0) !important;
        transform: translateZ(0) !important;
    }

    /* Safari 滾動空間 */
    .safari-scroll-spacer {
        position: relative;
        z-index: -1;
    }
}

/* Safari 特定滾動修復 */
@media not all and (min-resolution:.001dpcm) {
    @supports (-webkit-appearance:none) and (stroke-color:transparent) {
        .gasp-fixed-container.gasp-three-column {
            position: fixed !important;
            top: 0 !important;
            transform: none !important;
            -webkit-transform: none !important;
        }

        /* 確保 pin-spacer 不會干擾 */
        .pin-spacer {
            position: relative !important;
            overflow: visible !important;
        }
    }
}