* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Press Start 2P', cursive;
}

body {
    background-color: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    touch-action: none;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    flex-direction: column;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background-color: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#top-bar {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Hide top bar on main menu */
    opacity: 1;
    transition: opacity 0.3s;
}

#top-bar.hidden {
    opacity: 0;
    pointer-events: none;
}

.score-box {
    color: #fff;
    font-size: 16px;
    text-shadow: 2px 2px 0 #000;
    letter-spacing: 2px;
}

#controls {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #fff;
    color: white;
    font-family: sans-serif;
    font-size: 18px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    box-shadow: 2px 2px 0 #000;
    transition: transform 0.1s, background 0.2s;
}

.icon-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 0 0 0 #000;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, backdrop-filter 0.2s ease;
    pointer-events: auto;
    backdrop-filter: blur(2px);
}

.overlay.screen-active {
    opacity: 1;
    visibility: visible;
}

/* MENU LAYOUT */
.menu-content {
    background: rgba(20, 20, 20, 0.9);
    border: 4px solid #fff;
    padding: 20px 40px;
    box-shadow: 8px 8px 0 #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-height: 90%;
    overflow-y: auto;
}

.menu-content h1 {
    font-size: 36px;
    margin-bottom: 5px;
    color: #ffd700;
    text-shadow: 4px 4px 0 #b8860b, -2px -2px 0 #fff;
    letter-spacing: 2px;
    animation: pulseText 2s infinite alternate;
}

.difficulty-section,
.leaderboard {
    width: 100%;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border: 2px solid #444;
}

.difficulty-section h2,
.leaderboard h2 {
    font-size: 14px;
    color: #aaa;
    margin-bottom: 15px;
}

.diff-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.diff-btn {
    background: #333;
    color: #fff;
    border: 2px solid #666;
    padding: 10px 15px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 2px 2px 0 #000;
    transition: all 0.1s;
}

.diff-btn:hover {
    background: #444;
}

.diff-btn.active {
    background: #FF9800;
    border-color: #fff;
    color: #000;
    transform: translate(2px, 2px);
    box-shadow: 0 0 0 #000;
}

.score-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 8px;
    color: #fff;
    border-bottom: 1px dashed #444;
    padding-bottom: 4px;
}

.score-row span:first-child {
    color: #FFC107;
}

.controls-hint {
    font-size: 10px;
    color: #888;
    margin-top: -10px;
}

.overlay h1 {
    font-size: 40px;
    margin-bottom: 25px;
    color: #ffd700;
    text-shadow: 4px 4px 0 #b8860b;
}

.stats-box {
    background: rgba(0, 0, 0, 0.5);
    padding: 20px;
    border: 4px solid #fff;
    margin-bottom: 30px;
    box-shadow: 4px 4px 0 #000;
    position: relative;
}

.diff-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #FF9800;
    color: #000;
    padding: 4px 8px;
    font-size: 10px;
    border: 2px solid #fff;
}

.overlay p {
    font-size: 16px;
    margin: 10px 0;
    line-height: 1.5;
    text-shadow: 2px 2px 0 #000;
}

.retro-btn {
    background-color: #4CAF50;
    color: white;
    border: 4px solid #fff;
    padding: 15px 40px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 4px 4px 0 #000;
    transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
    text-transform: uppercase;
}

.retro-btn:active {
    transform: translate(4px, 4px);
    box-shadow: 0 0 0 #000;
}

.retro-btn:hover {
    background-color: #45a049;
}

.start-glow {
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.8), 4px 4px 0 #000;
}

.btn-secondary {
    background-color: #607D8B;
    font-size: 16px;
    padding: 10px 20px;
}

.btn-secondary:hover {
    background-color: #546E7A;
}

.game-over-buttons {
    display: flex;
    gap: 15px;
}

@keyframes pulseText {
    0% {
        transform: scale(1);
        text-shadow: 4px 4px 0 #b8860b, 0 0 10px rgba(255, 215, 0, 0.5);
    }

    100% {
        transform: scale(1.05);
        text-shadow: 4px 4px 0 #b8860b, 0 0 20px rgba(255, 215, 0, 0.9);
    }
}

@media (max-width: 850px) {
    #game-container {
        border-width: 0;
        box-shadow: none;
        width: 100vw;
        height: 50vw;
        max-height: 100vh;
    }

    .menu-content {
        padding: 15px 20px;
        gap: 10px;
    }

    .menu-content h1 {
        font-size: 24px;
    }

    .overlay h1 {
        font-size: 28px;
    }

    .retro-btn {
        padding: 10px 20px;
        font-size: 16px;
    }

    .btn-secondary {
        font-size: 12px;
    }

    .score-box {
        font-size: 12px;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    #top-bar {
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .diff-btn {
        padding: 8px 10px;
        font-size: 10px;
    }

    .score-row {
        font-size: 10px;
    }
}