/**
 * PKM-Universe Mobile Styles v3
 * Comprehensive mobile optimization for ALL pages
 */

/* Prevent horizontal scroll globally */
html, body {
    overflow-x: hidden;
    overflow-x: clip;
    max-width: 100%;
}

/* Ensure media doesn't overflow */
img, video, canvas {
    max-width: 100%;
    height: auto;
}

/* ===== GLOBAL MOBILE FIXES ===== */

/* Touch targets - minimum 44px for accessibility */
@media (hover: none) {
    button, a, .btn, .nav-link, .tab-btn, .filter-tab, .filter-btn {
        min-height: 44px;
        min-width: 44px;
    }
    /* Hide custom cursor on touch devices */
    .custom-cursor, .cursor-trail { display: none !important; }
}

/* ===== TABLET (1024px) ===== */
@media (max-width: 1024px) {
    /* Reduce padding on containers */
    .container, .content, .page-wrapper, .main-content {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Stack grids to 2 columns */
    .grid-3, .grid-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* === BOT MONITOR === */
    .main-layout {
        grid-template-columns: 1fr !important;
    }
    .bots-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .health-panel {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .stats-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* === MEMBERSHIPS === */
    .pricing-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
        max-width: 500px !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
    .timeline {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .game-coverage-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* === EVENTS === */
    .file-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* === LIVE TRADING === */
    .content-grid {
        grid-template-columns: 1fr !important;
    }
    .bots-grid {
        grid-template-columns: 1fr !important;
    }

    /* === TEAM BUILDER === */
    .team-container {
        grid-template-columns: 1fr !important;
    }

    /* === COLLECTION DEMO === */
    .calendar-container {
        grid-template-columns: 1fr !important;
    }
    .battle-layout {
        grid-template-columns: 1fr !important;
    }
    .ribbon-layout {
        grid-template-columns: 1fr !important;
    }

    /* === HALL OF FAME === */
    .team-picker {
        grid-template-columns: repeat(6, 1fr) !important;
    }
    .poke-results {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* ===== MOBILE (768px) ===== */
@media (max-width: 768px) {
    /* Global text scaling */
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1rem !important; }

    /* Prevent overflow */
    .hero-banner, .live-counter, .stats-section, .leaderboard, .command-box {
        max-width: 100%;
        box-sizing: border-box;
    }

    .hero-title {
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Announcement/alert banners */
    .announcement-banner, .alert-banner, .news-ticker {
        font-size: 0.72rem;
        padding: 6px 12px;
    }

    /* Cards */
    .glass-card, .card, .panel {
        border-radius: 12px;
    }

    /* Footer */
    .footer, .site-footer {
        padding: 20px 16px;
        font-size: 0.75rem;
    }

    /* Discord widget - keep visible but smaller */
    .discord-widget iframe {
        transform: scale(0.85);
        transform-origin: bottom left;
    }

    /* Chatbot button - prevent overlap with Discord widget */
    .chat-toggle, .pkm-chatbot-toggle {
        bottom: 70px !important;
        right: 14px !important;
        width: 48px !important;
        height: 48px !important;
        z-index: 9990 !important;
    }

    /* === PERFORMANCE: Hide heavy backgrounds === */
    #constellation,
    #matrixRain,
    .aurora-bg,
    .hex-grid,
    .radar-pulse,
    .scan-line,
    .bg-particles,
    .confetti-container,
    #stars-canvas {
        display: none !important;
    }

    /* === BOT MONITOR === */
    .bots-grid {
        grid-template-columns: 1fr !important;
    }
    .health-panel {
        grid-template-columns: 1fr 1fr !important;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .bot-stats {
        grid-template-columns: 1fr !important;
    }
    .modal-stats-grid {
        grid-template-columns: 1fr !important;
    }
    .new-features-grid {
        grid-template-columns: 1fr !important;
    }
    .boot-sequence {
        font-size: 12px !important;
    }
    .console-overlay {
        max-width: 100vw !important;
        width: 100% !important;
    }

    /* === MEMBERSHIPS === */
    .pricing-grid {
        grid-template-columns: 1fr !important;
    }
    .timeline {
        grid-template-columns: 1fr !important;
    }
    .game-coverage-grid {
        grid-template-columns: 1fr 1fr !important;
    }
    .comp-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        font-size: 12px !important;
    }
    .floating-pokemon {
        display: none !important;
    }

    /* === LEADERBOARD === */
    .stats-banner {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .leaderboard-grid {
        grid-template-columns: 1fr !important;
    }
    .period-filter {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .period-btn {
        flex: 1 1 auto !important;
        min-width: 60px !important;
        font-size: 11px !important;
        padding: 8px 10px !important;
        text-align: center !important;
    }

    /* === EVENTS === */
    .file-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .detail-grid {
        grid-template-columns: 1fr !important;
    }
    .side-panel {
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* === MYSTERY GIFTS === */
    .capsule-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .system-hud {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        width: 100% !important;
        margin-bottom: 16px !important;
    }
    .bottom-sheet {
        border-radius: 16px 16px 0 0 !important;
    }

    /* === SUPPORT === */
    .stats-bar {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .user-stats-dashboard {
        grid-template-columns: 1fr !important;
    }
    .chat-window {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 99999 !important;
    }
    .tab-bar {
        flex-wrap: wrap !important;
        gap: 4px !important;
    }
    .tab-btn {
        font-size: 11px !important;
        padding: 8px 12px !important;
        flex: 1 1 auto !important;
        min-width: 70px !important;
        text-align: center !important;
    }

    /* === DONUT MAKER === */
    .maker-layout {
        grid-template-columns: 1fr !important;
    }
    .stats-row {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .data-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* === LIVE TRADING === */
    .content-grid {
        grid-template-columns: 1fr !important;
    }
    .dex-stats {
        grid-template-columns: 1fr !important;
    }

    /* === TEAM BUILDER === */
    .team-container {
        grid-template-columns: 1fr !important;
    }
    .pokemon-list {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .team-slots {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .stat-bars {
        grid-template-columns: 1fr !important;
    }

    /* === POKEDEX === */
    .scroll-to-top, .scroll-top {
        bottom: 80px !important;
        right: 12px !important;
        width: 44px !important;
        height: 44px !important;
    }

    /* === COLLECTION DEMO === */
    .potd-layout {
        grid-template-columns: 1fr !important;
    }
    .potd-prev {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .section-nav {
        position: relative !important;
        width: 100% !important;
        overflow-x: auto !important;
        display: flex !important;
        gap: 6px !important;
        padding: 8px !important;
        -webkit-overflow-scrolling: touch;
    }

    /* === HALL OF FAME === */
    .form-grid {
        grid-template-columns: 1fr !important;
    }
    .team-picker {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .poke-results {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .poke-search-overlay {
        width: 100% !important;
        max-width: 100vw !important;
        inset: 0 !important;
        border-radius: 0 !important;
    }

    /* === LIVING DEX === */
    .dex-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
    .gen-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* === BALL COLLECTION === */
    .rate-table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* === WONDER TRADE === */
    .form-row {
        grid-template-columns: 1fr !important;
    }

    /* === ANNOUNCEMENTS === */
    .announcement-card {
        padding: 16px !important;
    }

    /* === TOAST NOTIFICATIONS === */
    .toast-container, .toast {
        left: 12px !important;
        right: 12px !important;
        max-width: calc(100vw - 24px) !important;
    }

    /* === MODAL OVERLAYS (global) === */
    .modal-overlay, .sheet-overlay, .trade-modal-overlay {
        padding: 8px !important;
    }
    .modal, .bottom-sheet, .trade-modal {
        max-width: 100% !important;
        border-radius: 14px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    /* === TABLES (global scroll wrapper) === */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    thead, tbody, tr {
        max-width: 100%;
    }

    /* === HERO SECTIONS (global) === */
    .hero, .hero-section, .hero-scanner, .vault-hero {
        padding: 80px 16px 30px !important;
        min-height: auto !important;
    }
    .hero h1, .hero-section h1, .vault-hero h1 {
        font-size: 1.5rem !important;
        word-break: break-word !important;
    }
    .hero p, .hero-section p {
        font-size: 0.9rem !important;
    }

    /* === FILTER BARS (global) === */
    .filter-bar, .filter-row {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .filter-bar select, .filter-bar input {
        font-size: 14px !important;
        min-width: 120px !important;
    }
}

/* ===== SMALL MOBILE (480px) ===== */
@media (max-width: 480px) {
    /* Even tighter spacing */
    .container, .content, .page-wrapper, .main-content {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .hero-title {
        letter-spacing: 1px !important;
        font-size: 1.2rem !important;
    }

    .hero-banner {
        max-width: calc(100vw - 20px);
        margin-left: auto;
        margin-right: auto;
        padding: 16px !important;
    }

    /* Stack all grids to single column */
    .grid-2, .grid-3, .grid-4, .stats-banner, .stats-bar {
        grid-template-columns: 1fr !important;
    }

    /* Buttons full width */
    .hero-buttons, .cta-buttons {
        flex-direction: column !important;
        width: 100%;
    }
    .hero-btn, .cta-btn, .btn-primary, .btn-secondary {
        width: 100% !important;
        max-width: 320px;
        text-align: center;
    }

    /* Tab navigation - wrap and shrink */
    .tab-nav, .period-filter, .filter-bar {
        flex-wrap: wrap;
        gap: 4px;
    }
    .tab-btn, .period-btn, .filter-tab {
        font-size: 0.68rem;
        padding: 8px 10px;
        flex: 1 1 auto;
        min-width: 60px;
        text-align: center;
    }

    /* Hide non-essential elements */
    .desktop-only, .nav-desktop-only { display: none !important; }

    /* Footer simplify */
    .footer kbd, .footer .keyboard-hint { display: none; }

    /* Chatbot fullscreen */
    .chat-window, .pkm-chatbot-window {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        z-index: 99999 !important;
    }

    /* === BOT MONITOR === */
    .health-panel {
        grid-template-columns: 1fr !important;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* === EVENTS === */
    .file-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* === MYSTERY GIFTS === */
    .capsule-grid {
        grid-template-columns: 1fr !important;
    }

    /* === SUPPORT === */
    .stats-bar {
        grid-template-columns: 1fr !important;
    }

    /* === DONUT MAKER === */
    .stats-row {
        grid-template-columns: 1fr !important;
    }

    /* === TEAM BUILDER === */
    .pokemon-list {
        grid-template-columns: 1fr 1fr !important;
    }

    /* === LIVING DEX === */
    .dex-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* === HALL OF FAME === */
    .team-picker {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .poke-results {
        grid-template-columns: 1fr 1fr !important;
    }

    /* === HERO (tighter) === */
    .hero, .hero-section, .hero-scanner, .vault-hero {
        padding: 70px 12px 20px !important;
    }
    .hero h1, .hero-section h1, .vault-hero h1 {
        font-size: 1.25rem !important;
    }

    /* === LEADERBOARD === */
    .stats-banner {
        grid-template-columns: 1fr !important;
    }
}

/* ===== VERY SMALL (360px) ===== */
@media (max-width: 360px) {
    .hero-title { font-size: 1rem !important; }
    .hero-banner {
        max-width: calc(100vw - 16px);
        padding: 12px !important;
    }

    /* Even smaller text */
    body { font-size: 14px; }
    .tab-btn, .period-btn, .filter-tab { font-size: 0.6rem; padding: 6px 6px; }

    /* Living dex 2 cols */
    .dex-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Events 1 col */
    .file-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== SAFE AREA (Notch phones) ===== */
@supports (padding-top: env(safe-area-inset-top)) {
    .nav, .nav-container, header {
        padding-top: env(safe-area-inset-top);
    }
    .footer, .site-footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .hero { min-height: auto !important; padding-top: 70px !important; }
    .pokemon-cluster { display: none; }
}

/* ===== REDUCE MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .mesh-blob, .bg-particle, .sparkle { display: none !important; }
}

/* ===== DARK MODE CONTRAST ===== */
@media (prefers-contrast: high) {
    :root {
        --text-dim: #aaa;
        --border: rgba(212, 175, 55, 0.3);
    }
}
