/* === Global: canvas never overflows viewport === */
canvas {
    max-width: 100%;
    height: auto;
}

/* === Small screens: h1 scaling === */
@media only screen and (max-width: 350px) {
    h1 {
        font-size: 32px;
    }
}

/* === Tablet & smaller (portrait): responsive start screen === */
@media only screen and (max-width: 500px) and (orientation: portrait) {
    h1 {
        font-size: 36px;
        margin-top: 12px;
    }
    #game-container {
        padding: 0 25px;
        box-sizing: border-box;
        width: 100%;
        align-items: stretch;
    }
    #canvas-wrapper {
        width: 100%;
    }
    canvas {
        width: 100%;
        height: auto;
        aspect-ratio: 720 / 480;
    }
    #start-screen-buttons {
        top: -10px;
    }
    #start-screen-buttons button {
        padding: 10px 14px;
    }
    #start-screen-buttons img {
        width: 56px;
        height: 56px;
    }
    #start-screen-buttons span {
        font-size: 16px;
        position: absolute;
        top:55px;
    }
}

/* === Landscape on small/medium screens === */
@media only screen and (max-height: 900px) and (orientation: landscape),
       only screen and (pointer: coarse) and (orientation: landscape) {

    canvas {
        width: 100%;
        height: auto;
        aspect-ratio: 720 / 480;
        display: block;
    }

    #start-screen-buttons {
        top: 12px;
        gap: 20px;
    }
    #start-screen-buttons button {
        padding: 0px 14px;
    }
    #start-screen-buttons img {
        width: 72px;
        height: 72px;
    }
    #start-screen-buttons span {
        font-size: 25px;
        position: absolute;
        top: 58px
    }
}

/* === Very short landscape (phones): canvas fits in height === */
@media only screen and (max-height: 600px) and (orientation: landscape) {
    body {
        min-height: 100dvh;
        overflow: hidden;
    }
    #navbar {
        height: 36px;
    }
    h1 {
        font-size: 60px;
        margin: 2px 0;
    }
    #canvas-wrapper {
        width: auto !important;
        height: calc(100dvh - 100px);
        max-width: 100%;
        margin-bottom: 0 !important;
    }
    #game-container {
        padding: 0 !important;
        align-items: center !important;
    }
    canvas {
        width: auto !important;
        height: 100% !important;
        aspect-ratio: 720 / 480;
    }
    #footer-inner {
        padding: 4px 16px;
        font-size: 11px;
    }
    #main-footer {
        box-shadow: none;
    }
}

/* === Game fullscreen (mobile landscape during gameplay) === */
body.game-fullscreen {
    overflow: hidden;
}
body.game-fullscreen #page-bg {
    max-width: 100%;
    width: 100%;
    border: none;
    box-shadow: none;
    background: #000;
    padding: 0;
}
body.game-fullscreen #navbar,
body.game-fullscreen #main-footer,
body.game-fullscreen h1 {
    display: none;
}
body.game-fullscreen #game-container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
    padding: 0;
}
body.game-fullscreen #canvas-wrapper {
    position: relative;
    width: min(100vw, calc(100dvh * 720 / 480));
    height: min(100dvh, calc(100vw * 480 / 720));
    line-height: 0;
    flex-shrink: 0;
}
body.game-fullscreen canvas {
    width: 100%;
    height: 100%;
    display: block;
    aspect-ratio: auto;
    border-radius: 0;
    border: none;
}
body.game-fullscreen #game-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 60;
    background: transparent;
    padding: 8px 12px 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    justify-content: center;
    pointer-events: none;
}
body.game-fullscreen #action-icons-left {
    gap: 20px;
    pointer-events: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
}
body.game-fullscreen #action-icons {
    display: none;
}
body.game-fullscreen .slider-group {
    gap: 4px;
    pointer-events: auto;
}
body.game-fullscreen .slider-group label {
    font-size: 11px;
}
body.game-fullscreen #music-slider,
body.game-fullscreen #sfx-slider {
    width: 70px;
    height: 5px;
    pointer-events: auto;
}
body.game-fullscreen #music-slider::-webkit-slider-thumb,
body.game-fullscreen #sfx-slider::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
}
body.game-fullscreen #music-slider::-moz-range-thumb,
body.game-fullscreen #sfx-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
}
body.game-fullscreen #game-toolbar button {
    pointer-events: auto;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
body.game-fullscreen #action-icons img,
body.game-fullscreen #action-icons-left img {
    width: 36px;
    height: 36px;
    filter: none;
    transition: none;
}
body.game-fullscreen #mobile-controls {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}
