/* ============================================================
   MOBILE CORE FIXES — Tokenomics ICO Pages
   Loads LAST in index.html for maximum specificity
   Target minimum width: 375px (iPhone SE / standard)
   Breakpoints: 375px | 480px | 600px | 768px | 1024px | 1400px
   ============================================================ */

/* ==========================================================
   1. PREVENT HORIZONTAL OVERFLOW (Global)
   ========================================================== */

html {
    overflow-x: hidden;
}

body {
    overflow-x: hidden !important;
    min-width: unset !important; /* Remove forced min-width */
}

.tab-content,
#tab_content,
.main-content,
.content-wrapper,
.page-content,
main {
    overflow-x: hidden;
    max-width: 100%;
}

/* ==========================================================
   2. WALLET CONNECTION — Fix absolute positioning off-screen
   ========================================================== */

/* On screens narrower than 1400px the hardcoded left:1320px
   pushes the wallet completely off the visible area.         */
@media (max-width: 1400px) {
    #wallet-connection-container {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        z-index: 50 !important;
        display: inline-flex !important;
        margin: 0 auto !important;
    }
}

/* ==========================================================
   3. TAB NAVIGATION — Horizontal scroll on mobile
   ========================================================== */

@media (max-width: 768px) {
    .tab-navigation {
        /* Enable smooth horizontal scroll */
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch; /* iOS momentum scroll */
        scroll-snap-type: x proximity;
        /* Keep all buttons in one row */
        flex-wrap: nowrap !important;
        /* Visual: hide scrollbar but keep functionality */
        scrollbar-width: none;       /* Firefox */
        -ms-overflow-style: none;    /* IE/Edge */
        /* Breathing room */
        padding: 10px 8px !important;
        gap: 6px !important;
    }

    .tab-navigation::-webkit-scrollbar {
        display: none;               /* Chrome/Safari */
    }

    .tab-btn {
        /* Allow buttons to shrink/grow naturally without a fixed min-width */
        min-width: unset !important;
        flex: 0 0 auto !important;   /* Don't stretch, don't shrink */
        scroll-snap-align: start;
        white-space: nowrap;
        padding: 8px 12px !important;
        font-size: 0.78rem !important;
        min-height: 44px !important; /* Accessible touch target */
    }
}

@media (max-width: 480px) {
    .tab-btn {
        padding: 8px 10px !important;
        font-size: 0.72rem !important;
        gap: 4px !important;
    }

    .tab-icon {
        font-size: 1rem !important;
    }
}

/* ==========================================================
   4. GLOBAL CARD & GRID REFLOW
   ========================================================== */

@media (max-width: 768px) {
    /* Any card grid that has hardcoded column widths */
    .token-packages-grid,
    .energy-pools-grid,
    .marketplace-grid,
    .nft-grid,
    .rewards-grid,
    .cards-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
        padding: 16px !important;
    }

    /* Course grid: 2 columns on small tablets */
    .course-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        padding: 12px !important;
    }

    /* Wide special-centered cards */
    .token-packages-grid .token-price-card:nth-child(13),
    .token-packages-grid .custom-amount-card,
    .energy-pools-grid .energy-pool-card:nth-child(8) {
        max-width: 100% !important;
        grid-column: auto !important;
    }

    /* Card min-heights: remove excessive minimums */
    .token-price-card,
    .energy-pool-card,
    .course-card {
        min-height: auto !important;
    }
}

@media (max-width: 480px) {
    .course-grid {
        grid-template-columns: 1fr !important;
    }

    .token-packages-grid,
    .energy-pools-grid,
    .marketplace-grid {
        padding: 10px !important;
        gap: 14px !important;
    }
}

/* ==========================================================
   5. TYPOGRAPHY SCALING
   ========================================================== */

@media (max-width: 768px) {
    h1 { font-size: clamp(1.4rem, 5vw, 2.5rem) !important; }
    h2 { font-size: clamp(1.2rem, 4vw, 2rem) !important; }
    h3 { font-size: clamp(1rem, 3.5vw, 1.5rem) !important; }
}

@media (max-width: 480px) {
    body { font-size: 14px; }
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.05rem !important; }
    p  { font-size: 0.875rem; }
}

/* ==========================================================
   6. IMAGES & MEDIA
   ========================================================== */

img,
video,
canvas,
svg {
    max-width: 100%;
    height: auto;
}

/* Allow canvas to scale but preserve aspect ratio */
canvas {
    max-width: 100%;
}

/* ==========================================================
   7. BUTTONS & INTERACTIVE ELEMENTS
   ========================================================== */

/* Accessible touch targets for ALL interactive elements */
@media (hover: none) and (pointer: coarse) {
    button,
    .tab-btn,
    a.btn,
    [role="button"],
    .btn-purchase,
    .btn-primary,
    .btn-secondary {
        min-height: 44px;
    }

    /* Remove hover transforms on touch devices */
    .tab-btn:hover:not(.active) {
        background: transparent;
        transform: none;
        box-shadow: none;
    }
}

@media (max-width: 480px) {
    .btn-purchase,
    .btn-primary,
    .btn-secondary,
    .quantum-btn {
        padding: 10px 16px !important;
        font-size: 0.875rem !important;
        width: 100% !important;
        max-width: 320px;
    }
}

/* ==========================================================
   8. MODAL & OVERLAYS
   ========================================================== */

@media (max-width: 600px) {
    .modal,
    .transaction-modal,
    .modal-content,
    .modal-inner {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 8px auto !important;
        padding: 16px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: 8px !important;
    }
}

/* ==========================================================
   9. TAB CONTENT PADDING
   ========================================================== */

@media (max-width: 768px) {
    .tab-content,
    #tab_content,
    .tab-content.active,
    #tab_content.active {
        padding: 12px !important;
    }
}

@media (max-width: 480px) {
    .tab-content,
    #tab_content,
    .tab-content.active,
    #tab_content.active {
        padding: 8px !important;
    }
}

/* ==========================================================
   10. STAT BUBBLES / CIRCLE ELEMENTS
   ========================================================== */

@media (max-width: 480px) {
    .stat-bubble {
        width: 72px !important;
        height: 72px !important;
        font-size: 0.75rem !important;
    }
}

/* ==========================================================
   11. TABLE/LEADERBOARD OVERFLOW
   ========================================================== */

@media (max-width: 768px) {
    /* Leaderboard tables: allow horizontal scroll as fallback */
    .leaderboard-table,
    .promo-table,
    .stats-table {
        overflow-x: auto;
        display: block;
        -webkit-overflow-scrolling: touch;
    }
}

/* ==========================================================
   12. FOOTER
   ========================================================== */

@media (max-width: 600px) {
    .site-footer,
    footer {
        flex-direction: column !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 20px 16px !important;
        text-align: center !important;
    }

    .social-links {
        justify-content: center !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
}

/* ==========================================================
   13. HOLOFOIL CARDS — Touch-specific tweaks
   ========================================================== */

/* On touch devices, maintain the holofoil active state longer
   since there's no hover. The JS touchmove handles the parallax.
   Here we ensure the CSS defaults are set for touch start/end. */
@media (hover: none) and (pointer: coarse) {
    .holo-card,
    .holofoil-card,
    [data-holo] {
        /* Keep effect visible during touch; JS will control --mouse-x/y */
        --mouse-x: 0.5;
        --mouse-y: 0.5;
        /* Slightly lower transform intensity to prevent motion sickness */
        transform-style: preserve-3d;
    }

    /* Remove :hover state effects that JS can't trigger on touch */
    .holo-card:hover .holo-shine,
    .holofoil-card:hover .holo-shine {
        opacity: 0;
    }
}

/* ==========================================================
   14. INPUT FIELDS (prevent iOS zoom on focus)
   ========================================================== */

@media (max-width: 768px) {
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }
}
