* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

body {
    background-color: #0d1117;
    color: #c9d1d9;
    font-family: 'Press Start 2P', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
}

#game-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    max-width: 1200px;
    height: 100%;
    max-height: 800px;
    background-color: transparent;
    padding: 20px;
    gap: 20px;
    align-items: stretch;
}

#play-box-wrapper {
    position: relative;
    flex: 1 1 0%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #161b22;
    border: 5px solid #238636;
    box-shadow: 0 0 20px rgba(35, 134, 54, 0.5);
    aspect-ratio: 1 / 1;
    padding: 20px;
}

#info-panel {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px;
    background-color: #161b22;
    border: 5px solid #238636;
    box-shadow: 0 0 20px rgba(35, 134, 54, 0.5);
    position: relative;
}

#gameCanvas {
    background-color: #0d1117;
    border: 0;
    width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
}

#game-header {
    margin-bottom: 20px;
    flex-shrink: 0;
}

h1 {
    font-size: 1.5rem;
    margin: 0;
    color: #58a6ff;
    text-shadow: 2px 2px #000;
}

#status-bar {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    margin-bottom: 20px; 
    font-size: 1rem;
    gap: 10px;
    flex-shrink: 0;
}

#current-rule {
    font-size: 1.1rem;
    color: #f0f6fc;
    line-height: 1.5;
    flex-grow: 1; /* Allow to take up space */
    display: flex;
    align-items: center;
    justify-content: center;
}

#message-container {
    width: 100%;
    flex-shrink: 0;
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
}

#message {
    font-size: 1.1rem;
    font-weight: bold;
    min-height: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

#correct-numbers-container {
    transition: opacity 0.3s ease-in-out;
    min-height: 1.5em; /* Reserve space */
}

#correct-numbers-container.hidden {
    opacity: 0;
}

canvas {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* --- Touch Controls --- */
.touch-only {
    display: none; /* Hidden by default on desktop */
}

body.touch-enabled .touch-only {
    display: flex; /* Becomes visible on touch devices */
    gap: 10px;
    justify-content: center;
    width: 100%;
    margin-bottom: 20px;
}

#powerup-touch-controls {
    flex-direction: column;
}

#powerup-touch-controls .button.hidden {
    display: none;
}

.touch-button {
    padding: 8px 12px;
    font-size: 0.8rem;
    flex-grow: 1;
}


/* --- Popup styles --- */
#popup-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 10;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-align: center;
}

#popup-box {
    background-color: #161b22;
    border: 2px solid #238636;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(35, 134, 54, 0.5);
    max-width: 80%;
}

#popup-message {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #f0f6fc;
    line-height: 1.5;
}

.button {
    font-family: 'Press Start 2P', monospace;
    background-color: #238636;
    color: #c9d1d9;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
    margin-top: 15px; /* Add margin to all buttons */
}

.button:hover { background-color: #26a241; }
.button:active { background-color: #1f6f2f; }

#difficulty-selection {
    display: flex;
    gap: 10px;
    justify-content: center;
}


/* --- Character Selector --- */
#character-selector {
    padding: 10px;
    margin-bottom: 10px;
}

#character-selector h4 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: #58a6ff;
}

.char-display-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

#char-canvas {
    background-color: #0d1117;
    border: 2px solid #238636;
    width: 100px;
    height: 100px;
}

.char-nav-button {
    font-family: 'Press Start 2P', monospace;
    background-color: #238636;
    color: #c9d1d9;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px 15px;
    transition: background-color 0.2s;
}
.char-nav-button:hover { background-color: #26a241; }
.char-nav-button:active { background-color: #1f6f2f; }


/* --- Powerup & Pause Screens --- */
.powerup-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 95%;
    height: 95%;
    background-color: rgba(13, 17, 23, 0.95);
    z-index: 20;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 5px solid #238636;
    padding: 20px;
    text-align: center;
}

.powerup-screen h2 { color: #58a6ff; margin-top: 0; }

.powerup-screen ul {
    list-style: none;
    padding: 0;
    margin: 20px 0;
    width: 90%;
    max-height: 70%;
    overflow-y: auto;
    font-size: 0.9rem;
}

.powerup-screen li {
    padding: 10px;
    margin: 5px 0;
    border: 2px solid transparent;
    transition: all 0.2s;
    line-height: 1.4;
}

/* Make list items with actions look clickable */
.powerup-screen li[data-powerup-id],
.powerup-screen li[data-action="confirm-activation"] {
    cursor: pointer;
}


.powerup-screen li.highlighted {
    border-color: #238636;
    background-color: rgba(35, 134, 54, 0.2);
}

.powerup-screen li.selected { color: #238636; font-weight: bold; }
.powerup-screen li.active { color: #238636; font-weight: bold; }
.powerup-screen li.used { color: #444; text-decoration: line-through; }
.powerup-screen .unpause-text { margin-top: 20px; font-size: 0.8rem; color: #888; }

/* --- Enemy Info Grid --- */
#enemy-info-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    padding: 0 10px;
    max-height: 70%;
    overflow-y: auto;
    font-size: 0.9rem;
    text-align: left;
}

.enemy-info-entry {
    display: flex;
    align-items: center;
    gap: 15px;
}

.enemy-info-img {
    width: 50px;
    height: 50px;
    image-rendering: pixelated;
    flex-shrink: 0;
}

.enemy-info-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.enemy-info-name {
    margin: 0 0 5px 0;
    color: #58a6ff;
}

.enemy-info-desc {
    margin: 0;
    line-height: 1.4;
}

/* --- Achievements --- */
#achievements-container {
    margin-top: 20px;
    border-top: 2px solid #238636;
    padding-top: 15px;
    width: 100%;
}

#achievements-container h3 {
    margin: 0 0 15px 0;
    color: #58a6ff;
}

#achievements-container ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.8rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    text-align: center;
}

#achievements-container li {
    padding: 8px;
    border: 1px solid #333;
    border-radius: 4px;
}

#achievements-container li.unlocked {
    color: #238636;
    font-weight: bold;
    border-color: #238636;
}

#achievements-container li.locked {
    color: #444;
}


/* --- Utility classes --- */
.hidden { display: none; }
.visible { display: flex; }

/* --- Mobile & Portrait Mode Adjustments --- */
@media screen and (max-width: 900px), screen and (max-height: 500px) {
    body {
        overflow-y: auto; 
        height: auto;
        /* Add some padding to prevent content from touching screen edges */
        padding: 10px;
    }

    #game-container {
        /* --- RADICAL CHANGE: Abandoning flexbox for a simple block layout --- */
        display: block; 
        height: auto;
        max-height: none;
        width: 100%;
        /* Constrain width on tablets and center the container */
        max-width: 500px;
        margin: 0 auto;
    }

    #play-box-wrapper {
        /* No flex properties needed, it's a simple block now */
        width: 100%;
        /* Add space between the game board and the info panel below it */
        margin-bottom: 20px; 
    }
    
    #info-panel {
        /* This is also a simple block now */
        width: 100%;
        min-height: 300px; 
        /* The flex layout for its CHILDREN is still needed for internal alignment */
        display: flex;
        flex-direction: column;
    }

    #current-rule {
        /* This fix is still required for the info-panel's internal layout */
        flex-grow: 0;
        min-height: 80px;
    }
    
    #message-container {
       /* Puts the message back in the normal document flow at the bottom */
       position: relative;
       bottom: auto;
       left: auto;
       right: auto;
       padding: 10px 0;
    }
}