:root {
    --bg-dark: #07100a;
    --bg-card: #0d1c12;
    --bg-input: #102417;
    --text-primary: #ecfdf5;
    --text-secondary: #90a498;
    --accent: #2e7d56;
    --accent-glow: rgba(46, 125, 86, 0.4);
    --border: #143320;
    
    --transition: all 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    background:
        radial-gradient(ellipse at 80% 0%, rgba(46, 125, 86, 0.25) 0%, transparent 50%),
        radial-gradient(ellipse at 20% 100%, rgba(16, 60, 36, 0.3) 0%, transparent 50%),
        linear-gradient(170deg, #07100a 0%, #0a1610 40%, #07100a 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    padding-bottom: 110px; /* Space for the sticky ad */
}

/* Background ambient effects */
.background-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow-orb {
    position: absolute;
    border-radius: 50%;
    /* Removed heavy filter: blur(100px) for Pi optimization */
    opacity: 0.2;
}

.orb-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, rgba(46,125,86,0.2) 0%, rgba(7,16,10,0) 70%);
}

.orb-2 {
    bottom: -20%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(46,125,86,0.1) 0%, rgba(7,16,10,0) 70%);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 4rem 2rem;
}

/* Hero & Search */
.hero {
    text-align: center;
    margin-bottom: 3rem;
}

.logo {
    font-size: 4rem;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 0.5rem;
}

.highlight {
    background: linear-gradient(135deg, #3cb371, #2e7d56);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.25rem;
    margin-bottom: 3rem;
}

.search-container {
    position: relative;
    max-width: 800px;
    margin: 0 auto;
    transition: var(--transition);
}

.search-flex {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.search-container:focus-within {
    transform: translateY(-2px);
}

.input-wrapper input {
    width: 100%;
    padding: 1.25rem 1.5rem 1.25rem 3.5rem;
    font-size: 1.25rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 1rem;
    color: var(--text-primary);
    font-family: inherit;
    outline: none;
    /* Removed backdrop-filter */
    transition: var(--transition);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.input-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow), 0 10px 30px rgba(0, 0, 0, 0.4);
}

.search-icon {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    transition: var(--transition);
}

.input-wrapper input:focus + .search-icon {
    color: var(--accent);
}

/* Custom Dropdown */
.custom-dropdown {
    position: relative;
    min-width: 160px;
    user-select: none;
}

.custom-dropdown-selected {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 1.25rem 2.5rem 1.25rem 1.5rem;
    border-radius: 1rem;
    font-size: 1.1rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

.custom-dropdown-selected::after {
    content: '▾';
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.custom-dropdown-selected:hover {
    border-color: var(--accent);
}

.custom-dropdown-options {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    min-width: 100%;
    max-height: 300px;
    overflow-y: auto;
    background: #0a1a0f;
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 0.5rem;
    z-index: 200;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

.custom-dropdown.open .custom-dropdown-options {
    display: block;
}

.custom-dropdown-option {
    padding: 0.65rem 1rem;
    border-radius: 0.6rem;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: background 0.15s ease;
    white-space: nowrap;
}

.custom-dropdown-option:hover {
    background: #000000;
}

.custom-dropdown-option.selected {
    background: var(--accent);
    color: white;
    font-weight: 600;
}

/* Small variant for season/episode */
.custom-dropdown.small .custom-dropdown-selected {
    padding: 0.5rem 2rem 0.5rem 1rem;
    font-size: 0.875rem;
    border-radius: 1rem;
}

.custom-dropdown.small .custom-dropdown-options {
    min-width: 140px;
}

/* Media Toggle Pill */
.media-toggle {
    display: inline-flex;
    background: var(--bg-input);
    padding: 0.35rem;
    border-radius: 3rem;
    margin-top: 2.5rem;
    border: 1px solid var(--border);
    /* Removed backdrop-filter */
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 600;
    border-radius: 2.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-btn:hover:not(.active) {
    color: var(--text-primary);
}

.toggle-btn.active {
    color: white;
    background: linear-gradient(135deg, #2e7d56, #1a5c3a);
    box-shadow: 0 4px 15px rgba(46, 125, 86, 0.4);
}


/* Home Layout & Categories */
.home-layout {
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

.category-section h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    padding-left: 0.5rem;
    font-weight: 600;
    color: #f4f4f5;
}

.row-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.category-row {
    display: flex;
    gap: 1.5rem;
    overflow-x: auto;
    padding: 1rem 0.5rem;
    scroll-snap-type: x mandatory;
    scrollbar-width: none; /* Firefox */
    
    /* Raspberry Pi scrolling optimization */
    transform: translateZ(0);
    will-change: scroll-position;
    width: 100%;
}

.category-row::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

/* Scroll Arrows */
.scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(24, 24, 27, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    transition: all 0.2s ease;
}

.scroll-btn:hover {
    background: var(--accent);
    transform: translateY(-50%) scale(1.1);
}

.left-arrow {
    left: -15px;
}

.right-arrow {
    right: -15px;
}

/* Base Card Styles */
.result-card {
    background: linear-gradient(180deg, rgba(13,28,18,0.95) 0%, rgba(7,16,10,0.98) 100%);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease, border-color 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative; /* For delete btn */
    will-change: transform; /* Pi optimization */
}

.result-card:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: var(--accent);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), 0 0 20px var(--accent-glow);
    z-index: 10;
}

/* In category rows, cards have fixed width */
.category-row .result-card {
    flex: 0 0 220px;
    scroll-snap-align: start;
}

/* In search results, cards use grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 2rem;
}

.poster-image {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    display: block;
    background: #18181b;
}

.rating-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(0, 0, 0, 0.85); /* Solid instead of blur */
    /* Removed backdrop-filter */
    color: #fbbf24;
    padding: 0.35rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.85rem;
    font-weight: 700;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.delete-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(220, 38, 38, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 1.1rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 6; /* above poster */
    transition: var(--transition);
    opacity: 0;
}

.result-card:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: rgba(220, 38, 38, 1);
    transform: scale(1.1);
}

.card-info {
    padding: 1.25rem;
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.badge {
    position: absolute;
    top: -1rem;
    right: 1rem;
    background: linear-gradient(135deg, #2e7d56, #1a5c3a);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    box-shadow: 0 4px 10px rgba(46, 125, 86, 0.3);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: auto;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    opacity: 1;
    visibility: visible;
    transition: var(--transition);
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    /* Removed backdrop-filter */
}

.modal-content {
    background: #18181b;
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    width: 100%;
    max-width: 1000px;
    position: relative;
    z-index: 101;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(1);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    will-change: transform;
}

.modal.hidden .modal-content {
    transform: scale(0.95);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    z-index: 10;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#modalTitle {
    font-size: 1.25rem;
    font-weight: 600;
}

.tv-controls {
    display: flex;
    gap: 1rem;
    margin-right: 3rem;
}

.tv-controls.hidden {
    display: none;
}

.select-wrapper select {
    appearance: none;
    background: rgba(14, 40, 24, 0.8);
    border: 1px solid var(--border);
    color: white;
    padding: 0.5rem 2rem 0.5rem 1rem;
    border-radius: 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}

.select-wrapper select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.select-wrapper select option {
    background-color: #0d1c12;
    color: #ecfdf5;
    padding: 0.5rem;
}

.iframe-container {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    height: 0;
    overflow: hidden;
    background: #000;
}

.iframe-container iframe {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
}

.player-ad-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.close-ad-btn {
    position: absolute;
    top: 10px; right: 10px;
    background: rgba(220, 38, 38, 0.9);
    color: white;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 51;
    font-family: inherit;
    transition: var(--transition);
}

.close-ad-btn:hover {
    background: red;
    transform: scale(1.05);
}

.sticky-footer-ad {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(9, 9, 11, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 0;
    z-index: 99; /* Below the modal (100) but above everything else */
    display: flex;
    justify-content: center;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.7);
}

/* Utils */
.hidden {
    display: none !important;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 0;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

@media (max-width: 768px) {
    .modal {
        padding: 0;
    }
    .modal-content {
        border-radius: 0;
        height: 100%;
        max-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    .iframe-container {
        flex: 1;
        padding-bottom: 0;
        height: auto;
    }
    .modal-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .category-row .result-card {
        flex: 0 0 160px;
    }
    .scroll-btn {
        display: none !important; /* Hide arrows on touch devices */
    }
}
