:root {
    --font-secondary: 'Press Start 2P', cursive;
    --font-scale: 10px;
    --width: 100%;
}

body {
    margin: auto;
    padding: 20px;
    background-image: url('https://i.ibb.co/2Y1f5Zg2/pokemon-wallpaper.jpg');
    background-size: cover;
    background-position: center bottom;
    background-attachment: fixed;
    image-rendering: pixelated;
    font-family: var(--font-secondary);
    font-size: var(--font-scale);
    max-width: var(--width);
    line-height: 1.7;
}

#transition-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 20;
}

#transition-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#reading-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 600px;
    background-color: white;
    border: 4px solid black;
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.2);
    padding: 2rem;
    z-index: 100;
    display: none;
    text-align: center;
    color: black;
}

#reading-window.visible {
    display: block;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: translate(-50%, -40%);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

#reading-window h2 {
    margin-top: 0;
    font-size: 24px;
    margin-bottom: 20px;
    text-transform: uppercase;
    border-bottom: 4px solid black;
    display: inline-block;
    padding-bottom: 5px;
}

#reading-window p {
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    line-height: 1.6;
    font-weight: bold;
}

#close-btn {
    margin-top: 20px;
    background: black;
    color: white;
    border: none;
    padding: 10px 20px;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    cursor: pointer;
    transition: transform 0.1s;
}

#close-btn:hover {
    transform: scale(1.05);
}

#close-btn:active {
    transform: scale(0.95);
}

.hidden {
    display: none !important;
}

#dev-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background: rgba(0, 255, 0, 0.9);
    color: black;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    font-family: 'Press Start 2P', cursive;
    font-size: 8px;
    border-bottom: 3px solid black;
}

body.editor-active #dev-tooltip {
    display: flex;
}

.rooftop-label {
    position: absolute;
    color: white;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 8px;
    pointer-events: none;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 #000;
    opacity: 0.9;
    z-index: 10;
    transform: translate(-50%, -100%);
    white-space: nowrap;
}

#desktop-controls-hud {
    display: none;
}


/* ═══════════════════════════════════════════
   MOBILE  (≤ 768px)
   Restore original GBA handheld specifications.
═══════════════════════════════════════════ */
@media (max-width: 768px) {
    body {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding-top: 20px;
        min-height: 100vh;
        overflow-y: auto;
    }

    #game-container {
        position: relative;
        width: 100%;
        height: auto;
        display: flex;
        justify-content: center;
        background: transparent;
    }

    canvas {
        display: block;
        width: 320px !important;
        height: 320px !important;
        image-rendering: pixelated;
        image-rendering: crisp-edges;
        background-color: #000;
        z-index: 1;
    }

    .gba-body {
        background: radial-gradient(circle at 50% 30%, #7d63c4, #634ba1, #4b367c);
        padding: 40px 12px 44px 12px;
        /* Original padding */
        border-radius: 20px 20px 40px 40px;
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 340px;
        /* Restored to 340px */
        max-width: 95vw;
        margin: 0 auto;
        border-bottom: 8px solid #3a2a60;
        position: relative;
        overflow: hidden;
        box-shadow: 0 15px 25px rgba(0, 0, 0, 0.6);
    }

    .screen {
        background-color: #222;
        padding: 20px 20px 30px 20px;
        /* Original padding */
        border-radius: 10px 10px 30px 10px;
        margin-bottom: 30px;
        width: 100%;
        display: flex;
        justify-content: center;
        position: relative;
        box-sizing: border-box;
        /* Restored to border-box */
        overflow: hidden;
        /* Stop map bleed */
    }

    .screen::after {
        content: 'GAME BOY';
        position: absolute;
        bottom: 8px;
        left: 0;
        right: 0;
        text-align: center;
        font-family: sans-serif;
        font-weight: bold;
        font-style: italic;
        font-size: 10px;
        color: #555;
        letter-spacing: 1px;
        pointer-events: none;
    }

    .screen::before {
        content: '';
        position: absolute;
        inset: 0;
        border-radius: 10px 10px 30px 10px;
        box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
        pointer-events: none;
        z-index: 5;
    }

    .controls {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 12px;
        width: 100%;
        padding: 0;
    }

    .controls-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0 36px 0 24px;
    }

    .d-pad {
        position: relative;
        width: 110px;
        height: 110px;
        flex: 0 0 auto;
    }

    .d-btn {
        position: absolute;
        width: 36px;
        height: 36px;
        background: #2a2a2a;
        border: none;
        outline: none;
        cursor: pointer;
        background-image: radial-gradient(circle, #333 10%, #222 90%);
        touch-action: manipulation;
        color: rgba(255, 255, 255, 0.35);
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
    }

    .d-btn.up::after {
        content: '▲';
    }

    .d-btn.down::after {
        content: '▼';
    }

    .d-btn.left::after {
        content: '◀';
    }

    .d-btn.right::after {
        content: '▶';
    }

    .d-btn.up {
        top: 0;
        left: 37px;
        border-radius: 4px 4px 0 0;
        height: 38px;
    }

    .d-btn.down {
        bottom: 0;
        left: 37px;
        border-radius: 0 0 4px 4px;
        height: 38px;
    }

    .d-btn.left {
        top: 37px;
        left: 0;
        border-radius: 4px 0 0 4px;
        width: 38px;
    }

    .d-btn.right {
        top: 37px;
        right: 0;
        border-radius: 0 4px 4px 0;
        width: 38px;
    }

    .d-center {
        position: absolute;
        top: 37px;
        left: 37px;
        width: 36px;
        height: 36px;
        background: #2a2a2a;
        z-index: 2;
    }

    .d-btn:active,
    .d-btn.active {
        box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.8);
        transform: translate(1px, 1px);
    }

    .action-pad {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 110px;
        height: 110px;
        flex: 0 0 110px;
        transform: translateX(-10px);
    }

    .a-btn {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: #e02020;
        background-image: radial-gradient(circle at 30% 30%, #ff6b6b, #d01010 60%, #8a0b0b);
        border: none;
        color: rgba(255, 255, 255, 0.55);
        font-weight: bold;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
        box-shadow: 0 3px 5px rgba(0, 0, 0, 0.4);
        touch-action: manipulation;
    }

    .a-btn:active,
    .a-btn.active {
        box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.6);
        transform: translateY(2px);
    }

    .spotify-pad {
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        width: calc(100% - 32px);
        margin: 0 16px;
        height: 80px;
        align-self: stretch;
        border-radius: 10px;
        background: rgba(0, 0, 0, 0.35);
        box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
        transform: translateY(8px);
        opacity: 0;
        max-height: 0;
        transition: max-height 180ms steps(6, end), opacity 120ms linear, transform 180ms steps(6, end);
    }

    .spotify-embed-frame-mobile {
        display: block;
        width: 100% !important;
        height: 80px !important;
        max-height: 80px !important;
        border: 0 !important;
    }

    .spotify-pad.spotify-hidden {
        display: flex; /* keep in flow so the animation can expand height */
        max-height: 0;
        opacity: 0;
        transform: translateY(8px);
        pointer-events: none;
    }

    .spotify-pad:not(.spotify-hidden) {
        max-height: 80px;
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }
}


/* ═══════════════════════════════════════════
   DESKTOP (≥ 769px) ISO
═══════════════════════════════════════════ */
@media (min-width: 769px) {
    * {
        box-sizing: border-box;
    }

    body {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        height: 100vh;
        overflow: hidden;
        gap: 16px;
    }

    #game-container {
        position: relative;
        width: 640px;
        height: 640px;
        background-color: #000;
        flex-shrink: 0;
        border: 4px solid #1a1a1a;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
        outline: 1px solid rgba(255, 255, 255, 0.1);
        outline-offset: -1px;
        /* Inside the border */
        border-radius: 4px;
    }

    canvas {
        display: block;
        width: 100%;
        height: 100%;
        image-rendering: pixelated;
        image-rendering: crisp-edges;
    }

    #desktop-controls-hud {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 16px;
        width: fit-content;
        padding: 12px 32px;
        background: rgba(26, 26, 26, 0.9);
        color: #ffffff;
        border-radius: 8px;
        font-size: 9px;
        text-transform: uppercase;
        letter-spacing: 1px;
        white-space: nowrap;
        margin-top: 20px;
        flex-shrink: 0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }

    #desktop-controls-hud .sub-text {
        opacity: 0.7;
    }

    #desktop-controls-hud .sub-text::before {
        content: "•";
        margin-right: 16px;
    }
}

/* Taller screens */
@media (min-width: 769px) and (min-height: 920px) {
    #game-container {
        width: 800px;
        height: 800px;
    }
}

@media (min-width: 769px) and (min-height: 1080px) {
    #game-container {
        width: 960px;
        height: 960px;
    }
}