/* Mobile Responsive Styles */

@media (max-width: 768px) {

    /* Global Container */
    /* Force reset of any fixed widths from other files */
    html,
    body {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
        min-width: 0 !important;
    }

    .container,
    body>section>.container,
    header>.container {
        padding: 0 10px;
        width: 100% !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        overflow-x: hidden;
    }

    /* Header */
    header .container {
        padding: 5px 10px;
        flex-wrap: nowrap;
        gap: 10px;
    }

    .logo {
        font-size: 1.2rem !important;
        /* Aggressively smaller for Index */
        white-space: nowrap;
        max-width: 60%;
        /* Ensure it doesn't push menu out */
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Standard Buttons adjustments */
    .btn,
    .btn-votar,
    #confirmarVotos,
    #confirmarFinal,
    .login-twitch,
    .login-google,
    .btn-menu-item {
        padding: 12px 15px !important;
        font-size: 0.9rem !important;
        white-space: normal !important;
        /* Allow wrapping if needed */
        height: auto !important;
        max-width: 100%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Nav - Hide strict desktop elements */
    header nav a:not(#loginBtn) {
        display: none;
    }

    .user-menu {
        gap: 10px;
    }

    .user-menu #userAvatar {
        display: none !important;
        /* Hide independent avatar on mobile */
    }

    #loginBtn {
        font-size: 0 !important;
        /* Hide text */
        padding: 0 !important;
        /* Remove padding to let image fill */
        width: 40px !important;
        height: 40px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background-color: transparent;
        /* Default transparent */
        border: 2px solid white;
        /* Optional ring */
        overflow: hidden;
        /* Clip image */
    }

    /* Icon for the button (Only if NO avatar image set via JS) */
    #loginBtn:not(.has-avatar)::before {
        content: '\f2f5';
        /* FontAwesome Sign Out Icon */
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
        font-size: 1.2rem;
        color: white;
    }

    /* Specific state for non-logged in: User Icon */
    body:not(.user-logged-in) #loginBtn::before {
        content: '\f007';
    }

    /* If it has avatar class, ensure background covers */
    #loginBtn.has-avatar {
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
    }

    /* Hero Section */
    #hero {
        height: 100dvh;
        margin-bottom: 2rem;
    }

    h1 {
        font-size: 2rem;
        letter-spacing: -1px;
    }

    h2 {
        font-size: 1.8rem;
    }

    h3 {
        font-size: 1.3rem;
    }

    /* Instructions */
    #Instrucciones {
        padding: 2rem 1rem;
    }

    #Instrucciones .container {
        flex-direction: column;
        gap: 2rem;
    }

    .img-atencion {
        width: 50px;
        height: 50px;
        border-radius: 50%;
    }

    /* Fix Blank Page Issue - Instructions Only */
    #Instrucciones .caja {
        visibility: visible !important;
        opacity: 1 !important;
        width: 100% !important;
        max-width: 100% !important;

        padding: 1.5rem;
        height: auto;
    }

    .caja h2 {
        font-size: 120%;
    }

    .caja h4 {
        font-size: 100%;
        font-weight: lighter;
    }

    /* Force visibility on empty cards specifically */
    .tarjeta-voto.vacia {
        display: flex !important;
        visibility: visible !important;
        opacity: 0.7 !important;
        min-height: 50px;
        /* Ensure height if empty */
    }

    /* Header Consistency */
    header {
        position: sticky;
        top: 0;
        z-index: 1000;
        width: 100%;
    }

    /* Grid Layouts - Fixed width cards centered */
    .flex-container {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 10px;
        width: 100% !important;
        display: flex;
        flex-direction: column;
        /* Center cards */
        box-sizing: border-box;
    }

    .cajita {
        height: 250px;
        width: 280px !important;
        /* Fixed width per user request */
        /* Fixed width per user request BUT ensure it fits small screens */
        max-width: 100%;
        margin: 0 auto;
        box-sizing: border-box;
    }

    .cajita h3 {
        font-size: 1.4rem;
    }

    /* Overlays */
    .redes-menu,
    .login-menu,
    .votos-container {
        width: 90%;
        max-width: 350px;
        /* Fit within 375px */
        padding: 1.5rem;
        max-height: 85vh;
        overflow-y: auto;
    }

    /* Menu Visibility */
    .hamburger-btn,
    #menuBtn {
        display: block !important;
        position: relative;
        z-index: 2000;
        /* Higher z-index just in case */
        color: white;
        font-size: 1.5rem;
    }

    /* Hero Section Adjustments */
    h1 {
        font-size: 1.5rem !important;
        /* Significantly smaller */
        line-height: 1.2;
        margin-bottom: 10px;
    }

    .clock {
        transform: scale(0.6);
        /* Scale down FlipClock */
        transform-origin: center top;
        margin: 0 auto !important;
        width: 100% !important;
        display: flex;
        justify-content: center;
    }

    .hero-video {
        object-position: 80% center !important;
        /* Focus to the right */
    }

    /* Grid Layouts - 2 Columns */
    /* Grid Layouts - Fluid Auto-Fit (The "Silver Bullet" solution) */
    .flex-container {
        display: grid;
        /* This magic line makes it 2 cols on wide phones, 1 col on narrow phones automatically */
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
        gap: 15px;
        padding: 10px;
        width: 100% !important;
        align-items: stretch;
        justify-content: center;
    }

    .cajita {
        height: auto !important;
        /* Allow growing */
        min-height: 220px;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 15px;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        /* Ensure content is at bottom */
    }

    .cajita h3 {
        font-size: 1rem !important;
        /* Smaller text */
        margin-bottom: 5px;
    }

    .cajita .btn {
        padding: 5px 10px !important;
        font-size: 0.8rem !important;
        min-height: 30px;
    }

    /* Footer */
    footer {
        padding: 2rem 0;
        margin-top: 2rem;
        width: 100%;
        overflow-x: hidden;
    }

    /* Vote Summary Mobile Fixes */
    .caja-votos {
        grid-column: 1 / -1;
        padding: 10px;
        gap: 10px;
        flex-direction: column;
        align-items: center;
        width: 80%;
        box-sizing: border-box;
        max-height: 100%;
    }

    .tarjeta-voto {
        /* Override desktop 300px */
        min-width: 0;
        /* Allow shrinking */
        flex-direction: row;
        /* Keep row for icon + info to save vertical space? OR column? User said shrinking text/icon. Row usually saves height. Let's keep existing structure but shrink content. */
        align-items: center;
        gap: 10px;
        padding: 10px !important;
        width: 80%;
        /* Fix rigid width causing overflow */
        max-width: 80%;
        box-sizing: border-box;
        /* Ensure padding aligns inside */
        margin-bottom: 10px;
    }

    .tarjeta-voto .rank-icon {
        font-size: 1.2rem !important;
        /* Smaller icon */
    }

    .tarjeta-voto .info h4,
    .tarjeta-voto .info p,
    .tarjeta-voto .place-text {
        font-size: 0.6rem !important;
        /* Smaller title */
    }

    .tarjeta-voto .btn-eliminar-voto {
        width: 25px;
        height: 25px;
        font-size: 0.8rem;
    }

    #Patreon {
        text-align: center;
        margin: auto;
        position: relative;
        z-index: 10;
        width: 80%;
    }

    #Patreon p {
        font-size: 0.8rem;
    }

    #Patreon a {
        font-size: 0.8rem;
    }

    .cajita p {
        display: none;
    }


}

/* Very small screens (Galaxy S8+ etc) */