body {
    margin: 0;
    padding: 0;
    background-color: #1a1a2e;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: white;
    /* Prevent pull-to-refresh & rubber-band scroll on iOS */
    overscroll-behavior: none;
    touch-action: none;
}

/* ── Intro Screen ── */
#intro-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    background-image: url('BACKGROUND.svg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
}

#intro-logo {
    width: 50%;
    max-width: 800px;
    height: auto;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
    animation: logoBob 3s ease-in-out infinite;
}

@keyframes logoBob {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-14px);
    }
}

#play-btn {
    padding: 18px 48px;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: #ffffff;
    background-color: #409250;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(64, 146, 80, 0.5);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    /* Prevent double-tap zoom on iOS */
    touch-action: manipulation;
}

#play-btn:hover {
    background-color: #4eac61;
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 10px 28px rgba(64, 146, 80, 0.65);
}

#play-btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 3px 10px rgba(64, 146, 80, 0.4);
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(to bottom, #87CEEB 0%, #E0F6FF 100%);
}

#gameCanvas {
    display: block;
}

#ui-layer {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 8px;
    pointer-events: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
}

#ui-layer h2 {
    margin: 0;
    font-size: 28px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    color: #fff;
    letter-spacing: 1px;
}

/* ── Portrait Warning Overlay ── */
#portrait-overlay {
    display: none;
    /* hidden by default, media query shows it */
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #1a1a2e;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #fff;
}

#portrait-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

#rotate-icon {
    font-size: 5rem;
    animation: rotateHint 2s ease-in-out infinite;
    display: block;
}

@keyframes rotateHint {

    0%,
    100% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(90deg);
    }
}

#portrait-message p {
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1.6;
    margin: 0;
    opacity: 0.9;
}

/* Show portrait overlay on mobile in portrait mode */
@media (pointer: coarse) and (orientation: portrait) {
    #portrait-overlay {
        display: flex;
    }
}

/* ── Mobile D-pad (touch devices only) ── */
#dpad {
    display: none;
    /* hidden by default */
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* children will re-enable */
    z-index: 50;
}

/* Left touch zone — left half of screen minus jump btn area */
#dpad-left {
    position: absolute;
    left: 0;
    top: 0;
    width: 45%;
    height: 100%;
    pointer-events: auto;
    /* Uncomment below for debug visibility: */
    /* background: rgba(255,0,0,0.1); */
}

/* Right touch zone — right half, avoiding jump btn */
#dpad-right {
    position: absolute;
    right: 120px;
    top: 0;
    width: calc(55% - 120px);
    height: 100%;
    pointer-events: auto;
}

/* Jump button — bottom-right corner */
#dpad-jump {
    position: absolute;
    bottom: 30px;
    right: 24px;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
    background: rgba(64, 146, 80, 0.85);
    border: 3px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    touch-action: manipulation;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: transform 0.1s ease, background 0.1s ease;
}

#dpad-jump:active {
    transform: scale(0.92);
    background: rgba(78, 172, 97, 0.95);
}

/* Show D-pad only on touch-capable devices */
@media (pointer: coarse) {
    #dpad {
        display: block;
    }

    /* Scale down UI layer text on small landscape screens */
    #ui-layer {
        top: 8px;
        left: 8px;
        padding: 6px 12px;
    }

    #ui-layer h2 {
        font-size: 16px;
    }
}

/* ── Intro responsive adjustments ── */
/* Tablet landscape */
@media (max-width: 1024px) {
    #intro-logo {
        width: 60%;
    }

    #play-btn {
        font-size: 1.2rem;
        padding: 15px 38px;
    }
}

/* Small phone landscape */
@media (pointer: coarse) and (max-height: 450px) {
    #intro-logo {
        width: 55vw;
    }

    #intro-screen {
        gap: 20px;
    }

    #play-btn {
        font-size: 1rem;
        padding: 10px 28px;
    }

    #dpad-jump {
        width: 72px;
        height: 72px;
        font-size: 1.6rem;
        bottom: 14px;
        right: 14px;
    }
}


/* ── Intro Screen ── */
#intro-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    background-image: url('BACKGROUND.svg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
}

#intro-logo {
    width: 50%;
    max-width: 800px;
    height: auto;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
    animation: logoBob 3s ease-in-out infinite;
}

@keyframes logoBob {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-14px);
    }
}

#play-btn {
    padding: 18px 48px;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: #ffffff;
    background-color: #409250;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(64, 146, 80, 0.5);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

#play-btn:hover {
    background-color: #4eac61;
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 10px 28px rgba(64, 146, 80, 0.65);
}

#play-btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 3px 10px rgba(64, 146, 80, 0.4);
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(to bottom, #87CEEB 0%, #E0F6FF 100%);
}

#gameCanvas {
    display: block;
}

#ui-layer {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 8px;
    pointer-events: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
}

#ui-layer h2 {
    margin: 0;
    font-size: 28px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    color: #fff;
    letter-spacing: 1px;
}