/* ===== 前台自定义样式 V2 - 现代化美化版 ===== */
/* 设计理念：沉浸式视频体验 + 玻璃拟态 + 流畅动画 + 移动端原生手感 */

:root {
    /* 主色调：紫色渐变 */
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-soft: linear-gradient(135deg, rgba(102,126,234,0.1) 0%, rgba(118,75,162,0.1) 100%);

    /* 背景色系 */
    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --bg-hover: #f8f9ff;

    /* 文字色系 */
    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #9ca3af;

    /* 阴影系 */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --shadow-glow: 0 0 20px rgba(102,126,234,0.3);

    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* 动画曲线 */
    --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== 全局 ===== */
* { -webkit-tap-highlight-color: transparent; }

body {
    background: var(--bg-body);
    background-image:
        radial-gradient(at 0% 0%, rgba(102,126,234,0.05) 0px, transparent 50%),
        radial-gradient(at 98% 1%, rgba(118,75,162,0.05) 0px, transparent 50%);
    background-attachment: fixed;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ===== 顶部导航栏（玻璃拟态） ===== */
.navbar {
    background: rgba(255,255,255,0.85) !important;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding: 0.6rem 0;
}
.navbar-brand {
    font-weight: 800;
    font-size: 1.25rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}
.navbar-brand img { height: 32px; }

/* 分类导航 */
.category-nav { gap: 0.25rem; }
.category-nav .nav-link {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-full);
    transition: all 0.25s var(--ease-smooth);
    white-space: nowrap;
}
.category-nav .nav-link:hover {
    background: var(--gradient-soft);
    color: var(--primary-color);
    transform: translateY(-1px);
}
.category-nav .nav-link.active {
    background: var(--gradient-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(102,126,234,0.4);
}

/* 搜索框 */
.search-box { min-width: 220px; position: relative; }
.search-box input {
    border-radius: var(--radius-full);
    padding: 0.45rem 1rem 0.45rem 2.5rem;
    border: 1.5px solid #e5e7eb;
    background: #f9fafb;
    font-size: 0.875rem;
    transition: all 0.2s;
}
.search-box input:focus {
    border-color: var(--primary-color);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
    outline: none;
}
.search-box .search-icon {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9rem;
    opacity: 0.6;
    pointer-events: none;
}

/* ===== 播放器容器（沉浸式） ===== */
.player-wrapper {
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    aspect-ratio: 16 / 9;
    position: relative;
    margin: 0 auto;
    transition: max-width 0.3s ease, aspect-ratio 0.3s ease;
    max-width: 100%;
}
/* 横屏视频：默认 16:9 */
.player-wrapper.horizontal-video {
    aspect-ratio: 16 / 9;
    max-width: 100%;
}
/* 竖屏视频：限制最大宽度，居中显示，避免桌面端过宽 */
.player-wrapper.vertical-video {
    aspect-ratio: 9 / 16;
    max-width: 420px;
    margin: 0 auto;
}
/* 正方形视频 */
.player-wrapper.square-video {
    aspect-ratio: 1 / 1;
    max-width: 500px;
    margin: 0 auto;
}
.player-wrapper::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: var(--gradient-primary);
    border-radius: var(--radius-lg);
    opacity: 0;
    z-index: -1;
    transition: opacity 0.3s;
}
.player-wrapper:hover::before { opacity: 0.6; }

/* Video.js：完全填充容器，不自己计算尺寸 */
.video-js {
    width: 100% !important;
    height: 100% !important;
    border-radius: var(--radius-lg);
    font-family: inherit;
    position: absolute !important;
    top: 0;
    left: 0;
}
/* Video.js v8 fill 模式：让播放器完全填充容器 */
.video-js.vjs-fill,
.video-js.vjs-fluid {
    width: 100% !important;
    height: 100% !important;
    padding-top: 0 !important;
    position: absolute !important;
    top: 0;
    left: 0;
}
/* 视频 tech 元素：保持视频比例，不拉伸 */
.video-js .vjs-tech {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
/* Video.js poster 也要填充 */
.video-js .vjs-poster {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}
/* 原生 video 播放器（降级模式） */
.native-player {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    background: #000;
    border-radius: var(--radius-lg);
}

/* ===== 全屏模式样式覆盖 ===== */
/* 解决问题：快手视频全屏后显示"大尺寸"（画面未正确填充/居中） */
/* 原因：Video.js 全屏时脱离 .player-wrapper 约束，需强制覆盖样式 */

/* 全屏模式：所有视频的基础样式 */
body.fullscreen-mode .video-js,
body.fullscreen-mode .video-js.vjs-fullscreen,
body.fullscreen-mode .native-player {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    object-fit: contain !important;
    background: #000 !important;
}

/* 竖屏视频全屏（抖音/快手竖向视频） */
/* 让视频在屏幕中居中显示，保持竖向比例，不拉伸 */
body.fullscreen-mode.fullscreen-vertical .video-js,
body.fullscreen-mode.fullscreen-vertical .video-js.vjs-fullscreen,
body.fullscreen-mode.fullscreen-vertical .native-player {
    object-fit: contain !important;
    /* 竖屏视频在横屏显示器上会左右留黑边，这是正确行为 */
}
body.fullscreen-mode.fullscreen-vertical .video-js .vjs-tech,
body.fullscreen-mode.fullscreen-vertical .native-player {
    object-fit: contain !important;
    width: 100% !important;
    height: 100% !important;
}

/* 横屏视频全屏 */
body.fullscreen-mode.fullscreen-horizontal .video-js .vjs-tech,
body.fullscreen-mode.fullscreen-horizontal .native-player {
    object-fit: contain !important;
}

/* Video.js 全屏时隐藏圆角和阴影 */
.video-js.vjs-fullscreen {
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* Video.js 大播放按钮 */
.vjs-default-skin .vjs-big-play-button {
    border-radius: 50%;
    width: 80px;
    height: 80px;
    line-height: 80px;
    top: 50%;
    left: 50%;
    margin-top: -40px;
    margin-left: -40px;
    background: var(--gradient-primary);
    border: none;
    box-shadow: 0 4px 20px rgba(102,126,234,0.5);
    transition: transform 0.2s var(--ease-bounce);
}
.vjs-default-skin:hover .vjs-big-play-button {
    transform: scale(1.1);
}

/* ===== 视频信息区 ===== */
.video-info {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-top: 1rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}
.video-info:hover { box-shadow: var(--shadow-md); }
.video-info h5 {
    margin: 0 0 0.25rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}
.video-meta {
    font-size: 0.825rem;
    color: var(--text-muted);
}
.video-meta .badge {
    font-weight: 500;
    padding: 0.3em 0.7em;
    border-radius: var(--radius-full);
}

/* ===== 集数列表（电视剧/多集视频） ===== */
.episodes-panel {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-top: 1rem;
    box-shadow: var(--shadow-sm);
}
.episodes-header {
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.episodes-header h6 {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}
/* 集数网格布局：自适应列数，每列最小60px */
.episodes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 0.5rem;
    max-height: 280px;
    overflow-y: auto;
    padding: 0.25rem 0.25rem 0.25rem 0;
}
/* 集数网格滚动条 */
.episodes-grid::-webkit-scrollbar { width: 6px; }
.episodes-grid::-webkit-scrollbar-track { background: transparent; }
.episodes-grid::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}
.episodes-grid::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* 单个集数按钮 */
.episode-btn {
    border: 1.5px solid #e5e7eb;
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
    text-align: center;
    min-width: 44px;
    min-height: 40px;
    line-height: 1.2;
    font-family: inherit;
}
.episode-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--bg-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102,126,234,0.15);
}
/* 当前播放集数高亮 */
.episode-btn.active {
    background: var(--gradient-primary);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(102,126,234,0.4);
}
.episode-btn.active:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102,126,234,0.5);
}

/* ===== 播放列表项的集数角标 ===== */
.playlist-item .item-ep {
    flex-shrink: 0;
    margin-left: 0.5rem;
    display: flex;
    align-items: center;
}
.playlist-item .item-ep-badge {
    font-size: 0.7rem;
    color: #fff;
    background: linear-gradient(135deg, #667eea, #764ba2);
    padding: 0.2em 0.6em;
    border-radius: var(--radius-full);
    font-weight: 600;
    white-space: nowrap;
}
.playlist-item.active .item-ep-badge {
    background: rgba(255,255,255,0.85);
    color: var(--primary-color);
}

/* ===== 播放列表 ===== */
.playlist-container {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 0.5rem;
}

/* 播放列表项容器 */
.playlist-item-wrapper {
    margin-bottom: 0.25rem;
}

/* 自定义滚动条 */
.playlist-container::-webkit-scrollbar { width: 6px; }
.playlist-container::-webkit-scrollbar-track { background: transparent; }
.playlist-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}
.playlist-container::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

.playlist-item {
    display: flex;
    align-items: center;
    padding: 0.6rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s var(--ease-smooth);
    text-decoration: none;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}
.playlist-item:hover {
    background: var(--bg-hover);
    transform: translateX(4px);
}
.playlist-item.active {
    background: var(--gradient-soft);
    box-shadow: inset 3px 0 0 var(--primary-color);
}
.playlist-item img {
    width: 100px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-right: 0.75rem;
    flex-shrink: 0;
    background: linear-gradient(135deg, #f0f0f0, #e0e0e0);
}
.playlist-item .item-title {
    flex-grow: 1;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.playlist-item .item-duration {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
    flex-shrink: 0;
    background: #f3f4f6;
    padding: 0.15em 0.5em;
    border-radius: var(--radius-full);
}
.playlist-item.active .item-title {
    color: var(--primary-color);
    font-weight: 600;
}
.playlist-item.active .item-duration {
    background: var(--primary-color);
    color: #fff;
}

/* ===== 骨架屏加载 ===== */
.loading-spinner {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.loading-spinner .spinner-border {
    color: var(--primary-color);
}

/* 骨架屏占位 */
.skeleton-item {
    display: flex;
    padding: 0.6rem;
    margin-bottom: 0.25rem;
}
.skeleton-thumb {
    width: 100px;
    height: 60px;
    border-radius: var(--radius-sm);
    margin-right: 0.75rem;
    flex-shrink: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}
.skeleton-text {
    flex-grow: 1;
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== 空状态 ===== */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.empty-state .empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}
.empty-state p { font-size: 0.95rem; }

/* ===== 底部 ===== */
footer {
    background: var(--bg-card);
    margin-top: 2rem;
}

/* ===== 移动端适配（< 768px） ===== */
@media (max-width: 768px) {
    :root {
        --radius-lg: 12px;
        --radius-md: 10px;
    }

    body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* 导航栏紧凑化 */
    .navbar { padding: 0.5rem 0; }
    .navbar-brand { font-size: 1.1rem; }
    .navbar-collapse {
        background: rgba(255,255,255,0.98);
        backdrop-filter: blur(20px);
        border-radius: var(--radius-md);
        padding: 0.75rem;
        margin-top: 0.5rem;
        box-shadow: var(--shadow-md);
    }

    /* 分类导航横向滚动 */
    .category-nav {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0.5rem 0;
    }
    .category-nav::-webkit-scrollbar { display: none; }
    .category-nav .nav-link {
        white-space: nowrap;
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }

    /* 搜索框全宽 */
    .search-box {
        min-width: 100%;
        margin-top: 0.5rem;
    }

    /* 播放器圆角缩小 */
    .player-wrapper {
        aspect-ratio: 16 / 9;
        border-radius: var(--radius-md);
    }
    /* 移动端竖屏视频可以更大 */
    .player-wrapper.vertical-video {
        max-width: 100%;
    }

    /* 移动端全屏模式：竖屏视频填满整个屏幕 */
    /* 移动端屏幕本身就是竖向的，竖屏视频应该完全填充 */
    body.fullscreen-mode.fullscreen-vertical .video-js,
    body.fullscreen-mode.fullscreen-vertical .video-js.vjs-fullscreen,
    body.fullscreen-mode.fullscreen-vertical .native-player {
        width: 100vw !important;
        height: 100vh !important;
        /* 移动端竖屏视频全屏时用 cover 填充，避免黑边 */
        /* 注意：cover 会裁剪边缘，但移动端竖屏视频通常是手机拍摄的，比例匹配 */
        object-fit: contain !important;
    }
    body.fullscreen-mode.fullscreen-vertical .video-js .vjs-tech {
        object-fit: contain !important;
        width: 100% !important;
        height: 100% !important;
    }
    /* 移动端横屏视频全屏时旋转屏幕的建议 */
    body.fullscreen-mode.fullscreen-horizontal .video-js .vjs-tech {
        object-fit: contain !important;
    }

    /* 播放列表高度自适应 */
    .playlist-container {
        max-height: 400px;
        margin-top: 1rem;
    }
    .playlist-item img {
        width: 80px;
        height: 48px;
    }
    .playlist-item .item-title { font-size: 0.85rem; }

    /* 视频信息紧凑 */
    .video-info {
        padding: 0.75rem 1rem;
    }
    .video-info h5 { font-size: 1rem; }

    /* 集数面板移动端 */
    .episodes-panel {
        padding: 0.75rem 1rem;
    }
    .episodes-grid {
        grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
        gap: 0.4rem;
        max-height: none; /* 移动端取消高度限制，显示所有剧集 */
        overflow-y: visible;
    }
    .episode-btn {
        padding: 0.4rem 0.2rem;
        font-size: 0.85rem;
        min-height: 36px;
    }

    /* 移动端集数面板标题更醒目 */
    .episodes-header h6 {
        font-size: 1rem;
        font-weight: 700;
    }
    .episodes-count {
        font-size: 0.85rem;
        color: var(--primary-color);
        font-weight: 600;
    }

    /* 大播放按钮缩小 */
    .vjs-default-skin .vjs-big-play-button {
        width: 60px;
        height: 60px;
        line-height: 60px;
        margin-top: -30px;
        margin-left: -30px;
    }
}

/* ===== 超小屏适配（< 375px） ===== */
@media (max-width: 375px) {
    .playlist-item img {
        width: 64px;
        height: 40px;
    }
    .playlist-item .item-duration { display: none; }
}

/* ===== 平板适配（768px - 1024px） ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .playlist-container { max-height: 500px; }
}

/* ===== 深色模式（跟随系统） ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-body: #0f0f1e;
        --bg-card: #1a1a2e;
        --bg-hover: #252540;
        --text-primary: #f0f0f5;
        --text-secondary: #c0c0d0;
        --text-muted: #6c7293;
        --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    }
    body {
        background-image:
            radial-gradient(at 0% 0%, rgba(102,126,234,0.1) 0px, transparent 50%),
            radial-gradient(at 98% 1%, rgba(118,75,162,0.1) 0px, transparent 50%);
    }
    .navbar {
        background: rgba(26,26,46,0.85) !important;
        border-bottom-color: rgba(255,255,255,0.08);
    }
    .search-box input {
        background: #252540;
        border-color: #2d2d4a;
        color: #f0f0f5;
    }
    .playlist-item .item-duration {
        background: #252540;
        color: var(--text-muted);
    }
    /* 集数按钮深色模式 */
    .episode-btn {
        background: #252540;
        border-color: #2d2d4a;
        color: var(--text-secondary);
    }
    .episode-btn:hover {
        background: #2d2d4a;
        color: var(--primary-color);
    }
    .episodes-header {
        border-bottom-color: rgba(255,255,255,0.08);
    }
}

/* ===== 播放列表剧集展开区域 ===== */
.playlist-episodes {
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    margin-top: 0.25rem;
    padding: 0.75rem;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
}

.playlist-episodes-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.playlist-episodes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 0.4rem;
    max-height: 200px;
    overflow-y: auto;
}

.playlist-episodes-grid::-webkit-scrollbar { width: 4px; }
.playlist-episodes-grid::-webkit-scrollbar-track { background: transparent; }
.playlist-episodes-grid::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

/* 播放列表中的剧集按钮 */
.playlist-episode-btn {
    border: 1px solid #e5e7eb;
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: 4px;
    padding: 0.4rem 0.2rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
    text-align: center;
    min-width: 44px;
    min-height: 32px;
    line-height: 1.2;
    font-family: inherit;
}

.playlist-episode-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.playlist-episode-btn.active {
    background: var(--gradient-primary);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(102,126,234,0.3);
}

/* 深色模式下的剧集展开区域 */
@media (prefers-color-scheme: dark) {
    .playlist-episodes {
        background: #252540;
    }
    .playlist-episodes-header {
        border-bottom-color: rgba(255,255,255,0.08);
    }
    .playlist-episode-btn {
        background: #1a1a2e;
        border-color: #2d2d4a;
        color: var(--text-secondary);
    }
    .playlist-episode-btn:hover {
        background: #252540;
        color: var(--primary-color);
    }
}
