/* =========================================================
   微信 H5 响应式适配层
   - 320px ~ 767px：移动端 / 微信内置浏览器
   - 768px ~ 1099px：平板与小屏电脑
   - 1100px 以上：桌面宽屏
   ========================================================= */

:root {
    --wechat-green: #07c160;
    --wechat-green-dark: #06ad56;
    --brand-dark: #171734;
    --brand-purple: #30204f;
    --page-bg: #f4f6fa;
    --card-bg: rgba(255, 255, 255, 0.96);
    --text-main: #1f2430;
    --text-secondary: #7b8190;
    --border-color: #edf0f5;
    --shadow-soft: 0 0.08rem 0.32rem rgba(31, 36, 48, 0.07);
    --radius-card: 0.2rem;
    color-scheme: light;
}

html {
    min-height: 100%;
    background: #e9edf4;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(circle at 10% 0%, rgba(7, 193, 96, 0.06), transparent 26rem),
        var(--page-bg);
    color: var(--text-main);
    overflow-x: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
a,
[role="button"] {
    touch-action: manipulation;
}

input,
textarea,
select {
    min-width: 0;
}

img {
    max-width: 100%;
}

.nav-bar {
    padding-top: max(0.28rem, env(safe-area-inset-top));
    background: rgba(255, 255, 255, 0.94);
    border-color: var(--border-color);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.nav-back {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 0.48rem;
    border-radius: 0.12rem;
}

.nav-back:active,
.tab-nav-item:active,
button:active {
    opacity: 0.72;
}

.bottom-tab {
    height: calc(1.1rem + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.96);
    border-color: var(--border-color);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.tab-nav-item.active .icon,
.tab-nav-item.active .label {
    color: var(--wechat-green);
}

.tab-nav-item .icon {
    transition: transform 0.2s ease;
}

.tab-nav-item.active .icon {
    transform: translateY(-0.02rem) scale(1.06);
}

.tab-nav-item .badge-dot {
    background: #fa5151;
}

.page-container {
    min-height: calc(100vh - 0.88rem);
    min-height: calc(100dvh - 0.88rem);
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}

.course-card,
.order-card,
.user-card,
.menu-list,
.info-section,
.stats-card,
.record-section,
.chart-section,
.form-wrapper,
.setting-section,
.free-preview,
.pay-cover,
.agreement {
    border: 1px solid rgba(232, 236, 243, 0.92);
    box-shadow: var(--shadow-soft);
}

.course-card,
.order-card,
.promo-item,
.menu-item,
.setting-item,
.info-item,
.record-item,
.stats-item {
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.toast {
    padding-bottom: max(0.24rem, env(safe-area-inset-bottom));
}

/* 手机端：形成微信内置浏览器中常见的单列信息流 */
@media (max-width: 767px) {
    html {
        font-size: clamp(85.333px, 26.6667vw, 100px);
    }

    body {
        width: 100%;
        max-width: 500px;
        margin: 0 auto;
    }

    .bottom-tab {
        width: min(100%, 500px);
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }

    .nav-title {
        max-width: 62%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .course-card:active,
    .order-card:active,
    .promo-item:active,
    .menu-item:active,
    .setting-item:active,
    .info-item:active,
    .record-item:active {
        transform: scale(0.985);
    }
}

/* 平板与 PC：从“放大的手机页”转换为真正的宽屏布局 */
@media (min-width: 768px) {
    html {
        font-size: 100px;
        background: #e9edf4;
    }

    body {
        width: 100%;
        min-width: 768px;
        padding: 0 24px 112px;
    }

    .nav-bar {
        width: min(1180px, calc(100vw - 48px));
        min-height: 72px;
        margin: 16px auto 0;
        padding: 0 24px;
        top: 16px;
        border: 1px solid rgba(224, 229, 238, 0.9);
        border-radius: 18px;
        box-shadow: 0 10px 30px rgba(30, 36, 50, 0.06);
    }

    .nav-back {
        min-width: 48px;
        min-height: 44px;
        padding: 0 10px;
        font-size: 34px;
    }

    .nav-title {
        font-size: 20px;
    }

    .nav-right {
        min-width: 48px;
        font-size: 14px;
    }

    .page-container {
        width: min(1180px, calc(100vw - 48px));
        min-height: calc(100vh - 104px);
        margin: 0 auto;
        padding: 24px 0 32px;
    }

    .bottom-tab {
        width: min(760px, calc(100vw - 48px));
        height: 72px;
        right: auto;
        bottom: 20px;
        left: 50%;
        padding: 0 12px;
        transform: translateX(-50%);
        border: 1px solid rgba(224, 229, 238, 0.92);
        border-radius: 22px;
        box-shadow: 0 16px 42px rgba(28, 35, 48, 0.16);
    }

    .tab-nav-item {
        min-width: 132px;
        min-height: 52px;
        flex-direction: row;
        justify-content: center;
        gap: 8px;
        padding: 8px 20px;
        border-radius: 16px;
    }

    .tab-nav-item:hover {
        background: #f1f8f4;
    }

    .tab-nav-item.active {
        background: rgba(7, 193, 96, 0.1);
    }

    .tab-nav-item .icon {
        font-size: 24px;
    }

    .tab-nav-item .label {
        font-size: 14px;
    }

    .tab-nav-item .badge-dot {
        top: 8px;
        right: 14px;
        width: 9px;
        height: 9px;
    }

    .toast {
        padding: 14px 24px;
        border-radius: 12px;
        font-size: 15px;
        max-width: 460px;
    }

    /* 首页 */
    body > .header,
    body > .tab-bar,
    body > .course-list {
        width: min(1180px, calc(100vw - 48px));
        margin-right: auto;
        margin-left: auto;
    }

    body > .header {
        margin-top: 16px;
        padding: 34px 38px 28px;
        top: 16px;
        border-radius: 22px 22px 0 0;
    }

    body > .tab-bar {
        top: 142px;
        height: 72px;
        padding: 0 28px;
        border-radius: 0 0 18px 18px;
    }

    .tab-search {
        width: min(420px, 45vw);
    }

    body > .course-list,
    .order-list,
    .record-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 20px;
    }

    body > .course-list {
        padding: 24px 0 12px;
    }

    .course-card,
    .order-card,
    .record-item {
        margin: 0;
    }

    .course-card:hover,
    .order-card:hover,
    .promo-item:hover,
    .menu-item:hover,
    .setting-item:hover,
    .info-item:hover,
    .record-item:hover,
    .stats-item:hover {
        transform: translateY(-3px);
        box-shadow: 0 14px 34px rgba(31, 36, 48, 0.1);
    }

    /* 订单与搜索区域 */
    .search-bar,
    .order-tabs {
        border-radius: 16px;
        margin-bottom: 18px;
        box-shadow: 0 7px 24px rgba(31, 36, 48, 0.05);
    }

    .order-list {
        padding: 0;
    }

    /* 我的 */
    .user-card {
        margin-top: 0;
        border-radius: 22px;
    }

    .promo-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 16px;
        padding: 0;
        margin: 20px 0;
    }

    .promo-item {
        min-height: 128px;
        justify-content: center;
        border: 1px solid var(--border-color);
        border-radius: 18px;
        box-shadow: var(--shadow-soft);
    }

    .menu-list,
    .logout-wrap {
        margin-right: 0;
        margin-left: 0;
    }

    /* 设置、账号、表单页面 */
    .page-container > .setting-section,
    .page-container > .avatar-section,
    .page-container > .info-section,
    .page-container > .form-wrapper,
    .page-container > .submit-wrap,
    .page-container > .success-state {
        width: min(820px, 100%);
        margin-right: auto;
        margin-left: auto;
    }

    .setting-section,
    .info-section,
    .form-wrapper {
        border-radius: 18px;
        overflow: hidden;
    }

    .setting-item,
    .info-item {
        min-height: 64px;
    }

    /* 钱包、统计、邀请 */
    .balance-card,
    .stats-card,
    .stats-grid,
    .record-section,
    .chart-section,
    .share-wrap {
        margin-right: 0;
        margin-left: 0;
    }

    .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 16px;
    }

    .stats-item {
        border-radius: 16px;
    }

    .record-section,
    .chart-section {
        border-radius: 20px;
    }

    /* 商品详情与协议 */
    .detail-wrapper,
    .free-preview,
    .pay-cover,
    .agreement {
        width: min(900px, calc(100vw - 48px));
        margin-right: auto;
        margin-left: auto;
    }

    .agreement {
        margin-top: 24px;
        padding: 42px 48px;
        border-radius: 20px;
    }

    .bottom-buy-bar {
        width: min(900px, calc(100vw - 48px));
        right: auto;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        border: 1px solid var(--border-color);
        border-radius: 20px;
        box-shadow: 0 16px 42px rgba(28, 35, 48, 0.16);
    }

    .content-wrapper {
        min-height: calc(100vh - 260px);
        background: rgba(255, 255, 255, 0.76);
        border: 1px solid var(--border-color);
        border-radius: 22px;
        box-shadow: var(--shadow-soft);
    }
}

@media (min-width: 1100px) {
    body > .course-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .order-list,
    .record-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 首页窄屏头部专项优化 */
@media (max-width: 767px) {
    body > .header {
        padding: max(0.32rem, env(safe-area-inset-top)) 0.28rem 0.28rem;
    }

    .header-top {
        align-items: center;
        gap: 0.16rem;
    }

    .header-title {
        flex: 1 1 auto;
        min-width: 0;
        align-items: center;
        gap: 0.08rem;
    }

    .header-title h1 {
        flex: 0 0 auto;
        white-space: nowrap;
        font-size: 0.4rem;
    }

    .header-title .sub {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.18rem;
    }

    .header-badge {
        flex: 0 0 auto;
        width: 1.48rem;
        padding: 0.07rem 0.1rem;
        text-align: center;
        line-height: 1.45;
        white-space: normal;
    }

    .header-sub {
        gap: 0.1rem;
        margin-top: 0.18rem;
    }

    .header-sub .tag {
        padding: 0.05rem 0.12rem;
        font-size: 0.17rem;
    }

    body > .tab-bar {
        top: 1.46rem;
        gap: 0.16rem;
        padding: 0 0.28rem;
    }

    .tab-search {
        min-width: 0;
    }

    .tab-search input {
        min-width: 0;
        font-size: 0.23rem;
    }
}

@media (max-width: 350px) {
    .header-title .sub {
        display: none;
    }

    .header-badge {
        width: 1.56rem;
        font-size: 0.16rem;
    }
}

.nav-bar.nav-bar-dark {
    background: linear-gradient(135deg, #1a1a3e 0%, #2d1b4e 100%);
    border-color: transparent;
}

.nav-bar.nav-bar-dark .nav-title,
.nav-bar.nav-bar-dark .nav-back,
.nav-bar.nav-bar-dark .nav-right {
    color: #ffffff;
}

@media (max-width: 767px) {
    .user-card {
        padding-right: 0.3rem;
        padding-left: 0.3rem;
    }

    .user-info {
        gap: 0.18rem;
    }

    .user-avatar {
        width: 1rem;
        height: 1rem;
        font-size: 0.42rem;
    }

    .user-detail {
        flex: 1 1 auto;
        min-width: 0;
    }

    .user-name {
        gap: 0.08rem;
        font-size: 0.29rem;
        white-space: nowrap;
    }

    .user-name .level-tag {
        flex: 0 0 auto;
        padding: 0.02rem 0.08rem;
        font-size: 0.14rem;
    }

    .user-id {
        overflow: hidden;
        margin-top: 0.06rem;
        font-size: 0.19rem;
        letter-spacing: 0.02rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .promo-item {
        gap: 0.06rem;
        padding-right: 0.02rem;
        padding-left: 0.02rem;
    }

    .promo-item .icon {
        font-size: 0.38rem;
    }

    .promo-item .label {
        font-size: 0.18rem;
        white-space: nowrap;
    }
}

/* 手机端统计卡片使用 2×2 网格，避免四列固定宽度产生横向滚动 */
@media (max-width: 767px) {
    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.12rem !important;
        padding-right: 0.3rem;
        padding-left: 0.3rem;
    }

    .stats-grid > .stats-item {
        width: auto !important;
        min-width: 0 !important;
        margin: 0 !important;
    }
}

