:root {
    --bg-dark: #0a0a0c;
    --bg-panel: #141418;
    --bg-card: #1a1a20;
    --accent: #e50914;
    --accent-glow: rgba(229, 9, 20, 0.3);
    --accent-dark: #b81d24;
    --text-main: #f0f0ec;
    --text-muted: #6b6b6b;
    --border: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);
    --radius: 10px;
    --transition: 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ── Header ── */
.app-header {
    background: linear-gradient(180deg, rgba(10, 10, 12, 0.98), rgba(10, 10, 12, 0.85));
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0 4vw;
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    max-width: 1600px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent);
    flex-shrink: 0;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-main);
}

.logo h1 span {
    color: var(--accent);
}

/* ── Search ── */
.search-form {
    position: relative;
    width: 100%;
    max-width: 360px;
}

.search-form .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-form input {
    width: 100%;
    padding: 10px 16px 10px 42px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: 50px;
    color: var(--text-main);
    font-size: 0.875rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition), background var(--transition);
}

.search-form input::placeholder {
    color: var(--text-muted);
}

.search-form input:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.08);
}

/* ── Main Content ── */
.main-content {
    padding: 36px 4vw 60px;
    max-width: 1600px;
    margin: 0 auto;
}

.section-title {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 20px;
    letter-spacing: -0.3px;
}

/* ── Movie Grid ── */
.movie-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
}

@media (min-width: 768px) {
    .movie-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

.movie-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    background-color: var(--bg-card);
    aspect-ratio: 2 / 3;
}

.movie-card:hover {
    transform: scale(1.06) translateY(-4px);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border-light);
    z-index: 2;
}

.movie-poster {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: filter 0.3s;
}

.movie-card:hover .movie-poster {
    filter: brightness(0.65);
}

.movie-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 32px 12px 12px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.95));
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.3s, transform 0.3s;
}

.movie-card:hover .movie-info {
    opacity: 1;
    transform: translateY(0);
}

.movie-title {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.movie-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.movie-rating {
    color: #fbbf24;
    font-weight: 600;
}

.play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 48px;
    height: 48px;
    background: rgba(229, 9, 20, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.play-icon svg {
    margin-left: 3px;
}

.movie-card:hover .play-icon {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* ── Modal ── */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 1;
    transition: opacity 0.3s;
}

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

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 1100px;
    background: var(--bg-panel);
    border-radius: 14px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--border);
    overflow: hidden;
    z-index: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.modal-movie-title {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.modal-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.source-selector {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 3px;
}

.source-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    font-family: inherit;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.source-btn:hover {
    color: var(--text-main);
}

.source-btn.active {
    background: var(--accent);
    color: #fff;
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.close-btn:hover {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

/* ── Native Player ── */
.player-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
}

.player-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
}

.player-loader {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: #000;
    z-index: 2;
    transition: opacity 0.4s;
}

.player-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.player-loader p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── Loading ── */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 0.8s ease-in-out infinite;
    margin: 40px auto;
}

.iframe-loader .spinner {
    margin: 0;
}

.spinner.hidden {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fade-in 0.4s ease forwards;
}

/* ── Error ── */
.error-msg {
    color: #888;
    font-size: 1rem;
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 0;
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .header-inner {
        flex-direction: column;
        height: auto;
        padding: 12px 0;
        gap: 10px;
    }
    
    .search-form {
        max-width: 100%;
    }
    
    .modal {
        padding: 0;
    }
    
    .modal-content {
        border-radius: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .player-container {
        flex: 1;
        aspect-ratio: unset;
    }
    
    .modal-header {
        flex-wrap: wrap;
    }
}

/* TV Controls */
.modal-title-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.tv-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}
.tv-controls.hidden {
    display: none;
}
.tv-select {
    padding: 6px 12px;
    border-radius: 6px;
    background: #2a2a2a;
    color: white;
    border: 1px solid #444;
    font-family: inherit;
    font-size: 0.9rem;
}
.tv-btn {
    padding: 6px 16px;
    border-radius: 6px;
    background: #E50914;
    color: white;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}
.tv-btn:hover {
    background: #b80710;
}
.media-type-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    backdrop-filter: blur(4px);
    z-index: 2;
}

/* Make sure iframe fills container correctly */
#iframe-player {
    display: block;
    width: 100%;
    height: 100%;
    border: none;
    background: #000;
}
#iframe-player.hidden {
    display: none !important;
}

.tv-controls {
    flex-wrap: wrap;
}
