* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background:
        radial-gradient(1200px 600px at 12% 8%, #7c3aed 0%, transparent 46%),
        radial-gradient(1000px 560px at 88% 82%, #06b6d4 0%, transparent 46%),
        radial-gradient(820px 520px at 50% 100%, #10b981 0%, transparent 52%),
        linear-gradient(160deg, #2e1065 0%, #0e2a47 50%, #07312f 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh; /* tracks the visible viewport as the URL bar collapses */
    font-family: 'SF Pro Display', 'SF Pro Text', 'Sarabun', 'Noto Sans Thai', sans-serif;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 9/16;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 26px;
    overflow: hidden;
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow:
        0 24px 70px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#game-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    touch-action: none;
}

#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(500px 240px at 15% 15%, rgba(125, 211, 252, 0.35) 0%, transparent 65%),
        radial-gradient(420px 240px at 85% 78%, rgba(74, 222, 128, 0.28) 0%, transparent 65%),
        linear-gradient(145deg, rgba(15, 23, 42, 0.92) 0%, rgba(2, 6, 23, 0.92) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: #fff;
}

#loading-screen h1 {
    font-size: 3rem;
    color: #f8fafc;
    text-shadow: 0 10px 24px rgba(14, 165, 233, 0.4);
    margin-bottom: 1rem;
}

#loading-screen p {
    font-size: 1.2rem;
    color: #94a3b8;
}

.loader {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(148, 163, 184, 0.35);
    border-top-color: #7dd3fc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-top: 2rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Mobile touch controls overlay */
#touch-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: none;
    justify-content: space-between;
    padding: 0 20px;
    pointer-events: none;
}

@media (max-width: 768px) {
    #game-container {
        max-width: 100%;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
        /* Keep the canvas clear of notches / rounded corners */
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
        box-sizing: border-box;
    }

    #touch-controls {
        display: flex;
    }
}

@media (display-mode: standalone) {
    /* Installed PWA: fill the screen edge to edge */
    #game-container {
        border-radius: 0;
        border: none;
    }
}
