/**
 * 🔧 VIEWPORT-SAFE POSITIONING COMPONENTS
 * 🌟 LEGENDARY UI Design System - Viewport Management
 *
 * Reusable CSS components to prevent content from appearing below viewport.
 * Based on successful fixes applied across all Aria's Games.
 *
 * USAGE: Include in game stylesheets:
 * <link rel="stylesheet" href="../assets/css/shared/viewport-safe.css">
 */

/* 🎯 CORE VIEWPORT SAFETY BASE */
.viewport-safe-base {
    /* Reset scroll behavior for all games */
    scroll-behavior: smooth;
    overflow-x: hidden;
}

.viewport-safe-body {
    /* Critical positioning fixes */
    margin: 0 !important;
    padding-top: 20px !important;
    padding-bottom: 0 !important;
    overflow-x: hidden;
    box-sizing: border-box;

    /* Force content to start at viewport top */
    display: block !important;
    align-items: flex-start !important;
    justify-content: center !important;
}

/* 🎮 GAME SCREEN POSITIONING */
.viewport-safe-screen {
    /* Ensure screens appear at viewport top */
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;

    /* Override any grid system positioning */
    align-self: flex-start !important;
    justify-self: center !important;
}

.viewport-safe-screen.active {
    /* Active screen specific positioning */
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;

    /* Prevent any transform-based centering */
    transform: none !important;
}

/* 🚫 CENTERING PREVENTION */
.viewport-safe-no-center > * {
    /* Prevent child elements from pushing content down */
    margin-top: 0 !important;
    transform: none !important;
}

/* 🎯 SPECIFIC COMPONENT CLASSES */

/* Navigation Screens - Used by difficulty/grade selection */
.viewport-safe-nav-screen {
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
    min-height: auto !important;

    /* Ensure content flows from top */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 20px;
}

/* Game Content Areas - Used by quiz/game areas */
.viewport-safe-game-content {
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;

    /* Flexible content positioning */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 20px;
}

/* Settings/Menu Screens - Used by options and settings */
.viewport-safe-menu {
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;

    /* Menu-specific positioning */
    display: block;
    padding: 20px;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}

/* 📱 RESPONSIVE VIEWPORT SAFETY */
@media (max-width: 768px) {
    .viewport-safe-nav-screen,
    .viewport-safe-game-content,
    .viewport-safe-menu {
        /* Mobile-specific viewport safety */
        padding-top: 10px;
        min-height: auto;
    }

    .viewport-safe-body {
        padding-top: 10px !important;
    }
}

@media (max-width: 480px) {
    .viewport-safe-nav-screen,
    .viewport-safe-game-content,
    .viewport-safe-menu {
        /* Small mobile viewport safety */
        padding-top: 5px;
    }

    .viewport-safe-body {
        padding-top: 5px !important;
    }
}

/* ⚡ CRITICAL: Screen Visibility Management System */
/* ESSENTIAL FIX: Prevents inactive screens from occupying layout space */
/* Problem: Inactive screens were taking 1653px+ space, pushing content below viewport */

/* UNIVERSAL PATTERN: Hide inactive screens completely from layout */
.viewport-safe-screen-hidden {
    display: none !important;
    /* Alternative for fade transitions: */
    /*
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    top: -9999px !important;
    left: -9999px !important;
    */
}

/* Show only active screen in layout */
.viewport-safe-screen-visible {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
}

/* For flex-based screens */
.viewport-safe-screen-flex {
    display: flex !important;
    flex-direction: column !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
}

/* Standard screen management classes - apply to all .screen elements */
.viewport-safe-managed-screen {
    /* Hide by default */
    display: none;
    position: relative;
    /* Smooth transitions when combined with active state */
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.viewport-safe-managed-screen.active {
    /* Show when active */
    display: block;
    opacity: 1;
    transform: none;

    /* Ensure proper positioning */
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
}

/* For games using flexbox layouts on screens */
.viewport-safe-managed-screen-flex {
    display: none;
    position: relative;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.viewport-safe-managed-screen-flex.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: none;

    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
}

/* 🔧 EMERGENCY OVERRIDES */
/* Use these classes when default positioning is extremely problematic */

.viewport-safe-emergency-reset {
    /* Nuclear option - resets everything */
    position: static !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: auto !important;
    margin: 0 !important;
    padding-top: 20px !important;
    transform: none !important;

    /* Force block layout */
    display: block !important;
    align-items: flex-start !important;
    justify-content: center !important;
    min-height: auto !important;
}

.viewport-safe-force-visible {
    /* Ensures content is always in viewport */
    position: relative !important;
    top: 0 !important;
    z-index: 1000 !important;
    margin-top: 0 !important;
    margin-bottom: 20px;
}

/* 🌟 LEGENDARY UI INTEGRATION */
/* Classes that work with existing LEGENDARY UI components */

.legendary-screen.viewport-safe {
    /* Integration with LEGENDARY UI screens */
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
}

.legendary-modal.viewport-safe {
    /* Modal positioning safety */
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 2000 !important;
    max-height: 90vh;
    overflow-y: auto;
}

.legendary-card.viewport-safe {
    /* Card component safety */
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 20px;
}

/* 🎯 UTILITY CLASSES */

.scroll-to-top-trigger {
    /* Apply to elements that should trigger scroll reset */
    cursor: pointer;
}

.viewport-debug {
    /* Debugging class - shows element positioning */
    outline: 2px solid red !important;
    background: rgba(255, 0, 0, 0.1) !important;
}

.viewport-debug::before {
    content: "VIEWPORT DEBUG: " attr(class);
    position: absolute;
    top: -20px;
    left: 0;
    font-size: 10px;
    color: red;
    background: white;
    padding: 2px 4px;
    border: 1px solid red;
    z-index: 10000;
}