/**
 * CiMovie - Master Smart TV Stylesheet (LG webOS TV)
 * 1920x1080 Native Canvas, 10-Foot UI/UX Pro Max Architecture
 * Standardized Cinema Dark OLED Palette, TV Safe Areas, RTL Typography
 */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800;900&family=Outfit:wght@500;600;700;800;900&display=swap');

:root {
    /* 10-Foot TV Surface Palette (Optimized for OLED & TV contrast without GPU-heavy blurs) */
    --bg-main: #080b11;
    --bg-surface: #0e131f;
    --bg-card: #141a28;
    --bg-card-hover: #1c2438;
    --bg-elevated: #1a2234;
    --bg-glass-subtle: rgba(255, 255, 255, 0.07);
    --border-subtle: rgba(255, 255, 255, 0.12);
    --border-light: rgba(255, 255, 255, 0.22);

    /* Brand & Accent Colors */
    --accent-primary: #e50914;
    --accent-primary-focus: #ff2432;
    --accent-primary-halo: rgba(229, 9, 20, 0.55);
    --accent-gold: #f59e0b;
    --accent-gold-bg: rgba(245, 158, 11, 0.18);
    --accent-badge-border: rgba(245, 158, 11, 0.45);

    /* Text Contrast Tokens (WCAG AA/AAA on #080B11) */
    --text-main: #ffffff;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    /* Focus Standard Tokens */
    --focus-border: #ffffff;
    --focus-shadow: 0 0 0 3px rgba(229, 9, 20, 0.6), 0 12px 32px rgba(0, 0, 0, 0.85);

    /* TV Safe Area Metrics (1920x1080) */
    --safe-top: 48px;
    --safe-side: 64px;
    --safe-bottom: 56px;

    /* Standardized Border Radii */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-full: 9999px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    outline: none;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
}

/* App Root Container */
#app-root {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* TV Navigation Rail (80px width) */
.android-tv-rail {
    width: 80px;
    height: 100%;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--safe-top) 0 var(--safe-bottom) 0;
    z-index: 50;
    flex-shrink: 0;
}

.rail-logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: 36px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7);
    border: 2px solid var(--border-light);
}

.rail-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rail-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    flex: 1;
}

.rail-icon-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 2.5px solid transparent;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1),
        border-color 0.2s ease,
        background-color 0.2s ease,
        color 0.2s ease;
}

.rail-icon-btn .nav-svg {
    width: 28px;
    height: 28px;
    transition: transform 0.2s ease, color 0.2s ease;
}

.rail-icon-btn.active {
    background: rgba(229, 9, 20, 0.22);
    color: #ff4d58;
    border-color: rgba(229, 9, 20, 0.5);
}

/* Main Viewport */
#main-viewport {
    flex: 1;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.view-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 var(--safe-side) var(--safe-bottom) var(--safe-side);
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.view-screen.active {
    display: block;
    opacity: 1;
}

.view-screen::-webkit-scrollbar {
    width: 6px;
}

.view-screen::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* Top Header Row (Respects Top Safe Area) */
.home-top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--safe-top) 0 20px 0;
}

.header-brand-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-badge {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: 0.5px;
}

.brand-divider {
    color: var(--accent-primary);
    font-size: 16px;
}

.brand-desc {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
}

.header-clock {
    text-align: left;
    direction: ltr;
}

.clock-time {
    font-family: 'Outfit', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
}

.clock-date {
    font-size: 14px;
    color: var(--text-muted);
    direction: rtl;
    text-align: right;
    font-weight: 500;
    margin-top: 2px;
}

/* Hero Featured Section */
.hero-container {
    position: relative;
    width: 100%;
    height: 550px;
    margin-bottom: 40px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.75);
    background: var(--bg-surface);
}

.hero-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center 20%;
    background-repeat: no-repeat;
    transition: background-image 0.4s ease-in-out;
}

.hero-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, rgba(8, 11, 17, 0.98) 0%, rgba(8, 11, 17, 0.78) 48%, rgba(8, 11, 17, 0.25) 100%),
        linear-gradient(0deg, rgba(8, 11, 17, 1) 0%, transparent 65%);
}

.hero-content {
    position: relative;
    z-index: 5;
    padding: 48px var(--safe-side) 40px 0;
    max-width: 450px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.hero-badges {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.badge {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
}

.badge.rating {
    background: rgba(245, 197, 24, 0.15);
    color: #f5c518;
    border: 1px solid rgba(245, 197, 24, 0.45);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
}

.imdb-tag {
    background: #f5c518;
    color: #000000;
    font-family: 'Outfit', sans-serif;
    font-weight: 900;
    font-size: 11px;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.5px;
    line-height: 1.2;
    display: inline-block;
}

.badge.type {
    background: rgba(229, 9, 20, 0.22);
    color: #ff666e;
    border: 1px solid rgba(229, 9, 20, 0.45);
}

.hero-title {
    font-size: 32px;
    font-weight: 800;
    line-height: 1.25;
    margin-bottom: 12px;
    color: var(--text-main);
    text-shadow: 0 4px 24px rgba(0, 0, 0, 0.9);
}

.hero-overview {
    font-size: 15px;
    line-height: 1.65;
    color: var(--text-secondary);
    margin-bottom: 24px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.hero-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

/* TV Action Buttons with Crisp SVG Support */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    background: var(--accent-primary);
    color: #ffffff;
    border: 2.5px solid transparent;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(229, 9, 20, 0.4);
    white-space: nowrap;
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1),
        border-color 0.2s ease,
        background-color 0.2s ease,
        box-shadow 0.2s ease;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 22px;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border: 2.5px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1),
        border-color 0.2s ease,
        background-color 0.2s ease,
        box-shadow 0.2s ease;
}

.btn-primary .btn-svg,
.btn-secondary .btn-svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    flex-shrink: 0;
}

/* Slider Thumbnail Strip - Expands to fill available width without ever overlapping buttons */
.hero-slider-thumbs-wrapper {
    position: absolute;
    left: var(--safe-side);
    right: 480px;
    bottom: 30px;
    z-index: 10;
    overflow: hidden;
    padding: 8px 4px;
}

.slider-thumbs-container {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 4px;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.slider-thumbs-container::-webkit-scrollbar {
    display: none;
}

.slider-thumb-card {
    width: 95px;
    height: 140px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    border: 2.5px solid transparent;
    cursor: pointer;
    flex-shrink: 0;
    background: var(--bg-card);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.slider-thumb-card.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(229, 9, 20, 0.4), 0 8px 24px rgba(0, 0, 0, 0.8);
    transform: scale(1.03);
}

.slider-thumb-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Section Rails */
.rail-section {
    margin-bottom: 44px;
}

.rail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.rail-title {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
}

.rail-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: var(--accent-primary);
    border-radius: 2px;
}

.rail-row {
    display: flex;
    gap: 24px;
    overflow-x: auto;
    /* Generous vertical padding to prevent focus-scale clipping */
    padding: 18px 8px 36px 8px;
    scroll-behavior: smooth;
}

.rail-row::-webkit-scrollbar {
    display: none;
}

/* Standardized 2:3 Media Card (220px x 330px Poster) */
.media-card {
    width: 220px;
    flex-shrink: 0;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    border: 2.5px solid transparent;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.22s cubic-bezier(0.2, 0, 0, 1),
        box-shadow 0.22s ease,
        border-color 0.22s ease,
        background-color 0.22s ease;
}

.media-card-poster-wrapper {
    width: 100%;
    height: 330px;
    position: relative;
    overflow: hidden;
    background: #090c14;
}

/* Multi-layered Deck Effect for Series / Shows */
.series-stack-layer {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-bottom: none;
    pointer-events: none;
    transition: transform 0.22s ease, opacity 0.22s ease;
}

/* Layer 1 (Furthest Back) - Lower Alpha */
.series-stack-layer.layer-back {
    top: 0px;
    width: 84%;
    height: 316px;
    opacity: 0.36;
    z-index: 1;
    filter: brightness(0.65);
}

/* Layer 2 (Middle Layer) - Medium Alpha */
.series-stack-layer.layer-mid {
    top: 7px;
    width: 92%;
    height: 316px;
    opacity: 0.65;
    z-index: 2;
    filter: brightness(0.82);
}

/* Main Front Poster */
.media-card.is-series .media-card-poster {
    position: relative;
    top: 14px;
    width: 100%;
    height: 316px;
    z-index: 3;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    background: #0f1422;
}

.media-card:not(.is-series) .media-card-poster {
    position: relative;
    top: 0;
    width: 100%;
    height: 330px;
    z-index: 2;
    overflow: hidden;
    background: #0f1422;
}

.media-card-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.media-card-info {
    padding: 14px 16px 16px 16px;
    background: var(--bg-card);
}

.media-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.35;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 40px;
}

.media-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.media-card-rating {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: #cbd5e1;
    direction: ltr;
}

.imdb-pill {
    background: #f5c518;
    color: #000000;
    font-family: 'Outfit', sans-serif;
    font-size: 11px;
    font-weight: 900;
    padding: 2px 4px;
    border-radius: 3px;
    letter-spacing: -0.3px;
    line-height: 1;
}

.media-card-year {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    font-family: 'Outfit', 'Vazirmatn', sans-serif;
}

/* Home Minimal Circular Loading Overlay */
.home-loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #080b11;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 9000;
    opacity: 1;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: all;
}

.home-loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.minimal-spinner-container {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.minimal-spinner {
    width: 72px;
    height: 72px;
    animation: spinnerRotate 1.4s linear infinite;
    transform-origin: center center;
}

.minimal-spinner .spinner-track {
    stroke: rgba(255, 255, 255, 0.1);
}

.minimal-spinner .spinner-circle {
    stroke: var(--accent-primary);
    stroke-linecap: round;
    stroke-dasharray: 90, 150;
    stroke-dashoffset: 0;
    animation: spinnerDash 1.4s ease-in-out infinite;
}

.loading-hint {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
}

@keyframes spinnerRotate {
    100% {
        transform: rotate(360deg);
    }
}

@keyframes spinnerDash {
    0% {
        stroke-dasharray: 1, 200;
        stroke-dashoffset: 0;
    }

    50% {
        stroke-dasharray: 90, 200;
        stroke-dashoffset: -35px;
    }

    100% {
        stroke-dasharray: 90, 200;
        stroke-dashoffset: -125px;
    }
}