@font-face {
    font-family: 'Press Start 2P';
    font-style: normal;
    font-weight: 400;
    src: url('assets/press-start-2p.woff2') format('woff2');
    font-display: swap; 
}

:root {
    --bg-color: #474747;
    --dot-color: #7c7c7c;
    /* Aspect ratio 1000/1650 */
    --aspect-ratio: 0.606; 
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none; 
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Press Start 2P', cursive;
    touch-action: none; 
}

/* --- Background --- */
.background-pattern {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-color);
    background-image: radial-gradient(var(--dot-color) 2px, transparent 1px);
    background-size: 20px 20px;
    z-index: -1;
}

/* --- Console Layout --- */
.console-wrapper {
    position: relative;
    width: auto;
    height: 95vh; 
    aspect-ratio: var(--aspect-ratio); 
    margin: 0 auto;
    box-shadow: none; 
}

@media (min-width: 769px) {
    .console-wrapper {
        height: 85vh;
        max-height: 95vh;
    }
}

@media (max-width: 768px) {
    .console-wrapper {
        width: 95vw;
        height: auto;
    }
}

.console-body img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: fill; 
}

/* --- Screen Layer --- */
.console-screen {
    position: absolute;
    background-color: #272f04;
    top: 12.12%; 
    left: 16.7%;
    width: 66.6%;
    height: 40.3%; 
    z-index: 5;
    overflow: hidden;
    /* Container Query for relative font sizing */
    container-type: size;
}

.console-screen img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: pixelated;
}

/* --- Controls Layer --- */
.controls-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 10;
}

.dpad-area {
    position: absolute;
    top: 61%; left: 8.2%;
    width: 35%; height: 20%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
}

.dpad-btn {
    background: transparent;
    border: none;
    cursor: pointer;
}

.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }

.action-area {
    position: absolute;
    top: 62%; right: 8%;
    width: 35%; height: 20%;
}

.action-btn {
    position: absolute;
    width: 40%; height: 40%;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
}

.btn-a { bottom: 35%; right: 0; }
.btn-b { bottom: 0; left: 25%; }

.options-area {
    position: absolute;
    top: 87%; left: 34%;
    width: 28%; height: 5%;
}

.opt-btn {
    position: absolute;
    width: 40%; height: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 20px;
    transform: rotate(-30deg);
}

.opt-btn.select { left: 0; bottom: 0; }
.opt-btn.start { right: 0; bottom: 0; }

/* --- UI Elements --- */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.5s;
}
.hidden { opacity: 0; pointer-events: none; }

.hidden-screen {
    display: none !important;
}

/* --- Lists (CSS Grid) --- */
#list-container {
    width: 100%;
    height: 100%;
    background-color: #272f04;
    display: grid;
    grid-template-rows: 25% 25% 25% 25%; 
    grid-template-columns: 100%;
    padding: 0;
    margin: 0;
}

.list-item-img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: fill;
    image-rendering: pixelated;
}

/* --- Screen Effects --- */
.screen-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 20; 
    pointer-events: none;
    /* SVG Pattern for perfect 64x64 grid */
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25'%3E%3Cdefs%3E%3Cpattern id='grid' width='1.5625%25' height='1.5625%25' patternUnits='objectBoundingBox'%3E%3Cpath d='M 100 0 L 0 0 0 100' fill='none' stroke='rgba(0, 20, 0, 0.5)' stroke-width='1'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='100%25' height='100%25' fill='url(%23grid)'/%3E%3C/svg%3E");
    background-size: auto;
    box-shadow: inset 0px 0px 25px rgba(0,0,0, 0.8);
    backdrop-filter: blur(0.5px);
}

/* --- Game Canvas --- */
#game-canvas {
    width: 100%;
    height: 100%;
    background-color: #272f04;
    image-rendering: pixelated;
    display: none;
}

#game-over-screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: #272f04; 
    display: none; 
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #9bbc0f;
    font-family: 'Press Start 2P', cursive;
    font-weight: normal; 
    text-shadow: 1px 1px 0 #272f04;
    z-index: 15; 
    text-transform: uppercase;
    line-height: 1.5;
}

/* Relative font sizing */
#game-over-screen p { font-size: 12cqh; margin: 0; }
#game-over-screen h2 { font-size: 12cqh; margin: 2cqh 0; }
#game-over-screen small { font-size: 12cqh; }