@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;700;900&display=swap');

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

body {
    background-color: #120b05;
    background-image: radial-gradient(circle at center, #2a1a0d 0%, #120b05 100%);
    color: #f0e0d0;
    font-family: 'Outfit', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

#app-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
    box-sizing: border-box;
    padding: 10px;
    gap: 15px;
    position: relative;
}

#game-container {
    position: relative;
    width: 95vw;
    height: calc(95vw * 0.75); /* 4:3 Aspect Ratio */
    max-width: calc(95vh * 1.3333);
    max-height: 95vh;
    box-shadow: 0 1.8cqw 6cqw rgba(0, 0, 0, 0.9), inset 0 0 2.5cqw rgba(0,0,0,0.5);
    background-color: #2c1a0b;
    border: 0.75cqw solid #4a2c11;
    border-radius: 1.5cqw;
    overflow: hidden;
    container-type: size;
    container-name: game;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#hud {
    position: absolute;
    top: 2cqw;
    left: 2cqw;
    right: 2cqw;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 10;
}

.hud-item {
    background: rgba(40, 20, 10, 0.85);
    padding: 1.5cqw 3cqw;
    border-radius: 4cqw;
    font-size: 2.75cqw;
    font-weight: 900;
    border: 0.25cqw solid #734a26;
    text-shadow: 0.25cqw 0.25cqw 0 #000, 0 0 1cqw rgba(255, 204, 0, 0.5);
    box-shadow: 0 0.5cqw 1.25cqw rgba(0, 0, 0, 0.6), inset 0 0 1.25cqw rgba(115, 74, 38, 0.5);
    color: #ffcc00;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    gap: 1cqw;
}

.hud-label {
    color: #f2e3d5;
    font-weight: 700;
    text-shadow: 0.25cqw 0.25cqw 0 #000;
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(18, 11, 5, 0.9);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 20;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#overlay-title {
    font-size: 9cqw;
    color: #ffaa00;
    text-transform: uppercase;
    letter-spacing: 0.75cqw;
    text-shadow: 0.5cqw 0.5cqw 0 #5c3a1e, 0 0 3cqw rgba(255, 170, 0, 0.6);
    margin-bottom: 2.5cqw;
    font-weight: 900;
}

#overlay-desc {
    font-size: 2.75cqw;
    line-height: 1.6;
    margin-bottom: 5cqw;
    color: #f2e3d5;
    text-shadow: 0.25cqw 0.25cqw 0.5cqw #000;
    font-weight: 400;
    max-width: 80%;
}

#overlay-instruction {
    font-size: 3.25cqw;
    font-weight: 700;
    animation: pulse 1.5s infinite;
    color: #fff;
    background: linear-gradient(135deg, #a6531c, #d97529);
    padding: 2cqw 4.5cqw;
    border-radius: 1.5cqw;
    border: 0.25cqw solid #ffaa00;
    box-shadow: 0 1cqw 2.5cqw rgba(217, 117, 41, 0.4), inset 0 0.25cqw 0.5cqw rgba(255,255,255,0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

#score-display {
    margin-top: 5cqw;
    font-size: 3.5cqw;
    color: #ffcc00;
    text-shadow: 0.35cqw 0.35cqw 0 #000;
    background: rgba(0, 0, 0, 0.6);
    padding: 3cqw 5cqw;
    border-radius: 2cqw;
    border: 0.25cqw solid #ff9900;
    box-shadow: 0 1.25cqw 3.75cqw rgba(0,0,0,0.8);
    font-weight: 700;
    display: flex;
    flex-direction: column;
    gap: 1.5cqw;
}

/* Mobile Controls Styling */
#mobile-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    z-index: 30;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 75px);
    grid-template-rows: repeat(3, 75px);
    gap: 8px;
    width: 240px;
    height: 240px;
    background: rgba(40, 20, 10, 0.4);
    padding: 8px;
    border-radius: 50%;
    border: 2px solid rgba(115, 74, 38, 0.3);
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6), 0 8px 25px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
}

.dpad-btn {
    background: linear-gradient(135deg, rgba(80, 40, 20, 0.85), rgba(40, 20, 10, 0.95));
    color: #ffcc00;
    border: 2px solid #734a26;
    border-radius: 50%;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.1);
    transition: transform 0.05s ease, background 0.05s ease, border-color 0.05s ease, box-shadow 0.05s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.dpad-btn:active, .dpad-btn.active {
    background: linear-gradient(135deg, #d97529, #a6531c);
    color: #fff;
    border-color: #ffaa00;
    box-shadow: 0 0 12px rgba(255, 170, 0, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.2);
    transform: scale(0.92);
}

/* Position D-Pad buttons in the grid */
.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }

/* Responsive Layout Logic */
@media (orientation: portrait) {
    #app-wrapper {
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    #mobile-controls {
        margin-top: 10px;
        margin-bottom: 10px;
    }
}

@media (orientation: landscape) {
    #app-wrapper {
        flex-direction: row;
        justify-content: center;
        align-items: center;
    }
    #mobile-controls {
        position: absolute;
        bottom: 20px;
        left: 20px;
    }
    .dpad {
        grid-template-columns: repeat(3, 56px);
        grid-template-rows: repeat(3, 56px);
        width: 180px;
        height: 180px;
        padding: 6px;
        gap: 6px;
        background: rgba(40, 20, 10, 0.55);
    }
    .dpad-btn {
        font-size: 20px;
    }
}

@media (max-width: 400px) and (orientation: portrait) {
    .dpad {
        grid-template-columns: repeat(3, 62px);
        grid-template-rows: repeat(3, 62px);
        width: 200px;
        height: 200px;
        padding: 6px;
        gap: 6px;
    }
    .dpad-btn {
        font-size: 22px;
    }
}

/* Hide controls on standard desktop pointer configurations */
@media (hover: hover) and (pointer: fine) {
    #mobile-controls {
        display: none !important;
    }
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 1cqw 2.5cqw rgba(217, 117, 41, 0.4); }
    50% { transform: scale(1.05); box-shadow: 0 1.5cqw 3.75cqw rgba(217, 117, 41, 0.6); }
    100% { transform: scale(1); box-shadow: 0 1cqw 2.5cqw rgba(217, 117, 41, 0.4); }
}
