/* ================= UI 系统 ================= */
:root {
    --primary: #4834d4;
    --accent: #686de0;
    --bg: #f1f2f6;
    --card-bg: #ffffff;
    --text-main: #2f3542;
    --text-sub: #747d8c;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text-main);
    /* 🔴 修复 1: 改为最小高度，允许页面随内容自然长高，不再强制一屏 */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 登录层 */
#auth-layer {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-box {
    width: 360px;
    padding: 40px;
    background: white;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.auth-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 10px;
}

.auth-input {
    width: 100%;
    padding: 14px;
    margin: 8px 0;
    border: 2px solid #f1f2f6;
    border-radius: 12px;
    box-sizing: border-box;
    font-size: 16px;
    transition: 0.2s;
    outline: none;
}

.auth-input:focus {
    border-color: var(--primary);
    background: #fff;
}

.auth-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 10px;
    transition: 0.2s;
}

.auth-btn:hover {
    background: var(--accent);
    transform: translateY(-2px);
}

/* 仪表盘 */
#dashboard-layer {
    display: none;
    /* 🔴 修复 2: 移除 height: 100% 限制，改为 flex: 1 自动填充或自然延伸 */
    flex: 1;
    flex-direction: column;
}

.nav-bar {
    background: white;
    height: 70px;
    padding: 0 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    z-index: 10;
    flex-shrink: 0;
    /* 🔴 修复 3: 增加吸顶效果，保证页面滚动时导航栏不消失 */
    position: sticky;
    top: 0;
}

.logo {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ========== 学科标签栏 ========== */
.subject-tabs-container {
    background: white;
    padding: 20px 40px;
    border-bottom: 1px solid #e8e8e8;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.subject-tabs {
    display: flex;
    gap: 15px;
    min-width: max-content;
}

.subject-tab {
    padding: 8px 20px;
    border-radius: 20px;
    background: #f1f2f6;
    border: 2px solid transparent;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-sub);
    white-space: nowrap;
    transition: all 0.3s ease;
}

.subject-tab:hover {
    background: #dfe6e9;
}

.subject-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ========== 筛选条件栏 ========== */
.filter-bar {
    background: white;
    padding: 15px 40px;
    display: flex;
    gap: 30px;
    align-items: center;
    border-bottom: 1px solid #e8e8e8;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-group label {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
}

.filter-group select {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    color: var(--text-main);
    font-size: 0.95rem;
    cursor: pointer;
    transition: 0.2s;
}

.filter-group select:hover {
    border-color: var(--primary);
}

.filter-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(72, 52, 212, 0.1);
}

/* 桌面端 Grid 默认设置 */
.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    padding: 40px;
}

/* 课程卡片 */
.card {
    background: white;
    border-radius: 20px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    border: 1px solid transparent;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
    /* 桌面端保留最大高度限制，防止个别卡片过长 */
    max-height: 420px;
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    border-color: rgba(72, 52, 212, 0.2);
}

/* 锁定状态卡片 */
.card.locked {
    filter: grayscale(0.8);
    opacity: 0.8;
}

.card.locked:hover {
    filter: grayscale(0);
    opacity: 1;
    transform: scale(1.02);
}

.card.locked::after {
    content: "🔒";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    text-shadow: 0 0 10px black;
}

.card-preview {
    height: 174px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    background: #eee;
    position: relative;
    flex-shrink: 0;
}

.card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-tag {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    color: white;
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: bold;
    z-index: 2;
}

.card-body {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 8px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.card-desc {
    font-size: 0.9rem;
    color: var(--text-sub);
    margin-bottom: 0;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 应用容器 */
#app-container {
    position: fixed;
    inset: 0;
    background: #1e272e;
    z-index: 1000;
    display: none;
    flex-direction: column;
    animation: zoomIn 0.2s;
}

@keyframes zoomIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.app-header {
    height: 50px;
    background: #2d3436;
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
    color: white;
    border-bottom: 1px solid #444;
}

.close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 6px 18px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    transition: 0.2s;
}

.close-btn:hover {
    background: #ff4757;
}

#app-frame {
    border: none;
    width: 100%;
    flex: 1;
    background: white;
}

/* 🟢 付费墙模态框 */
#paywall-layer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.paywall-box {
    background: white;
    width: 380px;
    padding: 35px 30px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    position: relative;
}

.paywall-icon {
    font-size: 3.5rem;
    margin-bottom: 10px;
    display: block;
    filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.1));
}

.paywall-title {
    font-size: 1.6rem;
    font-weight: 900;
    color: #2d3436;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.paywall-desc {
    color: #7f8c8d;
    line-height: 1.5;
    margin-bottom: 20px;
    font-size: 0.95rem;
    padding: 0 10px;
}

.paywall-price {
    font-size: 2.4rem;
    color: #ff4757;
    font-weight: 800;
    margin: 15px 0 25px 0;
    text-shadow: 0 2px 10px rgba(255, 71, 87, 0.2);
}

/* 微信区域 */
.paywall-wechat {
    background: #f5f6fa;
    padding: 15px 20px;
    border-radius: 16px;
    margin-bottom: 25px;
    display: flex;
    justify-content: center;
    gap: 30px;
    align-items: center;
    border: 1px solid #e1e2e6;
}

.wx-left {
    text-align: left;
}

.wx-label {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 4px;
    font-weight: bold;
}

.wx-id {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: 900;
    font-family: monospace;
}

.wx-qr {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    border: 2px solid white;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.pay-btn {
    background: #2ecc71;
    color: white;
    width: 60%;
    padding: 14px 0;
    border-radius: 50px;
    border: none;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(46, 204, 113, 0.4);
    transition: 0.2s;
}

.pay-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 35px rgba(46, 204, 113, 0.5);
    filter: brightness(1.05);
}

/* 配色方案 */
.theme-lego .card-preview {
    background: linear-gradient(135deg, #f6e58d 0%, #f0932b 100%);
}

.theme-video .card-preview {
    background: linear-gradient(135deg, #7ed6df 0%, #22a6b3 100%);
}

.theme-quiz .card-preview {
    background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
}

.theme-sentence .card-preview {
    background: linear-gradient(135deg, #55efc4 0%, #00b894 100%);
}

/* 🟢 刷新按钮动画 */
@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* ================= 📱 移动端/小屏适配 (V2 调整：更饱满、更高大) ================= */
@media (max-width: 768px) {

    /* 1. 导航栏调整 */
    .nav-bar {
        padding: 0 20px;
        height: 60px;
    }

    .logo {
        font-size: 1rem;
    }

    /* 2. 列表容器：单列，适中留白 */
    .course-grid {
        padding: 20px;
        /* 稍微增加外边距，更有呼吸感 */
        gap: 20px;
        /* 增加卡片间距 */
        grid-template-columns: 1fr;
        /* 强制单列 */
    }

    /* 3. 卡片调整：更高、更突出 */
    .card {
        /* 🔴 修复 5: 修正无效的 max-height: auto 为 max-height: none，防止内容被截断或挤压 */
        max-height: none;
        border-radius: 20px;
        /* 圆角加大 */
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
        /* 阴影加深 */
    }

    .card-preview {
        aspect-ratio: 16 / 9;
        height: auto;
        /* 🟢 手机端使用 16:9 比例，避免裁切关键信息 */
        font-size: 4rem;
        /* 图标加大 */
    }

    .card-body {
        padding: 20px 24px;
        /* 增加内边距，让文字不局促 */
    }

    .card-title {
        font-size: 1.25rem;
        /* 标题字号加大 */
        margin-bottom: 10px;
    }

    .card-desc {
        -webkit-line-clamp: 4;
        line-clamp: 4;
        /* 🟢 显示更多简介 (原3行 -> 4行) */
        font-size: 0.95rem;
        /* 简介字号微调 */
        line-height: 1.6;
        color: #666;
    }

    /* 4. 登录框适配 */
    .auth-box {
        width: 85%;
        padding: 30px 20px;
    }

    /* 5. 标签栏和筛选栏适配 */
    .subject-tabs-container {
        padding: 15px 20px;
    }

    .filter-bar {
        padding: 12px 20px;
        gap: 15px;
    }

    .filter-group {
        gap: 8px;
    }

    .filter-group label,
    .filter-group select {
        font-size: 0.9rem;
    }

    /* 6. Unit卡片网格适配 */
    .course-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 20px;
        padding: 20px;
    }

    .card {
        max-height: none;
    }

    .card-preview {
        aspect-ratio: 16 / 9;
        height: auto;
        /* 使用统一的16:9比例 */
    }

    .card-body {
        padding: 15px;
    }

    .card-title {
        font-size: 1.05rem;
    }

    .card-desc {
        font-size: 0.85rem;
        -webkit-line-clamp: 3;
        line-clamp: 3;
    }
}

/* ========== Unit 详情页面 Modal ========== */
.unit-detail-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.unit-detail-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.unit-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid #e8e8e8;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

.unit-detail-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-main);
}

.unit-detail-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-sub);
    transition: 0.2s;
}

.unit-detail-close:hover {
    color: var(--text-main);
    transform: scale(1.2);
}

.unit-detail-section {
    padding: 20px 24px;
    border-bottom: 1px solid #e8e8e8;
}

.unit-detail-section h3 {
    margin: 0 0 12px 0;
    font-size: 1.1rem;
    color: var(--text-main);
}

.unit-detail-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.unit-detail-section li {
    padding: 8px 0;
    color: var(--text-sub);
    display: flex;
    align-items: center;
    gap: 10px;
}

.unit-detail-section li:before {
    content: "•";
    color: var(--primary);
    font-weight: bold;
}

/* 标签页 */
.unit-detail-tabs {
    display: flex;
    gap: 0;
    padding: 0;
    border-bottom: 2px solid #e8e8e8;
    overflow-x: auto;
}

.unit-detail-tab {
    flex: 1;
    padding: 16px;
    background: none;
    border: none;
    font-size: 0.95rem;
    color: var(--text-sub);
    cursor: pointer;
    transition: 0.2s;
    border-bottom: 3px solid transparent;
    min-width: 140px;
    text-align: center;
}

.unit-detail-tab:hover {
    color: var(--primary);
    background: #f9f9f9;
}

.unit-detail-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* 资源容器 */
.unit-detail-resources {
    padding: 24px;
    min-height: 200px;
}

.resource-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.resource-item {
    padding: 16px;
    background: #f9f9f9;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
    transition: 0.2s;
}

.resource-item:hover {
    background: #f0f0f0;
    transform: translateX(4px);
}

.resource-item-title {
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 4px;
}

.resource-item-desc {
    font-size: 0.9rem;
    color: var(--text-sub);
    margin-bottom: 12px;
}

.resource-item-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    /* 🟢 修复垂直对齐 */
}

.resource-btn {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: 0.2s;
}

.resource-btn:hover {
    background: var(--accent);
    transform: translateY(-2px);
}

/* 底部操作栏 */
.unit-detail-footer {
    padding: 24px;
    border-top: 1px solid #e8e8e8;
    background: #f9f9f9;
    position: sticky;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.unit-progress-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-text {
    min-width: 80px;
    font-size: 0.9rem;
    color: var(--text-sub);
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 4px;
    transition: width 0.3s ease-out;
}

.progress-percent {
    min-width: 40px;
    text-align: right;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
}

.btn-primary {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.btn-primary:hover {
    background: var(--accent);
    transform: translateY(-2px);
}

/* 空状态 */
.resource-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-sub);
}

.resource-empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.resource-empty-text {
    font-size: 1rem;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .unit-detail-content {
        width: 95%;
        max-height: 90vh;
    }

    .unit-detail-header,
    .unit-detail-section,
    .unit-detail-resources,
    .unit-detail-footer {
        padding: 16px;
    }

    .unit-detail-tabs {
        flex-wrap: wrap;
    }

    .unit-detail-tab {
        min-width: 120px;
        padding: 12px;
        font-size: 0.85rem;
    }

    .resource-item {
        padding: 12px;
    }

    .resource-item-actions {
        flex-direction: column;
    }

    .resource-btn {
        width: 100%;
    }
}

/* ================= Phase 6: 统计与游戏化 ================= */
/* ================= Phase 6: 统计与游戏化 (Redesigned Phase 8) ================= */
.nav-stats {
    display: flex;
    gap: 20px;
    align-items: center;
    background: #f8f9fa;
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid #eee;
}

.nav-stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #2d3436;
    cursor: help;
}

.nav-stat-item span:first-child {
    font-size: 1.1rem;
}

/* 移动端隐藏统计栏，避免拥挤 */
@media (max-width: 768px) {
    .nav-stats {
        display: none !important;
    }
}

.stat-label {
    font-size: 0.85rem;
    color: #888;
}

.stat-divider {
    width: 1px;
    height: 30px;
    background: #eee;
}

/* 金牌图标 */
.gold-medal {
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 2rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    z-index: 10;
    transform: rotate(15deg);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0) rotate(0);
        opacity: 0;
    }

    to {
        transform: scale(1) rotate(15deg);
        opacity: 1;
    }
}