body {
    margin: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    background: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
    font-family: sans-serif;
    color: white;
    overflow: hidden; /* Prevents scrolling on mobile */
    touch-action: none; /* Prevents browser-native zoom/pan */
}

#game-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    box-sizing: border-box;
	border-radius: 15px; /* Matches the rounded aesthetic */
    overflow: hidden;
    z-index: 1;
}

/* Rounded corners for any external image assets (like in editor or gallery) */
.collectable-preview, img[src*="images/"] {
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; /* Ensures the full 800x600 game fits the screen */
    border: 2px solid #444;
    background: #222;
}

.ui {
    position: absolute;
    top: 10px;
    left: 10px;
    pointer-events: none;
}

.header-controls {
    position: absolute;
    top: env(safe-area-inset-top, 0px);
    right: calc(5px + env(safe-area-inset-right, 0px));
    display: flex;
    gap: 0px;
    z-index: 1001;
    pointer-events: auto;
}

.inventory-header-btn {
    position: relative;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(46, 83, 218, 0.2);
    border: 1px solid #2E53DA;
    border-radius: 5px;
    padding: 5px;
}

.inventory-header-btn:hover {
    background: rgba(46, 83, 218, 0.3);
}

.inventory-icon-img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.inventory-icon-fallback {
    font-size: 20px;
    line-height: 20px;
    display: block;
}

.inventory-count {
    position: absolute;
    top: -2px;
    right: -6px;
    background: #2E53DA;
    color: #000;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    padding: 0 4px;
    border: 1px solid #000;
    cursor: pointer;
    pointer-events: auto;
    z-index: 10;
}

.header-btn {
    padding: 8px;
    background: transparent;
    color: white;
    border: none;
    border-radius: 5px;
    font-family: monospace;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
}

.header-icon {
    width: 35px;
    height: 35px;
    object-fit: contain;
    vertical-align: middle;
    display: block;
}

/* ============================================
   DIFFICULTY BADGE
   ============================================ */

#levelset-difficulty-badge {
    position: absolute;
    top: 60px;
    right: 10px;
    z-index: 1000;
    pointer-events: none;
}

.difficulty-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
}

.difficulty-beginner { background: #20962B; color: #ddd; }
.difficulty-easy { background: #006400; color: #ddd; }
.difficulty-medium { background: #4A90E2; color: #111; }
.difficulty-hard { background: #ffaa00; color: #111; }
.difficulty-expert { background: #aa1010; color: #ddd; }

/* ============================================
   GAME FRAME - Simple grey border
   ============================================ */

.game-frame {
    position: relative;
    display: inline-block;
    border: none;
    border-radius: 15px; /* Match game-container rounded corners */
    box-shadow: 0 0 0 1.5px #333; /* Consistent border appearance with increased spread */
}

/* ============================================
   TOUCH CONTROLS
   Shown when body.touch-controls-active (TouchControlsPolicy: auto / on / off).
   Hides #mobile-controls when inactive — beats mobile route inline display:flex.
   ============================================ */

body:not(.touch-controls-active) #mobile-controls {
    display: none !important;
}

.touch-controls-keyboard-hint {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    max-width: min(90vw, 360px);
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.88);
    color: #fff;
    border: 1px solid #2e53da;
    border-radius: 8px;
    z-index: 100000;
    font: 14px/1.4 system-ui, -apple-system, sans-serif;
    text-align: center;
    pointer-events: none;
    box-sizing: border-box;
}

/* Embedded shell (game.php / quickstart.php): .touch-controls-embedded matches config_mobile.php
   sizing; scoped so id+body rules do not override dedicated mobile pages unexpectedly. */

#mobile-controls.touch-controls-embedded {
    display: none;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding-top: 0;
    padding-right: calc(20px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(20px + env(safe-area-inset-left, 0px));
    box-sizing: border-box;
    pointer-events: none;
    z-index: 1000;
    align-items: flex-end;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group {
    display: flex;
    gap: 20px;
    pointer-events: auto;
    margin-right: 0;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:first-child {
    display: grid;
    grid-template-columns: repeat(2, 100px);
    grid-template-rows: repeat(2, auto);
    justify-items: center;
    align-items: end;
    column-gap: 20px;
    row-gap: 12px;
    transform: translateX(-5vw);
}

body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-throw {
    grid-column: 1 / 3;
    grid-row: 1;
    width: 100px;
    height: 100px;
    font-size: 18px;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-left {
    grid-column: 1;
    grid-row: 2;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-right {
    grid-column: 2;
    grid-row: 2;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group-vertical {
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:last-child {
    margin-right: 10.5vw;
    transform: translateX(-5vw);
}

body.touch-controls-active #mobile-controls.touch-controls-embedded .touch-btn {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
    user-select: none;
    -webkit-user-select: none;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded .touch-btn:active {
    background: rgba(0, 255, 204, 0.4);
    border-color: #4a7c9e;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-jump,
body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-down {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.2);
    border-color: #ccc;
}

body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-down {
    font-size: 22px;
}

@media screen and (max-height: 430px) and (orientation: landscape) {
    body.touch-controls-active #mobile-controls.touch-controls-embedded {
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group {
        gap: 10px;
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:first-child {
        grid-template-columns: repeat(2, 72px);
        column-gap: 10px;
        row-gap: 8px;
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group-vertical {
        gap: 8px;
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .touch-btn,
    body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-jump,
    body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-down {
        width: 72px;
        height: 72px;
        font-size: 24px;
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded #btn-throw {
        width: 72px;
        height: 72px;
        font-size: 14px;
    }
}

@media screen and (min-aspect-ratio: 21/9) {
    body.touch-controls-active #mobile-controls.touch-controls-embedded {
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group {
        gap: 12px;
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:first-child {
        column-gap: 12px;
        row-gap: 8px;
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group-vertical {
        gap: 8px;
    }
    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:last-child {
        margin-right: 4.2vw;
    }
}

/* Tablet (both orientations): thumb reach at screen corners; ~2cm from physical viewport edge.
   (min-width + min-height) avoids treating large phones in landscape as tablets. */
@media screen and (min-width: 768px) and (min-height: 768px) {
    body.touch-controls-active #mobile-controls.touch-controls-embedded {
        position: fixed;
        left: calc(2cm + env(safe-area-inset-left, 0px));
        right: calc(2cm + env(safe-area-inset-right, 0px));
        width: auto;
        bottom: 0;
        padding-left: 0;
        padding-right: 0;
        padding-top: 0;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
        z-index: 10050;
    }

    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:first-child {
        transform: none;
    }

    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:last-child {
        margin-right: 0;
        transform: none;
    }
}

/* Desktop windowed or fullscreen: anchor bar to the layout viewport (browser tab/window), not the
   letterboxed #game-container. ~2cm horizontal inset. Applies with Automatic (when controls show)
   or On; fine pointer + hover excludes typical phones (hover: none). */
@media (hover: hover) and (pointer: fine) {
    body.touch-controls-active #mobile-controls.touch-controls-embedded {
        position: fixed;
        left: calc(2cm + env(safe-area-inset-left, 0px));
        right: calc(2cm + env(safe-area-inset-right, 0px));
        width: auto;
        bottom: 0;
        padding-left: 0;
        padding-right: 0;
        padding-top: 0;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
        z-index: 10050;
    }

    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:first-child {
        transform: none;
    }

    body.touch-controls-active #mobile-controls.touch-controls-embedded .button-group:last-child {
        margin-right: 0;
        transform: none;
    }
}

/* ============================================
   START SCREEN ANIMATIONS
   ============================================ */

@keyframes playerFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}