:root {
    /* DEFAULT THEME VARIABLES (FilmMatics Purple) */
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    
    --bg-start: #1e1b4b;
    --bg-end: #020617;
    
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    
    --glass-tint: #1e1b4b;
    
    /* DEFAULT FONT: Montserrat */
    --font-main: 'Montserrat', sans-serif; 
    --grid-cols: 6; 
}

/* Prevent unwanted horizontal scrollbars inside modals */
#settingsModal,
#settingsPanel {
    overflow-x: hidden;
}

/* --- TAILWIND & VARIABLE OVERRIDES --- */
.bg-indigo-600 { background-color: var(--accent) !important; }
.hover\:bg-indigo-500:hover { background-color: var(--accent-hover) !important; } 

.text-indigo-400, .text-indigo-300 { color: var(--accent) !important; }
.text-gray-500, .text-gray-400 { color: var(--text-secondary) !important; }
.text-white, .text-gray-300 { color: var(--text-primary) !important; }

/* Dynamic Logo Gradient */
.logo-text {
    background: linear-gradient(135deg, var(--accent) 0%, var(--text-primary) 50%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    background-size: 200% auto;
    transition: all 0.5s ease;
}

/* Dynamic Shadow/Glow Classes */
.shadow-accent { box-shadow: 0 10px 30px -10px var(--accent); }
.shadow-strong { box-shadow: 0 20px 60px -10px var(--accent); }
.shadow-indigo-600\/20, .shadow-indigo-600\/40 { box-shadow: 0 10px 25px -5px var(--accent) !important; }

/* SEARCH BAR FOCUS OVERRIDE */
.search-input:focus {
    /* Matches the 'Reconnect' button style (White/10) instead of accent color */
    border-color: rgba(255, 255, 255, 0.2) !important; 
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1) !important;
}

/* FAB TOOLTIP */
.fab-tooltip {
    position: absolute;
    right: 110%;
    top: 50%;
    transform: translateY(-50%) translateX(10px);
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    color: white;
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border: 1px solid rgba(255,255,255,0.1);
}
.group:hover .fab-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

body {
    background: radial-gradient(circle at 50% 0%, var(--bg-start) 0%, var(--bg-end) 100%);
    min-height: 100vh;
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow-x: hidden;
    transition: background 0.5s ease, color 0.5s ease;
}

/* --- DYNAMIC GRID --- */
.dynamic-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2.5rem 2.5rem;
}
@media (min-width: 640px) { .dynamic-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .dynamic-grid { grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr)); } }

/* --- UTILITIES --- */
.glass {
    background: linear-gradient(145deg, var(--glass-tint) 0%, rgba(0,0,0,0.4) 100%);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.poster-shadow { box-shadow: 0 20px 50px -15px rgba(0, 0, 0, 0.9); }
.hero-gradient { background: linear-gradient(to bottom, transparent, var(--bg-end) 98%); }

.animate-pop { animation: pop 0.4s cubic-bezier(0.26, 0.53, 0.74, 1.48); }
@keyframes pop { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-end); }
::-webkit-scrollbar-thumb { background: var(--bg-start); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* --- STAR RATING --- */
.star-rating-group {
    display: inline-flex; flex-direction: row-reverse; gap: 4px;
}
.star-rating-group input { display: none; }
.star-rating-group label {
    cursor: pointer; color: var(--text-secondary); transition: color 0.2s, transform 0.1s;
}
.star-rating-group label:hover,
.star-rating-group label:hover ~ label,
.star-rating-group input:checked ~ label { color: #fbbf24; }
.star-rating-group label:hover { transform: scale(1.2); }

/* --- VIDEO PLAYER FIXED --- */
.video-wrapper { 
    position: relative; width: 100%; height: 100%; background: #000; overflow: hidden; display: flex; align-items: center; justify-content: center; 
}
video::-webkit-media-controls { display:none !important; }

/* SHARED OVERLAY CLASS (Logic Handled in JS) */
.video-overlay {
    transition: opacity 0.4s ease, transform 0.4s ease;
    opacity: 1; 
    pointer-events: auto;
    /* FIX: Force max z-index so it sits on top of video in fullscreen */
    z-index: 2147483647; 
}

/* HIDE STATE */
.user-idle .video-overlay {
    opacity: 0;
    pointer-events: none;
}

/* HEADER POS */
.video-header {
    position: absolute; top: 0; left: 0; width: 100%; 
    background: linear-gradient(to bottom, rgba(0,0,0,0.9) 0%, transparent 100%);
    padding: 2.5rem; display: flex; justify-content: space-between; align-items: flex-start;
}

/* CONTROLS POS */
.video-controls {
    position: absolute; bottom: 0; left: 0; width: 100%; 
    background: linear-gradient(to top, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.6) 60%, transparent 100%);
    padding: 2rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 12px;
    transform: translateY(0);
}
.user-idle .video-controls { transform: translateY(20px); }

/* TIMELINE FIXED */
.video-progress { 
    width: 100%; 
    height: 8px; /* Thicker */
    background: rgba(255,255,255,0.2); 
    cursor: pointer; 
    border-radius: 4px; 
    position: relative; 
    transition: height 0.1s; 
    display: block; /* Ensure visibility */
    margin-bottom: 10px; /* Space from buttons */
}
.video-progress:hover { height: 12px; }

.video-progress-fill { 
    height: 100%; 
    background: var(--accent); 
    width: 0%; 
    border-radius: 4px; 
    position: relative; 
    pointer-events: none; 
}
.video-progress-fill::after {
    content: ''; position: absolute; right: -6px; top: 50%; margin-top: -8px; width: 16px; height: 16px; background: var(--text-primary);
    border-radius: 50%; transform: scale(0); transition: transform 0.1s; box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.video-wrapper:hover .video-progress-fill::after { transform: scale(1); }

.control-btn:hover { background: rgba(255,255,255,0.1); transform: scale(1.1); }
.control-btn:active { transform: scale(0.95); }

/* Fix for Dropdown Backgrounds */
select {
    background-color: var(--glass-tint) !important; /* Forces dark background */
    color: var(--text-primary) !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
}

/* Optional: Fix the dropdown options on some browsers */
select option {
    background-color: var(--bg-start);
    color: var(--text-primary);
}

/* --- FORM ELEMENTS --- */
input[type=range].volume-slider {
    -webkit-appearance: none; width: 0; height: 4px; background: rgba(255,255,255,0.3);
    border-radius: 2px; outline: none; transition: width 0.3s ease; cursor: pointer; overflow: hidden;
}
.volume-group:hover input[type=range].volume-slider { width: 80px; }
input[type=range].volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 10px; height: 10px; background: var(--text-primary);
    border-radius: 50%; box-shadow: -100px 0 0 100px var(--accent);
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent; /* important */
}

/* Chrome, Edge, Safari */
input[type=range]::-webkit-slider-runnable-track {
    height: 8px;
    background: var(--accent);
    border-radius: 999px;
}

/* Firefox */
input[type=range]::-moz-range-track {
    height: 8px;
    background: var(--accent);
    border-radius: 999px;
}

/* Optional: rounded thumb */
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    margin-top: -4px; /* centers thumb */
}

input[type=range]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
}

/* Generic tooltips (use: class="has-tip" data-tip="...") */
.has-tip { position: relative; }
.has-tip::after {
    content: attr(data-tip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%) translateY(6px);
    background: rgba(0,0,0,0.82);
    color: white;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.18s ease;
    border: 1px solid rgba(255,255,255,0.12);
    backdrop-filter: blur(6px);
    z-index: 9999;
}
.has-tip::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: calc(100% + 4px);
    transform: translateX(-50%) translateY(6px);
    border: 6px solid transparent;
    border-top-color: rgba(0,0,0,0.82);
    opacity: 0;
    pointer-events: none;
    transition: all 0.18s ease;
    z-index: 9999;
}
.has-tip:hover::after,
.has-tip:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .has-tip::after,
    .has-tip::before { transition: none; }
}

/*
  JS-driven tooltips
  -----------------
  The original CSS pseudo-element tooltips can be clipped near the viewport edges
  and by overflow containers. FilmMatics uses a single fixed-position tooltip
  element appended to <body> so tooltips never get cut off.
*/
.has-tip::after,
.has-tip::before {
    display: none !important;
    content: none !important;
}

.fm-tooltip {
    position: fixed;
    z-index: 2147483647;
    pointer-events: none;
    max-width: min(320px, calc(100vw - 24px));
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(10, 10, 14, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.10);
    color: white;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.02em;
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 35px rgba(0,0,0,0.45);
    transform: translate3d(0,0,0);
}

.fm-tooltip.hidden {
    opacity: 0;
    visibility: hidden;
}

/* Toggle switch (used in Settings) */
.fm-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.14);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.fm-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.fm-switch-slider {
    position: absolute;
    top: 50%;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.85);
    transform: translateY(-50%);
    transition: transform 0.2s ease, background 0.2s ease;
}

.fm-switch input:checked + .fm-switch-slider {
    transform: translateY(-50%) translateX(20px);
    background: var(--accent);
}

.fm-switch:has(input:checked) {
    background: rgba(99, 102, 241, 0.22);
    border-color: rgba(99, 102, 241, 0.45);
}

/* -------------------------
   Episode Drawer (Player)
--------------------------*/
.episode-drawer {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: flex-end;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(12px);
    /* Must be >= .video-overlay (which uses a very high z-index for fullscreen) */
    z-index: 2147483647;
}

.episode-drawer.hidden { display: none; }

.episode-drawer-panel {
    width: min(520px, 92vw);
    height: 100%;
    padding: 20px;
    background: rgba(10, 10, 14, 0.82);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: -20px 0 50px rgba(0,0,0,0.4);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.episode-drawer-list {
    overflow: auto;
    padding-right: 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.episode-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.05);
    color: white;
    text-align: left;
    transition: transform 0.15s ease, background 0.15s ease, border 0.15s ease;
}

.episode-row:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.14);
    transform: translateY(-1px);
}

.episode-row.is-current {
    border-color: rgba(99, 102, 241, 0.55);
    background: rgba(99, 102, 241, 0.14);
}

.episode-badge {
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.10);
}

.episode-filename {
    font-size: 12px;
    font-weight: 800;
    opacity: 0.9;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.episode-watched {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(34, 197, 94, 0.20);
    border: 1px solid rgba(34, 197, 94, 0.40);
    color: #86efac;
    font-size: 12px;
    font-weight: 900;
}

.episode-now {
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.1em;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.autoplay-pill {
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: white;
    transition: background 0.15s ease, border 0.15s ease;
}

.autoplay-pill:hover {
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(255, 255, 255, 0.18);
}
