/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-hover: #1f3460;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0b0;
    --text-muted: #6c6c80;
    --accent: #e50914;
    --accent-hover: #ff1a25;
    --accent-light: rgba(229, 9, 20, 0.15);
    --border: #2a2a40;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --radius: 8px;
    --radius-lg: 12px;
    --header-height: 60px;
    --max-width: 1400px;
    --transition: 0.25s ease;
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, select { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Header ===== */
.header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: rgba(15, 15, 15, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex-shrink: 0;
}

.logo-icon {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: #fff;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #ff6b6b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Navigation */
.nav-categories {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.nav-categories::-webkit-scrollbar { display: none; }

.nav-item {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.nav-item:hover { color: var(--text-primary); background: var(--accent-light); }
.nav-item.active { color: #fff; background: var(--accent); font-weight: 500; }

/* Header Right */
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.source-selector select {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
}

.source-selector select:focus { border-color: var(--accent); }

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    transition: var(--transition);
}

.search-box:focus-within { border-color: var(--accent); }

.search-box input {
    background: transparent;
    border: none;
    padding: 6px 14px;
    font-size: 14px;
    outline: none;
    width: 160px;
    color: var(--text-primary);
}

.search-box input::placeholder { color: var(--text-muted); }

.search-btn {
    padding: 6px 12px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.search-btn:hover { color: var(--accent); }

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 30px; height: 30px;
    padding: 2px;
}

.mobile-menu-btn span {
    display: block;
    width: 100%; height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: var(--transition);
}

/* ===== Mobile Sidebar ===== */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1100;
    opacity: 0;
    transition: opacity 0.3s;
}

.mobile-overlay.active { display: block; opacity: 1; }

.mobile-sidebar {
    position: fixed;
    top: 0; left: -280px;
    width: 280px; height: 100%;
    background: var(--bg-secondary);
    z-index: 1200;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.mobile-sidebar.active { left: 0; }

.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 18px;
}

.close-btn {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--bg-card);
    font-size: 16px;
}

.sidebar-search {
    padding: 12px 16px;
}

.sidebar-search input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
    color: var(--text-primary);
}

.sidebar-source {
    padding: 0 16px 12px;
}

.sidebar-source select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
    color: var(--text-primary);
}

.sidebar-nav {
    padding: 8px 12px;
}

.sidebar-nav-item {
    display: block;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 15px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.sidebar-nav-item:hover { background: var(--accent-light); color: var(--text-primary); }
.sidebar-nav-item.active { color: #fff; background: var(--accent); }

/* ===== Main Content ===== */
.main {
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

.page { max-width: var(--max-width); margin: 0 auto; padding: 20px; }

/* Section Header */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.result-info {
    font-size: 13px;
    color: var(--text-muted);
}

/* ===== Video Grid ===== */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

.video-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    background: var(--bg-card);
}

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

.video-card-poster {
    position: relative;
    width: 100%;
    padding-top: 140%;
    overflow: hidden;
    background: var(--bg-secondary);
}

.video-card-poster img {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform 0.4s;
}

.video-card:hover .video-card-poster img { transform: scale(1.05); }

.video-card-poster .placeholder-img {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    opacity: 0.3;
}

.video-card-remark {
    position: absolute;
    top: 8px; right: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.video-card-title {
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.video-card-sub {
    padding: 0 10px 8px;
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 30px 0;
    flex-wrap: wrap;
}

.page-btn {
    min-width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    transition: var(--transition);
    padding: 0 8px;
}

.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Detail Page ===== */
.detail-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    margin-bottom: 16px;
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
}

.detail-back:hover { background: var(--bg-hover); }

.detail-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.detail-player-section {
    width: 100%;
}

.player-wrapper {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* 16:9 */
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.player-wrapper iframe,
.player-wrapper video {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    border: none;
}

.player-placeholder {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 12px;
}

.detail-meta {
    display: flex;
    gap: 20px;
}

.detail-poster {
    width: 160px;
    flex-shrink: 0;
}

.detail-poster img {
    width: 100%;
    border-radius: var(--radius);
    aspect-ratio: 2/3;
    object-fit: cover;
    background: var(--bg-card);
}

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

.detail-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 10px;
    line-height: 1.3;
}

.detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.detail-tag {
    display: inline-block;
    padding: 3px 10px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.detail-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
    max-height: 120px;
    overflow-y: auto;
}

/* Play Sources Tabs */
.detail-sources {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}

.source-tab {
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.source-tab:hover { border-color: var(--accent); }
.source-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Episode List */
.detail-episodes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.episode-btn {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: var(--transition);
    min-width: 60px;
    text-align: center;
}

.episode-btn:hover { border-color: var(--accent); color: var(--accent); }
.episode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== Loading ===== */
.loading-spinner {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    color: var(--text-muted);
    gap: 12px;
}

.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.3;
}

/* ===== Back To Top ===== */
.back-to-top {
    position: fixed;
    bottom: 24px; right: 24px;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    z-index: 900;
}

.back-to-top.visible { opacity: 1; visibility: visible; }
.back-to-top:hover { background: var(--accent-hover); transform: translateY(-2px); }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 80px; right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 300px;
}

.toast.error { border-color: var(--accent); }
.toast.success { border-color: #22c55e; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .video-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }
}

@media (max-width: 768px) {
    :root { --header-height: 56px; }

    .nav-categories { display: none; }
    .search-box { display: none; }
    .source-selector { display: none; }
    .mobile-menu-btn { display: flex; }

    .header-inner { padding: 0 12px; gap: 8px; }

    .page { padding: 12px; }

    .video-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 10px;
    }

    .video-card-title { font-size: 12px; padding: 6px 8px; }
    .video-card-sub { padding: 0 8px 6px; font-size: 10px; }
    .video-card-remark { font-size: 10px; padding: 2px 6px; }

    .detail-meta { flex-direction: column; }
    .detail-poster { width: 120px; }
    .detail-title { font-size: 18px; }
    .detail-desc { max-height: 80px; font-size: 13px; }

    .episode-btn { padding: 5px 10px; font-size: 12px; min-width: 50px; }
    .source-tab { padding: 5px 12px; font-size: 12px; }

    .pagination { gap: 6px; padding: 20px 0; }
    .page-btn { min-width: 32px; height: 32px; font-size: 13px; }
}

@media (max-width: 480px) {
    .video-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .video-card-title { font-size: 11px; padding: 4px 6px; }
    .video-card-sub { display: none; }

    .detail-poster { width: 100px; }
    .detail-title { font-size: 16px; }

    .section-header h2 { font-size: 16px; }
}

/* ===== Image Loading Placeholder ===== */
.img-loading {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
