/* ==========================================
   MOBILE PROFILE PAGE OVERRIDES
   Target: Max-width 767px
   ========================================== */

@media screen and (max-width: 767px) {
    /* Mobile Context Header (Pill, Title, Desc) */
    .mobile-context-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        margin: 0.5rem 0;
        padding: 0; 
    }

    .profile-mobile-header {
        margin-bottom: 0 !important;
    }

    .profile-mobile-header + .neo-left-column {
        margin-top: -1rem !important;
    }

    .mobile-context-header h1 {
        font-size: 2rem; /* Matched to disclaimer */
        line-height: 1.2;
        margin-bottom: 1rem;
        font-weight: 800;
        color: #fff;
    }

    .mobile-context-header h1 span {
        color: var(--primary);
    }

    .mobile-context-header p {
        font-size: 1rem; /* Matched to disclaimer */
        line-height: 1.6;
        color: var(--text-dim);
    }

    /* Hide the global header if it ever appears elsewhere in Profile */
    .neo-title-group {
        display: none !important;
    }

    /* Hide Leaderboard and Game sections on Mobile */
    .neo-game-section,
    .leaderboards-wrapper,
    .neo-game-container,
    .neo-memory-container,
    .neo-typing-container {
        display: none !important;
    }

    /* Profile Grid Stacking */
    .neo-merged-dashboard {
        padding-bottom: 10rem !important; /* Extra gap for bottom nav comfort */
    }

    .profile-grid {
        display: flex;
        flex-direction: column;
        gap: 2rem;
    }

    /* Leaderboard Grid Stacking (Triple Column to Single) */
    .leaderboards-wrapper {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .leaderboard-arcade-section {
        padding: 1rem !important;
    }

    /* Game Container Scalings */
    .neo-game-container {
        min-height: 300px !important;
        padding: 1rem !important;
    }

    #game-canvas {
        max-width: 100%;
    }

    /* Typing Game Responsive Styles */
    .typing-word-display {
        font-size: 1.2rem !important;
    }

    .typing-input {
        padding: 0.8rem !important;
    }

    /* Memory Match Mobile Scaling */
    .memory-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.5rem !important;
    }

    .memory-card {
        height: 80px !important;
    }

    /* Risk Smasher Game */
    .bubble-game-score {
        font-size: 1rem !important;
    }
    /* Your Saved Calculations Header (Mobile) */
    .neo-onboarding-header {
        text-align: center !important;
        margin-bottom: 2rem !important;
    }

    .neo-onboarding-header h3 {
        color: var(--primary) !important;
        font-size: 1.5rem !important;
        font-weight: 850 !important;
        margin-bottom: 0.8rem !important;
    }

    .neo-onboarding-header p {
        color: var(--text-dim) !important;
        font-size: 1rem !important;
        line-height: 1.6 !important;
    }

    /* Profile Card Width Adjustment to match Saved Input Cards */
    .neo-left-column,
    .profile-card-panel,
    .profile-info-main,
    .profile-stats-grid {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    .profile-card-panel {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }

    .profile-card-panel,
    .profile-traffic-panel {
        position: relative !important;
    }

    .profile-traffic-inline-toggle {
        font-size: 0.7rem !important;
    }

    .profile-traffic-inline-panel {
        padding: 0.1rem 0 0.1rem !important;
    }

    .profile-traffic-list-item {
        padding: 0.45rem 0 !important;
    }

    .profile-card-panel > .neo-help-btn,
    .profile-traffic-panel > .neo-help-btn {
        display: none !important;
    }

    #btn-logout {
        background: transparent !important;
        color: rgba(255, 255, 255, 0.92) !important;
        border-color: rgba(255, 255, 255, 0.22) !important;
        box-shadow: none !important;
    }

    #btn-logout:hover,
    #btn-logout:active {
        background: linear-gradient(135deg, rgba(239, 68, 68, 0.24) 0%, rgba(153, 27, 27, 0.46) 100%) !important;
        border-color: rgba(248, 113, 113, 0.7) !important;
        color: #fff !important;
        box-shadow: 0 8px 18px rgba(127, 29, 29, 0.24) !important;
    }

    .profile-stats-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.5rem !important; /* Match saved-inputs-grid gap */
    }

    .profile-meta-item {
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 1.25rem !important; /* Standard card padding */
        border-radius: 16px !important;
    }

    .saved-input-card,
    #profile-loans-container .device-card-v2 {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 1.25rem !important;
    }

    #profile-loans-container,
    #profile-income-container,
    #profile-expense-container,
    .saved-inputs-grid,
    .compatibility-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 1.25rem !important;
        width: 100% !important;
    }

    #profile-loans-container .neo-placeholder-empty,
    #profile-income-container .neo-placeholder-empty,
    #profile-expense-container .neo-placeholder-empty {
        grid-column: 1 / -1 !important;
    }

    /* Component Stability: No scaling on click/press for mobile */
    .profile-meta-item:active,
    .saved-input-card:active,
    #profile-loans-container .device-card-v2:active,
    .profile-meta-item:hover,
    .saved-input-card:hover,
    #profile-loans-container .device-card-v2:hover {
        transform: none !important;
        scale: 1 !important;
    }

    /* Final Robust Fix: Mobile Center & Button Below Description */
    .profile-visibility-lock {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        width: 100% !important;
        opacity: 1 !important;
        visibility: visible !important;
        margin-top: 3rem !important;
    }

    .neo-onboarding-header {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
    }

    .header-desktop-row {
        display: flex !important;
        flex-direction: column !important; /* Stack: Title -> Button */
        flex-wrap: nowrap !important;
        align-items: center !important; 
        justify-content: center !important;
        width: 100% !important;
        gap: 0.75rem !important; /* Gap Title to Button */
        margin-bottom: 0.5rem !important;
    }

    .neo-onboarding-header h3 {
        color: var(--primary) !important;
        font-size: 1.3rem !important;
        font-weight: 950 !important;
        margin: 0 !important;
        display: block !important;
        text-align: center !important;
    }

    /* RECTANGULAR PILL BUTTON - Let it inherit 100% from desktop/inline styles */
    .profile-add-btn {
        flex-shrink: 0 !important;
        margin-top: 0 !important;
        height: 28px !important; /* Slightly taller for mobile tap */
    }

    .neo-onboarding-header .section-desc {
        color: var(--text-dim) !important;
        font-size: 0.85rem !important;
        line-height: 1.5 !important;
        margin-top: 0.75rem !important; /* Gap Button to Desc */
        margin-bottom: 0.25rem !important;
        text-align: justify !important;
        max-width: 100% !important;
        width: 100% !important;
        display: block !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
    .profile-add-btn.liquid-button.card-badge {
        display: inline-flex !important;
        height: 32px !important;
        padding: 0 1.25rem !important;
        font-size: 0.75rem !important;
        margin-top: 1rem !important;
        border-radius: 100px !important; /* Fixed: Should be pill shape */
        box-shadow: 0 5px 15px rgba(0, 102, 255, 0.2) !important;
        position: relative !important;
        overflow: hidden !important;
    }

}
