:root {
    --primary: #ff6b6b;
    --primary-dark: #ff5252;
    --secondary: #4dabf7;
    --dark: #0f172a;
    --darker: #0a0f1d;
    --card-bg: rgba(30, 41, 59, 0.85);
    --text-light: #f8fafc;
    --text-gray: #94a3b8;
    --border: rgba(148, 163, 184, 0.2);
    --success: #51cf66;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

body {
    background: linear-gradient(135deg, var(--darker), #1e293b, var(--darker));
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    color: var(--text-light);
    min-height: 100vh;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    line-height: 1.6;
    /* 移动端触摸全局优化 */
    touch-action: manipulation;
    pointer-events: auto;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    padding: 20px 0;
}

.logo {
    font-size: 2.8rem;
    margin-bottom: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    font-weight: 700;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline {
    font-size: 1.1rem;
    opacity: 0.85;
    margin-bottom: 25px;
    color: var(--text-gray);
    max-width: 600px;
    margin: 0 auto 15px;
}

.search-header {
    max-width: 800px;
    margin: 0 auto 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.api-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.api-btn {
    background: var(--card-bg);
    color: var(--text-light);
    border: 1px solid var(--border);
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s;
    touch-action: manipulation;
}

.api-btn.active {
    background: rgba(255, 107, 107, 0.2);
    border-color: var(--primary);
    color: var(--primary);
}

.recent-searches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.recent-item {
    background: rgba(255, 107, 107, 0.15);
    color: var(--primary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
    border: 1px solid rgba(255, 107, 107, 0.3);
    white-space: nowrap;
    overflow: hidden;
    max-width: 200px;
    touch-action: manipulation;
}

.recent-item:hover {
    background: rgba(255, 107, 107, 0.25);
    border-color: var(--primary);
}

.search-container {
    position: relative;
    display: flex;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    margin: 0 auto 10px;
}

#search-input {
    flex: 1;
    padding: 18px 25px;
    border: none;
    border-radius: 50px 0 50px 0;
    font-size: 16px;
    background: #fff;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    -webkit-user-select: text;
    user-select: text;
}
#search-btn {
    padding: 18px 30px;
    border: none;
    border-radius: 0 50px 50px 0;
    background: #ff6b6b;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    touch-action: manipulation;
}

#search-btn:hover {
    background: #ff5252;
}

.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 15px;
    margin-top: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: none;
    z-index: 1000;
}

.suggestion-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f0f0f0;
    touch-action: manipulation;
}

.suggestion-item:hover {
    background: #f8f9fa;
}

.suggestion-item i {
    margin-right: 15px;
    color: #ff6b6b;
}

.suggestion-text {
    flex: 1;
    font-weight: 500;
}

.suggestion-type {
    background: #e9ecef;
    color: #6c757d;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 10px;
    flex-wrap: wrap;
    gap: 15px;
    display: none;
}

.results-count {
    font-size: 1rem;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 30px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
}

.sort-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sort-btn {
    background: var(--card-bg);
    color: var(--text-light);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 5px;
    touch-action: manipulation;
}

.sort-btn.active {
    background: rgba(255, 107, 107, 0.2);
    border-color: var(--primary);
    color: var(--primary);
}

.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 10px;
}

.video-card {
    background: var(--card-bg);
    border-radius: 15px;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    position: relative;
}

.video-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 107, 107, 0.4);
}

.video-thumb {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
    border-bottom: 1px solid var(--border);
}

.episode-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 107, 107, 0.9);
    color: white;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.85rem;
    z-index: 10;
    font-weight: 500;
}

.video-info {
    padding: 15px;
}

.video-title {
    font-size: 1.15rem;
    margin-bottom: 10px;
    height: 54px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-weight: 600;
}

.video-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 0.85rem;
    color: var(--text-gray);
}

.video-type {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 107, 107, 0.15);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
}

.video-desc {
    font-size: 0.9rem;
    opacity: 0.85;
    margin-bottom: 12px;
    line-height: 1.5;
    height: 66px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.play-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    background: rgba(255, 107, 107, 0.15);
    color: var(--primary);
    border: 1px solid rgba(255, 107, 107, 0.3);
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    min-height: 44px;
    touch-action: manipulation;
}

.play-btn:hover {
    background: rgba(255, 107, 107, 0.25);
    border-color: var(--primary);
}

.player-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.98);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    z-index: 2000;
    display: none;
    padding: max(20px, env(safe-area-inset-top)) 10px 10px;
    overflow-y: auto;
}

.player-header {
    width: 90%;
    max-width: 1000px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    align-items: center;
}

.player-title {
    font-size: 1.4rem;
    color: white;
    max-width: 80%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.close-player {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    transition: all 0.2s;
    touch-action: manipulation;
}

.close-player:hover {
    transform: rotate(90deg);
}

/* 剧集容器核心修复：高度+触摸+点击兼容 */
.episodes-container {
    width: 90%;
    max-width: 1000px;
    background: var(--card-bg);
    border-radius: 10px;
    padding: 16px 12px;
    margin-bottom: 16px;
    display: none;
    min-height: 120px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border);
    z-index: 2001;
    position: relative;
    touch-action: pan-y;
    pointer-events: auto !important;
}

.episodes-title {
    margin-bottom: 12px;
    font-size: 1rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.episodes-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 6px;
    scrollbar-width: thin;
    touch-action: manipulation;
    pointer-events: auto !important;
}
.episodes-list::-webkit-scrollbar { height: 6px; }
.episodes-list::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }

/* 选集按钮 手机点击失效彻底修复 */
.episode-btn {
    background: rgba(30, 41, 59, 0.8);
    color: var(--text-light);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: 5px;
    cursor: pointer !important;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    min-width: 75px;
    min-height: 44px;
    flex-shrink: 0;
    pointer-events: auto !important;
    touch-action: manipulation;
    position: relative;
}
/* 扩大隐形点击热区，手指点边缘也能触发 */
.episode-btn::after {
    content: "";
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
}

.episode-btn:hover {
    background: rgba(255, 107, 107, 0.2);
    border-color: var(--primary);
}

.episode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.dplayer-container {
    width: 90%;
    max-width: 1000px;
    position: relative;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    aspect-ratio: 16/9;
    flex-shrink: 0;
}

#dplayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.loading {
    text-align: center;
    padding: 40px 20px;
    display: none;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loading-spinner {
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.2rem;
    color: var(--text-gray);
}

.error {
    text-align: center;
    padding: 40px 20px;
    background: rgba(255, 107, 107, 0.15);
    border-radius: 15px;
    max-width: 600px;
    margin: 20px auto;
    display: none;
    border: 1px solid rgba(255, 107, 107, 0.3);
}

.error-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 15px;
}

.empty-state {
    text-align: center;
    padding: 50px 30px;
    background: var(--card-bg);
    border-radius: 15px;
    max-width: 700px;
    margin: 20px auto;
    border: 1px solid var(--border);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    color: var(--primary);
    opacity: 0.8;
}

.empty-title {
    font-size: 1.8rem;
    margin-bottom: 15px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.empty-text {
    font-size: 1.1rem;
    color: var(--text-gray);
    max-width: 550px;
    margin: 0 auto 20px;
    line-height: 1.6;
}

.dplayer-next-btn {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    cursor: pointer;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
    touch-action: manipulation;
}

.dplayer-next-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.dplayer-container:hover .dplayer-next-btn {
    opacity: 1;
}

.dplayer-prev-btn {
    position: absolute;
    top: 50%;
    left: 15px;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    cursor: pointer;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
    touch-action: manipulation;
}

.dplayer-prev-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.dplayer-container:hover .dplayer-prev-btn {
    opacity: 1;
}

.mobile-controls {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 20px;
    z-index: 3000;
    display: none;
}

.mobile-control-btn {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    cursor: pointer;
    touch-action: manipulation;
}

footer {
    text-align: center;
    padding: 40px 0 20px;
    margin-top: 40px;
    border-top: 1px solid var(--border);
    font-size: 0.95rem;
    color: var(--text-gray);
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.footer-link {
    color: var(--text-gray);
    text-decoration: none;
    transition: color 0.2;
    display: flex;
    align-items: center;
    gap: 6px;
}

.footer-link:hover {
    color: var(--primary);
}

.recent-searches-container {
    max-width: 800px;
    margin: 0 auto 15px;
    padding: 0 10px;
}

.recent-searches-container .recent-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-gray);
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.recent-searches-container .recent-searches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.hidden {
    display: none !important;
}

/* 平板适配 */
@media (max-width: 768px) {
    .logo {
        font-size: 2.2rem;
    }
    .search-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .api-selector {
        width: 100%;
        justify-content: center;
    }
    .video-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }
    .dplayer-container {
        width: 95%;
    }
    .dplayer-next-btn, .dplayer-prev-btn {
        width: 38px;
        height: 38px;
        font-size: 1.2rem;
    }
    .recent-searches-container {
        padding: 0 10px;
    }
    #search-btn {
        padding: 0 20px;
        font-size: 0.95rem;
    }
    .player-container {
        padding-top: max(10px, env(safe-area-inset-top));
    }
    .episodes-container {
        width: 95%;
        max-height: 200px;
        min-height: 110px;
    }
}

/* 小手机适配 */
@media (max-width: 480px) {
    .logo {
        font-size: 1.9rem;
    }
    .tagline {
        font-size: 1rem;
    }
    .video-grid {
        grid-template-columns: 1fr;
    }
    .empty-icon {
        font-size: 3rem;
    }
    .empty-title {
        font-size: 1.5rem;
    }
    .empty-text {
        font-size: 1rem;
    }
    #search-btn {
        padding: 0 15px;
        font-size: 0.9rem;
    }
    .episodes-container {
        width: 98%;
        max-height: 180px;
        min-height: 100px;
        padding: 14px 10px;
    }
    .episode-btn {
        padding: 9px 12px;
        min-height: 40px;
    }
}