/* =========================================
   1. VARIABLES & RESET (MUST BE FIRST)
   ========================================= */
:root {
    --bg-main: #0a0a0a;
    --bg-glass: rgba(20, 20, 20, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary: #FF0057;
    --text-white: #ffffff;
    --text-gray: #b3b3b3;
    --nav-height: 70px;
    --card-width-mobile: 140px;
    --card-width-desktop: 220px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background-color: var(--bg-main);
    background-image: radial-gradient(circle at 10% 10%, rgba(255, 0, 87, 0.05) 0%, transparent 40%);
    color: var(--text-white);
    font-family: 'Outfit', sans-serif;
    overflow-x: hidden;
    padding-bottom: 90px;
    -webkit-tap-highlight-color: transparent;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { text-decoration: none; color: inherit; transition: 0.3s; }
img { max-width: 100%; display: block; }
ul { list-style: none; }
html { scroll-behavior: smooth; }

/* =========================================
   2. HYBRID SIDEBAR
   ========================================= */
#glass-sidebar {
    position: fixed; z-index: 2000;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    background: rgba(15, 15, 20, 0.85);
    backdrop-filter: blur(35px) saturate(180%);
    -webkit-backdrop-filter: blur(35px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
/* Mobile */
#glass-sidebar {
    top: 0; left: -300px; width: 280px; height: 100vh;
    border-radius: 0 25px 25px 0; box-shadow: 5px 0 30px rgba(0,0,0,0.5);
    padding-top: 20px; justify-content: flex-start;
}
.sidebar-open #glass-sidebar { left: 0; }
/* Desktop */
@media (min-width: 992px) {
    #glass-sidebar {
        left: 20px !important; top: 50%; transform: translateY(-50%);
        width: 70px; height: 80vh; border-radius: 35px;
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
        background: rgba(15, 15, 20, 0.65); justify-content: center; padding-top: 0;
    }
}
#sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px);
    z-index: 1999; opacity: 0; pointer-events: none; transition: 0.3s;
}
.sidebar-open #sidebar-backdrop { opacity: 1; pointer-events: auto; }
.sidebar-inner { display: flex; flex-direction: column; align-items: center; gap: 15px; width: 100%; padding: 30px 0; }
.sidebar-item {
    width: 45px; height: 45px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    color: #888; font-size: 1.2rem; transition: 0.3s; text-decoration: none; margin-bottom: 5px;
}
.sidebar-item:hover, .sidebar-item.active {
    background: var(--primary); color: white; box-shadow: 0 5px 15px rgba(255, 0, 87, 0.4);
}
.sidebar-divider { width: 30px; height: 1px; background: rgba(255,255,255,0.1); margin: 5px 0; }

/* =========================================
   3. AUTO-FIT LAYOUT
   ========================================= */
@media (min-width: 992px) { 
    #main-header { left: calc(50% + 35px); width: calc(92% - 80px); }
    body { padding-left: 90px; }
    footer { padding-left: 90px; }
}

/* =========================================
   4. HEADER
   ========================================= */
#main-header {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    width: 95%; max-width: 1200px; height: 72px; z-index: 1000;
    border-radius: 40px; padding: 0 10px; display: flex; align-items: center; justify-content: space-between;
    transition: all 0.4s; background: rgba(15, 15, 20, 0.3);
    backdrop-filter: blur(35px) saturate(200%); -webkit-backdrop-filter: blur(35px) saturate(200%);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2); border: 1px solid rgba(255, 255, 255, 0.05);
}
.logo-area { padding-left: 15px; z-index: 2; }
.logo-area .app-icon { height: 42px; border-radius: 0; box-shadow: none; background: transparent; }

/* =========================================
   5. SEARCH BAR
   ========================================= */
.ios-search-bar {
    position: relative; background: rgba(0, 0, 0, 0.2); border-radius: 18px;
    padding: 0 10px; height: 42px; width: 42px; display: flex; align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.05); transition: all 0.4s; cursor: pointer; overflow: hidden;
}
@media (min-width: 768px) { .ios-search-bar { width: 220px; background: rgba(0,0,0,0.4); } }
.ios-search-bar:focus-within, .ios-search-bar.active { 
    width: 260px; background: rgba(0,0,0,0.8); border-color: var(--primary); box-shadow: 0 0 15px rgba(255, 0, 87, 0.2);
}
.ios-search-bar i { font-size: 16px; color: rgba(255,255,255,0.6); min-width: 20px; text-align: center; }
.ios-search-bar input {
    background: transparent; border: none; outline: none; color: white; font-size: 14px; 
    display: block; width: 0; opacity: 0; margin-left: 0; transition: all 0.3s ease;
}
@media (min-width: 768px) { .ios-search-bar input { width: 100%; opacity: 1; margin-left: 10px; } }
.ios-search-bar:focus-within input, .ios-search-bar.active input { width: 100%; opacity: 1; margin-left: 10px; }

/* =========================================
   6. DOCK (Mobile)
   ========================================= */
.bottom-nav {
    position: fixed; bottom: 25px; left: 0; width: 100%; z-index: 9999;
    pointer-events: none; display: flex; justify-content: center;
}
.dock-container {
    pointer-events: auto; display: flex; justify-content: space-between; align-items: center;
    width: 90%; max-width: 360px; height: 70px; padding: 0 25px;
    background: rgba(15, 15, 20, 0.6); backdrop-filter: blur(30px) saturate(180%);
    border-radius: 40px; border: 1px solid rgba(255, 255, 255, 0.1); border-top: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
}
.dock-item {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 50px; height: 100%; color: rgba(255, 255, 255, 0.5); text-decoration: none;
    transition: 0.4s;
}
.dock-item .icon-box { font-size: 1.4rem; transition: 0.3s; }
.dock-label { position: absolute; bottom: 8px; font-size: 0.65rem; font-weight: 600; opacity: 0; transform: translateY(10px); transition: 0.3s; }
.dock-item.active { color: white; }
.dock-item.active .icon-box { transform: translateY(-8px); color: var(--primary); filter: drop-shadow(0 0 12px var(--primary)); }
.dock-item.active .dock-label { opacity: 1; transform: translateY(0); }

/* =========================================
   7. CARDS
   ========================================= */
.anime-card {
    position: relative; flex: 0 0 auto; width: 50vw; max-width: 160px; min-width: 120px;
    padding: 8px; border-radius: 10px; transition: 0.6s; cursor: pointer;
}
@media (min-width: 768px) { .anime-card { width: var(--card-width-desktop); max-width: none; } }
.anime-card:hover { background: rgba(255, 255, 255, 0.05); backdrop-filter: blur(10px); transform: translateY(-5px); }
.card-img-wrapper {
    position: relative; width: 100%; aspect-ratio: 2/3; border-radius: 10px; overflow: hidden; background: #151515;
}
.card-img-wrapper img { width: 100%; height: 100%; object-fit: cover; transition: 0.6s; }
.anime-card:hover .card-img-wrapper img { transform: scale(1.05); }

/* Trending Wide Cards */
.trending-card {
    position: relative; flex: 0 0 auto; width: 65vw !important; max-width: 200px; min-width: 220px;
    padding: 8px; cursor: pointer; transition: 0.3s;
}
.trending-card .card-img-wrapper { width: 100%; aspect-ratio: 16/9 !important; border-radius: 12px; overflow: hidden; background: #151515; }
.trending-card .card-img-wrapper img { width: 150%; height: 140%; object-fit: cover !important; object-position: 50% 20% !important; transition: 0.4s; }

.ep-badge {
    position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
    color: white; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.15); z-index: 5;
}
.card-title { font-size: 0.95rem; color: #ddd; margin-top: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; padding: 0 4px; }

/* =========================================
   8. SLIDER
   ========================================= */
.carousel-item { height: 65vh !important; min-height: 450px; position: relative; background-color: #000; }
.hero-bg { width: 100%; height: 100%; object-fit: cover !important; opacity: 0.6; mask-image: none !important; }
.hero-overlay {
    position: absolute; bottom: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(to top, #0a0a0a 15%, rgba(0,0,0,0.5) 50%, transparent 100%) !important;
    display: flex; align-items: flex-end; padding-bottom: 60px; padding-left: 5%; pointer-events: none;
}
.hero-content { max-width: 800px; z-index: 10; pointer-events: auto; text-align: left; }
.hero-title { font-size: 3rem; font-weight: 800; color: white; text-shadow: 2px 2px 15px rgba(0,0,0,0.9); margin-bottom: 15px; line-height: 1.1; }
@media (max-width: 768px) {
    .carousel-item { height: 55vh !important; min-height: 350px; }
    .hero-title { font-size: 1.8rem; }
    .hero-overlay { padding-bottom: 90px; padding-left: 20px; }
}

/* =========================================
   9. DETAILS & MISC
   ========================================= */
.details-hero { position: relative; min-height: 100vh; padding-top: 100px; padding-bottom: 50px; }
.details-bg { position: fixed; top: 0; left: 0; width: 100%; height: 100vh; background-size: cover; background-position: center; opacity: 0.15; z-index: -1; filter: blur(20px); }
.details-overlay-gradient { position: fixed; top: 0; left: 0; width: 100%; height: 100vh; background: linear-gradient(to top, var(--bg-main) 20%, transparent 100%); z-index: -1; }
.poster-card { border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.1); }
.anime-title-large { font-size: 2.5rem; font-weight: 800; margin-bottom: 15px; line-height: 1.1; }
.meta-badge { background: rgba(255,255,255,0.1); padding: 5px 12px; border-radius: 6px; font-size: 0.8rem; border: 1px solid rgba(255,255,255,0.1); }
.glass-panel { background: rgba(255, 255, 255, 0.03); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.05); border-radius: 16px; padding: 20px; }
.btn-watch { background: var(--primary); color: white; padding: 12px 35px; border-radius: 50px; font-weight: 600; box-shadow: 0 5px 20px rgba(255, 0, 87, 0.4); display: flex; align-items: center; border: none; transition: 0.3s; }
.btn-watch:hover { transform: scale(1.05); box-shadow: 0 10px 30px rgba(255, 0, 87, 0.6); }

/* =========================================
   10. RAILS & SCROLL
   ========================================= */
.rail-wrapper { 
    display: flex !important; flex-wrap: nowrap !important; overflow-x: auto !important; gap: 15px;
    padding: 10px 4% 20px 4%; scrollbar-width: none; -ms-overflow-style: none;
}
.rail-wrapper::-webkit-scrollbar { display: none !important; }
.anime-card { flex: 0 0 auto !important; width: 140px; margin: 0 !important; }
@media (min-width: 768px) { .anime-card { width: 200px; } }
html, body { background-color: #0a0a0a !important; overscroll-behavior-y: none; }
section, .content-rail { border: none !important; outline: none !important; background: transparent !important; }

/* =========================================
   11. SCROLLBARS
   ========================================= */
html { scrollbar-gutter: stable; background-color: var(--bg-main); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 10px; border: 2px solid #0a0a0a; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
.rail-wrapper { -webkit-overflow-scrolling: touch; padding-bottom: 25px !important; margin-bottom: -10px; overflow-y: hidden; }

/* =========================================
   12. PLAYER PAGE & CONTROLS (NEW & UPDATED)
   ========================================= */

/* Main Containers */
.watch-container { padding-top: 100px !important; min-height: 100vh; position: relative; z-index: 10; }
.player-wrapper { 
    position: relative; width: 100%; padding-top: 56.25%; /* 16:9 Aspect Ratio */
    background: #000; border-radius: 20px; overflow: hidden; 
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); 
    border: 1px solid rgba(255, 255, 255, 0.08); 
    z-index: 20; /* Keep above lights-off */
}
.player-iframe, .video-js { position: absolute; top: 0; left: 0; width: 100% !important; height: 100% !important; border: none; }

/* Lights Off Overlay */
#lights-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.95); z-index: 15; /* Below player, above page */
    opacity: 0; pointer-events: none; transition: opacity 0.5s ease;
}
body.lights-off #lights-overlay { opacity: 1; pointer-events: auto; }
body.lights-off .player-wrapper { z-index: 20; box-shadow: 0 0 50px rgba(255, 255, 255, 0.1); }
body.lights-off #main-header, body.lights-off .bottom-nav, body.lights-off .glass-panel { 
    opacity: 0.2; pointer-events: none; transition: 0.5s; 
}

/* Modern Control Bar (Prev/Next/Servers) */
.controls-glass { 
    background: rgba(25, 25, 30, 0.8); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.05); border-radius: 20px; padding: 20px; 
    margin-top: 20px; display: flex; flex-direction: column; gap: 15px;
}
.control-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }

/* Action Buttons (Light Off, etc) */
.action-btn {
    background: rgba(255,255,255,0.08); color: #ccc; border: none;
    padding: 10px 18px; border-radius: 12px; font-size: 0.9rem; font-weight: 500;
    display: flex; align-items: center; gap: 8px; transition: 0.3s; cursor: pointer;
}
.action-btn:hover, .action-btn.active { background: white; color: black; transform: translateY(-2px); }
.action-btn i { font-size: 1.1rem; }

/* Navigation Buttons (Next/Prev) */
.nav-btn {
    background: var(--primary); color: white; padding: 10px 25px;
    border-radius: 50px; font-weight: 600; text-transform: uppercase; font-size: 0.85rem;
    display: flex; align-items: center; gap: 10px; text-decoration: none;
    box-shadow: 0 4px 15px rgba(255, 0, 87, 0.3); transition: 0.3s;
}
.nav-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(255, 0, 87, 0.5); color: white; }
.nav-btn.disabled { background: #333; color: #666; pointer-events: none; box-shadow: none; }

/* Server Buttons */
.server-btn {
    background: transparent; color: #888; border: 1px solid rgba(255,255,255,0.1);
    padding: 6px 14px; border-radius: 8px; font-size: 0.8rem; cursor: pointer; transition: 0.2s;
}
.server-btn:hover, .server-btn.active { border-color: var(--primary); color: var(--primary); background: rgba(255, 0, 87, 0.1); }

/* Netflix-Style Episode Grid */
.ep-panel { margin-top: 20px; }
.ep-header { font-size: 1.2rem; font-weight: 700; margin-bottom: 15px; display: flex; align-items: center; gap: 10px; }
.ep-header span { color: var(--primary); }

#ep-list {
    display: grid !important; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 10px;
    max-height: 400px; overflow-y: auto; padding: 5px;
}
.ep-link {
    display: flex; align-items: center; justify-content: center;
    height: 45px; background: rgba(255,255,255,0.03); 
    border: 1px solid rgba(255,255,255,0.08); border-radius: 10px;
    color: #ccc; font-weight: 600; font-size: 0.95rem; text-decoration: none; transition: 0.2s;
}
.ep-link:hover { background: rgba(255,255,255,0.1); color: white; border-color: rgba(255,255,255,0.3); }
.ep-link.btn-danger { 
    background: var(--primary) !important; color: white !important; 
    border-color: var(--primary) !important; box-shadow: 0 0 15px rgba(255, 0, 87, 0.4);
}