/* --- Grid 列表樣式 --- */
.sonic-market-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 40px;
    align-items: start;
}

@media (min-width: 768px) {
    .sonic-market-grid { grid-template-columns: repeat(3, 1fr); gap: 30px; }
}

@media (min-width: 1024px) {
    .sonic-market-grid { grid-template-columns: repeat(4, 1fr); gap: 40px; }
}

/* 單一項目樣式 */
.market-trigger {
    background: none; border: none; padding: 0; width: 100%;
    cursor: pointer; text-align: left; display: block;
}

.market-thumb-box {
    position: relative; width: 100%; overflow: hidden;
    border-radius: 4px; margin-bottom: 12px;
    line-height: 0; background: #f5f5f5;
}

.market-thumb-box img {
    width: 100%; height: auto; display: block;
    transition: transform 0.5s ease;
}

.market-trigger:hover .market-thumb-box img { transform: scale(1.05); }

.market-hover-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4); opacity: 0;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.3s ease;
}
.market-trigger:hover .market-hover-overlay { opacity: 1; }

.read-more-btn {
    color: #fff; border: 1px solid #fff; padding: 6px 16px;
    font-size: 0.85rem; letter-spacing: 1px; text-transform: uppercase;
    background: rgba(0,0,0,0.2);
}

.market-title {
    font-size: 1.1rem; font-weight: 700; margin: 0;
    color: inherit; line-height: 1.4; margin-top: 10px;
}

/* --- ★★★ 彈跳視窗 (Modal) UX 優化版 ★★★ --- */
.sonic-market-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 99999; opacity: 0; visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    display: flex; justify-content: center; align-items: center;
    /* 確保 Modal 本身不會被手機網址列遮擋 */
    padding: 20px; 
}

.sonic-market-modal.is-open { opacity: 1; visibility: visible; }

.sonic-market-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(5px);
}

/* 容器：設定為 Flex 佈局，禁止容器本身捲動 */
.sonic-market-container {
    position: relative;
    background: #fff;
    width: 100%;
    max-width: 1100px;
    
    /* 關鍵：限制最大高度，並預留上下空間 */
    max-height: 85vh; 
    max-height: 85dvh; /* 針對手機動態高度優化 */
    
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    z-index: 2;
    opacity: 0; transform: translateY(30px) scale(0.98);
    transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.5s ease;
    
    /* 關鍵：Flex 佈局讓內容區獨立捲動 */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 防止圓角被內容切掉 */
}

.sonic-market-modal.is-open .sonic-market-container {
    opacity: 1; transform: translateY(0) scale(1);
}

/* 關閉按鈕：固定在容器右上角，加上背景色 */
.sonic-market-close {
    position: absolute;
    top: 15px; 
    right: 15px;
    
    /* 樣式優化：圓形白底按鈕，確保在圖片上也能看見 */
    background: rgba(255, 255, 255, 0.9);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    
    font-size: 28px;
    line-height: 1;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: #333;
    z-index: 20; /* 確保在內容之上 */
    transition: transform 0.3s, background 0.3s;
}

.sonic-market-close:hover {
    transform: rotate(90deg);
    background: #fff;
}

/* 內容區域：獨立捲動 (Scroll Body) */
.sonic-market-body {
    /* 讓這個區域填滿剩餘空間並產生捲軸 */
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* iOS 慣性捲動 */
    
    /* 內距設定在這裡，而不是容器 */
    padding: 30px;
    padding-top: 40px; /* 避開關閉按鈕 */
}

/* --- Modal 內部排版 --- */
.market-modal-layout {
    display: flex; flex-direction: column;
}

.market-modal-img { width: 100%; margin-bottom: 25px; }
.market-modal-img img { width: 100%; height: auto; display: block; border-radius: 4px; }

.market-modal-title {
    font-size: 1.8rem; margin-bottom: 15px;
    line-height: 1.2; text-transform: uppercase;
}

.market-modal-desc {
    font-size: 1rem; line-height: 1.7; color: #333;
}

/* 手機版微調 */
@media (max-width: 768px) {
    .sonic-market-modal { padding: 10px; } /* 縮小邊距讓視窗大一點 */
    .sonic-market-container { max-height: 90dvh; }
    .sonic-market-body { padding: 20px; padding-top: 50px; } /* 增加頂部空間給按鈕 */
    .market-modal-title { font-size: 1.5rem; }
}

/* 桌機版佈局 */
@media (min-width: 769px) {
    .sonic-market-body { padding: 40px; }
    
    .market-modal-layout {
        flex-direction: row; align-items: flex-start; gap: 50px;
    }

    .market-modal-img {
        flex: 1; width: 50%; margin-bottom: 0;
        /* 在內部捲動區 sticky 效果會失效，所以這裡改回一般流動，或者視需求調整 */
    }

    .market-modal-info { flex: 1; width: 50%; }
}
