/**
 * SafeKidsTV - Smart TV Interface Styling
 * Optimized for 10-foot viewing experience (Samsung Tizen, LG webOS, Android TV)
 * Features: Horizontal cinema carousel, fullscreen buttons, and ad-free player.
 */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
    --bg-primary: #0b0f19;
    --bg-secondary: #131b2e;
    --bg-card: rgba(26, 36, 61, 0.75);
    --bg-card-hover: rgba(40, 54, 92, 0.95);
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-purple: #8b5cf6;
    --accent-pink: #ec4899;
    --accent-amber: #f59e0b;
    --accent-emerald: #10b981;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --focus-ring: #38bdf8;
    --focus-glow: rgba(56, 189, 248, 0.7);
    --border-card: rgba(255, 255, 255, 0.08);
}

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

body {
    background: radial-gradient(circle at 50% 0%, #1e1b4b 0%, #0b0f19 75%);
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    cursor: default;
}

/* Background animated stars */
.stars-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, #ffffff, rgba(0,0,0,0)),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.7), rgba(0,0,0,0)),
        radial-gradient(1px 1px at 90px 40px, #ffffff, rgba(0,0,0,0)),
        radial-gradient(2px 2px at 160px 120px, #38bdf8, rgba(0,0,0,0)),
        radial-gradient(3px 3px at 240px 180px, #ec4899, rgba(0,0,0,0));
    background-repeat: repeat;
    background-size: 350px 350px;
    opacity: 0.35;
}

/* TV Shell Container - Fullscreen App Experience */
.tv-app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    padding: 12px 36px 14px 36px;
    box-sizing: border-box;
}

/* Hide mouse pointer cursor on TV */
html, body, button, div, a, img, span, main, section {
    cursor: none !important;
}

/* Ultra-Compact TV Header Bar (Brand + Inline Categories + Fullscreen: Single Slim Row ~48px) */
.tv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
    height: 48px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    z-index: 100;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.brand-logo {
    font-size: 1.6rem;
    filter: drop-shadow(0 2px 8px rgba(236, 72, 153, 0.4));
    animation: gentle-bounce 3s ease-in-out infinite;
}

@keyframes gentle-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.brand-title {
    font-family: 'Fredoka', cursive;
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -0.4px;
    background: linear-gradient(135deg, #38bdf8 0%, #ec4899 50%, #f59e0b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
    white-space: nowrap;
}

/* Inline Category Filter Pills - Shrinkable and Scrollable, Never Overlaps Controls */
.category-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 4px;
    scrollbar-width: none;
    flex: 1;
    min-width: 0; /* CRITICAL: Enables proper flex shrinking without overlapping siblings */
    justify-content: flex-start;
    margin-bottom: 0;
}

.category-nav::-webkit-scrollbar {
    display: none;
}

.cat-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 2px solid transparent;
    padding: 5px 14px;
    border-radius: 9999px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    height: 34px;
    box-sizing: border-box;
}

.cat-btn.active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(139, 92, 246, 0.25));
    border-color: var(--accent-cyan);
    color: #ffffff;
}

.cat-btn.tv-focused {
    transform: scale(1.06);
    border-color: #ffffff;
    background: linear-gradient(135deg, #38bdf8, #8b5cf6);
    color: #0b0f19;
    font-weight: 700;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.9);
}

.header-right-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* Compact TV Fullscreen Button */
.tv-fullscreen-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    color: #0b0f19;
    border: 2px solid #fff;
    padding: 5px 14px;
    border-radius: 9999px;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(56, 189, 248, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    height: 34px;
    box-sizing: border-box;
    white-space: nowrap;
}

.tv-fullscreen-btn:hover,
.tv-fullscreen-btn.tv-focused {
    transform: scale(1.08);
    box-shadow: 0 0 25px rgba(56, 189, 248, 0.9), 0 0 40px rgba(255, 255, 255, 0.5);
    background: #fff;
    color: #0284c7;
}

.tv-fullscreen-btn.is-fullscreen {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.6);
}

.tv-fullscreen-btn.is-fullscreen:hover,
.tv-fullscreen-btn.is-fullscreen.tv-focused {
    background: #ffffff;
    color: #059669;
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.9);
}

.tv-clock {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    height: 34px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

/* Horizontal Cinema Carousel (Dominating 85-90% of the screen!) */
.video-carousel-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.carousel-outer-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

.carousel-arrow-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.92);
    border: 3px solid rgba(56, 189, 248, 0.7);
    backdrop-filter: blur(14px);
    color: #ffffff;
    font-size: 2.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 30;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.7), 0 0 25px rgba(56, 189, 248, 0.5);
}

.carousel-arrow-btn.prev { left: -10px; }
.carousel-arrow-btn.next { right: -10px; }

.carousel-arrow-btn:hover,
.carousel-arrow-btn.tv-focused {
    background: #38bdf8;
    color: #0b0f19;
    transform: translateY(-50%) scale(1.15);
    border-color: #ffffff;
    box-shadow: 0 0 35px rgba(56, 189, 248, 0.95);
}

/* Horizontal Scroll Track */
.video-carousel-track {
    width: 100%;
    display: flex;
    flex-direction: row;
    gap: 32px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 24px 84px 28px 84px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.video-carousel-track::-webkit-scrollbar {
    display: none;
}

/* TV Video Card in Horizontal Track (Accessible Button - Front & Center!) */
.tv-card {
    flex: 0 0 430px;
    position: relative;
    background: var(--bg-card);
    border: 2px solid var(--border-card);
    border-radius: 20px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s, border-color 0.25s;
    outline: none;
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
    font-family: inherit;
    text-align: left;
    color: inherit;
    appearance: none;
    -webkit-appearance: none;
    user-select: none;
    -webkit-user-select: none;
}

.tv-card:hover,
.tv-card:focus-visible {
    border-color: rgba(255, 255, 255, 0.3);
}

/* D-Pad Focused State (Horizontal Cinema Focus) */
.tv-card:focus,
.tv-card.tv-focused {
    transform: scale(1.08) translateY(-8px);
    border-color: #38bdf8;
    background: var(--bg-card-hover);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7), 0 0 35px rgba(56, 189, 248, 0.85);
    z-index: 10;
    outline: none;
}

.tv-card:focus .play-badge-icon,
.tv-card.tv-focused .play-badge-icon {
    transform: scale(1.2);
    background: #38bdf8;
    color: #0b0f19;
}

.tv-card:focus .card-thumb,
.tv-card.tv-focused .card-thumb {
    transform: scale(1.05);
}

.card-thumb-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    overflow: hidden;
}

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

.tv-card.tv-focused .card-thumb {
    transform: scale(1.05);
}

.duration-tag {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    color: #fff;
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
}

.category-tag {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.3);
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.play-badge-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(6px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 1.5rem;
    transition: all 0.25s ease;
}

.card-info {
    padding: 16px 18px 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.35;
    color: #f1f5f9;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 6px;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.card-channel {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70%;
}

/* Samsung TV Remote Mode Helper Hint */
.samsung-mode-tip {
    margin: 10px auto 0 auto;
    padding: 6px 16px;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 9999px;
    font-size: 0.95rem;
    color: #bae6fd;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    backdrop-filter: blur(8px);
}

.tv-footer-legend,
.samsung-mode-tip {
    display: none !important;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.key-badge {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffffff;
}

.key-badge.ok { background: #0284c7; border-color: #38bdf8; }
.key-badge.fs { background: #8b5cf6; border-color: #a78bfa; }
.key-badge.back { background: #b91c1c; border-color: #ef4444; }

/* Fullscreen Video Player Modal */
.tv-player-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000000;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.tv-player-modal.active {
    display: flex;
}

#tv-video-element {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.tv-iframe-player {
    width: 100%;
    height: 100%;
    border: none;
    background: #000;
    display: none;
}

.tv-iframe-player.active {
    display: block;
}

/* Big Play Button Prompt (For TV Autoplay restrictions) */
.player-prompt-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    z-index: 105;
}

.player-prompt-play.active {
    display: flex;
}

.prompt-play-circle {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: linear-gradient(135deg, #38bdf8, #0284c7);
    border: 4px solid #ffffff;
    color: #0b0f19;
    font-size: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 0 50px rgba(56, 189, 248, 0.9);
    animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.prompt-play-label {
    font-size: 1.4rem;
    font-weight: 700;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 18px;
    border-radius: 12px;
}

.player-osd {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 40px 60px;
    pointer-events: none;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    opacity: 1;
    visibility: visible;
    background: linear-gradient(180deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0) 25%, rgba(0,0,0,0) 65%, rgba(0,0,0,0.92) 100%);
    z-index: 110;
}

.player-osd.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none !important;
}

.player-osd.hidden * {
    pointer-events: none !important;
}

.osd-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: auto;
}

.osd-video-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.osd-title {
    font-family: 'Fredoka', cursive;
    font-size: 2.2rem;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

.osd-channel {
    font-size: 1.25rem;
    color: #94a3b8;
}

.osd-control-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
}

.osd-control-btn:hover {
    background: #38bdf8;
    color: #0b0f19;
}

.osd-control-btn.danger:hover {
    background: #ef4444;
    color: #ffffff;
}

.osd-bottom {
    display: flex;
    flex-direction: column;
    gap: 16px;
    pointer-events: auto;
}

/* Horizontal Player Video Navigation Switcher */
.player-nav-buttons-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 8px;
}

.player-arrow-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 10px 24px;
    border-radius: 9999px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.player-arrow-btn:hover,
.player-arrow-btn.tv-focused {
    background: #38bdf8;
    color: #0b0f19;
    border-color: #ffffff;
    transform: scale(1.08);
}

.player-play-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #ffffff;
    color: #0b0f19;
    border: none;
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.player-play-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.8);
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 20px;
}

.time-label {
    font-size: 1.2rem;
    font-weight: 600;
    color: #cbd5e1;
    min-width: 60px;
}

.progress-bar-bg {
    flex: 1;
    height: 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 9999px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #38bdf8, #8b5cf6, #ec4899);
    border-radius: 9999px;
    transition: width 0.1s linear;
}

.osd-controls-legend {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.1rem;
    color: #94a3b8;
}

.next-up-badge {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 1.05rem;
    color: #f1f5f9;
}

/* Center Status OSD */
.osd-center-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: #ffffff;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 105;
}

.osd-center-status.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
}

/* Autoplay Overlay */
.autoplay-overlay {
    position: absolute;
    bottom: 60px;
    right: 60px;
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid #38bdf8;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8), 0 0 25px rgba(56, 189, 248, 0.5);
    padding: 24px 30px;
    border-radius: 20px;
    display: none;
    flex-direction: column;
    gap: 10px;
    max-width: 420px;
    z-index: 120;
}

.autoplay-overlay.active {
    display: flex;
}

.autoplay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.1rem;
    color: #38bdf8;
    font-weight: 700;
}

.autoplay-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.autoplay-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 9999px;
    overflow: hidden;
    margin-top: 4px;
}

.autoplay-bar-fill {
    height: 100%;
    width: 100%;
    background: #38bdf8;
    transition: width 5s linear;
}

/* Sleep Screen */
.sleep-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, #1e1b4b 0%, #05070f 100%);
    z-index: 2000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.sleep-screen.active {
    display: flex;
}

.sleep-moon {
    font-size: 7rem;
    filter: drop-shadow(0 0 40px rgba(251, 191, 36, 0.6));
    animation: gentle-sleep 4s ease-in-out infinite;
    margin-bottom: 25px;
}

@keyframes gentle-sleep {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.05) rotate(5deg); }
}

.sleep-title {
    font-family: 'Fredoka', cursive;
    font-size: 3.5rem;
    font-weight: 700;
    color: #fef08a;
    margin-bottom: 16px;
    text-shadow: 0 4px 20px rgba(251, 191, 36, 0.4);
}

.sleep-message {
    font-size: 1.8rem;
    color: #cbd5e1;
    max-width: 700px;
    line-height: 1.6;
}

/* Spinner Loader */
.spinner {
    display: inline-block;
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: spin 1s ease-in-out infinite;
}

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

.player-loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    color: #fff;
    font-size: 1.4rem;
    z-index: 105;
}

.player-loading-overlay.active {
    display: flex;
}
