/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Tablet (768px and below) */
@media (max-width: 768px) {
    .map-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .brand {
        font-size: 1.2rem;
    }

    .user-stats {
        gap: 8px;
    }

    .stat-item {
        font-size: 0.85rem;
    }

    .map-scroll-area {
        padding: 80px 16px 120px 16px;
    }

    .nodes-container {
        max-width: 400px;
    }
}

/* Mobile (600px and below) */
@media (max-width: 600px) {

    /* Header Optimization */
    .map-header {
        padding: 10px 12px;
        position: fixed;
        background: rgba(9, 9, 11, 0.95);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
    }

    .brand {
        font-size: 1rem;
        gap: 6px;
    }

    .brand i {
        font-size: 1.2rem;
    }

    /* Compact Stats */
    .user-stats {
        display: none;
        /* Hide on very small screens, show in bottom bar */
    }

    .header-controls {
        gap: 8px;
    }

    .glossary-btn-icon {
        width: 44px;
        /* Touch-friendly minimum */
        height: 44px;
        font-size: 1.1rem;
    }

    /* Bottom Navigation Bar */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(20, 20, 23, 0.98);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--border);
        padding: 8px 12px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: 999;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    }

    .mobile-stat {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        font-size: 0.7rem;
        color: var(--text-muted);
    }

    .mobile-stat i {
        font-size: 1.2rem;
        color: var(--primary);
    }

    .mobile-stat span {
        font-weight: 600;
    }

    /* Map Scroll Area */
    .map-scroll-area {
        padding: 70px 12px 90px 12px;
    }

    /* Unit Sections */
    .unit-section {
        margin-bottom: 40px;
    }

    .unit-header {
        font-size: 0.9rem;
        padding: 8px 12px;
        margin-bottom: 20px;
    }

    /* Nodes Container - Single Column */
    .nodes-container {
        max-width: 100%;
        padding: 0 8px;
    }

    .node-wrapper {
        margin-bottom: 40px;
    }

    /* Remove zigzag on mobile - center all nodes */
    .node-wrapper:nth-child(4n+1),
    .node-wrapper:nth-child(4n+2),
    .node-wrapper:nth-child(4n+3),
    .node-wrapper:nth-child(4n+4) {
        transform: translateX(0) !important;
    }

    /* Learning Overlay - Full Screen */
    .learning-overlay {
        border-radius: 0;
        box-shadow: none;
    }

    .learning-overlay.open {
        transform: translateY(0);
    }

    .overlay-header {
        padding: 16px;
        position: sticky;
        top: 0;
        background: var(--bg-card);
        z-index: 100;
    }

    .close-overlay {
        width: 44px;
        height: 44px;
        font-size: 1.5rem;
    }

    .overlay-info {
        margin-left: 12px;
    }

    .breadcrumb {
        font-size: 0.75rem;
    }

    .overlay-info h1 {
        font-size: 1.3rem;
    }

    .overlay-content {
        padding: 16px;
    }

    /* Tabs */
    .tabs-header {
        gap: 8px;
        padding: 0 4px;
        margin-bottom: 20px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .tabs-header::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
        white-space: nowrap;
        min-width: auto;
        flex-shrink: 0;
    }

    /* Content */
    .welcome-screen {
        padding: 30px 16px;
    }

    .welcome-screen h2 {
        font-size: 1.5rem;
    }

    /* Theory */
    .theory-block h2 {
        font-size: 1.3rem;
    }

    .theory-block h3 {
        font-size: 1.1rem;
    }

    .theory-block p,
    .theory-block li {
        font-size: 0.95rem;
        line-height: 1.6;
    }

    /* Code Blocks */
    pre code {
        font-size: 0.8rem;
    }

    .copy-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    /* Practice */
    .practice-item {
        padding: 16px;
    }

    .req-badge {
        font-size: 0.7rem;
        padding: 3px 8px;
    }

    /* Modals - Full Screen on Mobile */
    .modal-card,
    glossary-modal,
    achievements-modal {
        width: 100% !important;
        max-width: 100% !important;
        height: 100%;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-header h2,
    .modal-header h3 {
        font-size: 1.3rem;
    }

    .modal-body {
        padding: 16px;
    }

    /* Achievements Grid */
    .achievements-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
        gap: 12px !important;
    }

    .achievement {
        padding: 12px !important;
    }

    .ach-icon {
        font-size: 2.5rem !important;
    }

    .ach-name {
        font-size: 0.85rem !important;
    }

    .ach-desc {
        font-size: 0.75rem !important;
    }

    /* Success Modal */
    success-modal .success-card {
        width: 95% !important;
        padding: 24px !important;
    }

    /* Touch Improvements */
    button,
    .tab-btn,
    .quiz-option,
    .glossary-btn-icon {
        min-height: 44px;
        /* iOS minimum */
        -webkit-tap-highlight-color: rgba(99, 102, 241, 0.3);
    }

    /* Prevent zoom on focus (but keep accessible) */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Hide scrollbars but keep functionality */
    * {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    *::-webkit-scrollbar {
        display: none;
    }

    /* Pull to refresh hint */
    body {
        overscroll-behavior-y: contain;
    }
}

/* Extra Small Mobile (400px and below) */
@media (max-width: 400px) {
    .brand span {
        display: none;
        /* Hide text, keep icon only */
    }

    .mobile-stat {
        font-size: 0.65rem;
    }

    .mobile-stat i {
        font-size: 1rem;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .achievements-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Landscape Mode for Mobile */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .map-header {
        padding: 8px 12px;
    }

    .mobile-bottom-nav {
        padding: 4px 12px;
    }

    .mobile-stat {
        font-size: 0.65rem;
    }

    .map-scroll-area {
        padding: 60px 12px 60px 12px;
    }

    .overlay-header {
        padding: 12px;
    }

    .overlay-content {
        padding: 12px;
    }
}

/* Hover states only on non-touch devices */
@media (hover: hover) and (pointer: fine) {
    .glossary-btn-icon:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    button:hover {
        transform: translateY(-2px);
    }
}

/* iOS Safe Area Support */
@supports (padding: max(0px)) {
    .map-header {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .mobile-bottom-nav {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .map-scroll-area {
        padding-bottom: max(90px, calc(90px + env(safe-area-inset-bottom)));
    }
}