@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Space+Mono:wght@400;700&display=swap');

:root {
    --bg-color: #0d1117;
    --text-color: #c9d1d9;
    --npm-red: #cb3837;
    --npm-dark: #8c2323;
    --success: #2ea043;
    --warning: #d29922;
    --accent: #58a6ff;
    --panel-bg: rgba(22, 27, 34, 0.9);
    --grid-bg: #161b22;
    --tile-empty: #0d1117;
    --tile-wall: #30363d;
    --tile-trap: rgba(203, 56, 55, 0.2);
    --font-heading: 'Press Start 2P', monospace;
    --font-body: 'Space Mono', monospace;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    user-select: none;
}

.app-container {
    width: 100%;
    max-width: 900px;
    height: 100%;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--tile-wall);
    margin-bottom: 20px;
}

h1 {
    font-family: var(--font-heading);
    color: var(--npm-red);
    font-size: 1.2rem;
    text-transform: uppercase;
    text-shadow: 2px 2px 0 var(--npm-dark);
}

.stats-panel {
    display: flex;
    gap: 20px;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--accent);
}

.screen {
    background: var(--panel-bg);
    border: 2px solid var(--tile-wall);
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.screen h2 {
    font-family: var(--font-heading);
    color: var(--text-color);
    margin-bottom: 15px;
}

.text-danger { color: var(--npm-red) !important; text-shadow: 2px 2px 0 var(--npm-dark); }
.text-success { color: var(--success) !important; }

.legend {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    text-align: left;
    background: #000;
    padding: 20px;
    border-radius: 4px;
    margin: 20px 0;
}

.btn {
    background: var(--npm-red);
    color: #fff;
    font-family: var(--font-heading);
    border: none;
    padding: 15px 30px;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 4px 0 var(--npm-dark);
    transition: all 0.1s;
}

.btn:hover {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--npm-dark);
}

.btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.btn-secondary {
    background: var(--tile-wall);
    box-shadow: 0 4px 0 #161b22;
}
.btn-secondary:hover { box-shadow: 0 2px 0 #161b22; }

.hidden { display: none !important; }

/* Game Layout */
.game-layout {
    display: flex;
    gap: 20px;
    width: 100%;
    height: 100%;
    align-items: flex-start;
}

.sidebar {
    width: 250px;
    background: #000;
    border: 1px solid var(--tile-wall);
    border-radius: 4px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    text-align: left;
}

.sidebar h3 {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--accent);
    border-bottom: 1px solid var(--tile-wall);
    padding-bottom: 10px;
}

#inventoryList {
    list-style: none;
    flex-grow: 1;
}

#inventoryList li {
    padding: 5px 0;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.empty-inv { color: #666; font-style: italic; }

.status-feed {
    height: 100px;
    overflow-y: hidden;
    font-size: 0.8rem;
    color: #8b949e;
    border-top: 1px solid var(--tile-wall);
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.status-feed p {
    margin: 2px 0;
    animation: fadeIn 0.3s forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.grid-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--grid-bg);
    border-radius: 8px;
    padding: 20px;
    border: 2px solid var(--tile-wall);
    position: relative;
}

#gridWrap {
    position: relative;
}

#gameGrid {
    display: grid;
    gap: 2px;
    background: var(--tile-wall);
    padding: 2px;
}

.cell {
    width: 40px;
    height: 40px;
    background: var(--tile-empty);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
}

.cell.wall { background: var(--tile-wall); }
.cell.trap { background: var(--tile-trap); }
.cell.door { background: rgba(203, 56, 55, 0.4); border: 1px solid var(--npm-red); }
.cell.door::after {
    content: '⛔';
    font-size: 20px;
}

/* Entities */
.player {
    font-size: 28px;
    z-index: 10;
    transition: all 0.1s ease;
}
.key { font-size: 20px; }
.exit { font-size: 28px; animation: pulse 1s infinite alternate; }
.force { font-size: 20px; animation: glow 1s infinite alternate; }

@keyframes pulse {
    0% { transform: scale(0.9); }
    100% { transform: scale(1.1); }
}

@keyframes glow {
    0% { filter: drop-shadow(0 0 2px var(--accent)); }
    100% { filter: drop-shadow(0 0 8px var(--accent)); }
}

/* Mobile Controls */
.mobile-controls {
    display: none;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 10px;
    margin-top: 20px;
    width: 100%;
}

.dpad-btn {
    background: var(--tile-wall);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
}

.dpad-btn:active { background: var(--accent); }

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: var(--grid-bg);
    border: 2px solid var(--accent);
    padding: 30px;
    border-radius: 8px;
    min-width: 300px;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 10px; right: 15px;
    font-size: 24px;
    color: #fff;
    cursor: pointer;
}

#leaderboardList {
    list-style: none;
    margin-top: 20px;
}
#leaderboardList li {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--tile-wall);
}

@media (max-width: 768px) {
    .game-layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: 120px;
        flex-direction: row;
    }
    .status-feed {
        border-top: none;
        border-left: 1px solid var(--tile-wall);
        padding-top: 0;
        padding-left: 10px;
        height: 100%;
    }
    #inventoryList {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
    }
    .mobile-controls {
        display: grid;
    }
    .cell { width: 30px; height: 30px; font-size: 18px; }
}
