:root {
    --bg-color: #2c3e50;
    --game-bg: #000;
    --accent-color: #e74c3c;
    --text-color: #ecf0f1;
    --canvas-size: 400px;
}

* {
    box-sizing: border-box;
    touch-action: manipulation;
    /* Prevent double-tap zoom */
    user-select: none;
    /* Prevent text selection on mobile tap */
    -webkit-user-select: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Patrick Hand', cursive;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
}

#game-title {
    font-size: 3rem;
    margin: 0 0 25px 0;
    color: #F1C40F;
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.3);
    letter-spacing: 2px;
}

/* Game Container */
#game-container {
    position: relative;
    width: var(--canvas-size);
    height: var(--canvas-size);
    background-color: var(--game-bg);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    margin-bottom: 20px;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    /* Crisp pixel art */
}

/* UI Layer Overlays */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas by default */
}

.hidden {
    display: none !important;
}

/* Text Box */
#text-box {
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 100%;
    height: 80px;
    background: rgba(0, 0, 0, 0.85);
    border-top: 2px solid white;
    padding: 10px;
    display: flex;
    flex-direction: column;
    pointer-events: auto;
}

#text-box p {
    margin: 0;
    font-size: 16px;
    line-height: 1.4;
    color: white;
}

.continue-hint {
    align-self: flex-end;
    margin-top: auto;
    font-size: 12px;
    animation: bounce 1s infinite;
}

@keyframes bounce {

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

    50% {
        transform: translateY(3px);
    }
}

/* Inventory Screen */
#inventory-screen {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    background: rgba(20, 20, 30, 0.95);
    border: 2px solid white;
    padding: 15px;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
}

#inventory-screen h2 {
    margin-top: 0;
    text-align: center;
    border-bottom: 1px solid #555;
    padding-bottom: 0px;
}

#inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 10px;
    margin: 0px 0;
}

.inv-slot {
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid #555;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.inv-slot.selected {
    border-color: yellow;
    background: rgba(255, 255, 0, 0.2);
}

.inventory-controls {
    margin-top: auto;
    display: flex;
    justify-content: space-around;
}

button {
    background: #444;
    color: white;
    border: 1px solid #666;
    padding: 8px 16px;
    font-family: 'Patrick Hand', cursive;
    cursor: pointer;
}

button:active {
    background: #666;
}

/* Virtual Gamepad */
#gamepad-container {
    width: 100%;
    max-width: 400px;
    display: flex;
    justify-content: space-between;
    padding: 10px 20px;
}

#dpad {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.dpad-middle {
    display: flex;
}

.dpad-btn {
    width: 50px;
    height: 50px;
    background: #444;
    border: none;
    border-radius: 8px;
    color: #aaa;
    font-size: 24px;
    /* Increased size for better visibility */
    margin: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 0 #222;
    font-family: Arial, sans-serif;
    /* Use a system font for arrows to ensure consistency */
    line-height: 1;
    font-variant-emoji: text;
    /* Prevent emoji rendering on mobile */
    -webkit-font-variant-emoji: text;
}

.dpad-btn:active,
.dpad-btn.pressed {
    transform: translateY(4px);
    box-shadow: none;
    background: #666;
}

.dpad-center {
    width: 50px;
    height: 50px;
}

#action-buttons {
    display: flex;
    align-items: center;
    gap: 15px;
}

.action-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    font-size: 24px;
    font-weight: bold;
    box-shadow: 0 4px 0 #222;
}

#btn-x {
    background-color: #e74c3c;
    /* Red */
    color: white;
    margin-bottom: -20px;
}

#btn-z {
    background-color: #f1c40f;
    /* Yellow */
    color: #333;
    margin-top: -20px;
}

.action-btn:active,
.action-btn.pressed {
    transform: translateY(4px);
    box-shadow: none;
    filter: brightness(0.9);
}

.action-btn.interactable {
    animation: glow-pulse 1s ease-in-out infinite;
    box-shadow: 0 4px 0 #222, 0 0 20px rgba(231, 76, 60, 0.8);
}

.action-btn.interactable:active,
.action-btn.interactable.pressed {
    animation: none;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.6);
}

@keyframes glow-pulse {
    0%, 100% {
        box-shadow: 0 4px 0 #222, 0 0 15px rgba(231, 76, 60, 0.6);
    }
    50% {
        box-shadow: 0 4px 0 #222, 0 0 25px rgba(231, 76, 60, 1);
    }
}

/* Mobile Adjustments */
@media (max-height: 700px) {
    :root {
        --canvas-size: 300px;
        /* Shrink game for small screens */
    }
}

/* Small Width Screens (iPhone SE, etc.) */
@media (max-width: 400px) {
    :root {
        --canvas-size: 280px;
    }

    body {
        justify-content: flex-start;
        padding-top: 10px;
    }

    #game-title {
        font-size: 2rem;
        margin: 0 0 10px 0;
    }

    #game-container {
        margin-bottom: 10px;
    }

    #gamepad-container {
        max-width: 100%;
        padding: 5px 10px;
    }

    .dpad-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
        margin: 1px;
    }

    .dpad-center {
        width: 40px;
        height: 40px;
    }

    .action-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    #action-buttons {
        gap: 10px;
    }

    #btn-a {
        margin-bottom: -15px;
    }

    #btn-b {
        margin-top: -15px;
    }

    #text-box {
        height: 70px;
        padding: 8px;
    }

    #text-box p {
        font-size: 14px;
    }

    #inventory-screen {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        padding: 10px;
    }

    #inventory-screen h2 {
        font-size: 1.3rem;
    }

    #inventory-grid {
        gap: 8px;
    }

    button {
        padding: 6px 12px;
        font-size: 14px;
    }
}