* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    background-color: #000;
    font-family: arial;
}

#loadingCanvas, #canvas {
    position: absolute;
    display: block;
    border: 0px none;
    padding: 0;
    margin: 0;
}

/* Desktop: fullscreen */
@media (min-width: 800px) {
    #loadingCanvas, #canvas {
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
    }
}

/* Mobile: fixed dimensions with aspect ratio scaling */
@media (max-width: 799px), (max-height: 799px) {
    #loadingCanvas, #canvas {
        /* Mobile dimensions: 540x960 */
        width: 540px;
        height: 960px;
        /* Center horizontally and vertically */
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        /* Scale to fit screen while maintaining aspect ratio */
        max-width: 100vw;
        max-height: 100vh;
        object-fit: contain;
    }
    
    /* If screen width is smaller than canvas width, scale to fit width */
    @media (max-width: 540px) {
        #loadingCanvas, #canvas {
            width: 100vw;
            height: calc(100vw * 960 / 540);
        }
    }
    
    /* If screen height is smaller than canvas height, scale to fit height */
    @media (max-height: 960px) {
        #loadingCanvas, #canvas {
            height: 100vh;
            width: calc(100vh * 540 / 960);
        }
    }
    
    /* For very small screens, ensure it fits */
    @media (max-width: 540px) and (max-height: 960px) {
        #loadingCanvas, #canvas {
            /* Use whichever constraint is tighter */
            width: min(100vw, calc(100vh * 540 / 960));
            height: min(100vh, calc(100vw * 960 / 540));
        }
    }
}

#canvas {
    visibility: hidden;
}

#loadingCanvas {
    visibility: visible;
}
