/* imagetarget.html 專用樣式 (載入順序在 common.css 之後)
   Tailwind Play CDN 的 <style> 在執行時插入、排在本檔之後，同權重時會蓋過本檔：
   以 ID 開頭的規則權重已高於 Tailwind class，不需要 !important；
   !important 只用在元素 / class 選擇器要蓋過 Tailwind class，或要蓋過 JS 寫入的 inline style (three.js canvas) */

/* 3D Canvas Container */
#canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: #0f172a;
    border-radius: 0.75rem;
    overflow: hidden;
    touch-action: none;
}

#canvas-container canvas,
#canvas-container * {
    width: 100% !important;
    height: 100% !important;
    display: block;
    touch-action: none;
}

@media (max-width: 767px),
(max-height: 480px) {
    header {
        height: 44px !important;
        min-height: 0;
    }

    header .text-base {
        font-size: 1rem;
    }

    footer {
        padding: 6px !important;
    }

    #footer-container button {
        font-size: 0.95rem;
        min-width: 36px;
        min-height: 36px;
    }

    #footer-container span {
        font-size: 0.95rem;
    }
}

/* Asset Picker Modal：原生 <dialog> (showModal)，本身即滿版半透明背景；未開啟時由瀏覽器隱藏 */
#asset-picker-modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    border: 0;
    color: inherit;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#asset-picker-modal::backdrop {
    background: transparent;
}

#asset-picker-modal[open] {
    display: flex;
}

/* 動態激活 (由 JS 控制加入 .active) */
#asset-picker-modal.active {
    opacity: 1;
    pointer-events: auto;
}

/* 內部面板 (電腦版預設縮放動畫) */
#asset-picker-modal>div {
    background-color: white;
    border-radius: 1.5rem;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

#asset-picker-modal.active>div {
    transform: scale(1);
}

/* Mobile Adjustments */
@media (max-width: 767px),
(max-height: 480px) {
    body {
        height: 100dvh !important;
        overflow: hidden;
    }

    main {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    header {
        flex-shrink: 0;
    }

    footer {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 50;
        background: white;
    }

    #mobile-tab-bar {
        position: sticky;
        bottom: 0;
        z-index: 40;
    }

    #asset-picker-modal {
        align-items: flex-end;
        padding: 0;
    }

    :root {
        --mobile-panel-h: 280px;
        --mobile-picker-h: 380px;
    }

    #asset-picker-modal>div {
        max-width: 100%;
        width: 100%;
        border-radius: 1.5rem 1.5rem 0 0;
        height: var(--mobile-picker-h);
        max-height: 70vh;
        margin: 0;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    }

    #asset-picker-modal.active>div {
        transform: translateY(0);
        scale: 1;
    }
}

/* 手機模式：列表改為左右捲動 (Carousel Style) */
@media (max-width: 767px),
(max-height: 480px) {

    /* 素材列表容器 */
    #source-images-list,
    #assets-image-list,
    #assets-video-list,
    #assets-model-list,
    #compiled-minds-list,
    #ui-asset-picker-list {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        gap: 16px;
        padding: 12px 24px 32px 24px;
        margin-left: 0;
        margin-right: 0;
        scroll-snap-type: x mandatory;
        scroll-padding: 0 24px;
        -webkit-overflow-scrolling: touch;
        max-height: none;
    }

    /* 確保橫向捲動列的最後一個元素之後也有間隔 */
    #ui-asset-picker-list::after,
    #assets-image-list::after,
    #assets-video-list::after,
    #assets-model-list::after,
    #compiled-minds-list::after {
        content: '';
        flex: 0 0 8px;
        /* 加上 padding 24 總共 32px 的收尾間隔 */
    }

    /* 針對內層還有 grid 的情況 (Step 2 Source Images) */
    #source-images-list>.grid,
    #compiled-minds-list>.grid {
        display: flex;
        flex-wrap: nowrap;
        gap: 12px;
        width: max-content;
    }

    /* 每個卡片的基礎控制 (Step 1) */
    #source-images-list .grid>li,
    #compiled-minds-list .grid>li {
        flex: 0 0 130px;
        width: 130px;
        height: 130px;
        scroll-snap-align: start;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0;
        position: relative;
    }

    /* 素材素材列表 (Step 2 & Step 3 Picker) - 需允許溢出以顯示右上角刪除按鈕 */
    #assets-image-list>li,
    #assets-video-list>li,
    #assets-model-list>li,
    #ui-asset-picker-list>li {
        flex: 0 0 130px;
        width: 130px;
        height: 145px;
        scroll-snap-align: start;
        display: flex;
        flex-direction: column;
        overflow: visible;
        padding: 0;
        position: relative;
    }

    /* Picker 卡片按鈕填滿外層 li */
    #ui-asset-picker-list>li>.asset-picker-card {
        display: flex;
        flex-direction: column;
        height: 100%;
        padding: 0;
    }

    /* 專案列表資訊層在方形模式下的處理 (JS 已處理絕多數，此處強化行動端表現) */
    #compiled-minds-list .grid>li .absolute.bottom-0 {
        padding: 4px 6px;
    }

    /* 修正 Picker List 的 Grid 為 Flex */
    #ui-asset-picker-list.grid {
        display: flex;
    }

    /* 修正底圖位移 (Gap Fix) */
    body.mobile-panel-active #editor-center-panel {
        margin-bottom: min(var(--mobile-panel-h), 35vh);
    }

    /* 確保 Step 2 & 3 的素材縮圖容器依然保持裁切 */
    #assets-image-list>li>div:first-child,
    #assets-video-list>li>div:first-child,
    #assets-model-list>li>div:first-child,
    #ui-asset-picker-list .asset-picker-card>span:first-child {
        height: 100px;
        overflow: hidden;
        border-radius: 0.75rem;
    }

    /* 隱藏捲軸但保留功能 */
    .custom-scroll::-webkit-scrollbar {
        height: 4px;
    }

    /* 空狀態或空列表處理，消除多餘 scroll gap */
    .is-empty, .is-empty.grid {
        gap: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .is-empty::after {
        display: none !important;
        flex: 0 0 0 !important;
    }

    /* 空狀態處理 */
    #source-images-list .grid>.col-span-full,
    #compiled-minds-list>.text-center,
    #assets-image-list>.text-center,
    #assets-video-list>.text-center,
    #assets-model-list>.text-center,
    .empty-state {
        flex: 1 1 100% !important;
        height: auto !important;
        min-height: 100px !important;
        width: 100% !important;
        scroll-snap-align: center;
        margin-right: 0 !important;
    }
}
