/*
Live Access Page - Synthetic Kids
Live streaming camera grid interface
*/

/* --- CSS Variables (inherited from main site) --- */
:root {
    /* Core Colors */
    --accent-pink: #ff00a0;
    --dark-bg: #101010;
    --content-bg: rgba(24, 24, 24, 0.88);
    --light-grey: #e0e0e0;
    --medium-grey: #a0a0a0;
    --dark-grey: #555555;
    --white: #ffffff;
    --border-color: rgba(255, 255, 255, 0.1);
    --border-highlight: var(--accent-pink);

    /* Fonts */
    --font-sans: 'Poppins', sans-serif;
    --font-mono: 'Roboto Mono', monospace;

    /* Live Page Specific */
    --stream-bg: rgba(20, 20, 22, 0.9);
    --stream-border: rgba(255, 0, 160, 0.3);
    --stream-hover: rgba(255, 0, 160, 0.5);
}

/* --- Reset & Base --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--dark-bg);
    color: var(--white);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100svh;
}



/* --- Header --- */
.live-header {
    position: relative;
    z-index: 100;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(24, 24, 24, 0.9);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 10px;
    text-align: center;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-direction: column;
}

.live-logo {
    height: 40px;
    width: auto;
}

.live-title {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    color: var(--accent-pink);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-pink);
    border-radius: 50%;
    animation: pulse 2s infinite;
    box-shadow: 0 0 8px rgba(255, 0, 160, 0.7);
}

.status-text {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--accent-pink);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Truthful aggregate status, driven by real node states in JS. */
.status-indicator.has-active .status-dot {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.75);
}
.status-indicator.has-active .status-text { color: #86efac; }
.status-indicator.has-errors .status-dot {
    background: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.7);
}
.status-indicator.has-errors .status-text { color: #fbbf24; }
.status-indicator.is-offline .status-dot {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.7);
    animation: none;
}
.status-indicator.is-offline .status-text { color: #f87171; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* --- Main Content --- */
.live-content {
    position: relative;
    z-index: 10;
    padding: 30px 20px;
    min-height: calc(100svh - 140px);
}

.streams-container {
    max-width: 1400px;
    margin: 0 auto;
}

/* --- Stream Grid --- */
.stream-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    width: 100%;
    min-height: 80vh; /* Increased height for better 16:9 ratio */
}

.stream-box {
    position: relative;
    background: var(--stream-bg);
    border: 2px solid var(--stream-border);
    border-radius: 12px;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    aspect-ratio: 16/9; /* Force 16:9 aspect ratio for each video */
    width: 100%;
    contain: layout style paint;
}

.stream-box:hover {
    border-color: var(--stream-hover);
    transform: scale(1.02);
    box-shadow: 0 8px 32px rgba(255, 0, 160, 0.3);
}



.stream-frame {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Clip any UI elements that extend beyond bounds */
}

.stream-frame iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 10px;
    /* Grid view is intentionally non-interactive; use the accessible enlarge
       button for full YouTube controls. Popup CSS re-enables pointer events. */
    pointer-events: none;
backface-visibility: hidden;
}

/* Stream container styling */
.stream-box {
    /* Prevent right-click context menu on videos */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.stream-frame {
    position: relative;
}

.stream-label {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: var(--white);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    z-index: 10;
}

/* Hidden until the stream actually loads. JS adds .stream-ready to the
   parent .stream-box on the iframe's own 'load' event, so a label never
   sits on top of a black loading box. */
.stream-label {
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}

.stream-box.stream-ready .stream-label {
    opacity: 1;
    transform: translateY(0);
}

/* Failed stream: reveal the label so the location stays identifiable. */
.stream-box.stream-failed .stream-label {
    opacity: 1;
    transform: translateY(0);
}


/* --- Footer --- */
.live-footer {
    position: relative;
    z-index: 100;
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background: rgba(24, 24, 24, 0.9);
    text-align: center;
}

.footer-text {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--medium-grey);
    letter-spacing: 0.5px;
}

.highlight-brand {
    color: var(--medium-grey);
    font-weight: 600;
}

.highlight-status {
    color: var(--medium-grey);
    font-weight: 600;
}

/* --- Back Button --- */
.back-button-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
}

.back-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: linear-gradient(145deg, rgba(255, 0, 160, 0.1), rgba(255, 0, 160, 0.2));
    border: 2px solid var(--accent-pink);
    border-radius: 25px;
    color: var(--white);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.back-button:hover {
    background: linear-gradient(145deg, rgba(255, 0, 160, 0.2), rgba(255, 0, 160, 0.4));
    border-color: #ff66cc;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(255, 0, 160, 0.4);
}

.back-icon {
    font-size: 1.1rem;
}

/* Mobile adjustments to prevent overlap */
@media (max-width: 768px) {
    .back-button-container {
        position: fixed;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1001;
    }
    
    .live-header {
        padding-top: 60px; /* Add space for centered back button */
    }
}

/* --- Enhanced Loading Overlay --- */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.95), rgba(20, 20, 30, 0.95));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15; /* Higher z-index to ensure it covers everything */
    border-radius: 10px;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    border: 1px solid rgba(255, 0, 160, 0.2);
}

.loading-overlay.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    display: none !important; /* Force complete removal */
}

.loading-text {
    color: var(--accent-pink);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: loadingPulse 1.5s infinite;
    text-shadow: 0 0 10px rgba(255, 0, 160, 0.5);
    position: relative;
}



/* Enhanced loading animation */
@keyframes loadingPulse {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
        text-shadow: 0 0 10px rgba(255, 0, 160, 0.5);
    }
    50% { 
        opacity: 0.7; 
        transform: scale(1.05);
        text-shadow: 0 0 20px rgba(255, 0, 160, 0.8);
    }
}



/* Mobile loading text */
@media (max-width: 768px) {
    .loading-text {
        font-size: 0.8rem;
        letter-spacing: 1px;
    }
}

@media (max-width: 480px) {
    .loading-text {
        font-size: 0.7rem;
        letter-spacing: 0.5px;
    }
}

/* Mobile loading treatment: faster fade, no blur/GPU-heavy effects. */
@media (max-width: 768px) {
    .live-header,
    .live-footer,
    .back-button,
    .stream-box,
    .loading-overlay {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .loading-overlay {
        border-radius: 8px;
        transition: opacity 0.2s ease, visibility 0.2s ease;
    }

    .loading-text {
        font-size: 0.7rem;
        text-align: center;
        animation-duration: 1.4s;
    }
}

/* Ensure loading overlays don't interfere with touch events */
.loading-overlay.hidden,
.loading-overlay[style*="display: none"] {
    pointer-events: none !important;
    touch-action: none !important;
}

/* --- Responsive Design --- */
@media (max-width: 1200px) {
    .stream-grid {
        gap: 15px;
    }
    
    .live-content {
        padding: 20px 15px;
    }
}

@media (max-width: 768px) {
    .stream-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(5, 1fr); /* 5 rows for 9 videos in 2 columns (4+4+1) */
        gap: 10px;
        min-height: 90vh; /* Adjusted for mobile */
    }
    
    .stream-box {
        aspect-ratio: 16/9; /* Maintain 16:9 on mobile */
    }
    
    .header-content {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .live-title {
        font-size: 1rem;
    }
    
    .status-text {
        font-size: 0.8rem;
    }
    
    .stream-label {
        font-size: 0.65rem;
        padding: 3px 7px;
        /* Enhanced visibility on mobile */
        background: rgba(0, 0, 0, 0.9);
        border: 1px solid rgba(255, 0, 160, 0.4);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
        /* Better positioning for mobile */
        bottom: 6px;
        right: 6px;
        left: 6px;
        text-align: center;
        z-index: 15;
    }
    
    .back-button {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .live-content {
        padding: 15px 10px;
    }
}

@media (max-width: 480px) {
    .stream-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .stream-box {
        aspect-ratio: 16/9; /* Maintain 16:9 even on small screens */
    }
    
    .live-header {
        padding: 70px 10px 15px; /* Extra top padding for back button */
    }
    
    .live-logo {
        height: 30px;
    }
    
    .live-title {
        font-size: 0.9rem;
    }
    
    .logo-section {
        gap: 8px;
    }
    
    .stream-label {
        font-size: 0.6rem;
        padding: 4px 6px;
        background: rgba(0, 0, 0, 0.95);
        border: 2px solid rgba(255, 0, 160, 0.6);
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.8);
        /* Full width for better readability */
        bottom: 4px;
        left: 4px;
        right: 4px;
        text-align: center;
        font-weight: 700;
        letter-spacing: 0.3px;
        z-index: 20;
        /* Slight glow for better contrast */
        text-shadow: 0 0 4px rgba(255, 0, 160, 0.5);
    }
    
    .back-button {
        padding: 6px 10px;
        font-size: 0.75rem;
        gap: 6px;
    }
}

/* ================================================================ */
/* --- LOADING / ERROR STATES ------------------------------------- */
/* ================================================================ */

/* Failed stream: JS adds .is-error to the overlay after the 25s
   backstop. Without a rule the failure looked identical to loading. */
.loading-overlay.is-error .loading-text {
    color: #ff3b3b;
    text-shadow: 0 0 10px rgba(255, 59, 59, 0.5);
    animation: none;
}

/* Respect reduced-motion: stop the pulsing loading text. */
@media (prefers-reduced-motion: reduce) {
    .loading-text { animation: none !important; }
    .stream-label { transition: none !important; }
}

/* ================================================================ */
/* --- MOBILE / RESPONSIVE ---------------------------------------- */
/* ================================================================ */

/* Single column on phones. The previous 2-col x 5-row grid squeezed
   each 16:9 stream into a very short box; one column per row keeps a
   real aspect ratio and stays readable. */
@media (max-width: 560px) {
    .stream-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;      /* let rows size to content */
        grid-auto-rows: auto;
        min-height: 0;                 /* drop the 90vh stretch */
        gap: 12px;
    }

    /* Reserve correct 16:9 space so the page does not reflow as each
       stream loads (avoids layout shift on slow connections). */
    .stream-box,
    .stream-frame {
        aspect-ratio: 16 / 9;
        height: auto;
        min-height: 0;
    }

    .stream-label {
        font-size: 0.6rem;
        bottom: 6px;
        right: 6px;
        padding: 3px 6px;
    }

    .loading-text { font-size: 0.8rem; letter-spacing: 1px; }

    /* Bigger tap target -- 24px was below the ~44px touch guideline. */
    .fullscreen-icon {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Prevent horizontal overflow on small screens. */
@media (max-width: 768px) {
    html, body { max-width: 100%; overflow-x: hidden; }
    .streams-container { padding-left: 10px; padding-right: 10px; }
}

/* Landscape phones: keep the grid usable in limited height. */
@media (max-width: 900px) and (orientation: landscape) {
    .stream-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: auto;
        min-height: 0;
    }
}

/* ================================================================ */
/* --- NODE STATUS + YOUTUBE TITLE MASK ---------------------------- */
/* Loading order is an implementation detail, so the former green / */
/* yellow / orange HIGH-MEDIUM-LOW badges have been removed.         */
/*                                                                  */
/* YouTube's title is rendered inside a cross-origin iframe; CSS     */
/* cannot select or remove it. This non-interactive top-edge mask is */
/* the reliable visual workaround. It does not block player input.  */
/* ================================================================ */
.stream-box {
    border-color: var(--stream-border);
}

.loading-overlay {
    border-color: rgba(255, 0, 160, 0.3);
}

.loading-overlay::before {
    content: "NODE." attr(data-node) " :: ACQUIRING";
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    color: var(--accent-pink);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.08em;
    opacity: 0.78;
}



.stream-frame::before {
    content: "";
    position: absolute;
    z-index: 8;
    top: 0;
    left: 0;
    right: 0;
    height: 34px;
    pointer-events: none;
    background: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.96) 58%, transparent 100%);
}

/* Popup title mask: the iframe is moved out of .stream-frame when enlarged. */
.popup-stream-container::after {
    content: "";
    position: absolute;
    z-index: 3;
    top: 0;
    left: 0;
    right: 0;
    height: 42px;
    pointer-events: none;
    background: linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.98) 62%, transparent 100%);
}

/* ================================================================ */
/* --- STREAM CONTROLS + POPUP (static CSS, not injected by JS) ---- */
/* ================================================================ */
.fullscreen-icon {
    appearance: none;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 25; /* above loading overlay so user can force-load */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--accent-pink);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.78);
    color: var(--accent-pink);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease, background 0.2s ease,
                border-color 0.2s ease, transform 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
    .stream-box:hover { border-color: var(--stream-hover); transform: translateY(-2px); }
    .stream-box:hover .fullscreen-icon { opacity: 1; }
    .fullscreen-icon:hover { background: var(--accent-pink); color: #fff; }
}

@media (hover: none), (pointer: coarse) {
    .fullscreen-icon { opacity: 1; min-width: 44px; min-height: 44px; }
    .stream-box:hover { transform: none; box-shadow: none; }
}

.fullscreen-icon:focus-visible,
.popup-close-btn:focus-visible,
.loading-overlay.is-error:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Failed overlays are interactive retry targets. */
.loading-overlay.is-error {
    cursor: pointer;
}
.loading-overlay.is-error::after {
    content: "TAP TO RETRY";
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    color: #ff8a8a;
    font-family: var(--font-mono);
    font-size: 0.58rem;
    letter-spacing: 0.08em;
}

/* While enlarged, leave an intentional placeholder instead of a broken hole. */
.stream-box.is-enlarged .loading-overlay,
.stream-box.is-enlarged .stream-label,
.stream-box.is-enlarged .fullscreen-icon,
.stream-box.is-enlarged .stream-frame::before {
    display: none !important;
}
.stream-box.is-enlarged .stream-frame::after {
    content: "ENLARGED VIEW ACTIVE";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border: 1px dashed rgba(255, 0, 160, 0.4);
    color: var(--medium-grey);
    background: rgba(0, 0, 0, 0.7);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
}

body.stream-popup-open { overflow: hidden; }

.popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.popup-overlay.hidden { display: none; }
.popup-overlay.visible { opacity: 1; }
.popup-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.88); }

.popup-container {
    position: relative;
    width: min(92vw, 1200px);
    height: min(78vh, 760px);
    background: #121216;
    border: 1px solid var(--accent-pink);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 24px rgba(255, 0, 160, 0.25);
    transform: translateY(8px);
    transition: transform 0.2s ease;
}
.popup-overlay.visible .popup-container { transform: translateY(0); }

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 52px;
    padding: 8px 12px 8px 16px;
    background: #09090b;
    border-bottom: 1px solid rgba(255, 0, 160, 0.5);
}
.popup-title {
    overflow: hidden;
    color: var(--accent-pink);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}
.popup-close-btn {
    appearance: none;
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #ff6f91;
    font-size: 26px;
    cursor: pointer;
}
.popup-close-btn:hover { background: rgba(255, 0, 160, 0.14); color: #fff; }
.popup-stream-container { position: relative; height: calc(100% - 52px); }
.popup-stream-container iframe { width: 100%; height: 100%; border: 0; pointer-events: auto; }

@media (max-width: 768px) {
    .popup-container { width: 96vw; height: min(72vh, 620px); }
    .popup-title { font-size: 0.68rem; }
}

/* Keep location labels hidden until a stream genuinely settles, including
   mobile rules earlier in this file that previously forced opacity:1. */
.stream-box:not(.stream-ready):not(.stream-failed) .stream-label {
    opacity: 0;
    transform: translateY(4px);
}
