/* ═══════════════════════════════════════════════════════════════
   676 SURVEILLANCE NETWORK - MOBILE RESPONSIVE DESIGN
   Complete mobile overhaul for optimal touch experience
   ═══════════════════════════════════════════════════════════════ */

/* ── TABLET & MOBILE (768px and below) ── */
@media (max-width: 768px) {
    
    /* ═══ BASE LAYOUT ═══ */
    body {
        font-size: 14px;
        overflow-x: hidden;
    }
    
    /* ═══ HERO SECTION ═══ */
    .hero {
        padding: 1.5rem 1rem !important;
        min-height: auto !important;
    }
    
    .lycoris-logo-img {
        max-width: 280px !important;
        margin: 0 auto 1rem auto !important;
    }
    
    .main-title {
        font-size: 3.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .collective-text {
        font-size: 1.1rem !important;
        letter-spacing: 4px !important;
    }
    
    .subtitle {
        font-size: 0.85rem !important;
        padding: 0 1rem;
    }
    
    .warning-banner {
        font-size: 0.75rem !important;
        padding: 0.6rem 1rem !important;
    }
    
    .status-indicator {
        font-size: 0.85rem !important;
        padding: 0.5rem 1rem !important;
    }
    
    /* ═══ MAIN CONTENT GRID - STACK ON MOBILE ═══ */
    .main-content-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
        padding: 0 1rem !important;
        max-width: 100% !important;
        margin: 1rem auto !important;
        width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    /* Prevent overlapping - ensure sections stack with clear spacing */
    .main-content-grid > div {
        min-width: 0 !important;
        overflow: hidden !important;
    }
    
    /* ═══ BOSS BANNER ═══ */
    #boss-banner {
        padding: 1rem !important;
        margin: 1rem !important;
    }
    
    .boss-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
    }
    
    .boss-stat {
        padding: 0.6rem !important;
        font-size: 0.8rem !important;
    }
    
    .boss-stat-value {
        font-size: 1.2rem !important;
    }
    
    /* ═══ THREAT ALERT PANEL ═══ */
    #threat-alert-panel {
        width: 95% !important;
        max-width: 95vw !important;
        left: 2.5% !important;
        right: 2.5% !important;
    }
    
    .threat-alert {
        padding: 0.8rem !important;
        font-size: 0.85rem !important;
    }
    
    /* ═══ NAVIGATION ═══ */
    .navbar {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        padding: 0.8rem 0.9rem !important;
        gap: 0.75rem !important;
        justify-content: space-between !important;
        align-items: center !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 9999 !important;
    }
    
    .nav-logo {
        font-size: 1.25rem !important;
        letter-spacing: 4px !important;
        line-height: 1.1 !important;
        flex-shrink: 0 !important;
        max-width: 60% !important;
    }
    
    .nav-toggle {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex: 0 0 auto !important;
        height: 46px !important;
        width: 46px !important;
        min-height: 46px !important;
        min-width: 46px !important;
        border-radius: 12px !important;
    }
    
    .nav-menu {
        width: 100% !important;
        order: 99 !important;
        flex: 1 1 100% !important;
        display: none !important;
        margin-top: 0.5rem !important;
        padding-top: 0.5rem !important;
        border-top: 1px solid rgba(255, 0, 0, 0.25) !important;
    }
    
    .navbar.nav-open .nav-menu {
        display: block !important;
    }
    
    .nav-links {
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.5rem !important;
    }
    
    .nav-links a, .nav-links button {
        width: 100% !important;
        text-align: center !important;
        padding: 0.95rem 1rem !important;
        font-size: 0.95rem !important;
        min-height: 48px !important;
        border-radius: 12px !important;
        background: rgba(0, 0, 0, 0.25) !important;
        border: 1px solid rgba(255, 0, 0, 0.18) !important;
    }
    
    .nav-links a.discord-link {
        justify-content: center !important;
    }
    
    /* ═══ INSTANCE TRACKER ═══ */
    .instance-tracker {
        padding: 1rem !important;
        margin: 0 0 1rem 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .instance-header h2 {
        font-size: 1.5rem !important;
    }
    
    .instance-stats {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.6rem !important;
        width: 100% !important;
    }
    
    .instance-stat {
        width: 100% !important;
        padding: 0.6rem 0.5rem !important;
        font-size: 0.85rem !important;
    }
    
    .instance-stat .instance-stat-value {
        font-size: 1.5rem !important;
    }
    
    .instance-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    .instance-card {
        padding: 1rem !important;
    }
    
    /* Mobile-only: group tabs to reduce scroll */
    .mobile-group-tabs {
        display: flex !important;
        gap: 0.6rem !important;
        margin: 1rem 0 1.25rem 0 !important;
        padding: 0.5rem !important;
        border-radius: 14px !important;
        background: rgba(0, 0, 0, 0.35) !important;
        border: 1px solid rgba(255, 255, 255, 0.08) !important;
    }
    
    .mobile-group-tab {
        flex: 1 1 50% !important;
        border: 1px solid rgba(255, 255, 255, 0.12) !important;
        background: rgba(0, 0, 0, 0.25) !important;
        color: #fff !important;
        padding: 0.75rem 0.7rem !important;
        border-radius: 12px !important;
        font-size: 0.85rem !important;
        letter-spacing: 1px !important;
        text-transform: uppercase !important;
        min-height: 48px !important;
    }
    
    .mobile-group-tab.is-active {
        border-color: rgba(255, 0, 0, 0.55) !important;
        box-shadow: 0 0 18px rgba(255, 0, 0, 0.25) !important;
        background: rgba(120, 0, 0, 0.18) !important;
    }
    
    body.mobile-tabs .instance-group {
        display: none !important;
    }
    
    body.mobile-tabs .instance-group.active {
        display: block !important;
    }
    
    .instance-header-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }
    
    .player-count-badge {
        align-self: flex-start !important;
        font-size: 0.8rem !important;
        padding: 0.4rem 0.8rem !important;
    }
    
    /* Boss player cards on mobile */
    .boss-player-card {
        padding: 0.8rem !important;
        font-size: 0.85rem !important;
    }
    
    .boss-action-buttons {
        flex-direction: column !important;
        gap: 0.4rem !important;
    }
    
    .boss-action-buttons button {
        width: 100% !important;
        padding: 0.6rem !important;
        font-size: 0.85rem !important;
    }
    
    /* ═══ RULES SECTION ═══ */
    .rules-section {
        padding: 1.5rem 1rem !important;
        margin-top: 1.5rem !important;
    }
    
    .rules-toggle {
        width: 100% !important;
        margin: 0 0 1rem 0 !important;
        padding: 0.85rem 1rem !important;
        border-radius: 12px !important;
        border: 1px solid rgba(255, 0, 0, 0.28) !important;
        background: rgba(0, 0, 0, 0.35) !important;
        color: #fff !important;
        font-weight: 700 !important;
        letter-spacing: 1px !important;
        text-transform: uppercase !important;
    }
    
    .rules-body {
        position: relative !important;
    }
    
    .rules-section.rules-collapsed .rules-body {
        max-height: 520px !important;
        overflow: hidden !important;
        border-radius: 10px !important;
    }
    
    .rules-section.rules-collapsed .rules-body::after {
        content: '' !important;
        position: absolute !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        height: 90px !important;
        background: linear-gradient(to bottom, rgba(0,0,0,0), rgba(0,0,0,0.95)) !important;
        pointer-events: none !important;
    }
    
    .rules-section h2 {
        font-size: 1.5rem !important;
        letter-spacing: 2px !important;
    }
    
    .rules-section h3 {
        font-size: 1rem !important;
    }
    
    .rules-section p {
        font-size: 0.85rem !important;
    }
    
    /* ═══ LOGIN PAGE ═══ */
    .login-container {
        padding: 2rem 1.5rem !important;
        width: 92% !important;
        max-width: 400px !important;
    }
    
    .login-title {
        font-size: 2.2rem !important;
    }
    
    .login-form input {
        padding: 0.9rem !important;
        font-size: 16px !important;
    }
    
    .login-button {
        padding: 1rem !important;
        font-size: 1rem !important;
        min-height: 50px !important;
    }
    
    /* ═══ ADMIN PANEL ═══ */
    .admin-tabs {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        padding: 0.5rem !important;
    }
    
    .admin-tab {
        font-size: 0.85rem !important;
        padding: 0.7rem 1rem !important;
        min-height: 44px !important;
        flex: 1 1 calc(50% - 0.5rem) !important;
        text-align: center !important;
    }
    
    .dropdown-btn {
        font-size: 0.85rem !important;
        padding: 0.7rem 1rem !important;
        min-height: 44px !important;
    }
    
    .dropdown-content {
        position: static !important;
        width: 100% !important;
        box-shadow: none !important;
        margin-top: 0.5rem !important;
    }
    
    .dropdown-item {
        padding: 0.9rem !important;
        font-size: 0.9rem !important;
        min-height: 48px !important;
    }
    
    /* Dashboard cards stack on mobile */
    .dashboard-grid, .admin-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    .dashboard-card, .admin-card {
        padding: 1rem !important;
        margin: 0 !important;
    }
    
    .dashboard-card h2, .admin-card h2 {
        font-size: 1.3rem !important;
    }
    
    /* Boss Intel Section */
    #boss-intel-section > div {
        grid-template-columns: 1fr !important;
    }
    
    .network-stat, .health-stat {
        padding: 0.7rem !important;
        font-size: 0.85rem !important;
    }
    
    /* ═══ TABLES - HORIZONTAL SCROLL ═══ */
    .table-container, 
    table,
    #staff-leaderboard-container,
    #staff-registry-table,
    #moderation-stats-grid,
    [style*="overflow-x: auto"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    table {
        min-width: 600px;
        font-size: 0.8rem !important;
    }
    
    table th, table td {
        padding: 0.6rem 0.4rem !important;
        white-space: nowrap;
    }
    
    /* Staff leaderboard compact */
    #staff-leaderboard-container table th,
    #staff-leaderboard-container table td {
        font-size: 0.75rem !important;
        padding: 0.5rem 0.3rem !important;
    }
    
    /* ═══ BUTTONS & CONTROLS ═══ */
    button, .btn, input[type="submit"], input[type="button"] {
        padding: 0.8rem 1rem !important;
        font-size: 0.9rem !important;
        min-height: 48px !important;
        min-width: 48px !important;
    }
    
    /* Filter/sort controls stack on mobile */
    [style*="display: flex"][style*="gap"] > select,
    [style*="display: flex"][style*="gap"] > button,
    [style*="display: flex"][style*="gap"] > input {
        flex: 1 1 100% !important;
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Period buttons */
    .period-btn {
        flex: 1 1 calc(50% - 0.5rem) !important;
        padding: 0.7rem 0.5rem !important;
        font-size: 0.8rem !important;
    }
    
    /* ═══ MODALS & POPUPS ═══ */
    .modal-content {
        width: 95% !important;
        max-width: 95vw !important;
        margin: 5% auto !important;
        padding: 1.5rem 1rem !important;
    }
    
    /* ═══ FORMS ═══ */
    input, textarea, select {
        font-size: 16px !important;
        padding: 0.8rem !important;
    }
    
    /* ═══ STATS GRIDS ═══ */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    #leaderboard-stats,
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.8rem !important;
    }
    
    /* ═══ HIDE DECORATIVE ELEMENTS ON MOBILE ═══ */
    #phrolova-particles,
    .glitch-overlay,
    canvas {
        display: none !important;
    }
}

/* ── SMALL MOBILE (480px and below) ── */
@media (max-width: 480px) {
    
    /* Smaller text overall */
    body {
        font-size: 13px;
    }
    
    .main-title {
        font-size: 2.8rem !important;
    }
    
    .lycoris-logo-img {
        max-width: 220px !important;
    }
    
    .warning-banner {
        font-size: 0.65rem !important;
        padding: 0.5rem 0.8rem !important;
    }
    
    .hero {
        padding: 1rem 0.5rem !important;
    }
    
    .login-title {
        font-size: 1.8rem !important;
    }
    
    .admin-tab {
        font-size: 0.75rem !important;
        padding: 0.6rem 0.5rem !important;
    }
    
    /* Single column stats */
    #leaderboard-stats,
    .stats-grid,
    .boss-stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Even smaller tables */
    table {
        font-size: 0.7rem !important;
    }
    
    table th, table td {
        padding: 0.4rem 0.25rem !important;
    }
    
    /* Compact buttons */
    button, .btn {
        font-size: 0.85rem !important;
        padding: 0.7rem 0.8rem !important;
    }
}

/* ── TOUCH DEVICE OPTIMIZATION ── */
@media (hover: none) and (pointer: coarse) {
    
    /* All interactive elements must be at least 44x44px (Apple/Google standard) */
    button, a, .dropdown-btn, .admin-tab, .dropdown-item,
    .instance-card, .rule-item, .nav-links a, .nav-links button {
        min-height: 48px !important;
        min-width: 48px !important;
    }
    
    /* Prevent text zoom on input focus (iOS) */
    input, textarea, select {
        font-size: 16px !important;
    }
    
    /* Larger tap targets for checkboxes/radios */
    input[type="checkbox"], input[type="radio"] {
        min-width: 24px !important;
        min-height: 24px !important;
    }
    
    /* Remove hover effects (don't work on touch) */
    *:hover {
        transform: none !important;
    }
    
    /* Smooth scrolling for tables */
    [style*="overflow-x: auto"],
    [style*="overflow-y: auto"] {
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth !important;
    }
}

/* ── LANDSCAPE MOBILE (480-768px wide, but short height) ── */
@media (max-width: 768px) and (max-height: 500px) {
    
    .hero {
        padding: 1rem 0.5rem !important;
    }
    
    .lycoris-logo-img {
        max-width: 180px !important;
    }
    
    .main-title {
        font-size: 2.5rem !important;
    }
    
    .collective-text {
        font-size: 0.9rem !important;
    }
    
    .subtitle {
        font-size: 0.75rem !important;
    }
}

/* ── SPECIFIC COMPONENT FIXES ── */
@media (max-width: 768px) {
    
    /* ═══ ADMIN PANEL SPECIFIC ═══ */
    
    /* Control rows wrap properly */
    .admin-card > div[style*="display: flex"] {
        flex-wrap: wrap !important;
    }
    
    /* Search inputs full width on mobile */
    input[type="text"],
    input[type="search"],
    input[placeholder*="Search"],
    input[placeholder*="search"] {
        width: 100% !important;
        min-width: 100% !important;
        flex: 1 1 100% !important;
        margin: 0.3rem 0 !important;
    }
    
    /* Select dropdowns full width */
    select {
        width: 100% !important;
        min-width: 100% !important;
        flex: 1 1 100% !important;
        margin: 0.3rem 0 !important;
    }
    
    /* Staff registry buttons stack */
    #staff-registry-table ~ div button {
        width: 100% !important;
        margin: 0.3rem 0 !important;
    }
    
    /* Moderation stats grid - 1 column on small mobile */
    #moderation-stats-grid {
        grid-template-columns: 1fr !important;
        max-height: none !important;
    }
    
    /* Live instances compact view */
    .instance-card h3 {
        font-size: 1.1rem !important;
    }
    
    .instance-card p {
        font-size: 0.85rem !important;
    }
    
    /* ═══ LEADERBOARD MOBILE ═══ */
    
    /* Period buttons wrap nicely */
    .period-btn {
        padding: 0.6rem 0.8rem !important;
        font-size: 0.8rem !important;
        white-space: nowrap !important;
    }
    
    /* Stats cards 2 per row on mobile */
    #leaderboard-stats {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Expandable detail - full width */
    #staff-leaderboard-container td[colspan] > div {
        display: block !important;
    }
    
    #staff-leaderboard-container td[colspan] > div > div {
        width: 100% !important;
        margin-bottom: 1rem !important;
    }
    
    /* Action breakdown bars */
    .boss-player-card,
    [style*="Action Breakdown"] ~ div {
        padding: 0.5rem !important;
    }
    
    /* ═══ UTILITY CLASSES ═══ */
    
    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }
    
    /* Reduce margins/padding globally */
    section {
        margin: 1rem 0 !important;
    }
    
    /* Better spacing for stacked elements */
    .stacked-mobile {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }
}

/* ── VERY SMALL SCREENS (360px and below) ── */
@media (max-width: 360px) {
    
    .main-title {
        font-size: 2.5rem !important;
    }
    
    .lycoris-logo-img {
        max-width: 180px !important;
    }
    
    .collective-text {
        font-size: 0.95rem !important;
        letter-spacing: 2px !important;
    }
    
    .subtitle {
        font-size: 0.75rem !important;
    }
    
    button, .btn {
        font-size: 0.8rem !important;
        padding: 0.6rem 0.7rem !important;
    }
    
    .admin-tab {
        font-size: 0.7rem !important;
        padding: 0.5rem 0.4rem !important;
    }
}

/* ── ACCESSIBILITY: REDUCE MOTION ── */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ── HIGH CONTRAST MODE ── */
@media (prefers-contrast: high) {
    button, .btn, .admin-tab {
        border: 2px solid currentColor !important;
    }
}

/* ── PERFORMANCE: kill expensive effects on touch devices ── */
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
    /* stop repaint-heavy animations */
    .glitch, .glitch::before, .glitch::after,
    #phrolova-particles, #phrolova-petals, #phrolova-aura,
    .red-lightning, .blood-drip, .cursor-trail,
    canvas {
        display: none !important;
        animation: none !important;
        transition: none !important;
    }

    /* stop will-change thrashing */
    * {
        will-change: auto !important;
    }

    /* stop backdrop-filter on mobile (huge perf cost) */
    .navbar, .modal, .card, .stat-box, .panel {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* stop looping logo glow animation */
    .nav-logo {
        animation: none !important;
        text-shadow: 0 0 10px #ff0000 !important;
    }

    /* hardware acceleration for scrolling only */
    body {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }
}
