/* =========================================================================
   底部弹窗横幅 —— 斑狗课程页插件
   所有类名带 .cgbpg 前缀，不会污染子比主题
   尺寸/位置全部走 CSS 变量，电脑端与手机端各自一套（由 PHP 用媒体查询下发）
   ========================================================================= */

.cgbpg {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9990;
    display: flex;
    /* 电脑端 / 手机端各自可设 居中 / 居左 / 居右（由 PHP 下发 --cgbpg-bar-jc） */
    justify-content: var(--cgbpg-bar-jc, center);
    pointer-events: none;
    transform: translateY(0);
    opacity: 1;
    transition: transform .35s cubic-bezier(.4, 0, .2, 1), opacity .3s ease;
    will-change: transform;
}

.cgbpg.is-hidden {
    transform: translateY(115%);
    opacity: 0;
}

.cgbpg__bar {
    pointer-events: auto;
    box-sizing: border-box;
    width: 100%;
    min-width: 0; /* 关键：作为 flex 子项允许收缩到视口宽，否则内容会把横幅撑出屏幕 */
    max-width: var(--cgbpg-bar-w, 680px);
    /* 不能写 margin:auto，否则会盖掉父级的 justify-content，居左/居右失效 */
    margin: 0;
    padding: var(--cgbpg-bar-py, 12px) var(--cgbpg-bar-px, 20px);
    display: flex;
    align-items: center;
    gap: 16px;
    background: linear-gradient(135deg, var(--cgbpg-bar-bg1, #1a1a1a) 0%, var(--cgbpg-bar-bg2, #2d2d2d) 100%);
    color: var(--cgbpg-bar-fg, #fff);
    /* 只留顶部一道极淡高光，不做四周描边（否则窄条居中时左右会出现两条竖线） */
    border: 0;
    border-radius: var(--cgbpg-bar-r, 18px) var(--cgbpg-bar-r, 18px) 0 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07), 0 -10px 30px rgba(0, 0, 0, .35);
}

.cgbpg *,
.cgbpg *::before,
.cgbpg *::after {
    box-sizing: border-box;
}

/* ---------------- 文案 ---------------- */

.cgbpg__text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.cgbpg__title {
    font-size: var(--cgbpg-title-fs, 15px);
    font-weight: 600;
    line-height: 1.4;
    color: var(--cgbpg-bar-fg, #fff);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.cgbpg__sub {
    font-size: var(--cgbpg-sub-fs, 13px);
    line-height: 1.35;
    opacity: .7;
    color: var(--cgbpg-bar-fg, #fff);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------------- 按钮 ---------------- */

.cgbpg__acts {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cgbpg__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--cgbpg-btn-h, 40px);
    padding: 0 var(--cgbpg-btn-px, 22px);
    background: var(--cgbpg-btn-bg, #ff7a00);
    color: var(--cgbpg-btn-fg, #fff);
    border: none;
    border-radius: var(--cgbpg-btn-r, 999px);
    font-size: var(--cgbpg-btn-fs, 14px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: .2px;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, .22);
    transition: filter .2s ease, transform .2s ease, box-shadow .2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* 悬停上浮只给「真有鼠标」的设备用。
   手机上 tap 会先触发 :hover、随即被清掉，配合 .2s transition，
   表现就是点按钮时按钮「上下闪一下」——触摸设备一律不做位移。 */
@media (hover: hover) and (pointer: fine) {
    .cgbpg__btn:hover {
        color: var(--cgbpg-btn-fg, #fff);
        text-decoration: none;
        filter: brightness(1.1);
        transform: translateY(-1px);
        box-shadow: 0 10px 22px rgba(0, 0, 0, .28);
    }
}

.cgbpg__btn:active {
    transform: translateY(0);
    filter: brightness(.95);
}

.cgbpg__coupon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--cgbpg-btn-h, 40px);
    padding: 0 calc(var(--cgbpg-btn-px, 22px) - 6px);
    background: transparent;
    color: var(--cgbpg-bar-fg, #fff);
    border: 2px solid var(--cgbpg-btn-bg, #ff7a00);
    border-radius: var(--cgbpg-btn-r, 999px);
    font-size: calc(var(--cgbpg-btn-fs, 14px) - 1px);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* 同上：优惠券按钮的 hover 变色也只给鼠标设备，避免手机上点完「卡」在悬停态 */
@media (hover: hover) and (pointer: fine) {
    .cgbpg__coupon:hover {
        background: var(--cgbpg-btn-bg, #ff7a00);
        color: #fff;
    }
}

/* 跳转瞬间：掐掉横幅与按钮的所有过渡，并把按钮位移归零。
   手机点击链接时浏览器会短暂保留/清除 :hover、:active，若还有 transition
   就会看到按钮「弹一下」，页面才开始切换。 */
.cgbpg.is-leaving,
.cgbpg.is-leaving .cgbpg__btn,
.cgbpg.is-leaving .cgbpg__coupon {
    transition: none !important;
}

.cgbpg.is-leaving .cgbpg__btn {
    transform: none !important;
}

/* ---------------- 电脑端按钮位置 ---------------- */

@media (min-width: 641px) {
    /* 居中：文案与按钮作为一个整体居中 */
    .cgbpg[data-pc-pos="center"] .cgbpg__bar {
        justify-content: center;
    }

    .cgbpg[data-pc-pos="center"] .cgbpg__text {
        flex: 0 1 auto;
        max-width: 68%;
    }

    /* 靠左：按钮在左、文案在右 */
    .cgbpg[data-pc-pos="left"] .cgbpg__bar {
        flex-direction: row-reverse;
    }
}

/* ---------------- 手机端布局 ---------------- */

@media (max-width: 640px) {
    .cgbpg__bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: var(--cgbpg-bar-py, 12px) var(--cgbpg-bar-px, 14px)
                 calc(var(--cgbpg-bar-py, 12px) + env(safe-area-inset-bottom, 0px));
    }

    .cgbpg__text {
        align-items: center;
        text-align: center;
    }

    .cgbpg__sub {
        max-width: 100%;
    }

    .cgbpg__acts {
        justify-content: center;
    }

    .cgbpg__btn {
        flex: 1 1 auto;
    }

    /* 并排模式：文案在左、按钮在右 */
    .cgbpg[data-mb-pos="inline"] .cgbpg__bar {
        flex-direction: row;
        align-items: center;
        gap: 12px;
    }

    .cgbpg[data-mb-pos="inline"] .cgbpg__text {
        align-items: flex-start;
        text-align: left;
    }

    .cgbpg[data-mb-pos="inline"] .cgbpg__acts {
        flex: 0 0 auto;
        justify-content: flex-end;
    }

    .cgbpg[data-mb-pos="inline"] .cgbpg__btn {
        flex: 0 0 auto;
    }
}

/* ---------------- 端侧显示开关 ---------------- */

@media (max-width: 640px) {
    .cgbpg--no-mb {
        display: none !important;
    }
}

@media (min-width: 641px) {
    .cgbpg--no-pc {
        display: none !important;
    }
}

/* ---------------- 优惠券弹图 ---------------- */

.cgbpg-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9995;
}

.cgbpg-modal.is-open {
    display: block;
}

.cgbpg-modal__mask {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .72);
    animation: cgbpgFadeIn .25s ease;
}

.cgbpg-modal__box {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 460px;
    max-height: 86vh;
    overflow: auto;
    padding: 16px;
    background: #fff;
    border-radius: 14px;
    box-sizing: border-box;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .4);
    animation: cgbpgPop .25s ease;
}

.cgbpg-modal__box img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}

.cgbpg-modal__close {
    position: absolute;
    top: 2px;
    right: 8px;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: none;
    color: #999;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    transition: color .2s ease;
}

.cgbpg-modal__close:hover {
    color: #000;
}

@keyframes cgbpgFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes cgbpgPop {
    from { opacity: 0; transform: translate(-50%, -50%) scale(.95); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .cgbpg,
    .cgbpg__btn {
        transition: none;
    }
}
