/* ==================== */
/* Global Styles        */
/* ==================== */

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

/* Global Touch Scrolling FIX for scaled views */
* {
    -webkit-overflow-scrolling: touch;
}

:root {
    /* Smartest Player Color Palette */
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #141414;
    --accent-gold: #a855f7;
    --accent-blue: #00A8FF;
    --text-primary: #FFFFFF;
    --text-secondary: #B3B3B3;
    --text-muted: #666666;
    --focus-glow: rgba(168, 85, 247, 0.5);
    --overlay-bg: rgba(0, 0, 0, 0.9);

    /* Spacing */
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-xxl: 48px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.7);
    --shadow-glow: 0 0 20px var(--focus-glow);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    width: 1920px;
    height: 1080px;
}

/* ==================== */
/* Utility Classes      */
/* ==================== */

.hidden {
    display: none !important;
}

.focusable {
    transition: all var(--transition-normal);
}

.focusable:focus,
.focusable.focused {
    outline: none;
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
    z-index: 10;
}

/* ==================== */
/* Loading Overlay      */
/* ==================== */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-lg);
    z-index: 9999;
}

.loader-large {
    width: 80px;
    height: 80px;
    border: 6px solid var(--bg-tertiary);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loader {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ==================== */
/* Activation Screen    */
/* ==================== */

.activation-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #000000 0%, #1a1a2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.activation-container {
    max-width: 800px;
    padding: var(--spacing-xxl);
    text-align: center;
}

.activation-logo h1 {
    font-size: 64px;
    font-weight: 900;
    background: linear-gradient(45deg, var(--accent-gold), var(--accent-blue));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: var(--spacing-xl);
    letter-spacing: 4px;
}

.activation-content h2 {
    font-size: 36px;
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.activation-instruction {
    font-size: 20px;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.activation-url {
    background: var(--bg-tertiary);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-xl);
    border: 2px solid var(--accent-gold);
}

.url-text {
    font-size: 48px;
    font-weight: bold;
    color: var(--accent-gold);
    letter-spacing: 2px;
}

.activation-details {
    margin-bottom: var(--spacing-xl);
}

.detail-item {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    margin-bottom: var(--spacing-sm);
    border-radius: var(--radius-md);
}

.detail-label {
    font-size: 20px;
    color: var(--text-secondary);
}

.detail-value {
    font-size: 20px;
    color: var(--accent-blue);
    font-weight: bold;
}

.btn-retry {
    background: linear-gradient(135deg, var(--accent-gold), #FFA500);
    color: var(--bg-primary);
    font-size: 24px;
    font-weight: bold;
    padding: var(--spacing-md) var(--spacing-xxl);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-retry:focus,
.btn-retry.focused {
    transform: scale(1.02);

    .btn-retry:focus,
    .btn-retry.focused {
        transform: scale(1.02);
        box-shadow: 0 0 30px rgba(168, 85, 247, 0.8);
    }
}

/* ==================== */
/* Main Application     */
/* ==================== */

.main-app {
    display: flex;
    width: 100%;
    height: 100%;
}

/* ==================== */
/* Sidebar              */
/* ==================== */

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    border-right: 2px solid var(--bg-tertiary);
}

.sidebar-header {
    margin-bottom: var(--spacing-xl);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.logo-icon {
    font-size: 36px;
    color: var(--accent-gold);
}

.logo-text {
    font-size: 28px;
    font-weight: 900;
    background: linear-gradient(45deg, var(--accent-gold), var(--accent-blue));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-list {
    list-style: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    margin-bottom: var(--spacing-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    background: var(--bg-primary);
    transition: all var(--transition-normal);
}

.nav-item:hover,
.nav-item.focused {
    background: var(--bg-tertiary);
    transform: translateX(10px);
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(0, 168, 255, 0.2));
    border-left: 4px solid var(--accent-gold);
}

.nav-icon {
    font-size: 24px;
}

.nav-label {
    font-size: 20px;
    font-weight: 600;
}

/* ==================== */
/* Main Content         */
/* ==================== */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg) var(--spacing-xl);
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--bg-tertiary);
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-md);
}

.category-title {
    font-size: 36px;
    font-weight: bold;
}

.content-count {
    font-size: 18px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

.btn-icon {
    width: 56px;
    height: 56px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-icon:focus,
.btn-icon.focused {
    border-color: var(--accent-gold);
    background: rgba(168, 85, 247, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.user-name {
    font-size: 18px;
    color: var(--accent-gold);
    font-weight: bold;
}

/* ==================== */
/* Content Grid         */
/* ==================== */

/* ==================== */
/* Premium Content Grid */
/* ==================== */

#contentGrid {
    flex: 1;
    padding: var(--spacing-lg) var(--spacing-xl);
    overflow-y: auto;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-start;
    gap: 20px;
    align-content: start;
    scroll-behavior: smooth;
    padding-bottom: 250px;
    box-sizing: border-box;
}

/* Base Card Container */
.movie-card {
    position: relative;
    background: #111 !important;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    outline: none;
    border: 3px solid transparent;
    display: flex !important;
    flex-direction: column !important;
    width: 270px !important;
    /* [ADJUST] Fits exactly 5 items per row */
    height: 450px !important;
    overflow: hidden !important;
    margin-bottom: 25px;
}

/* Card Interaction: FOCUS / HOVER */
.movie-card:focus,
.movie-card.focused {
    transform: scale(1.08);
    z-index: 100;
    border-color: var(--accent-gold);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.9);
}

.movie-card .card-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: transparent;
    /* Allow dynamic background to show */
    border-radius: var(--radius-md);
}

/* Poster Area */
.poster-container {
    position: relative;
    width: 100%;
    height: 380px;
    overflow: hidden;
    background: transparent;
    flex-shrink: 0;
    transition: height 0.3s ease;
}

/* [NEW] Full-height container for items without posters */
.movie-card.no-poster .poster-container {
    height: 100% !important;
}

/* Hide fallback metadata row for items without posters to avoid redundancy */
.movie-card.no-poster .card-info {
    display: none !important;
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 1;
    transition: transform 0.5s ease;
}

.movie-card:focus .card-img {
    transform: scale(1.1);
}

/* Stylish Premium Placeholder (Used when no poster exists) */
.premium-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    text-align: center;
    z-index: 1;
    display: none;
    /* Hidden by default */
    background: inherit;
    /* Use the card's dynamic background */
    border-radius: inherit;
}

/* Show placeholder only when card has no successfully loaded poster */
.movie-card.no-poster .premium-placeholder {
    display: flex !important;
}

.premium-placeholder .placeholder-logo {
    font-size: 80px !important;
    /* Larger for 'All Card' look */
    color: var(--accent-gold);
    margin-bottom: var(--spacing-md);
    opacity: 0.9;
    text-shadow: 0 0 20px var(--focus-glow);
}

.premium-placeholder .placeholder-text {
    font-size: 28px !important;
    font-weight: 800;
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1.2;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.8);
    margin-bottom: var(--spacing-sm);
    max-width: 90%;
}

.premium-placeholder .placeholder-sub {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-gold);
    opacity: 0.7;
    letter-spacing: 3px;
    margin-top: 5px;
}

/* Cinematic Overlays */
.card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, transparent 100%);
    opacity: 0.9;
}

.movie-card:focus .card-overlay {
    height: 80%;
}

/* Floating Badges (Rating, Favorites) */
.card-badges {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 5;
}

.badge {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 800;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.badge.rating {
    background: rgba(168, 85, 247, 0.9);
    /* Purple */
    color: white;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.badge.favorite {
    background: rgba(0, 0, 0, 0.5);
    color: #ffd700;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.badge.favorite.active {
    color: #ff4d4d;
    background: rgba(255, 255, 255, 0.2);
}

/* Info Section Content (Appears over/below) */
.card-info {
    padding: var(--spacing-md);
    background: var(--bg-secondary);
}

.card-title {
    font-size: 18px;
    font-weight: 800;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.card-meta {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.meta-year {
    color: var(--accent-blue);
}

.meta-genre {
    opacity: 0.7;
}

/* Series Progress Bar */
.card-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    z-index: 10;
}

.progress-fill {
    height: 100%;
    background: var(--accent-gold);
    box-shadow: 0 0 10px var(--accent-gold);
}

.loading-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    padding: var(--spacing-xxl);
}

/* ==================== */
/* Player Overlay       */
/* ==================== */

.player-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    z-index: 500;
}

.player-container {
    width: 100%;
    height: 100%;
    position: relative;
}

#av-player {
    width: 100%;
    height: 100%;
}

.player-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95), transparent);
    padding: var(--spacing-xxl) var(--spacing-xl);
    transform: translateY(100%);
    transition: transform var(--transition-normal);
}

.player-overlay.show-controls .player-controls {
    transform: translateY(0);
}

.player-info {
    margin-bottom: var(--spacing-lg);
}

.player-info h3 {
    font-size: 32px;
    margin-bottom: var(--spacing-xs);
}

.player-info p {
    font-size: 18px;
    color: var(--text-secondary);
}

.player-progress {
    margin-bottom: var(--spacing-md);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: var(--spacing-sm);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-gold), var(--accent-blue));
    width: 0%;
    transition: width 0.3s linear;
}

.progress-time {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    color: var(--text-secondary);
}

/* ==================== */
/* Scrollbar Styling    */
/* ==================== */

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-gold);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-blue);
}

/* ==========================================================================
   MOBILE OVERRIDES FOR styles.css
   Only active when body has .is-mobile-device class (set by scaling.js)
   ========================================================================== */

body.is-mobile-device {
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important;
}

/* Disable the TV focusable scale-up effect on touch devices */
body.is-mobile-device .focusable:focus,
body.is-mobile-device .focusable.focused {
    transform: none !important;
}

/* Movie Cards: fluid sizing instead of fixed 270x450px */
body.is-mobile-device .movie-card {
    width: 100% !important;
    height: auto !important;
    margin-bottom: 8px !important;
    border-width: 2px !important;
}

body.is-mobile-device .movie-card:focus,
body.is-mobile-device .movie-card.focused {
    transform: none !important;
    border-color: var(--accent-gold) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5) !important;
}

body.is-mobile-device .poster-container {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 2/3 !important;
}

body.is-mobile-device .card-info {
    display: none !important;
}

/* Content Grid: switch from flex to CSS Grid for fluid columns */
body.is-mobile-device #contentGrid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
    gap: 10px !important;
    padding: 10px !important;
    padding-bottom: 70px !important;
    flex-wrap: nowrap !important;
}

/* Activation screen fixes */
body.is-mobile-device .activation-container {
    max-width: 100% !important;
    padding: 15px !important;
}

/* Player controls */
body.is-mobile-device .player-controls {
    padding: 10px 15px !important;
}

/* Scrollbar - thinner on mobile */
body.is-mobile-device ::-webkit-scrollbar {
    width: 3px !important;
}

/* Hide Live TV Channel Name and Badge safely without triggering the broken mobile UI */
body.hide-epg-title #currentChannelName,
body.hide-epg-title #currentChannelBadge {
    display: none !important;
}