/* === CSS Variables === */
:root {
    --accent:      #e50914;
    --accent-glow: rgba(229, 9, 20, 0.18);
    --bg-base:     #0a0a0f;
    --bg-card:     #14141a;
    --bg-elevated: #1a1a24;
    --border-subtle: rgba(255, 255, 255, 0.07);
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(229, 9, 20, 0.25);
    --transition:  0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === Base Layout === */
body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-base);
    color: #f0f0f0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: #e50914;
    text-decoration: none;
}

.container {
    margin: 0 auto;
    padding: clamp(16px, 3vw, 28px) clamp(12px, 4vw, 64px);
}

/* === Section Titles === */
h2 {
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    font-weight: 700;
    margin-bottom: 4px;
    margin-top: 0;
    letter-spacing: -0.3px;
    padding-left: 12px;
    border-left: 3px solid var(--accent);
    line-height: 1.2;
}

/* === Content Sections === */
.content-section {
    margin-bottom: 40px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(229, 9, 20, 0.12);
}

/* === Entrance Animation === */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === Shimmer Skeleton === */
@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, #1e1e2a 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite linear;
    border-radius: 8px;
    pointer-events: none;
}

.skeleton-poster {
    aspect-ratio: 2 / 3;
    min-width: clamp(105px, 13vw, 260px);
    max-width: clamp(105px, 13vw, 260px);
    flex-shrink: 0;
}

/* === Horizontal Scroll Row (Netflix-style) === */
.scroll-row-wrapper {
    position: relative;
}

.scroll-row {
    display: flex;
    gap: clamp(10px, 1.2vw, 24px);
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 8px 0 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.scroll-row::-webkit-scrollbar {
    display: none;
}

/* Scroll Arrows */
.scroll-arrow {
    position: absolute;
    top: 0;
    bottom: 12px;
    width: 48px;
    background: linear-gradient(to right, rgba(10, 10, 15, 0.95), transparent);
    color: #fff;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition);
    opacity: 0.3;
    border-radius: 0;
}

.scroll-arrow:focus-visible {
    outline: 2px solid #e50914;
    outline-offset: -2px;
    opacity: 1;
}

.scroll-row-wrapper:hover .scroll-arrow {
    opacity: 0.9;
}

.scroll-arrow:hover {
    color: #e50914;
}

.scroll-left {
    left: 0;
    background: linear-gradient(to right, rgba(10, 10, 15, 0.95), transparent);
}

.scroll-right {
    right: 0;
    background: linear-gradient(to left, rgba(10, 10, 15, 0.95), transparent);
}

/* === Movie/Show Item (Poster Card) === */
.movie-item {
    position: relative;
    min-width: clamp(105px, 13vw, 260px);
    max-width: clamp(105px, 13vw, 260px);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
    flex-shrink: 0;
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-subtle);
}

/* Stagger entrance animation — genre grid only (scroll rows skip animation
   because it creates a compositing layer that clips the hover scale) */

.movie-item:hover {
    transform: scale(1.1) translateY(-4px);
    box-shadow: var(--shadow-hover), 0 4px 28px var(--accent-glow);
    z-index: 5;
    border-color: rgba(229, 9, 20, 0.2);
}

.movie-item a {
    display: block;
    position: relative;
    color: #fff;
    cursor: pointer;
}

/* Keyboard focus for movie cards */
.movie-item a:focus-visible {
    outline: 3px solid #e50914;
    outline-offset: -3px;
    border-radius: var(--radius-md);
}

.movie-item:has(a:focus-visible) {
    transform: scale(1.1) translateY(-4px);
    box-shadow: var(--shadow-hover), 0 4px 28px var(--accent-glow);
    z-index: 5;
    border-color: rgba(229, 9, 20, 0.2);
}

.movie-item img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px 8px 0 0;
    aspect-ratio: 2 / 3;
    object-fit: cover;
}

/* Title Overlay — always visible */
.movie-title-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent 0%, rgba(0, 0, 0, 0.88) 55%, rgba(0, 0, 0, 0.97) 100%);
    color: #fff;
    padding: 32px 10px 10px;
    font-size: clamp(0.68rem, 1vw, 0.82rem);
    font-weight: 600;
    text-align: center;
    opacity: 1;
    transition: opacity 0.3s;
    line-height: 1.3;
    z-index: 2;
}

.movie-item:hover .movie-title-overlay {
    opacity: 1;
}

/* Remove Button (continue watching) */
.remove-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.15);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s;
    line-height: 1;
    opacity: 0;
}

.movie-item:hover .remove-btn {
    opacity: 1;
}

.remove-btn:hover {
    background: #e50914;
    border-color: #e50914;
}

/* Poster Progress Bar (recently watched) */
.poster-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    z-index: 5;
}

.poster-progress-bar {
    height: 100%;
    background: #e50914;
    border-radius: 0 2px 2px 0;
    transition: width 0.3s ease;
    box-shadow: 0 0 6px rgba(229, 9, 20, 0.5);
}

/* Continue Watching Badge — sits above title overlay */
.continue-text {
    position: absolute;
    bottom: 20px; /* above the title overlay text */
    left: 0;
    right: 0;
    color: #fff;
    padding: 4px 8px;
    font-size: clamp(0.58rem, 0.8vw, 0.68rem); /* slightly smaller than .movie-title-overlay */
    text-align: center;
    font-weight: 600;
    letter-spacing: 0.3px;
    z-index: 4;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* === Announcement Banner === */
.announcement-banner {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    padding: clamp(10px, 1.5vw, 14px) 50px clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 24px);
    text-align: center;
    border-bottom: 2px solid #ff4e4e;
    position: relative;
    font-size: clamp(0.82rem, 1.2vw, 0.95rem);
}

.dismiss-announcement {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 78, 78, 0.2);
    color: white;
    border: 1px solid rgba(255, 78, 78, 0.3);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.dismiss-announcement:hover {
    background: #ff4e4e;
    border-color: #ff4e4e;
}

/* === Genre Grid (for genre.php) === */
.genre-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 13vw, 240px), 1fr));
    gap: clamp(10px, 1.2vw, 24px);
}

.genre-grid .movie-item {
    min-width: unset;
    max-width: unset;
    animation: fadeInUp 0.4s ease both;
}

.genre-grid .movie-item:nth-child(1) { animation-delay: 0ms; }
.genre-grid .movie-item:nth-child(2) { animation-delay: 50ms; }
.genre-grid .movie-item:nth-child(3) { animation-delay: 100ms; }
.genre-grid .movie-item:nth-child(4) { animation-delay: 150ms; }
.genre-grid .movie-item:nth-child(5) { animation-delay: 200ms; }
.genre-grid .movie-item:nth-child(n+6) { animation-delay: 250ms; }

.genre-grid .movie-item a {
    position: relative;
}

/* === Responsive === */
@media (max-width: 768px) {
    .section-header {
        border-bottom: none;
        margin-bottom: 8px;
        padding-bottom: 0;
    }

    /* Bigger poster cards — 105px was too small to tap. Bump to ~140px so
       each card is thumb-friendly while still showing ~2.5 posters per row
       (prompting horizontal scroll). */
    .movie-item {
        min-width: 140px;
        max-width: 140px;
        border-radius: 6px;
        animation: none;
    }

    .movie-item img {
        border-radius: 6px 6px 0 0;
    }

    .movie-item:hover {
        transform: none;
        box-shadow: none;
    }

    .scroll-arrow {
        display: none;
    }

    .scroll-row {
        padding: 4px 0 10px;
        gap: 10px;
        scroll-snap-type: x proximity;
        scroll-padding-left: 12px;
    }
    .scroll-row .movie-item { scroll-snap-align: start; }

    /* Keep row & section horizontal padding modest so first card sits
       close to the edge and users can visually tell there's more content. */
    .content-section { padding-left: 12px; padding-right: 12px; }

    .genre-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .genre-grid .movie-item {
        min-width: unset;
        max-width: unset;
    }

    /* Show title below poster on mobile instead of overlay */
    .movie-title-overlay {
        position: static;
        background: none;
        opacity: 1;
        padding: 6px 6px 8px;
        color: #ccc;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .remove-btn {
        opacity: 1;
        width: 22px;
        height: 22px;
        font-size: 13px;
        top: 4px;
        right: 4px;
    }

    .content-section {
        margin-bottom: 20px;
    }
}

@media (max-width: 480px) {
    .genre-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
}

/* === Fire Stick / TV Browser Support === */
body.is-firestick .movie-item {
    min-width: 200px;
    max-width: 200px;
}

body.is-firestick .movie-item a:focus {
    outline: 3px solid #e50914;
    outline-offset: -3px;
    border-radius: 8px;
    display: block;
}

body.is-firestick .movie-item a:focus .movie-title-overlay {
    opacity: 1;
}

body.is-firestick .movie-item a {
    outline: none;
}

body.is-firestick .movie-item:has(a:focus) {
    transform: scale(1.08);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(229, 9, 20, 0.3), 0 4px 28px var(--accent-glow);
    z-index: 5;
}

body.is-firestick .movie-item:hover {
    transform: none;
}

body.is-firestick .scroll-arrow {
    display: none;
}

body.is-firestick h2 {
    font-size: 1.6rem;
}

body.is-firestick .genre-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

body.is-firestick .genre-grid .movie-item a:focus {
    outline: 3px solid #e50914;
    outline-offset: -3px;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
    .movie-item:hover {
        transform: none;
    }

    .movie-item:has(a:focus-visible) {
        transform: none;
    }

    .genre-grid .movie-item {
        animation: none !important;
    }

    .skeleton {
        animation: none;
    }
}