.elementor-6138 .elementor-element.elementor-element-09e347a{--display:flex;--flex-direction:row;--container-widget-width:initial;--container-widget-height:100%;--container-widget-flex-grow:1;--container-widget-align-self:stretch;--flex-wrap-mobile:wrap;--justify-content:center;--gap:10px 30px;--row-gap:10px;--column-gap:30px;}.elementor-6138 .elementor-element.elementor-element-f5020c4{--display:flex;--flex-direction:column;--container-widget-width:100%;--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;--gap:30px 30px;--row-gap:30px;--column-gap:30px;}.elementor-6138 .elementor-element.elementor-element-962ea8a{text-align:center;}.elementor-6138 .elementor-element.elementor-element-962ea8a .elementor-heading-title{font-size:35px;color:var( --e-global-color-primary );}.elementor-6138 .elementor-element.elementor-element-9bdb6f8 > .elementor-widget-container{margin:0px 0px -19px 0px;padding:0px 0px 0px 0px;}.elementor-6138 .elementor-element.elementor-element-9bdb6f8{text-align:center;}.elementor-6138 .elementor-element.elementor-element-9bdb6f8 img{width:1000px;max-width:390px;height:180px;border-radius:30px 30px 30px 30px;}.elementor-6138 .elementor-element.elementor-element-7a6edc3{--display:flex;--flex-direction:column;--container-widget-width:100%;--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;--gap:30px 30px;--row-gap:30px;--column-gap:30px;}.elementor-6138 .elementor-element.elementor-element-766277a{text-align:center;}.elementor-6138 .elementor-element.elementor-element-766277a .elementor-heading-title{font-size:35px;color:var( --e-global-color-primary );}.elementor-6138 .elementor-element.elementor-element-fa78a1b > .elementor-widget-container{margin:0px 0px -19px 0px;padding:0px 0px 0px 0px;}.elementor-6138 .elementor-element.elementor-element-fa78a1b{text-align:center;}.elementor-6138 .elementor-element.elementor-element-fa78a1b img{width:1000px;max-width:390px;height:180px;border-radius:30px 30px 30px 30px;}.elementor-6138 .elementor-element.elementor-element-dde454e{--display:flex;--min-height:0px;--flex-direction:row;--container-widget-width:calc( ( 1 - var( --container-widget-flex-grow ) ) * 100% );--container-widget-height:100%;--container-widget-flex-grow:1;--container-widget-align-self:stretch;--flex-wrap-mobile:wrap;--justify-content:center;--align-items:center;--gap:10px 40px;--row-gap:10px;--column-gap:40px;--flex-wrap:nowrap;}.elementor-6138 .elementor-element.elementor-element-69cc273{--display:flex;--min-height:0px;--flex-direction:column;--container-widget-width:100%;--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;--gap:30px 30px;--row-gap:30px;--column-gap:30px;}.elementor-6138 .elementor-element.elementor-element-df02a0d{text-align:center;}.elementor-6138 .elementor-element.elementor-element-df02a0d .elementor-heading-title{font-size:35px;color:var( --e-global-color-primary );}.elementor-6138 .elementor-element.elementor-element-028d124 > .elementor-widget-container{margin:0px 0px -19px 0px;padding:0px 0px 0px 0px;}.elementor-6138 .elementor-element.elementor-element-028d124{text-align:center;}.elementor-6138 .elementor-element.elementor-element-028d124 img{width:1000px;max-width:390px;height:180px;border-radius:30px 30px 30px 30px;}.elementor-6138 .elementor-element.elementor-element-4c8a09f{--display:flex;--flex-direction:column;--container-widget-width:100%;--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;--gap:30px 30px;--row-gap:30px;--column-gap:30px;}.elementor-6138 .elementor-element.elementor-element-b41acc9{text-align:center;}.elementor-6138 .elementor-element.elementor-element-b41acc9 .elementor-heading-title{font-size:35px;color:var( --e-global-color-primary );}.elementor-6138 .elementor-element.elementor-element-f822200 > .elementor-widget-container{margin:0px 0px -19px 0px;padding:0px 0px 0px 0px;}.elementor-6138 .elementor-element.elementor-element-f822200{text-align:center;}.elementor-6138 .elementor-element.elementor-element-f822200 img{width:1000px;max-width:390px;height:180px;border-radius:30px 30px 30px 30px;}@media(min-width:768px){.elementor-6138 .elementor-element.elementor-element-f5020c4{--width:40%;}.elementor-6138 .elementor-element.elementor-element-7a6edc3{--width:40%;}.elementor-6138 .elementor-element.elementor-element-dde454e{--content-width:1000px;}.elementor-6138 .elementor-element.elementor-element-69cc273{--width:40%;}.elementor-6138 .elementor-element.elementor-element-4c8a09f{--width:40%;}}@media(max-width:1366px){.elementor-6138 .elementor-element.elementor-element-09e347a{--margin-top:0px;--margin-bottom:0px;--margin-left:0px;--margin-right:0px;--padding-top:0px;--padding-bottom:0px;--padding-left:50px;--padding-right:0px;}.elementor-6138 .elementor-element.elementor-element-f5020c4{--padding-top:0px;--padding-bottom:0px;--padding-left:20px;--padding-right:0px;}.elementor-6138 .elementor-element.elementor-element-7a6edc3{--padding-top:0px;--padding-bottom:0px;--padding-left:0px;--padding-right:20px;}}@media(max-width:1024px){.elementor-6138 .elementor-element.elementor-element-09e347a{--flex-direction:column;--container-widget-width:100%;--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;--padding-top:0px;--padding-bottom:0px;--padding-left:30px;--padding-right:0px;}.elementor-6138 .elementor-element.elementor-element-f5020c4{--margin-top:0px;--margin-bottom:0px;--margin-left:0px;--margin-right:0px;--padding-top:0px;--padding-bottom:0px;--padding-left:50px;--padding-right:50px;}.elementor-6138 .elementor-element.elementor-element-c8c6926 > .elementor-widget-container{padding:0px 100px 0px 100px;}.elementor-6138 .elementor-element.elementor-element-c8c6926{text-align:start;}.elementor-6138 .elementor-element.elementor-element-c8c6926 p{margin-block-end:3px;}.elementor-6138 .elementor-element.elementor-element-9bdb6f8 img{max-width:584px;height:200px;}.elementor-6138 .elementor-element.elementor-element-7a6edc3{--padding-top:0px;--padding-bottom:0px;--padding-left:50px;--padding-right:50px;}.elementor-6138 .elementor-element.elementor-element-51a320b > .elementor-widget-container{padding:0px 100px 0px 100px;}.elementor-6138 .elementor-element.elementor-element-fa78a1b img{max-width:584px;height:200px;}.elementor-6138 .elementor-element.elementor-element-be5cbd3 > .elementor-widget-container{margin:0px 0px 0px 60px;padding:0px 0px 0px 100px;}.elementor-6138 .elementor-element.elementor-element-028d124 img{max-width:584px;height:200px;}.elementor-6138 .elementor-element.elementor-element-f822200 img{max-width:584px;height:200px;}}@media(max-width:767px){.elementor-6138 .elementor-element.elementor-element-09e347a{--padding-top:100px;--padding-bottom:100px;--padding-left:100px;--padding-right:100px;}.elementor-6138 .elementor-element.elementor-element-f5020c4{--padding-top:100px;--padding-bottom:100px;--padding-left:100px;--padding-right:100px;}.elementor-6138 .elementor-element.elementor-element-9bdb6f8 img{width:266px;height:117px;}.elementor-6138 .elementor-element.elementor-element-fa78a1b img{width:266px;height:117px;}.elementor-6138 .elementor-element.elementor-element-be5cbd3 > .elementor-widget-container{margin:0px 0px 0px 50px;padding:0px 0px 0px 50px;}.elementor-6138 .elementor-element.elementor-element-dde454e{--content-width:500px;--min-height:0px;--flex-direction:row;--container-widget-width:calc( ( 1 - var( --container-widget-flex-grow ) ) * 100% );--container-widget-height:100%;--container-widget-flex-grow:1;--container-widget-align-self:stretch;--flex-wrap-mobile:wrap;--align-items:center;--flex-wrap:nowrap;}.elementor-6138 .elementor-element.elementor-element-dde454e.e-con{--align-self:center;--flex-grow:1;}.elementor-6138 .elementor-element.elementor-element-69cc273{--width:40%;--flex-direction:column;--container-widget-width:calc( ( 1 - var( --container-widget-flex-grow ) ) * 100% );--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;--justify-content:center;--align-items:flex-start;--flex-wrap:nowrap;}.elementor-6138 .elementor-element.elementor-element-69cc273.e-con{--align-self:center;}.elementor-6138 .elementor-element.elementor-element-028d124 img{width:266px;height:117px;}.elementor-6138 .elementor-element.elementor-element-4c8a09f{--justify-content:center;--align-items:center;--container-widget-width:calc( ( 1 - var( --container-widget-flex-grow ) ) * 100% );}.elementor-6138 .elementor-element.elementor-element-f822200 img{width:266px;height:117px;}}/* Start custom CSS */<script>
// Wait for the DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function() {
    // State management
    let isMetric = true;
    let selectedGender = 'male';
    
    // DOM elements
    const maleBtn = document.getElementById('caliperMaleBtn');
    const femaleBtn = document.getElementById('caliperFemaleBtn');
    const metricBtn = document.getElementById('caliperMetricBtn');
    const imperialBtn = document.getElementById('caliperImperialBtn');
    const maleSites = document.getElementById('caliperMaleSites');
    const femaleSites = document.getElementById('caliperFemaleSites');
    const calculateBtn = document.getElementById('caliperCalculateBtn');
    const results = document.getElementById('caliperResults');
    const errorMessage = document.getElementById('caliperErrorMessage');
    const resultValue = document.getElementById('caliperResultValue');
    const resultCategory = document.getElementById('caliperResultCategory');
    const fatMass = document.getElementById('caliperFatMass');
    const leanMass = document.getElementById('caliperLeanMass');
    const bodyDensity = document.getElementById('caliperBodyDensity');
    const userMarker = document.getElementById('caliperUserMarker');
    const recommendationGrid = document.getElementById('caliperRecommendationGrid');
    const shareBtn = document.getElementById('caliperShareBtn');
    const consultationBtn = document.getElementById('caliperConsultationBtn');
    const toast = document.getElementById('caliperToast');
    const weightUnit = document.getElementById('caliperWeightUnit');

    // Check if elements exist
    if (!maleBtn || !femaleBtn) {
        console.error('Caliper calculator elements not found');
        return;
    }

    // Event listeners for gender buttons
    maleBtn.addEventListener('click', function() {
        selectedGender = 'male';
        maleBtn.classList.add('active');
        femaleBtn.classList.remove('active');
        maleSites.style.display = 'block';
        femaleSites.style.display = 'none';
    });
    
    femaleBtn.addEventListener('click', function() {
        selectedGender = 'female';
        femaleBtn.classList.add('active');
        maleBtn.classList.remove('active');
        maleSites.style.display = 'none';
        femaleSites.style.display = 'block';
    });

    // Event listeners for unit buttons
    metricBtn.addEventListener('click', function() {
        isMetric = true;
        metricBtn.classList.add('active');
        imperialBtn.classList.remove('active');
        weightUnit.textContent = 'kg';
    });
    
    imperialBtn.addEventListener('click', function() {
        isMetric = false;
        imperialBtn.classList.add('active');
        metricBtn.classList.remove('active');
        weightUnit.textContent = 'lbs';
    });

    // Calculate button
    calculateBtn.addEventListener('click', calculateBodyFat);

    // Share button functionality
    shareBtn.addEventListener('click', function() {
        const bfValue = resultValue.textContent;
        if (bfValue === '0.0%') {
            showToast('Please calculate your body fat first');
            return;
        }
        
        if (navigator.share) {
            navigator.share({
                title: 'My Body Fat Results',
                text: `My body fat is ${bfValue} - Check out this calculator!`,
                url: window.location.href
            });
        } else {
            navigator.clipboard.writeText(window.location.href);
            showToast('Link copied to clipboard!');
        }
    });

    // Consultation button functionality
    consultationBtn.addEventListener('click', function() {
        window.open('https://calendly.com', '_blank');
        showToast('Opening consultation booking...');
    });

    // Show error message
    function showError(message) {
        errorMessage.textContent = message;
        errorMessage.classList.add('show');
        setTimeout(() => {
            errorMessage.classList.remove('show');
        }, 3000);
    }

    // Show toast message
    function showToast(message) {
        toast.textContent = message;
        toast.classList.add('show');
        setTimeout(() => toast.classList.remove('show'), 3000);
    }

    // Calculate body density using Jackson & Pollock 7-site formula
    function calculateBodyDensity(age, measurements, gender) {
        const sum = measurements.reduce((a, b) => a + b, 0);
        let bodyDensity;
        
        if (gender === 'male') {
            // Jackson & Pollock 7-site formula for men
            bodyDensity = 1.112 - (0.00043499 * sum) + (0.00000055 * Math.pow(sum, 2)) - (0.00028826 * age);
        } else {
            // Jackson & Pollock 7-site formula for women
            bodyDensity = 1.097 - (0.00046971 * sum) + (0.00000056 * Math.pow(sum, 2)) - (0.00012828 * age);
        }
        
        return bodyDensity;
    }

    // Convert body density to body fat percentage using Siri equation
    function calculateBodyFatPercentage(bodyDensity) {
        return (495 / bodyDensity) - 450;
    }

    // Get recommendations based on body fat and gender
    function getRecommendations(bodyFat, gender) {
        let recommendations = [];
        
        if (gender === 'male') {
            if (bodyFat < 6) {
                recommendations = [
                    { 
                        icon: '💪',
                        title: 'Essential Hypertrophy', 
                        desc: 'Precision muscle growth programming with progressive overload for maximum gains' 
                    },
                    { 
                        icon: '❤️',
                        title: 'Cardio for Health', 
                        desc: 'Strategic heart rate zone training to support cardiovascular health without compromising muscle growth' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Nutrition for Lean Muscle', 
                        desc: 'Caloric surplus with high protein (1.6-2.2g/kg) to fuel muscle growth while minimizing fat gain' 
                    }
                ];
            } else if (bodyFat < 14) {
                recommendations = [
                    { 
                        icon: '🏋️‍♂️',
                        title: 'Strength for Performance', 
                        desc: 'Raw power development through compound lifts and progressive overload for elite athleticism' 
                    },
                    { 
                        icon: '✨',
                        title: 'Body Tone & Definition', 
                        desc: 'Strategic body recomposition to reveal muscle definition while maintaining performance' 
                    },
                    { 
                        icon: '❤️',
                        title: 'Cardio for Health', 
                        desc: 'Optimized heart rate training to support endurance and cardiovascular efficiency' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Health Nutrition', 
                        desc: 'Performance-focused eating strategy to fuel workouts and support recovery' 
                    }
                ];
            } else if (bodyFat < 18) {
                recommendations = [
                    { 
                        icon: '🏋️‍♂️',
                        title: 'Strength Building', 
                        desc: 'Foundation strength development through compound movements and proper form' 
                    },
                    { 
                        icon: '✨',
                        title: 'Body Tone', 
                        desc: 'Lean muscle development with strategic training to improve body composition' 
                    },
                    { 
                        icon: '❤️',
                        title: 'Cardio for Health', 
                        desc: 'Heart-healthy cardiovascular training to boost stamina and overall wellness' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Health Nutrition', 
                        desc: 'Balanced eating plan focusing on whole foods for sustained energy and vitality' 
                    },
                    { 
                        icon: '🚶‍♂️',
                        title: 'NEAT Optimization', 
                        desc: 'Increase daily non-exercise activity to boost metabolism and calorie burn' 
                    }
                ];
            } else if (bodyFat < 25) {
                recommendations = [
                    { 
                        icon: '🔥',
                        title: 'Metabolic Training', 
                        desc: 'Full-body metabolic circuits to maximize calorie burn and boost metabolism 24/7' 
                    },
                    { 
                        icon: '💨',
                        title: 'Strategic Cardio for Fat Loss', 
                        desc: 'Optimal mix of steady-state and HIIT cardio in proper heart rate zones' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Nutrition for Fat Loss', 
                        desc: 'Sustainable eating plan with strategic calorie deficit and high protein intake' 
                    },
                    { 
                        icon: '🚶‍♂️',
                        title: 'NEAT Maximization', 
                        desc: 'Leverage daily movement to burn hundreds of extra calories without formal exercise' 
                    }
                ];
            } else {
                recommendations = [
                    { 
                        icon: '🔥',
                        title: 'Metabolic Training for Fat Loss', 
                        desc: 'Intensive full-body circuits engineered to burn maximum calories and stimulate metabolic afterburn' 
                    },
                    { 
                        icon: '💨',
                        title: 'Strategic Cardio for Fat Loss', 
                        desc: 'Precision heart rate zone training combining steady-state and HIIT for optimal fat burning' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Nutrition for Fat Loss', 
                        desc: 'Structured eating strategy focusing on habit-based changes and sustainable calorie deficit' 
                    },
                    { 
                        icon: '🚶‍♂️',
                        title: 'NEAT Focus', 
                        desc: 'Daily movement optimization to significantly increase non-exercise calorie expenditure' 
                    }
                ];
            }
        } else {
            if (bodyFat < 14) {
                recommendations = [
                    { 
                        icon: '💪',
                        title: 'Essential Hypertrophy', 
                        desc: 'Smart muscle building with precision programming and progressive overload' 
                    },
                    { 
                        icon: '❤️',
                        title: 'Cardio for Health', 
                        desc: 'Strategic cardiovascular training to support heart health and recovery' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Nutrition for Lean Muscle', 
                        desc: 'Calorie-controlled surplus with optimal protein timing for lean muscle growth' 
                    }
                ];
            } else if (bodyFat < 21) {
                recommendations = [
                    { 
                        icon: '🏋️‍♀️',
                        title: 'Strength for Performance', 
                        desc: 'Build functional strength and power through compound lifts and proper technique' 
                    },
                    { 
                        icon: '✨',
                        title: 'Body Tone & Definition', 
                        desc: 'Strategic training to enhance muscle definition and create a lean, athletic physique' 
                    },
                    { 
                        icon: '❤️',
                        title: 'Cardio for Health', 
                        desc: 'Cardiovascular training optimized for endurance and overall fitness' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Health Nutrition', 
                        desc: 'Performance-focused nutrition to support training and recovery goals' 
                    }
                ];
            } else if (bodyFat < 25) {
                recommendations = [
                    { 
                        icon: '🏋️‍♀️',
                        title: 'Strength Building', 
                        desc: 'Foundation strength development with focus on proper form and progressive overload' 
                    },
                    { 
                        icon: '✨',
                        title: 'Body Tone', 
                        desc: 'Create lean muscle definition through strategic resistance training' 
                    },
                    { 
                        icon: '❤️',
                        title: 'Cardio for Health', 
                        desc: 'Heart-healthy cardio to improve cardiovascular efficiency and stamina' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Health Nutrition', 
                        desc: 'Balanced eating plan focusing on whole foods and proper macronutrients' 
                    },
                    { 
                        icon: '🚶‍♀️',
                        title: 'NEAT Optimization', 
                        desc: 'Increase daily non-exercise movement to boost metabolism and energy expenditure' 
                    }
                ];
            } else if (bodyFat < 32) {
                recommendations = [
                    { 
                        icon: '🔥',
                        title: 'Metabolic Training', 
                        desc: 'Full-body metabolic workouts to maximize calorie burn and boost resting metabolism' 
                    },
                    { 
                        icon: '💨',
                        title: 'Strategic Cardio for Fat Loss', 
                        desc: 'Smart cardio programming combining zone 2 training and HIIT for optimal results' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Nutrition for Fat Loss', 
                        desc: 'Sustainable eating strategy with controlled deficit and high protein for muscle preservation' 
                    },
                    { 
                        icon: '🚶‍♀️',
                        title: 'NEAT Maximization', 
                        desc: 'Leverage daily activities to significantly increase non-exercise calorie burn' 
                    }
                ];
            } else {
                recommendations = [
                    { 
                        icon: '🔥',
                        title: 'Metabolic Training for Fat Loss', 
                        desc: 'Intensive metabolic circuits designed for maximum calorie burn and fat loss' 
                    },
                    { 
                        icon: '💨',
                        title: 'Strategic Cardio for Fat Loss', 
                        desc: 'Precision cardio programming using optimal heart rate zones for efficient fat burning' 
                    },
                    { 
                        icon: '🍽️',
                        title: 'Nutrition for Fat Loss', 
                        desc: 'Comprehensive eating strategy focusing on habit changes and sustainable deficit' 
                    },
                    { 
                        icon: '🚶‍♀️',
                        title: 'NEAT Focus', 
                        desc: 'Maximize daily non-exercise activity to create significant calorie deficit' 
                    }
                ];
            }
        }
        
        return recommendations;
    }

    // Update scale marker position
    function updateScaleMarker(bodyFat, gender) {
        let markerPos;
        if (gender === 'male') {
            if (bodyFat < 6) markerPos = (bodyFat / 6) * 20;
            else if (bodyFat < 14) markerPos = 20 + ((bodyFat - 6) / 8) * 15;
            else if (bodyFat < 18) markerPos = 35 + ((bodyFat - 14) / 4) * 10;
            else if (bodyFat < 25) markerPos = 45 + ((bodyFat - 18) / 7) * 15;
            else markerPos = 60 + Math.min(((bodyFat - 25) / 15) * 40, 40);
        } else {
            if (bodyFat < 14) markerPos = (bodyFat / 14) * 20;
            else if (bodyFat < 21) markerPos = 20 + ((bodyFat - 14) / 7) * 15;
            else if (bodyFat < 25) markerPos = 35 + ((bodyFat - 21) / 4) * 10;
            else if (bodyFat < 32) markerPos = 45 + ((bodyFat - 25) / 7) * 15;
            else markerPos = 60 + Math.min(((bodyFat - 32) / 8) * 40, 40);
        }
        
        userMarker.style.left = Math.min(Math.max(markerPos, 2), 98) + '%';
    }

    // Main calculation function
    function calculateBodyFat() {
        results.classList.remove('show');
        
        try {
            // Get basic information
            const age = parseFloat(document.getElementById('caliperAge').value);
            let weight = parseFloat(document.getElementById('caliperWeight').value);
            
            // Get skinfold measurements based on gender
            let measurements = [];
            
            if (selectedGender === 'male') {
                measurements = [
                    parseFloat(document.getElementById('caliperChest').value),
                    parseFloat(document.getElementById('caliperAbdominal').value),
                    parseFloat(document.getElementById('caliperThigh').value),
                    parseFloat(document.getElementById('caliperTricepsMale').value),
                    parseFloat(document.getElementById('caliperSubscapular').value),
                    parseFloat(document.getElementById('caliperSuprailiacMale').value),
                    parseFloat(document.getElementById('caliperMidaxillary').value)
                ];
            } else {
                measurements = [
                    parseFloat(document.getElementById('caliperTriceps').value),
                    parseFloat(document.getElementById('caliperThighFemale').value),
                    parseFloat(document.getElementById('caliperSuprailiac').value),
                    parseFloat(document.getElementById('caliperAbdominalFemale').value),
                    parseFloat(document.getElementById('caliperSubscapularFemale').value),
                    parseFloat(document.getElementById('caliperChestFemale').value),
                    parseFloat(document.getElementById('caliperMidaxillaryFemale').value)
                ];
            }

            // Validate inputs
            if (isNaN(age) || age < 18 || age > 80) {
                showError('Please enter a valid age (18-80)');
                return;
            }
            if (isNaN(weight) || weight <= 0) {
                showError('Please enter a valid weight');
                return;
            }
            
            // Validate all skinfold measurements
            let validMeasurements = true;
            measurements.forEach((measurement, index) => {
                if (isNaN(measurement) || measurement <= 0 || measurement > 50) {
                    validMeasurements = false;
                }
            });
            
            if (!validMeasurements) {
                showError('Please enter valid skinfold measurements (1-50mm) for all 7 sites');
                return;
            }

            // Convert weight to kg if imperial
            if (!isMetric) {
                weight = weight * 0.453592; // Convert lbs to kg
            }

            // Calculate body density using 7-site formula
            const density = calculateBodyDensity(age, measurements, selectedGender);
            
            // Calculate body fat percentage
            let bodyFatPercentage = calculateBodyFatPercentage(density);
            
            // Ensure reasonable values
            bodyFatPercentage = Math.max(3, Math.min(50, bodyFatPercentage));
            const roundedBodyFat = Math.round(bodyFatPercentage * 10) / 10;
            
            // Calculate additional metrics
            const fatMassValue = (weight * roundedBodyFat / 100).toFixed(1);
            const leanMassValue = (weight - (weight * roundedBodyFat / 100)).toFixed(1);
            
            // Determine category
            let category, categoryClass;
            if (selectedGender === 'male') {
                if (roundedBodyFat < 6) {
                    category = 'Essential Fat';
                    categoryClass = 'caliper-category-essential';
                } else if (roundedBodyFat < 14) {
                    category = 'Athletic';
                    categoryClass = 'caliper-category-athletic';
                } else if (roundedBodyFat < 18) {
                    category = 'Fit';
                    categoryClass = 'caliper-category-fit';
                } else if (roundedBodyFat < 25) {
                    category = 'Average';
                    categoryClass = 'caliper-category-average';
                } else {
                    category = 'Obese';
                    categoryClass = 'caliper-category-obese';
                }
            } else {
                if (roundedBodyFat < 14) {
                    category = 'Essential Fat';
                    categoryClass = 'caliper-category-essential';
                } else if (roundedBodyFat < 21) {
                    category = 'Athletic';
                    categoryClass = 'caliper-category-athletic';
                } else if (roundedBodyFat < 25) {
                    category = 'Fit';
                    categoryClass = 'caliper-category-fit';
                } else if (roundedBodyFat < 32) {
                    category = 'Average';
                    categoryClass = 'caliper-category-average';
                } else {
                    category = 'Obese';
                    categoryClass = 'caliper-category-obese';
                }
            }
            
            // Display results
            resultValue.textContent = roundedBodyFat.toFixed(1) + '%';
            resultCategory.textContent = category;
            resultCategory.className = 'caliper-category-badge ' + categoryClass;
            
            if (isMetric) {
                fatMass.textContent = fatMassValue + ' kg';
                leanMass.textContent = leanMassValue + ' kg';
            } else {
                fatMass.textContent = (fatMassValue / 0.453592).toFixed(1) + ' lbs';
                leanMass.textContent = (leanMassValue / 0.453592).toFixed(1) + ' lbs';
            }
            
            bodyDensity.textContent = density.toFixed(4) + ' g/ml';

            // Update scale marker
            updateScaleMarker(roundedBodyFat, selectedGender);

            // Update recommendations
            const recommendations = getRecommendations(roundedBodyFat, selectedGender);
            recommendationGrid.innerHTML = '';
            recommendations.forEach(rec => {
                const card = document.createElement('div');
                card.className = 'caliper-recommendation-card';
                card.innerHTML = `
                    <div class="caliper-recommendation-icon">${rec.icon}</div>
                    <div class="caliper-recommendation-content">
                        <h4>${rec.title}</h4>
                        <p>${rec.desc}</p>
                    </div>
                `;
                recommendationGrid.appendChild(card);
            });

            // Show results
            results.classList.add('show');
            
            setTimeout(() => {
                results.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
            }, 100);
            
            showToast('Body fat calculated successfully!');
        } catch (error) {
            console.error('Calculation error:', error);
            showError('An error occurred during calculation. Please check your inputs.');
        }
    }
});
</script>/* End custom CSS */