/**
 * BEAMY 16:10 Aspect Ratio Global Styles
 * Ensures consistent 16:10 aspect ratio across ALL pages
 */

/* ========================================
   CRITICAL: Base HTML/Body Setup
   ======================================== */

* {
    box-sizing: border-box;
}

html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #000; /* Black letterboxing */
}

/* ========================================
   16:10 ASPECT RATIO CONTAINER
   ======================================== */

#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    background-color: #ffffff;
    overflow: hidden;
}

/* Responsive 16:10 enforcement */
@media (min-aspect-ratio: 16/10) {
    /* Wider than 16:10 - limit width */
    #app-container {
        width: calc(100vh * 1.6);
        height: 100vh;
    }
}

@media (max-aspect-ratio: 16/10) {
    /* Taller than 16:10 - limit height */
    #app-container {
        width: 100vw;
        height: calc(100vw / 1.6);
    }
}

@media (aspect-ratio: 16/10) {
    /* Exact 16:10 */
    #app-container {
        width: 100vw;
        height: 100vh;
    }
}

/* ========================================
   CONTENT WRAPPER - Scrollable Content
   ======================================== */

#content-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Custom scrollbar for content wrapper */
#content-wrapper::-webkit-scrollbar {
    width: 8px;
}

#content-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#content-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#content-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ========================================
   MAIN CONTENT AREA
   ======================================== */

main {
    width: 100%;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* ========================================
   PREVENT CONTENT OVERFLOW
   ======================================== */

img, video, iframe, canvas {
    max-width: 100%;
    height: auto;
}

/* Prevent horizontal scroll on any element */
* {
    max-width: 100%;
}

/* ========================================
   TABLET-SPECIFIC STYLES
   ======================================== */

body.tablet-page {
    touch-action: none;
    -ms-touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.tablet-page #content-wrapper {
    touch-action: pan-y;
}

.tablet-page .category-container,
.tablet-page .items-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    touch-action: pan-y;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Prevent double-tap zoom */
.tablet-page * {
    touch-action: manipulation;
}

@media (max-width: 1400px) and (min-width: 600px) {
    .tablet-page {
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* ========================================
   DEVICE-SPECIFIC OPTIMIZATIONS
   ======================================== */

/* Smartphones in portrait */
@media (max-width: 767px) and (orientation: portrait) {
    #app-container {
        width: 100vw;
        height: calc(100vw / 1.6);
    }
}

/* Smartphones in landscape */
@media (max-width: 767px) and (orientation: landscape) {
    #app-container {
        width: calc(100vh * 1.6);
        height: 100vh;
    }
}

/* Tablets in portrait */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    #app-container {
        width: 100vw;
        height: calc(100vw / 1.6);
    }
}

/* Tablets in landscape */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    #app-container {
        width: calc(100vh * 1.6);
        height: 100vh;
    }
}

/* Desktop */
@media (min-width: 1025px) {
    #app-container {
        /* Let the aspect-ratio media queries handle it */
    }
}

/* ========================================
   ORIENTATION CHANGE HANDLING
   ======================================== */

@media (orientation: portrait) {
    body {
        background-color: #000;
    }
}

@media (orientation: landscape) {
    body {
        background-color: #000;
    }
}

/* ========================================
   PRINT STYLES (maintain ratio)
   ======================================== */

@media print {
    html, body {
        width: 100%;
        height: 100%;
        overflow: visible;
    }
    
    #app-container {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 10;
    }
    
    #content-wrapper {
        overflow: visible;
    }
}

/* ========================================
   ACCESSIBILITY & FALLBACKS
   ======================================== */

/* Ensure content is visible if CSS fails */
body {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========================================
   DEBUG MODE (remove in production)
   ======================================== */

/* Uncomment to see aspect ratio boundaries */
/*
#app-container {
    border: 3px solid red;
}

#content-wrapper {
    border: 3px solid blue;
}

main {
    border: 3px solid green;
}
*/