:root {
    --primary-color: #FFD54F;
    --accent-color: #FF7043;
    --sky-blue: #87CEEB;
    --text-color: #333;
    --font-stack: 'Fredoka', sans-serif;
}

body {
    margin: 0;
    overflow: hidden;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    /* Colorful background */
    font-family: var(--font-stack);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    user-select: none;
}

/* Main Layout Wrapper */
#main-wrapper {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Use gap to separate sidebar from game */
    gap: 20px;
    padding: 20px;
    box-sizing: border-box;
}

/* Game Canvas Container */
#game-container {
    position: relative;
    /* Default Max size settings */
    width: 1024px;
    height: 768px;
    max-width: 100%;
    /* Maintain aspect ratio */
    aspect-ratio: 4/3;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 4px solid #FFF;
    cursor: none;
    /* Hide default cursor */
    /* Ensure it doesn't shrink aggressively */
    flex-shrink: 0;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #87CEEB;
}

/* HUD System (Sidebar/Topbar) */
#game-hud {
    z-index: 100;
}

.hud-panel {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 25px;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.5);
}

.hud-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-label {
    font-size: 0.8rem;
    font-weight: 800;
    color: #888;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.hud-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #333;
}

.hud-timer {
    color: #FF5722;
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #fce38a, #f38181);
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    margin: 0 5px;
    color: #FFF;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
}

.control-btn:hover {
    transform: scale(1.1);
}

/* Mobile Responsive: Top Bar Layout */
@media (max-width: 1024px) {
    #main-wrapper {
        flex-direction: column;
        padding: 10px;
        gap: 15px;
        height: 100vh;
        /* Ensure full viewport height */
        display: flex;
        overflow: hidden;
        /* Prevent body scroll */
    }

    #game-hud {
        width: 100%;
        max-width: 800px;
        order: -1;
        flex: 0 0 auto;
        /* Do not grow/shrink */
    }

    .hud-panel {
        flex-direction: row;
        width: 100%;
        padding: 10px 20px;
        border-radius: 15px;
        justify-content: space-around;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    }

    #game-container {
        width: 100%;
        /* Flex Grow to fill remaining space minus gap/padding */
        flex: 1 1 auto;
        height: 0;
        /* Important for flex child to shrink properly */
        min-height: 200px;
        /* Safety minimum */
        border-radius: 15px;
        /* Revert aspect-ratio auto so it fills flex area */
        aspect-ratio: unset;
    }

    /* Adjust text sizes for smaller mobile screens */
    .hud-label {
        font-size: 0.7rem;
    }

    .hud-value {
        font-size: 1.2rem;
    }

    .control-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .game-title {
        font-size: 2.5rem;
        margin-bottom: 1rem;
    }

    .main-btn {
        font-size: 1.2rem;
        padding: 12px 30px;
    }

    .menu-buttons {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    #difficulty-select {
        display: flex;
        justify-content: center;
        width: 100%;
        padding: 5px 10px;
        gap: 5px;
        margin-bottom: 15px;
    }

    .diff-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* Desktop Responsive: Sidebar Layout */
@media (min-width: 1025px) {
    #main-wrapper {
        flex-direction: row;
    }

    #game-hud {
        width: 160px;
        height: auto;
        /* Match height somewhat or be flexible */
        align-self: center;
    }

    .hud-panel {
        flex-direction: column;
        gap: 25px;
        /* Vertical spacing */
        width: 100%;
        height: 100%;
        padding: 30px 15px;
    }

    /* Make canvas responsive to fit with sidebar */
    #game-container {
        max-height: 90vh;
        max-width: calc(100vw - 220px);
        /* Account for sidebar */
    }
}

/* Custom Crosshair */
#crosshair {
    position: absolute;
    width: 40px;
    height: 40px;
    pointer-events: none;
    border: 3px solid red;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    display: none;
    /* Shown via JS on mouse move */
}

/* Center align menus */
.menu-content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

#crosshair::after {
    content: '+';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -54%);
    color: red;
    font-size: 24px;
    font-weight: bold;
}

/* Screens & Overlays */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.screen,
.popup {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.6);
    pointer-events: auto;
    transition: opacity 0.3s;
}

.hidden {
    opacity: 0;
    pointer-events: none !important;
    display: none !important;
}

/* Countdown Overlay */
#countdown-overlay {
    background: rgba(0, 0, 0, 0.3);
    z-index: 50;
    pointer-events: none;
    /* Let click through? Maybe not during countdown */
}

#countdown-text {
    font-size: 10rem;
    color: var(--primary-color);
    text-shadow: 5px 5px 0 #000;
    animation: pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) infinite alternate;
}

@keyframes pop {
    from {
        transform: scale(0.8);
    }

    to {
        transform: scale(1.1);
    }
}

/* Title Screen */
.game-title {
    font-size: 4rem;
    color: white;
    text-shadow: 4px 4px 0 var(--accent-color);
    margin-bottom: 2rem;
}

/* Premium Button Styles */
.main-btn {
    font-family: var(--font-stack);
    font-size: 1.8rem;
    padding: 15px 50px;
    border: none;
    border-radius: 50px;
    background: linear-gradient(to bottom, #FFD54F, #FFCA28);
    color: #4E342E;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 0 #FF6F00, 0 15px 20px rgba(0, 0, 0, 0.2);
    margin: 15px;
    transition: transform 0.1s, box-shadow 0.1s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.main-btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 #FF6F00, 0 10px 10px rgba(0, 0, 0, 0.2);
}

.secondary-btn {
    font-family: var(--font-stack);
    font-size: 1.2rem;
    padding: 12px 30px;
    border: none;
    border-radius: 40px;
    background: #FFF;
    color: #555;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 0 #CCC, 0 8px 15px rgba(0, 0, 0, 0.1);
    margin: 10px;
    transition: all 0.2s;
}

.secondary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #CCC, 0 12px 20px rgba(0, 0, 0, 0.15);
}

.secondary-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #CCC;
}

/* Difficulty Buttons */
#difficulty-select {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
    background: rgba(0, 0, 0, 0.5);
    /* Darker backing */
    padding: 15px 25px;
    border-radius: 15px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.diff-btn {
    font-family: var(--font-stack);
    font-weight: 800;
    font-size: 1rem;
    padding: 12px 24px;
    border: 3px solid transparent;
    /* Box border placeholder */
    border-radius: 10px;
    cursor: pointer;
    color: #EEE;
    background: rgba(255, 255, 255, 0.1);
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-width: 100px;
}

.diff-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* Selected States with "Boxy" feel */
.diff-btn[data-diff="easy"].selected {
    background: #4CAF50;
    border-color: #A5D6A7;
    color: white;
    box-shadow: 0 0 10px #4CAF50, inset 0 0 10px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

.diff-btn[data-diff="medium"].selected {
    background: #FF9800;
    border-color: #FFCC80;
    color: white;
    box-shadow: 0 0 10px #FF9800, inset 0 0 10px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

.diff-btn[data-diff="hard"].selected {
    background: #F44336;
    border-color: #EF9A9A;
    color: white;
    box-shadow: 0 0 10px #F44336, inset 0 0 10px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

.diff-btn:hover:not(.selected) {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.3);
}

/* Instructions */
.popup-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
    border: 4px solid var(--primary-color);
    position: relative;
}

.close-btn {
    position: absolute;
    right: 15px;
    top: 10px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

.instruction-grid {
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
}

.inst-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.inst-item .icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

/* Stats Box */
.stats-box {
    background: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    text-align: center;
    min-width: 200px;
}

.stats-box p {
    margin: 5px 0;
    font-size: 1.2rem;
    font-weight: 600;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #game-container {
        width: 100vw;
        height: 75vw;
        /* Maintain aspect roughly */
        max-height: 100vh;
    }

    .game-title {
        font-size: 2.5rem;
    }

    .header-group .label {
        display: none;
    }

    /* Compact header */
}