/* 文章弹窗广告样式 */
.popup-ad-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    padding: 20px;
}

.popup-ad-overlay.active {
    opacity: 1;
}

.popup-ad-container {
    position: relative;
    background: #fff;
    border-radius: 12px;
    max-width: 900px;
    width: 100%;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.popup-ad-overlay.active .popup-ad-container {
    transform: scale(1);
}

.popup-ad-close {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 40px;
    height: 40px;
    background: #ff4444;
    color: white;
    border: 3px solid white;
    border-radius: 50%;
    font-size: 28px;
    line-height: 34px;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: all 0.2s;
}

.popup-ad-close:hover {
    background: #cc0000;
    transform: rotate(90deg);
}

.popup-ad-content {
    width: 100%;
}

/* 广告布局 */
.ad-layout {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 第一行：大图 + 6小图 */
.ad-row-1 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.ad-large {
    aspect-ratio: 1/1;
    overflow: hidden;
    border-radius: 8px;
    background: #f0f0f0;
}

.ad-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.ad-large:hover img {
    transform: scale(1.05);
}

.ad-small-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ad-small-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.ad-small-row > * {
    aspect-ratio: 1/1;
    overflow: hidden;
    border-radius: 6px;
    background: #f0f0f0;
}

.ad-small-row img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.ad-small-row > *:hover img {
    transform: scale(1.1);
}

/* 第二行：4张底部图 */
.ad-row-2 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.ad-row-2 > * {
    aspect-ratio: 1/1;
    overflow: hidden;
    border-radius: 6px;
    background: #f0f0f0;
}

.ad-row-2 img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.ad-row-2 > *:hover img {
    transform: scale(1.1);
}

/* 广告占位符 */
.ad-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 14px;
    font-weight: 500;
}

/* 链接样式 */
.ad-layout a {
    display: block;
    width: 100%;
    height: 100%;
    text-decoration: none;
}

/* =====================================================
   移动端自适应广告样式 - 容器根据图片大小自动调整
   ===================================================== */

/* 移动端遮罩层 - 居中显示 */
.popup-ad-overlay.mobile-fullscreen {
    padding: 15px;
    align-items: center;
    justify-content: center;
}

/* 移动端弹窗容器 - 自适应图片大小，无固定尺寸 */
.popup-ad-container.mobile-fullscreen {
    position: relative;
    width: auto !important;
    height: auto !important;
    min-height: unset;
    max-width: 95vw;
    max-height: 90vh;
    padding: 0;
    border-radius: 12px;
    background: transparent;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    display: inline-block;
    overflow: visible;
}

/* 移动端关闭按钮 - 右上角外部 */
.popup-ad-container.mobile-fullscreen .popup-ad-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 36px;
    height: 36px;
    font-size: 24px;
    line-height: 30px;
    background: #ff4444;
    border: 2px solid white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
    z-index: 100;
}

/* 移动端内容区域 - 自适应 */
.popup-ad-container.mobile-fullscreen .popup-ad-content {
    display: block;
    padding: 0;
    overflow: hidden;
    border-radius: 12px;
}

/* 移动端广告容器 - 自适应 */
.ad-mobile-fullscreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    line-height: 0;
}

.ad-mobile-fullscreen-item {
    display: block;
    overflow: hidden;
    border-radius: 12px;
    background: transparent;
    line-height: 0;
}

/* 第二个广告项 */
.ad-mobile-fullscreen-item.ad-second-item {
    margin-top: 0; /* gap 已经处理间距 */
}

/* 单图模式 - 图片自适应 */
.ad-mobile-fullscreen[data-mode="single"] .ad-mobile-fullscreen-item img,
.ad-mobile-fullscreen[data-mode="pending"] .ad-mobile-fullscreen-item img {
    display: block;
    width: auto;
    height: auto;
    max-width: 95vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 12px;
}

/* 双图模式 - 每张图片占屏幕约40%高度 */
.ad-mobile-fullscreen[data-mode="double"] .ad-mobile-fullscreen-item img {
    display: block;
    width: auto;
    height: auto;
    max-width: 95vw;
    max-height: 42vh; /* 两张图加间隙约占85%高度 */
    object-fit: contain;
    border-radius: 12px;
}

.ad-mobile-fullscreen-item a {
    display: block;
    line-height: 0;
}

/* 移动端广告提示文字 - 底部外部显示 */
.ad-mobile-hint {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    background: rgba(0,0,0,0.5);
    padding: 4px 12px;
    border-radius: 12px;
    white-space: nowrap;
}

/* 传统移动端单广告显示（保留兼容） */
.ad-mobile-single {
    max-width: 400px;
    margin: 0 auto;
}

.ad-mobile-item {
    width: 100%;
    aspect-ratio: 1/1;
    overflow: hidden;
    border-radius: 12px;
    background: #f0f0f0;
}

.ad-mobile-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ad-mobile-item a {
    display: block;
    width: 100%;
    height: 100%;
}

/* 移动端自适应 */
@media (max-width: 768px) {
    .popup-ad-container {
        padding: 15px;
        max-width: 95%;
    }
    
    .popup-ad-close {
        top: -10px;
        right: -10px;
        width: 35px;
        height: 35px;
        font-size: 24px;
        line-height: 29px;
    }
    
    /* 移动端自适应广告 - 不设固定尺寸 */
    .popup-ad-container.mobile-fullscreen {
        max-width: 95vw;
        max-height: 90vh;
    }
    
    .popup-ad-container.mobile-fullscreen .popup-ad-close {
        top: -10px;
        right: -10px;
        width: 34px;
        height: 34px;
        font-size: 22px;
        line-height: 28px;
    }
}

@media (max-width: 480px) {
    .popup-ad-container {
        max-width: 90%;
        padding: 12px;
    }
    
    .ad-mobile-single {
        max-width: 100%;
    }
    
    .popup-ad-close {
        width: 32px;
        height: 32px;
        font-size: 22px;
        line-height: 26px;
    }
    
    /* 小屏幕移动端自适应广告 */
    .popup-ad-container.mobile-fullscreen {
        max-width: 96vw;
        border-radius: 10px;
    }
    
    .popup-ad-container.mobile-fullscreen .popup-ad-close {
        top: -8px;
        right: -8px;
        width: 32px;
        height: 32px;
        font-size: 20px;
        line-height: 26px;
    }
    
    .ad-mobile-fullscreen-item img {
        max-width: 96vw;
        border-radius: 10px;
    }
}

/* 动画效果 */
@keyframes slideInFromPosition {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.popup-ad-overlay.active .popup-ad-container.mobile-fullscreen {
    animation: slideInFromPosition 0.4s ease-out;
}
