/* Touch devices in portrait mode */

@media (orientation: portrait) and (hover: none) and (pointer: coarse) {
    .orientation-warning {
        display: flex;
    }
}


/* Smartphone landscape mode */

@media only screen and (max-width: 900px) and (orientation: landscape) {
    body {
        min-height: 100dvh;
    }

    h1 {
        display: none;
    }

    .orientation-warning {
        display: none;
    }

    .game-container {
        width: min(100vw, calc(100dvh * 1.5), 720px);
    }

    #fullscreen {
        position: relative;
        width: fit-content;
    }

    .sound-controls {
        position: absolute;
        top: 0;
        left: calc(100% + 8px);
        right: auto;

        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .sound-controls button:not(.fullscreen-button) {
        width: 68px;
        height: 28px;
        padding: 2px 5px;
        font-size: 10px;
    }

    .sound-controls button.fullscreen-button {
        width: 68px;
        min-width: 28px;
        height: 28px;
        padding: 0;
        font-size: 14px;
    }

    .game-over-overlay,
    .winner-overlay {
        padding-bottom: 32px;
    }

    .game-over-overlay .result-button,
    .winner-overlay .result-button {
        width: min(45%, 320px);
        font-size: 18px;
        padding: 8px 18px;
    }
}


/* Small landscape screens */

@media only screen and (max-height: 480px) {
    h1 {
        display: none;
    }

    .game-container {
        width: min(100vw, calc(100dvh * 1.5), 720px);
    }

    .impressum-page {
        padding: 16px 10px;
    }

    .impressum-card {
        width: 100%;
    }

    .impressum-card .menu-button {
        font-size: 16px;
        padding: 8px 16px;
    }
}

/* Very small landscape screens, e.g. iPhone SE */

@media only screen and (max-height: 400px) and (orientation: landscape) {

    .game-over-overlay,
    .winner-overlay {
        gap: 7px;
        padding-bottom: 10px;
    }

    .game-over-overlay .result-button,
    .winner-overlay .result-button {
        width: min(42%, 280px);
        padding: 5px 12px;
        font-size: 14px;
        line-height: 1.1;
        border-width: 2px;
        border-radius: 12px;
    }

    .game-over-overlay .small-button,
    .winner-overlay .small-button {
        padding: 4px 10px;
        font-size: 11px;
        border-width: 2px;
        border-radius: 10px;
    }
}

/* Touch devices and tablet emulation */

/* Touch devices */

@media (hover: none) and (pointer: coarse) {
    .mobile-controls:not(.hidden) {
        display: flex;
    }

    .controls-info {
        display: none;
    }
}

/* Wide screens with limited height */

@media only screen and (max-height: 650px) and (orientation: landscape) {
    body {
        min-height: 100dvh;
    }

    h1 {
        display: none;
    }

    .game-container {
        width: min(100vw, calc(100dvh * 1.5), 720px);
    }

    #fullscreen {
        position: relative;
        width: fit-content;
    }

    .sound-controls {
        position: absolute;
        top: 0;
        left: calc(100% + 8px);
        right: auto;

        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .sound-controls button:not(.fullscreen-button) {
        width: 68px;
        height: 28px;
        padding: 2px 5px;
        font-size: 10px;
    }

    .sound-controls button.fullscreen-button {
        width: 68px;
        min-width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .start-screen {
        gap: 8px;
        padding-bottom: 18px;
    }

    .menu-button {
        font-size: 22px;
        padding: 8px 22px;
    }

    .small-button {
        font-size: 14px;
        padding: 6px 14px;
    }
}

/* Native fullscreen and mobile fallback */

#fullscreen:fullscreen,
#fullscreen:-webkit-full-screen,
#fullscreen.fullscreen-fallback {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: black;
}

#fullscreen:fullscreen,
#fullscreen:-webkit-full-screen {
    display: flex;
    align-items: center;
    justify-content: center;
}

#fullscreen.fullscreen-fallback {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.fullscreen-active {
    overflow: hidden;
}

#fullscreen:fullscreen .game-container,
#fullscreen:-webkit-full-screen .game-container,
#fullscreen.fullscreen-fallback .game-container {
    width: min(100vw, calc(100dvh * 1.5));
    height: min(100dvh, calc(100vw / 1.5));
    max-width: none;
    max-height: none;
    margin: 0;
}

#fullscreen:fullscreen canvas,
#fullscreen:-webkit-full-screen canvas,
#fullscreen.fullscreen-fallback canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#fullscreen:fullscreen .controls-info,
#fullscreen:-webkit-full-screen .controls-info,
#fullscreen.fullscreen-fallback .controls-info {
    display: none;
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
    .mobile-controls:not(.hidden) {
        position: fixed;
        left: 0;
        right: 0;
        bottom: max(16px, env(safe-area-inset-bottom));
        width: 100vw;

        display: flex;
        justify-content: space-between;

        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        box-sizing: border-box;

        z-index: 10000;
        pointer-events: none;
    }

    .mobile-controls-left,
    .mobile-controls-right {
        pointer-events: auto;
    }
}

/* Sound controls inside fullscreen mode */

@media only screen and (orientation: landscape) {
    #fullscreen:fullscreen .sound-controls {
        position: absolute;
        top: 8px;
        right: 8px;
        left: auto;

        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 4px;

        z-index: 9999;
    }
}