    @import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@700&display=swap');

    :root {
        --primary-color: #2E7D32;
        --accent-color: #FDD835;
        --text-color: #FFFFFF;
    }

    body,
    html {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        background-color: #000;
        font-family: 'Nunito', sans-serif;
        touch-action: none;
        /* Prevent browser zooming/scrolling */
    }

    #game-container {
        position: relative;
        width: 100vw;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        background-image: url('assets/bg_farm.png');
        background-size: cover;
        background-position: center bottom;
        /* Anchor to bottom */
    }

    canvas {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: contain;
        /* Keep aspect ratio logic in JS, or fill */
    }

    #ui-layer {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
        /* Let clicks pass through to canvas */
    }

    /* SCORE PANEL */
    #score-panel {
        position: absolute;
        top: 20px;
        right: 20px;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 20px;
        padding: 10px 20px;
        display: flex;
        align-items: center;
        gap: 15px;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
        border: 3px solid var(--primary-color);
        pointer-events: auto;
        /* Enable clicks for buttons inside UI layer */
    }

    #hud-logo {
        height: 85px;
        /* Increased from 65px */
    }

    .score-container {
        display: flex;
        align-items: center;
        gap: 8px;
        background: var(--primary-color);
        padding: 5px 15px;
        border-radius: 15px;
        color: white;
    }

    .score-icon {
        width: 24px;
        height: 24px;
    }

    #score-display {
        font-family: 'Fredoka One', cursive;
        font-size: 28px;
        line-height: 1;
    }

    /* SCREENS */
    #game-over-screen,
    #start-screen,
    #pause-screen {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.7);
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        color: white;
        pointer-events: auto;
        /* Re-enable clicks */
        backdrop-filter: blur(5px);
        z-index: 100;
    }

    #pause-btn {
        background: #FDD835;
        /* Yellow */
        border: none;
        border-radius: 10px;
        /* Less rounded */
        width: 60px;
        /* Larger */
        height: 60px;
        /* Larger */
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 30px;
        /* Larger icon */
        cursor: pointer;
        box-shadow: 0 4px 0 #F9A825;
        padding: 0;
        margin-left: 10px;
    }

    #pause-btn:active {
        transform: translateY(2px);
        box-shadow: 0 2px 0 #F9A825;
    }

    .hidden {
        display: none !important;
    }

    h1 {
        font-family: 'Fredoka One', cursive;
        font-size: 64px;
        color: var(--accent-color);
        text-shadow: 3px 3px 0px #000;
        margin-bottom: 20px;
    }

    p {
        font-size: 24px;
        margin-bottom: 40px;
    }

    button {
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 15px 40px;
        font-size: 24px;
        font-family: 'Fredoka One', cursive;
        border-radius: 50px;
        cursor: pointer;
        box-shadow: 0 6px 0 #1B5E20;
        transition: transform 0.1s;
        width: 100%;
        max-width: 300px;
        margin: 10px 0;
    }

    #start-catch-btn {
        background: #4CAF50;
        box-shadow: 0 6px 0 #1B5E20;
    }

    #start-puzzle-btn {
        background: #FF9800;
        /* Orange for puzzle */
        box-shadow: 0 6px 0 #E65100;
    }

    .menu-buttons-row {
        display: flex;
        gap: 10px;
        justify-content: center;
        width: 100%;
        max-width: 300px;
    }

    .menu-buttons-row button {
        padding: 10px 15px;
        font-size: 16px;
        width: auto;
        flex: 1;
        background: #795548;
        /* Brown for secondary */
        box-shadow: 0 4px 0 #3E2723;
    }

    button:active {
        transform: translateY(4px);
        box-shadow: 0 2px 0 #1B5E20;
    }

    .big-logo {
        width: 300px;
        margin-bottom: 20px;
    }

    /* LOGIN SCREEN */
    #login-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-image: url('assets/bg_farm.png');
        background-size: cover;
        background-position: center bottom;
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 200;
    }

    .login-box {
        background: #8D6E63;
        /* Wooden brown base */
        background-image: linear-gradient(to right, #8D6E63, #795548);
        border: 8px solid #5D4037;
        padding: 20px;
        /* Reduced from 30px */
        border-radius: 30px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 12px;
        /* Slightly Reduced gap */
        width: 90%;
        max-width: 320px;
        /* Reduced from 360px */
        box-shadow: 0 10px 0 #3E2723, 0 20px 40px rgba(0, 0, 0, 0.5);
        position: relative;
        box-sizing: border-box;
        /* Ensure padding is included in width */
    }

    /* Nails effect for wooden board */
    .login-box::before,
    .login-box::after {
        content: '';
        position: absolute;
        top: 15px;
        width: 12px;
        height: 12px;
        background: #3E2723;
        border-radius: 50%;
        box-shadow: inset 2px 2px 5px rgba(255, 255, 255, 0.2);
    }

    .login-box::before {
        left: 15px;
    }

    .login-box::after {
        right: 15px;
    }

    .big-logo {
        width: 320px;
        /* Increased from 260px */
        margin-bottom: 5px;
    }

    .characters-img {
        width: 200px;
        margin-bottom: 10px;
    }

    .login-box h1 {
        font-size: 36px;
        /* Reduced from 48px */
        margin: 5px 0;
        color: #FFECB3;
        text-shadow: 2px 2px 0 #3E2723;
    }

    input {
        width: 100%;
        padding: 12px;
        border-radius: 12px;
        border: 3px solid #5D4037;
        background: #FFF8E1;
        font-size: 16px;
        font-family: 'Nunito', sans-serif;
        outline: none;
        box-sizing: border-box;
        color: #5D4037;
        font-weight: bold;
    }

    input:focus {
        border-color: var(--accent-color);
        background: #FFFFFF;
    }

    .auth-buttons {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: 100%;
        margin-top: 5px;
    }

    .auth-buttons button {
        width: 100%;
        text-transform: uppercase;
        letter-spacing: 1px;
        padding: 12px;
        /* Smaller padding */
        font-size: 20px;
    }

    #login-btn,
    #auth-action-btn {
        /* Ensure ID matches JS */
        background: #43A047;
        box-shadow: 0 4px 0 #1B5E20;
    }

    #auth-action-btn:active {
        transform: translateY(4px);
        box-shadow: 0 0 0 #1B5E20;
    }

    #toggle-auth-btn {
        background: transparent;
        box-shadow: none;
        color: #FFECB3;
        padding: 8px;
        font-size: 14px;
        text-decoration: underline;
        text-shadow: 1px 1px 0 #3E2723;
        margin-top: 0;
        border: none;
    }

    #toggle-auth-btn:active {
        transform: none;
        box-shadow: none;
        color: #FFFFFF;
    }

    .error-msg {
        color: #FFCDD2;
        background: rgba(183, 28, 28, 0.4);
        border-radius: 8px;
        padding: 8px;
        width: 100%;
        font-size: 14px;
        min-height: 20px;
        font-weight: bold;
        text-align: center;
        box-sizing: border-box;
        text-shadow: 1px 1px 0 #000;
    }

    /* Logout Button */
    #logout-btn {
        background: #E53935;
        box-shadow: 0 4px 0 #B71C1C;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        position: absolute;
        top: 20px;
        left: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 24px;
        z-index: 1000;
        pointer-events: auto;
        /* Enable clicks */
        cursor: pointer;
    }

    #logout-btn:active {
        transform: translateY(2px);
        box-shadow: 0 2px 0 #B71C1C;
    }


    /* LEADERBOARD */
    /* LEADERBOARD - Default: Centered Modal (Menu Mode) */
    #leaderboard-modal {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;

        /* Game Background */
        background-color: #000;
        background-image: url('assets/bg_farm.png');
        background-size: cover;
        background-position: center bottom;

        display: flex;
        justify-content: center;
        /* Center by default */
        align-items: center;
        z-index: 300;
        pointer-events: auto;
        /* Block clicks on background in menu */
    }

    .leaderboard-content {
        background: rgba(46, 125, 50, 0.6);
        /* Forest Green 60% opacity */
        backdrop-filter: blur(5px);
        /* Optional readability boost */
        border: 4px solid #1B5E20;
        border-radius: 15px;

        width: 90%;
        max-width: 450px;
        height: auto;
        max-height: 80vh;
        margin: 0;

        padding: 20px;
        overflow-y: auto;
        overflow-x: hidden;
        text-align: center;
        position: relative;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);

        /* Custom Scrollbar */
        scrollbar-width: thin;
        scrollbar-color: #A5D6A7 #1B5E20;
    }

    .leaderboard-content::-webkit-scrollbar {
        width: 8px;
    }

    .leaderboard-content::-webkit-scrollbar-track {
        background: #1B5E20;
        border-radius: 4px;
    }

    .leaderboard-content::-webkit-scrollbar-thumb {
        background: #A5D6A7;
        /* Light Green */
        border-radius: 4px;
    }

    /* LEADERBOARD - Sidebar Mode (In-Game) */
    #leaderboard-modal.sidebar-mode {
        justify-content: flex-start;
        background: transparent;
        pointer-events: none;
        align-items: flex-start;
    }

    #leaderboard-modal.sidebar-mode .leaderboard-content {
        pointer-events: auto;
        background: rgba(46, 125, 50, 0.6);
        /* Match transparency */
        border-left: none;
        border-radius: 0 25px 25px 0;

        width: 250px;
        margin-top: 100px;
        padding: 10px;
        box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.4);
    }

    /* Close Button positioned top-right */
    /* Close Button positioned top-right */
    .close-btn {
        position: absolute;
        top: 2px !important;
        right: 5px !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        width: auto !important;

        color: #FDD835;
        font-size: 21px !important;
        /* Increased by 50% from 14px */
        font-weight: bold;
        cursor: pointer;
        z-index: 20;
        text-shadow: 1px 1px 0 #000;
        opacity: 0.8;
        line-height: normal;
        border-radius: 0 !important;
    }

    .close-btn:hover {
        opacity: 1;
        transform: scale(1.1);
        color: #FFF;
    }

    /* HEADER ART: Stars + Ribbon */
    .leaderboard-header-art {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-bottom: 20px;
    }

    .stars-deco {
        display: flex;
        gap: 15px;
        margin-bottom: -15px;
        /* Overlap with ribbon slightly */
        z-index: 2;
    }

    .deco-avo {
        filter: drop-shadow(0 2px 0 #000);
    }

    .star-main {
        width: 40px;
        height: auto;
    }

    .star-side {
        width: 30px;
        height: auto;
        margin-top: 10px;
    }

    .ribbon {
        background: #D32F2F;
        /* Red Ribbon Color */
        padding: 5px 30px;
        position: relative;
        text-align: center;
        border: 3px solid #FFF;
        box-shadow: 0 5px 0 #8B0000;
        /* 3D depth */
        transform: skew(-5deg) rotate(-2deg);
        /* Jaunty angle */
        z-index: 1;
        width: 100%;
        /* Fit container */
        max-width: 300px;
    }

    /* Little triangles for ribbon ends effect (optional simplified) */
    .ribbon::before,
    .ribbon::after {
        content: '';
        position: absolute;
        top: 10px;
        z-index: -1;
        border: 15px solid #8B0000;
    }

    .leaderboard-content h2 {
        font-size: 24px;
        color: #FFD700;
        /* Gold Text */
        margin: 0;
        font-family: 'Fredoka One', cursive;
        text-shadow: 2px 2px 0 #000;
        text-transform: uppercase;
        transform: skew(5deg);
        /* Counter-skew text */
        letter-spacing: 1px;
    }

    #leaderboard-list {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin: 20px 0;
    }

    .leaderboard-entry {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
        background: #FFF;
        border-radius: 10px;
        border: 2px solid #5D4037;
        font-weight: bold;
        font-size: 18px;
    }

    /* Top 3 Highlighting */
    .rank-1 {
        background: linear-gradient(to right, #FFD700, #FDB931);
        border-color: #B8860B;
        color: #FFF;
        text-shadow: 1px 1px 0 #8B4513;
        transform: scale(1.05);
    }

    .rank-2 {
        background: linear-gradient(to right, #E0E0E0, #BDBDBD);
        border-color: #757575;
        color: #424242;
    }

    .rank-3 {
        background: linear-gradient(to right, #CD7F32, #A0522D);
        border-color: #8B4513;
        color: #FFF;
    }

    #close-leaderboard {
        background: #F44336;
        box-shadow: 0 4px 0 #D32F2F;
        margin-top: 10px;
    }

    /* Utility */
    .hidden {
        display: none !important;
    }

    #leaderboard-modal {
        z-index: 9999 !important;
        /* Ensure it is on top */
    }

    /* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

    @media (max-width: 768px) {

        /* Login Screen Adjustments */
        .login-box {
            max-width: 90%;
            padding: 15px;
            gap: 10px;
        }

        .big-logo {
            width: 180px !important;
        }

        .characters-img {
            width: 150px !important;
        }

        .login-box h1 {
            font-size: 28px;
        }

        .login-box input {
            font-size: 16px;
            padding: 12px;
        }

        .login-box button {
            font-size: 18px;
            padding: 12px 30px;
        }

        /* HUD Score Panel */
        #score-panel {
            top: 10px;
            right: 10px;
            padding: 8px 12px;
            gap: 10px;
            flex-wrap: wrap;
        }

        #hud-logo {
            height: 35px;
        }

        .score-container {
            padding: 4px 10px;
            font-size: 14px;
        }

        #score-display {
            font-size: 20px;
        }

        #pause-btn {
            width: 45px;
            height: 45px;
            font-size: 24px;
        }

        /* Leaderboard Modal Mode (Menu) */
        .leaderboard-content {
            max-width: 90%;
            padding: 15px;
            background: rgba(46, 125, 50, 0.35) !important;
            /* More transparent on mobile */
        }

        .leaderboard-content h2 {
            font-size: 20px;
        }

        .ribbon {
            max-width: 250px;
            padding: 4px 20px;
        }

        .star-main {
            width: 30px;
        }

        .star-side {
            width: 22px;
        }

        .leaderboard-entry {
            padding: 8px 12px;
            font-size: 14px;
        }

        .close-btn {
            font-size: 18px !important;
        }

        /* Leaderboard Sidebar Mode (In-Game) */
        #leaderboard-modal.sidebar-mode .leaderboard-content {
            width: 200px;
            margin-top: 60px;
            padding: 8px;
            background: rgba(46, 125, 50, 0.35) !important;
            /* More transparent on mobile */
        }

        #leaderboard-modal.sidebar-mode .leaderboard-content h2 {
            font-size: 16px;
        }

        #leaderboard-modal.sidebar-mode .ribbon {
            max-width: 180px;
            padding: 3px 15px;
        }

        #leaderboard-modal.sidebar-mode .star-main {
            width: 24px;
        }

        #leaderboard-modal.sidebar-mode .star-side {
            width: 18px;
        }

        /* Game Screens */
        #game-over-screen h1,
        #start-screen h1,
        #pause-screen h1 {
            font-size: 48px;
        }

        #game-over-screen p,
        #start-screen p {
            font-size: 18px;
        }

        button {
            font-size: 20px;
            padding: 12px 32px;
        }

        /* Logout Button */
        #logout-btn {
            top: 70px;
            left: 10px;
            padding: 8px 16px;
            font-size: 14px;
        }
    }

    /* Extra Small Devices (phones in portrait, less than 576px) */
    @media (max-width: 576px) {
        .login-box {
            max-width: 95%;
            padding: 12px;
        }

        .big-logo {
            width: 150px !important;
        }

        .characters-img {
            width: 120px !important;
        }

        .login-box h1 {
            font-size: 24px;
        }
    }

    /* ============================================
    PUZZLE MODE STYLES
    ============================================ */
    #puzzle-container {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: transparent;
        /* Match main game background */
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        /* Center visually */
        z-index: 10;
        /* Below UI layer but above bg */
        pointer-events: auto !important;
        /* Force interactive */
    }

    #puzzle-header {
        position: relative;
        display: flex;
        gap: 15px;
        margin-bottom: 20px;
        background: transparent;
        /* Remove container bg */
        padding: 0;
    }

    #puzzle-header h2 {
        font-family: 'Fredoka One', cursive;
        color: white;
        text-shadow: 2px 2px 0 #000;
        padding: 8px 16px;
        border-radius: 50px;
        border: 3px solid white;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
        margin: 0;
        font-size: 20px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    /* Level Badge - Orange */
    #puzzle-header h2:first-child {
        background: linear-gradient(180deg, #FF9800, #F57C00);
        border-color: #FFE0B2;
    }

    /* Timer Badge - Blue/Purple */
    #puzzle-header h2:last-child {
        background: linear-gradient(180deg, #2196F3, #1976D2);
        border-color: #BBDEFB;
    }

    #puzzle-grid {
        display: grid;
        gap: 0;
        /* Wooden Background for empty slot */
        background: #3E2723;
        padding: 0;

        /* Wooden Frame Aesthetic */
        border: 12px solid #5D4037;
        border-right-color: #3E2723;
        border-bottom-color: #3E2723;
        border-left-color: #8D6E63;
        border-top-color: #8D6E63;
        border-radius: 4px;
        box-shadow:
            inset 0 0 20px rgba(0, 0, 0, 0.5),
            /* Inner shadow for depth */
            0 10px 20px rgba(0, 0, 0, 0.5);
        /* Drop shadow */

        width: 95vw;
        max-width: 650px;
        margin-bottom: 20px;
        aspect-ratio: auto;
    }

    #puzzle-countdown {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-family: 'Fredoka One', cursive;
        font-size: 120px;
        color: white;
        text-shadow: 4px 4px 0 #FF9800, -2px -2px 0 #000;
        z-index: 50;
        pointer-events: none;
        animation: pulseCount 0.8s infinite alternate;
    }

    @keyframes pulseCount {
        from {
            transform: translate(-50%, -50%) scale(1);
        }

        to {
            transform: translate(-50%, -50%) scale(1.2);
        }
    }

    .puzzle-tile {
        width: 100%;
        height: 100%;
        background: #FFF;
        cursor: pointer;
        transition: transform 0.2s ease;
        overflow: hidden;
        border-radius: 4px;
    }

    .puzzle-tile.empty {
        background: transparent;
        cursor: default;
    }

    .puzzle-tile:hover:not(.empty) {
        transform: scale(0.98);
    }

    #reference-modal {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.8);
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        z-index: 300;
    }

    #reference-img {
        max-width: 90%;
        max-height: 80%;
        border: 5px solid #FFF;
        border-radius: 10px;
        margin-bottom: 20px;
    }

    #score-panel {
        top: 5px;
        right: 5px;
        padding: 6px 10px;
        gap: 8px;
        border-radius: 15px;
    }

    #hud-logo {
        height: 28px;
    }

    .score-container {
        padding: 3px 8px;
        font-size: 12px;
    }

    #score-display {
        font-size: 18px;
    }

    #pause-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    #leaderboard-modal.sidebar-mode {
        background: transparent;
        justify-content: flex-start;
        align-items: flex-start;
        pointer-events: none;
    }

    #leaderboard-modal.sidebar-mode .leaderboard-content {
        width: 260px;
        /* Mas ancha: Increased from ~180px default */
        height: 60vh;
        /* Mas pequeña: specific height, not full screen */
        margin-left: 10px;
        margin-top: 110px;
        /* Increased separation from logout button */
        padding: 5px;
        /* Minimal padding */

        background: rgba(46, 125, 50, 0.4);
        /* Less obtrusive opacity */
        border: 2px solid rgba(27, 94, 32, 0.5);
        /* Thinner border */
        border-radius: 10px;

        pointer-events: auto;
        transform: scale(0.85);
        /* Mas pequeña: Scale down entire element */
        transform-origin: top left;
    }

    /* Compact entries for Sidebar */
    #leaderboard-modal.sidebar-mode .leaderboard-entry {
        padding: 4px 8px;
        /* Compact padding */
        margin-bottom: 4px;
        font-size: 13px;
        /* Smaller font */
        min-height: auto;
    }

    #leaderboard-modal.sidebar-mode .ribbon {
        max-width: 140px;
        padding: 2px 10px;
        font-size: 14px;
        /* Smaller title */
        margin-bottom: 5px;
    }

    #leaderboard-modal.sidebar-mode h2 {
        margin: 5px 0;
        font-size: 16px;
    }

    #leaderboard-modal.sidebar-mode .star-main,
    #leaderboard-modal.sidebar-mode .star-side {
        width: 20px;
        /* Smaller icons */
    }

    #game-over-screen h1,
    #start-screen h1,
    #pause-screen h1 {
        font-size: 36px;
    }

    button {
        font-size: 18px;
        padding: 10px 24px;
    }
    }
/* UPDATED HUD STYLES */
#score-panel {
    align-items: flex-end;
    pointer-events: none;
}
#score-panel > * {
    pointer-events: auto;
}
#hud-logo {
    width: 280px;
    height: auto;
    filter: drop-shadow(0 4px 0 #000);
}
.stats-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}
.score-container {
    min-width: 140px;
    justify-content: center;
}
.hud-controls {
    display: flex;
    gap: 10px;
}
#lobby-btn-hud {
    background: #FFD700;
    border: 3px solid #FFF;
    color: #FFF;
    width: 50px;
    height: 50px;
    border-radius: 15px;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 0 #FF8F00;
    display: flex;
    align-items: center;
    justify-content: center;
}
#lobby-btn-hud:active {
    transform: scale(0.95);
    box-shadow: 0 2px 0 #FF8F00;
}


/* UI FIXES */
.hud-controls {
    display: flex;
    flex-direction: row !important; /* Force horizontal */
    gap: 10px;
    margin-top: 10px;
}

#lobby-btn-hud {
    background: #FFD700 !important; /* Force Gold */
    border: 3px solid #FFF;
    color: #FFF;
    width: 60px; /* Slightly wider */
    height: 50px;
}

#pause-btn {
    width: 60px;
    height: 50px;
    background: #FFD700 !important;
}

#score-panel {
    align-items: flex-end !important;
    gap: 5px; /* Tighter vertical spacing */
}


/* NEW LOGO SIZE & CONTROLS */
#hud-logo {
    width: 380px !important; /* Even Bigger Logo */
    max-width: 90vw;
}

#top-left-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    gap: 10px;
    z-index: 200;
}

#logout-btn {
    position: static !important; /* Reset absolute positioning */
    background: #FF5252;
    color: white;
    border: 3px solid white;
    box-shadow: 0 4px 0 #D32F2F;
    border-radius: 15px;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
    font-size: 18px;
    padding: 10px 20px;
}

#logout-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 0 #D32F2F;
}

/* Re-style lobby button for top-left context */
#lobby-btn-hud {
    width: auto !important; /* Auto width for text */
    padding: 10px 20px;
    font-size: 18px;
    height: auto !important;
}

@media (max-width: 768px) {
    #top-left-controls {
        top: 10px;
        left: 10px;
        flex-direction: column; /* Stack on mobile if needed, or row */
        gap: 5px;
    }
    #logout-btn, #lobby-btn-hud {
        font-size: 14px;
        padding: 5px 10px;
    }
    #hud-logo {
        width: 180px !important;
    }
}


/* URGENT UI FIX - Hide logo during gameplay */
.game-active #hud-logo {
    display: none !important;
}

#hud-logo {
    width: 200px !important; /* Smaller by default */
}

/* Compact HUD for gameplay */
#score-panel {
    gap: 3px !important;
}

.score-container {
    padding: 6px 12px !important;
    font-size: 18px !important;
    min-width: 100px !important;
}

/* Semi-transparent HUD during puzzle */
.puzzle-active #score-panel {
    opacity: 0.85;
}

@media (max-width: 768px) {
    #hud-logo {
        width: 120px !important;
    }
    .score-container {
        padding: 4px 8px !important;
        font-size: 14px !important;
        min-width: 80px !important;
    }
}


/* LOGO PROPORTIONAL FIX - Show smaller during gameplay */
.game-active #hud-logo {
    display: block !important; /* Override previous hide */
    width: 120px !important; /* Smaller proportional size */
    max-width: 25vw;
}

/* Even smaller on mobile during gameplay */
@media (max-width: 768px) {
    .game-active #hud-logo {
        width: 80px !important;
        max-width: 20vw;
    }
}


/* HORIZONTAL LAYOUT - Everything in one line */
.game-active #score-panel {
    flex-direction: row !important; /* Horizontal instead of vertical */
    align-items: center !important;
    gap: 10px !important;
}

.game-active .stats-group {
    flex-direction: row !important;
    gap: 8px !important;
}

/* Smaller spacing for inline layout */
.game-active #score-panel {
    gap: 8px !important;
}

@media (max-width: 768px) {
    .game-active #score-panel {
        gap: 5px !important;
        flex-wrap: wrap; /* Allow wrapping on very small screens */
    }
}


/* COMPACT HUD - Much narrower */
.game-active #hud-logo {
    width: 80px !important; /* Even smaller logo */
    max-width: 15vw;
}

.game-active .score-container {
    padding: 5px 10px !important;
    font-size: 16px !important;
    min-width: 90px !important;
}

.game-active #pause-btn {
    width: 40px !important;
    height: 40px !important;
    font-size: 20px !important;
}

/* Tighter spacing */
.game-active #score-panel {
    gap: 6px !important;
}

.game-active .stats-group {
    gap: 6px !important;
}

@media (max-width: 768px) {
    .game-active #hud-logo {
        width: 60px !important;
    }
    .game-active .score-container {
        padding: 4px 8px !important;
        font-size: 14px !important;
        min-width: 75px !important;
    }
    .game-active #pause-btn {
        width: 35px !important;
        height: 35px !important;
    }
}


/* LOGO VISIBILITY FIX - Better contrast and sizing */
.game-active #hud-logo {
    width: 100px !important; /* Slightly bigger for readability */
    height: auto;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)) !important; /* Better shadow */
    background: rgba(255,255,255,0.9); /* White background */
    padding: 4px 8px;
    border-radius: 8px;
}

/* Ensure logo is crisp */
#hud-logo {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}


/* WHITE LOGO WITH DARK BACKGROUND */
.game-active #hud-logo {
    background: linear-gradient(135deg, #2E7D32, #1B5E20) !important; /* Green gradient background */
    padding: 6px 10px !important;
    border-radius: 10px !important;
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3) !important;
}


/* CLEAN LOGO - No background, just the logo */
.game-active #hud-logo {
    background: none !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2)) !important; /* Subtle shadow only */
}


/* ============================================
   RESPONSIVE HUD - MOBILE & TABLET
   ============================================ */

/* Tablets (Portrait) */
@media (max-width: 1024px) and (min-width: 769px) {
    .game-active #hud-logo {
        width: 90px !important;
    }
    
    .game-active .score-container {
        padding: 6px 12px !important;
        font-size: 15px !important;
        min-width: 85px !important;
    }
    
    .game-active #score-panel {
        gap: 6px !important;
        top: 15px;
        right: 15px;
    }
}

/* Mobile Landscape & Small Tablets */
@media (max-width: 768px) and (min-width: 481px) {
    .game-active #hud-logo {
        width: 70px !important;
    }
    
    .game-active .score-container {
        padding: 5px 10px !important;
        font-size: 14px !important;
        min-width: 75px !important;
    }
    
    .game-active #pause-btn {
        width: 38px !important;
        height: 38px !important;
        font-size: 18px !important;
    }
    
    .game-active #score-panel {
        gap: 5px !important;
        top: 10px;
        right: 10px;
    }
    
    #top-left-controls {
        top: 10px;
        left: 10px;
        gap: 6px;
    }
    
    #top-left-controls button {
        font-size: 13px !important;
        padding: 6px 12px !important;
    }
}

/* Mobile Portrait */
@media (max-width: 480px) {
    .game-active #hud-logo {
        width: 55px !important;
        max-width: 12vw;
    }
    
    .game-active .score-container {
        padding: 4px 8px !important;
        font-size: 12px !important;
        min-width: 65px !important;
    }
    
    .game-active #pause-btn {
        width: 35px !important;
        height: 35px !important;
        font-size: 16px !important;
    }
    
    .game-active #score-panel {
        gap: 4px !important;
        top: 8px;
        right: 8px;
        flex-wrap: nowrap; /* Keep single line */
    }
    
    .game-active .stats-group {
        gap: 4px !important;
    }
    
    #top-left-controls {
        top: 8px;
        left: 8px;
        gap: 4px;
        flex-direction: row; /* Horizontal on mobile */
    }
    
    #top-left-controls button {
        font-size: 11px !important;
        padding: 5px 10px !important;
        border-radius: 10px;
    }
    
    #lobby-btn-hud {
        padding: 5px 8px !important;
    }
}

/* Extra Small Mobile (< 360px) */
@media (max-width: 360px) {
    .game-active #hud-logo {
        width: 45px !important;
    }
    
    .game-active .score-container {
        padding: 3px 6px !important;
        font-size: 11px !important;
        min-width: 55px !important;
    }
    
    .game-active #pause-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 14px !important;
    }
    
    #top-left-controls button {
        font-size: 10px !important;
        padding: 4px 8px !important;
    }
}


/* FIX OVERLAP - Stack HUD vertically on small screens */
@media (max-width: 768px) {
    .game-active #score-panel {
        flex-direction: column !important; /* Vertical stack on mobile */
        align-items: flex-end !important;
        gap: 5px !important;
    }
    
    .game-active .stats-group {
        flex-direction: column !important;
        align-items: flex-end !important;
        gap: 5px !important;
    }
    
    /* Move left controls lower to avoid overlap */
    #top-left-controls {
        top: auto !important;
        bottom: 20px !important;
        left: 10px !important;
    }
}

@media (max-width: 480px) {
    #top-left-controls {
        bottom: 15px !important;
        left: 8px !important;
    }
}


/* HORIZONTAL HUD FIX - Override vertical layout */
@media (max-width: 768px) {
    .game-active #score-panel {
        flex-direction: row !important; /* Keep horizontal */
        align-items: center !important;
        flex-wrap: wrap !important; /* Allow wrapping if needed */
        gap: 4px !important;
        max-width: calc(100vw - 160px); /* Leave space for left controls */
    }
    
    .game-active .stats-group {
        flex-direction: row !important; /* Horizontal stats */
        gap: 4px !important;
    }
    
    /* Keep left controls at bottom to avoid overlap */
    #top-left-controls {
        top: auto !important;
        bottom: 10px !important;
        left: 10px !important;
        z-index: 150 !important;
    }
}


/* SINGLE LINE HUD - No wrapping, no stacking */
.game-active #score-panel {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 8px !important;
    max-width: none !important;
}

.game-active .stats-group {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
}

.game-active .hud-controls {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
}

/* Compact everything for single line */
.game-active #hud-logo {
    width: 70px !important;
}

.game-active .score-container {
    padding: 4px 10px !important;
    font-size: 14px !important;
    min-width: auto !important;
    white-space: nowrap;
}

.game-active #pause-btn {
    width: 36px !important;
    height: 36px !important;
    font-size: 18px !important;
}


/* MOBILE BUTTONS FIX - Ensure Salir/Lobby visible on mobile */
@media (max-width: 768px) {
    #top-left-controls {
        position: fixed !important;
        bottom: 15px !important;
        left: 15px !important;
        top: auto !important;
        z-index: 9999 !important;
        display: flex !important;
        gap: 8px !important;
        flex-direction: row !important;
    }
    
    #logout-btn, #lobby-btn-hud {
        display: block !important;
        background: #FF5252 !important;
        color: white !important;
        border: 2px solid white !important;
        padding: 8px 14px !important;
        font-size: 13px !important;
        border-radius: 10px !important;
        box-shadow: 0 3px 0 #D32F2F !important;
    }
    
    #lobby-btn-hud {
        background: #FFD700 !important;
        box-shadow: 0 3px 0 #FF8F00 !important;
    }
}

@media (max-width: 480px) {
    #top-left-controls {
        bottom: 10px !important;
        left: 10px !important;
        gap: 5px !important;
    }
    
    #logout-btn, #lobby-btn-hud {
        padding: 6px 10px !important;
        font-size: 11px !important;
    }
}


/* HIDE LOBBY BUTTON IN LOBBY - Only show during gameplay */
#start-screen ~ #top-left-controls #lobby-btn-hud,
#lobby-btn-hud.hidden {
    display: none !important;
}

/* Ensure logout button is always visible */
#logout-btn {
    display: block !important;
}


/* FIX PUZZLE IMAGE WHITE BORDERS ON MOBILE */
#puzzle-grid {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

#puzzle-grid canvas {
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

@media (max-width: 768px) {
    #puzzle-container {
        padding: 0 !important;
        margin: 0 !important;
    }
    
    #puzzle-grid {
        max-width: 100vw !important;
        width: 95vw !important;
        border: none !important;
        outline: none !important;
    }
}


/* FIX PUZZLE BORDERS - Keep outer frame, remove inner piece borders */
#puzzle-grid canvas {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    display: block; /* Removes bottom space */
}

/* Ensure outer grid maintains its frame */
#puzzle-grid {
    border: 12px solid #5D4037 !important; /* Force frame back */
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5), 0 10px 20px rgba(0,0,0,0.5) !important;
    padding: 0 !important;
    background: #3E2723 !important;
    gap: 0 !important; /* Ensure seamless */
}

/* Override previous mobile override that removed the frame */
@media (max-width: 768px) {
    #puzzle-grid {
        border: 12px solid #5D4037 !important;
        width: 90vw !important; /* Slightly smaller to fit frame */
    }
}


/* FIX MOBILE BUTTON TEXT TRUNCATION */
@media (max-width: 768px) {
    #logout-btn, #lobby-btn-hud {
        min-width: 70px !important; /* Ensure enough width */
        white-space: nowrap !important; /* Prevent text wrapping */
        padding: 8px 16px !important; /* increased side padding */
        text-align: center !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        height: auto !important;
    }
}

@media (max-width: 480px) {
    #logout-btn, #lobby-btn-hud {
        min-width: 60px !important;
        font-size: 12px !important;
        padding: 6px 12px !important;
    }
}


/* STRONG FIX FOR MOBILE BUTTON TRUNCATION */
@media (max-width: 768px) {
    #logout-btn, #lobby-btn-hud {
        width: auto !important;
        min-width: 85px !important; /* Forced wider */
        padding: 8px 15px !important;
        white-space: nowrap !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }
}

@media (max-width: 480px) {
    #logout-btn, #lobby-btn-hud {
        min-width: 75px !important; /* Wider on small screens too */
        font-size: 13px !important; /* Slightly bigger text */
        padding: 6px 14px !important;
    }
}


/* FINAL FIX FOR MOBILE BUTTON TRUNCATION */
@media (max-width: 768px) {
    #logout-btn {
        width: auto !important;
        min-width: 100px !important; /* Much wider to be safe */
        padding: 8px 12px !important;
        white-space: nowrap !important;
        overflow: visible !important;
        text-overflow: clip !important;
        display: inline-flex !important;
        justify-content: center !important;
        align-items: center !important;
        font-size: 16px !important; /* Ensure font isn't too huge */
    }
}

@media (max-width: 480px) {
    #logout-btn {
        min-width: 90px !important;
        font-size: 14px !important;
        padding: 6px 10px !important;
    }
}


/* WHITE LOGIN BUTTON */
#auth-action-btn {
    background: white !important;
    color: #2E7D32 !important; /* Dark Green text for contrast */
    border: 2px solid #E0E0E0 !important;
    box-shadow: 0 4px 0 #E0E0E0 !important;
}

#auth-action-btn:hover {
    background: #F5F5F5 !important;
    transform: translateY(-2px);
}

#auth-action-btn:active {
    background: #EEEEEE !important;
    transform: scale(0.98);
    box-shadow: 0 2px 0 #BDBDBD !important;
}


/* ULTRA FIX FOR MOBILE BUTTON TRUNCATION */
@media (max-width: 768px) {
    #logout-btn {
        width: 90px !important; /* Fixed width */
        min-width: 90px !important;
        max-width: 90px !important;
        padding: 0 !important; /* Reset padding to rely on flex center */
        height: 40px !important; /* Fixed height */
        white-space: nowrap !important;
        overflow: visible !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        box-sizing: border-box !important;
        font-size: 14px !important; /* Slightly smaller font to fit */
    }
}


/* FINAL ATTEMPT MOBILE BUTTON FIX */
@media (max-width: 768px) {
    #logout-btn {
        width: 100px !important;
        min-width: 100px !important;
        height: 44px !important;
        padding: 0 !important;
        margin: 0 !important;
        
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        
        font-size: 16px !important;
        line-height: 1 !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: visible !important;
        
        /* Ensure no weird indent */
        text-indent: 0 !important;
    }
}

