/* =========================================================================
   responsive.css - Dinamic Variables & Breakpoints
   ========================================================================= */

/* -- 1. MOBILE SMALL (320px - 480px) -- */
@media (max-width: 480px) {
    :root {
        --sidebar-width: 0;
        --content-padding: 1rem;
        --header-height: 56px;
        --button-padding: 0.7rem 1rem;
        --button-font-size: 0.9rem;
        --card-padding: 1rem;
        --gap-default: 0.8rem;
        --grid-cols-stat: 2;
        --grid-cols-card: 1;
        --max-app-width: 100%;
    }

    html {
        font-size: 14px;
    }

    body {
        padding-bottom: 0;
    }

    .app-sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        width: 280px;
        z-index: 100;
        height: 100vh;
        display: flex !important;
        flex-direction: column;
    }

    .app-sidebar.open {
        transform: translateX(0);
    }
}

/* -- 2. MOBILE LARGE (481px - 768px) -- */
@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --sidebar-width: 0;
        --content-padding: 1.2rem;
        --header-height: 60px;
        --button-padding: 0.75rem 1.2rem;
        --button-font-size: 0.95rem;
        --card-padding: 1.2rem;
        --gap-default: 1rem;
        --grid-cols-stat: 2;
        --grid-cols-card: 2;
        --max-app-width: 100%;
    }

    html {
        font-size: 15px;
    }

    body {
        padding-bottom: 0;
    }
}

/* -- 3. TABLET (769px - 1024px) -- */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
        --content-padding: 1.5rem;
        --header-height: 64px;
        --button-padding: 0.8rem 1.5rem;
        --button-font-size: 1rem;
        --card-padding: 1.5rem;
        --gap-default: 1.2rem;
        --grid-cols-stat: 3;
        --grid-cols-card: 2;
        --max-app-width: 100%;
        /* Lasciamo espandere nel contenitore che ha la sidebar */
    }

    html {
        font-size: 16px;
    }

    body {
        padding-bottom: 0;
    }

    .app-sidebar {
        display: flex !important;
        transform: translateX(0);
        width: var(--sidebar-width);
    }

    .bottom-nav {
        display: none !important;
    }

    .app-main {
        margin-left: 0;
    }
}

/* -- 4. DESKTOP (1025px+) -- */
@media (min-width: 1025px) {
    :root {
        --sidebar-width: 280px;
        --content-padding: 2rem;
        --header-height: 70px;
        --button-padding: 0.9rem 2rem;
        --button-font-size: 1.05rem;
        --card-padding: 2rem;
        --gap-default: 1.5rem;
        --grid-cols-stat: 4;
        --grid-cols-card: 3;
        --max-app-width: 100%;
        /* Espandiamo a tutta la pagina invece di chiuderlo in centro con i 1200 */
    }

    html {
        font-size: 17px;
    }

    body {
        padding-bottom: 0;
    }

    /* FIX: Unblock scroll on desktop explicitly */
    html,
    body {
        overflow-y: auto !important;
        height: auto !important;
    }

    .app-sidebar {
        display: flex !important;
        transform: translateX(0);
        width: var(--sidebar-width);
    }

    .bottom-nav {
        display: none !important;
    }

    .app-main {
        margin-left: 0;
        max-width: 100%;
    }
}

/* -- DESKTOP: Constrain standalone pages (no sidebar) -- */
@media (min-width: 1025px) {

    .page-hero,
    .fuel-tabs,
    .tab-panel,
    .arcade-header,
    .fuel-header,
    .stats-bar,
    .store-header,
    .patentiamoci-card,
    .store-note,
    .section-title,
    .rewards-grid,
    .lb-section,
    .daily-card {
        max-width: 900px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* -- COMPONENT RESPONSIVE RULES (Using Variables) -- */

/* Buttons */
button,
.btn {
    padding: var(--button-padding);
    font-size: var(--button-font-size);
}

@media (max-width: 768px) {

    button:not(.hamburger):not(.icon-btn):not(.dash-mini-btn):not(.dash-customize-btn):not(.dash-copy-btn):not(.ans-btn),
    .btn {
        width: 100%;
    }
}

@media (min-width: 769px) {

    button,
    .btn {
        width: auto;
        min-width: 120px;
    }
}

/* Cards & Layout */
.card,
.stat-card {
    padding: var(--card-padding);
}

.stats-grid,
.stat-grid,
.grid-responsive {
    display: grid;
    gap: var(--gap-default);
    grid-template-columns: repeat(var(--grid-cols-stat), 1fr);
}

.card-grid {
    display: grid;
    gap: var(--gap-default);
    grid-template-columns: repeat(var(--grid-cols-card), 1fr);
}

.quick-grid {
    display: grid;
    gap: var(--gap-default);
}

@media (max-width: 480px) {
    .quick-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 481px) {
    .quick-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* -- FIX: LEADERBOARD OVERFLOW -- */
@media (max-width: 768px) {
    .lb-item {
        display: grid;
        grid-template-columns: 40px 1fr;
        grid-template-rows: auto auto auto;
        gap: 0.8rem;
        padding: 0.8rem;
    }

    .lb-rank {
        grid-column: 1;
        grid-row: 1;
        font-size: 0.9rem;
    }

    .lb-avatar {
        grid-column: 1;
        grid-row: 2;
        width: 40px;
        height: 40px;
    }

    .lb-nick {
        grid-column: 2;
        grid-row: 1;
        text-align: left;
    }

    .lb-league {
        grid-column: 2;
        grid-row: 2;
        font-size: 0.8rem;
    }

    .lb-xp {
        grid-column: 2;
        grid-row: 3;
        text-align: right;
    }

    .lb-delta {
        grid-column: 2;
        grid-row: 3;
        justify-self: end;
    }
}

@media (min-width: 769px) {
    .lb-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        padding: 1rem 1.2rem;
    }
}

/* -- FIX: SCROLL-TO-TOP BUTTON -- */
#scroll-top-btn {
    position: fixed;
    z-index: 999;
    transition: opacity 0.3s, transform 0.3s;
}

@media (max-width: 768px) {
    #scroll-top-btn {
        bottom: 100px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
}

@media (min-width: 1025px) {
    #scroll-top-btn {
        bottom: 40px;
        right: 40px;
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
}

/* -- SIDEBAR RESPONSIVE TOGGLE (Hamburger Overlay) -- */
@media (max-width: 768px) {
    .hamburger {
        display: block;
    }

    .app-sidebar {
        position: fixed !important;
        left: 0;
        transform: translateX(-100%);
        width: 280px;
        z-index: 100;
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-overlay {
        display: none;
    }

    .app-overlay.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 49;
    }
}

@media (min-width: 769px) {
    .hamburger {
        display: none;
    }

    .app-overlay {
        display: none !important;
    }
}

/* -- ANDROID SCROLL LOCK FIX -- */
body {
    overflow: auto !important;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    height: auto;
}

.page-content {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.quiz-container,
.card-stack {
    overflow: hidden !important;
    touch-action: none;
}