:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-main: #ffffff;
    --text-sec: #aaaaaa;
    --accent: #e50914; 
    --watched: #2ecc71;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 0;
}

/* Mobile-Friendly Header */
header {
    background-color: #000;
    padding: 1rem;
    position: sticky; /* Keeps search visible */
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #333;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.logo { font-weight: 900; font-size: 1.2rem; color: var(--accent); letter-spacing: 1px; }
a { color: var(--text-main); text-decoration: none; font-size: 0.9rem; }

/* Search Bar Styling */
.search-bar {
    max-width: 1200px;
    margin: 10px auto 0 auto;
}

.search-bar input {
    width: 100%;
    padding: 10px;
    box-sizing: border-box; /* Fixes padding width issues */
    border-radius: 5px;
    border: none;
    background: #333;
    color: white;
    font-size: 1rem;
}

main { padding: 1rem; max-width: 1200px; margin: 0 auto; }

/* OPTIMIZED GRID FOR MOBILE & LAZY LOADING */
.grid-container {
    display: grid;
    /* Min 140px allows 2 columns on most phones, more on desktop */
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); 
    gap: 15px;
}

.card {
    background: var(--card-bg);
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.card:hover { opacity: 0.8; }

/* Aspect ratio hack to prevent layout jumps before image loads */
.image-wrapper {
    width: 100%;
    aspect-ratio: 2/3; 
    background-color: #222; /* Placeholder color */
    overflow: hidden;
}

.card img { 
    width: 100%; 
    height: 100%; 
    object-fit: cover; 
    display: block;
}

.card h3 { 
    padding: 8px; 
    font-size: 0.9rem; 
    margin: 0; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}

/* Player & Buttons */
.show-header { 
    display: flex; 
    flex-direction: column; /* Stack on mobile */
    gap: 20px; 
    margin-bottom: 30px; 
}

@media(min-width: 768px) {
    .show-header { flex-direction: row; }
    .show-header img { width: 220px; }
}

.show-header img { width: 100%; max-width: 250px; border-radius: 8px; margin: 0 auto; }

.episode-row {
    background: var(--card-bg);
    margin-bottom: 10px;
    padding: 15px;
    border-radius: 5px;
}

.links-area { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.btn {
    padding: 8px 12px;
    background: #333;
    color: white;
    border-radius: 4px;
    font-size: 0.85rem;
    border: 1px solid #444;
    cursor: pointer;
    text-align: center;
    flex: 1 1 auto; /* Grow buttons to fill space on mobile */
    max-width: 200px;
}

.btn.visited { border-left: 3px solid var(--watched); color: #888; }

/* Responsive Video Container */
.player-container { margin-top: 15px; }
iframe, video { width: 100%; aspect-ratio: 16/9; background: black; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px; /* Space between icon and text */
    padding: 10px 14px;
    background: #2a2a2a;
    color: white;
    border-radius: 6px;
    font-size: 0.85rem;
    border: 1px solid #444;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:hover { background: #333; border-color: #666; }

/* Styling for the SVG icons */
.btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Persistent Watched State */
.btn.visited {
    border-color: var(--watched);
    background: #16261a;
    color: #9fdfb8;
}

.checkmark {
    margin-left: auto;
    font-weight: bold;
}

/* Ensure images don't break layout while lazy loading */
.image-wrapper {
    background: #1a1a1a;
    aspect-ratio: 2/3;
}