/* ============================================================
   英语听力练习 H5 - 主样式表
   移动优先 · 响应式 · 面向初中生
   ============================================================ */

/* ------------------ CSS 变量 ------------------ */
:root {
    /* 主色调 */
    --primary: #5B7FFF;
    --primary-dark: #4A6AE0;
    --primary-light: #E8ECFF;

    /* 强调色 */
    --accent: #FF6B6B;
    --accent-dark: #E55A5A;

    /* 背景 */
    --bg: #F3F4FA;
    --bg-card: #FFFFFF;
    --bg-player: #FFFFFF;

    /* 文字 */
    --text: #2D3436;
    --text-secondary: #636E72;
    --text-muted: #A0A4A8;

    /* 功能色 */
    --success: #00B894;
    --warning: #FDCB6E;
    --easy: #00B894;
    --medium: #FDCB6E;
    --hard: #FF6B6B;

    /* 圆角 */
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --radius-full: 9999px;

    /* 阴影 */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);
    --shadow-btn: 0 4px 14px rgba(91,127,255,0.35);

    /* 间距 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* 触摸 */
    --touch-min: 44px;

    /* 字体 */
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: "SF Mono", "Menlo", "Consolas", monospace;

    /* 动效 */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 300ms;
    --duration-slow: 500ms;
}

/* ------------------ Reset & Base ------------------ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
}

a { color: inherit; text-decoration: none; }
button { border: none; background: none; cursor: pointer; font-family: inherit; }
button:active { transform: scale(0.96); }

/* ------------------ 页面切换 ------------------ */
.page {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    animation: fadeSlideIn var(--duration-normal) var(--ease-out);
}
.page.active {
    display: flex;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== 首页 ==================== */

/* --- 返回首页按钮 --- */
.btn-home {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 10;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: background 0.15s;
    text-decoration: none;
}

.btn-home:active {
    background: rgba(255,255,255,0.35);
}

.btn-home-link {
    text-decoration: none;
}

/* --- 顶部导航 --- */
.header {
    position: relative;
    background: linear-gradient(135deg, var(--primary) 0%, #7B93FF 50%, #A5B4FF 100%);
    padding: var(--space-xl) var(--space-lg) 60px;
    color: #fff;
    text-align: center;
    overflow: hidden;
}

.header-bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(255,255,255,0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.header-content {
    position: relative;
    z-index: 1;
}

.header-icon {
    font-size: 48px;
    display: block;
    margin-bottom: var(--space-sm);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.header-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-xs);
}

.header-subtitle {
    font-size: 14px;
    opacity: 0.85;
    font-weight: 400;
}

.header-wave {
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 50px;
    pointer-events: none;
}

/* --- 统计栏 --- */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xl);
    margin: calc(-1 * var(--radius-lg)) var(--space-md) 0;
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 2;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-num {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-divider {
    width: 1px;
    height: 32px;
    background: #E8ECFF;
    border-radius: 1px;
}

/* --- 卡片列表 --- */
.list-container {
    flex: 1;
    padding: var(--space-lg) var(--space-md);
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
}

.card-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* --- 听力卡片 --- */
.card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: transform var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-md);
}

.card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--card-color, var(--primary));
}

.card.playing {
    box-shadow: 0 0 0 2px var(--primary), var(--shadow-md);
    background: var(--primary-light);
}

.card.playing::before {
    background: var(--card-color, var(--primary));
    width: 5px;
}

.card-index {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary);
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.card.playing .card-index {
    background: var(--primary);
    color: #fff;
}

.card-body {
    flex: 1;
    min-width: 0;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.card-meta {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.card-duration {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.card-difficulty {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    font-weight: 500;
    white-space: nowrap;
}

.diff-easy {
    background: #E6FAF3;
    color: var(--easy);
}

.diff-medium {
    background: #FFF8E7;
    color: #D4A017;
}

.diff-hard {
    background: #FFEBEE;
    color: var(--hard);
}

.card-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
    opacity: 0.4;
    transition: opacity var(--duration-fast), transform var(--duration-fast);
}

.card:active .card-arrow {
    opacity: 1;
    transform: translateX(3px);
}

/* --- 空状态 --- */
.empty-state {
    text-align: center;
    padding: 60px var(--space-lg);
}

.empty-icon {
    font-size: 64px;
    margin-bottom: var(--space-md);
}

.empty-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-sm);
}

.empty-hint {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.6;
}

/* --- 底部安全区 --- */
.bottom-safe-area {
    height: env(safe-area-inset-bottom, 0px);
}

/* ==================== 播放页 ==================== */

/* --- 顶部导航 --- */
.player-nav {
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    padding-top: max(var(--space-sm), env(safe-area-inset-top, 0px));
    gap: var(--space-sm);
    background: var(--bg-card);
    border-bottom: 1px solid rgba(0,0,0,0.06);
    position: sticky;
    top: 0;
    z-index: 10;
}

.btn-icon {
    width: var(--touch-min);
    height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: background var(--duration-fast);
    flex-shrink: 0;
}

.btn-icon:active {
    background: var(--primary-light);
}

.player-nav-info {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.player-nav-title {
    font-size: 16px;
    font-weight: 600;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-nav-sub {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
}

/* --- 播放器内容 --- */
.player-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-lg) var(--space-lg);
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
    gap: var(--space-lg);
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

/* --- 封面区域 --- */
.cover-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
    padding-top: var(--space-md);
}

.cover-art {
    position: relative;
    width: 180px;
    height: 180px;
}

.cover-ring {
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 3px dashed rgba(91,127,255,0.2);
    animation: rotate 20s linear infinite;
}

.cover-art.playing .cover-ring {
    border-color: rgba(91,127,255,0.4);
    animation-duration: 8s;
}

.cover-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light) 0%, #DCE3FF 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

.cover-art.playing .cover-inner {
    animation: pulse 2s ease-in-out infinite;
}

.cover-emoji {
    font-size: 72px;
    line-height: 1;
    transition: transform var(--duration-slow) var(--ease-spring);
}

.cover-art.playing .cover-emoji {
    animation: bounce 0.6s var(--ease-spring) infinite;
}

.cover-title {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    color: var(--text);
}

/* --- 难度标签 --- */
.badge {
    font-size: 13px;
    padding: 4px 14px;
    border-radius: var(--radius-full);
    font-weight: 600;
}

.badge-easy { background: #E6FAF3; color: var(--easy); }
.badge-medium { background: #FFF8E7; color: #D4A017; }
.badge-hard { background: #FFEBEE; color: var(--hard); }

/* --- 进度条 --- */
.progress-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.progress-track-wrapper {
    position: relative;
    width: 100%;
    height: 40px;
    display: flex;
    align-items: center;
}

/* 进度填充（非拖拽时可见的填充效果） */
.progress-fill {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 6px;
    border-radius: 3px;
    background: var(--primary);
    pointer-events: none;
    z-index: 1;
}

/* 自定义 range input */
.progress-bar {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #E8ECFF;
    outline: none;
    position: relative;
    z-index: 2;
    cursor: pointer;
}

/* 进度条轨道 - Webkit */
.progress-bar::-webkit-slider-runnable-track {
    -webkit-appearance: none;
    height: 6px;
    border-radius: 3px;
    background: transparent;
}

/* 进度条滑块 - Webkit */
.progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(91,127,255,0.4);
    margin-top: -8px;
    transition: transform var(--duration-fast) var(--ease-spring),
                box-shadow var(--duration-fast);
    cursor: grab;
}

.progress-bar::-webkit-slider-thumb:active {
    transform: scale(1.3);
    box-shadow: 0 4px 16px rgba(91,127,255,0.5);
    cursor: grabbing;
}

/* 进度条 - Firefox */
.progress-bar::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: transparent;
    border: none;
}

.progress-bar::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(91,127,255,0.4);
    cursor: grab;
}

.progress-bar::-moz-range-thumb:active {
    transform: scale(1.3);
    cursor: grabbing;
}

/* 时间显示 */
.time-row {
    display: flex;
    justify-content: space-between;
}

.time-text {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* --- 播放控制按钮 --- */
.controls-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-lg);
}

.btn-ctrl {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-secondary);
    transition: color var(--duration-fast), transform var(--duration-fast);
}

.btn-ctrl:active {
    transform: scale(0.9);
}

.btn-ctrl-sm {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-full);
    background: var(--bg);
}

.ctrl-sm-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
}

.btn-ctrl-play {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: var(--shadow-btn);
    transition: transform var(--duration-fast) var(--ease-spring),
                box-shadow var(--duration-fast);
}

.btn-ctrl-play:active {
    transform: scale(0.92);
    box-shadow: 0 2px 8px rgba(91,127,255,0.3);
}

.play-icon {
    display: block;
}

/* --- 播放速度 --- */
.speed-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
}

.speed-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.speed-group {
    display: flex;
    gap: var(--space-sm);
    background: var(--bg);
    padding: 4px;
    border-radius: var(--radius-md);
}

.btn-speed {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
}

.btn-speed.active {
    background: #fff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* --- 上下首导航 --- */
.lesson-nav {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    width: 100%;
    justify-content: center;
}

.btn-lesson {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 10px 18px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    transition: all var(--duration-fast);
    background: var(--primary-light);
}

.btn-lesson:active {
    background: #D8DDFF;
}

.btn-lesson:disabled {
    opacity: 0.35;
    pointer-events: none;
}

.lesson-indicator {
    font-size: 14px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    min-width: 40px;
    text-align: center;
}

/* ==================== Toast ==================== */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    padding: 10px 24px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    transition: all var(--duration-normal) var(--ease-out);
    z-index: 1000;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==================== 动画关键帧 ==================== */
@keyframes rotate {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { box-shadow: var(--shadow-lg); }
    50%      { box-shadow: 0 8px 40px rgba(91,127,255,0.25); }
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    30%      { transform: scale(1.08); }
    50%      { transform: scale(0.95); }
    70%      { transform: scale(1.04); }
}

/* ==================== 响应式：平板及以上 ==================== */
@media (min-width: 768px) {
    .header {
        padding: 48px var(--space-xl) 70px;
    }

    .header-title {
        font-size: 30px;
    }

    .header-icon {
        font-size: 56px;
    }

    /* 双列卡片 */
    .card-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-lg);
    }

    .list-container {
        max-width: 800px;
        margin: 0 auto;
        padding: var(--space-xl) var(--space-lg);
    }

    .stats-bar {
        max-width: 400px;
        margin-left: auto;
        margin-right: auto;
    }

    /* 播放页 */
    .player-content {
        padding-top: var(--space-xl);
    }

    .cover-art {
        width: 220px;
        height: 220px;
    }

    .cover-emoji {
        font-size: 88px;
    }
}

/* ==================== 响应式：大屏设备 ==================== */
@media (min-width: 1024px) {
    .list-container {
        max-width: 900px;
    }

    .card-list {
        grid-template-columns: repeat(2, 1fr);
    }

    .card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }

    .btn-speed:hover {
        color: var(--primary);
    }

    .btn-lesson:hover:not(:disabled) {
        background: #D8DDFF;
    }
}

/* ==================== 暗色模式支持（可选） ==================== */
@media (prefers-color-scheme: dark) {
    /* 默认保持亮色主题，若需暗色可取消注释 */
    /*
    :root {
        --bg: #1A1B2E;
        --bg-card: #242538;
        --bg-player: #242538;
        --text: #EAEAEF;
        --text-secondary: #A0A4B8;
        --text-muted: #6B6F82;
        --primary-light: #2A2D4A;
    }
    */
}
