html,
body {
    margin: 0;
    padding: 0;
}
    
body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: black;
    font-family: 'Lucida Console', Monaco, monospace;
    transition: background 0.3s ease-in-out;
}

body.windowed-mode {
    background: white;
    overflow-y: auto;
    height: auto;
}

* {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Wrapper */
#wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    overflow: hidden;
    transition: all 0.3s ease-in-out;
}

/* Fullscreen State */
#wrapper.fullscreen {
    width: 100vw;
    height: 100vh;
}

#wrapper.fullscreen .frame {
    display: none;
}

/* Windowed State */
#wrapper.windowed {
    width: 516px;
    height: 810px;
}

#wrapper.windowed .frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: block;
}

#wrapper.windowed #frame-back {
    z-index: 0;
}

#wrapper.windowed #frame-front {
    z-index: 2;
}

/* Canvas */
.emscripten { 
    padding-right: 0; 
    margin-left: auto; 
    margin-right: auto; 
    display: block; 
    z-index: 1;

    position: relative;
    top: 0px;
    left: 0px;
    margin: 0px;
    border: 0;
    overflow: hidden;
    display: block;
    image-rendering: optimizeSpeed;
    image-rendering: -moz-crisp-edges;
    image-rendering: -o-crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    -ms-interpolation-mode: nearest-neighbor;
}

div.emscripten { text-align: center; }

#wrapper.windowed canvas.emscripten {
    width: 424px;
    height: 733px;
    margin-left: 2px;
    margin-top: 0px;
}


canvas.emscripten {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* UI */
#ui {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
}

#resize-btn {
    background: rgba(0,0,0,0.5);
    border: 1px solid white;
    color: white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    outline: none;
    transition: background 0.2s;
}

#resize-btn:hover {
    background: rgba(0,0,0,0.8);
}

/* Info */
#info {
    position: fixed;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    width: 300px;
    font-family: inherit;
    color: black;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    z-index: 10;
}

body.windowed-mode #info {
    opacity: 1;
    pointer-events: auto;
}

#info h1 {
    font-size: 24px;
    margin: 0 0 10px 0;
    text-transform: uppercase;
}

#info h2 {
    font-size: 14px;
    margin: 0 0 20px 0;
    font-weight: normal;
    color: #666;
}

#info p {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 10px;
    color: #333;
}

/* Longer Info */
#longer-info {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
    width: 100%;
    max-width: 690px;
    margin: 0 auto;
    padding-bottom: 50px;
    text-align: center;
}

/* Desktop Windowed Mode Logic */
body.windowed-mode #wrapper.windowed {
    position: relative;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 40px;
    margin-bottom: 20px;
}

body.windowed-mode #info {
    opacity: 1;
    pointer-events: auto;
}

body.windowed-mode #longer-info {
    opacity: 1;
    pointer-events: auto;
    position: relative;
}

@media (max-width: 800px) {
    body.windowed-mode {
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
    }

    body.windowed-mode #wrapper.windowed {
        position: relative;
        top: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-width: 500px;
        height: auto; 
        margin: 20px auto;
    }

    /* Use relative positioning for the background frame to establish height without aspect-ratio */
    #wrapper.windowed #frame-back {
        position: relative;
        width: 100%;
        height: auto;
    }

    #wrapper.windowed canvas.emscripten {
        width: 81.7%;
        height: 89.8%;
        margin: 0;
    }

    body.windowed-mode #info {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        width: 100%;
        max-width: 500px;
        margin: 20px auto;
        padding: 0 20px 40px 20px;
    }

    body.windowed-mode #longer-info {
        max-width: 500px;
        padding: 0 20px 40px 20px;
    }
}

