Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const state = {
+ currentMl: 0,
+ goalMl: 2500,
+ achievements: []
+ };
+
+ // Load saved data
+ const savedData = localStorage.getItem('waterData');
+ if (savedData) {
+ const parsed = JSON.parse(savedData);
+ if (isToday(new Date(parsed.date))) {
+ state.currentMl = parsed.currentMl;
+ state.achievements = parsed.achievements;
+ updateDisplay();
+ }
+ }
+
+ function isToday(date) {
+ const today = new Date();
+ return date.getDate() === today.getDate() &&
+ date.getMonth() === today.getMonth() &&
+ date.getFullYear() === today.getFullYear();
+ }
+
+ function updateDisplay() {
+ // Update numbers
+ document.getElementById('current-ml').textContent = state.currentMl;
+ document.getElementById('cups-count').textContent = (state.currentMl / 250).toFixed(1);
+
+ // Update water level visualization
+ const percentage = (state.currentMl / state.goalMl) * 100;
+ document.querySelector('.water-level').style.height = `${Math.min(percentage, 100)}%`;
+
+ // Save to localStorage
+ localStorage.setItem('waterData', JSON.stringify({
+ currentMl: state.currentMl,
+ achievements: state.achievements,
+ date: new Date()
+ }));
+
+ // Check achievements
+ checkMilestones();
+ }
+
+ function addWater(ml) {
+ state.currentMl += ml;
+ updateDisplay();
+
+ // Add animation effect
+ const circle = document.querySelector('.circle-progress');
+ circle.style.transform = 'scale(1.05)';
+ setTimeout(() => {
+ circle.style.transform = 'scale(1)';
+ }, 200);
+ }
+
+ function checkMilestones() {
+ const milestones = [
+ { ml: 1000, message: "Great start! 1L reached! 💧" },
+ { ml: 2000, message: "Halfway there! 2L achieved! 💪" },
+ { ml: state.goalMl, message: "Daily goal reached! 🎉" }
+ ];
+
+ milestones.forEach(milestone => {
+ if (state.currentMl >= milestone.ml &&
+ !state.achievements.includes(milestone.ml)) {
+ state.achievements.push(milestone.ml);
+ showAchievement(milestone.message);
+ }
+ });
+ }
+
+ function showAchievement(message) {
+ const achievementsDiv = document.getElementById('achievements');
+ const achievement = document.createElement('div');
+ achievement.className = 'achievement';
+ achievement.textContent = message;
+ achievementsDiv.prepend(achievement);
+ }
+
+ // Event Listeners
+ document.querySelectorAll('.quick-add button').forEach(button => {
+ button.addEventListener('click', () => {
+ addWater(parseInt(button.dataset.ml));
+ });
+ });
+
+ document.getElementById('add-custom').addEventListener('click', () => {
+ const input = document.getElementById('custom-amount');
+ const amount = parseInt(input.value);
+ if (amount > 0) {
+ addWater(amount);
+ input.value = '';
+ }
+ });
+
+ document.getElementById('reset').addEventListener('click', () => {
+ if (confirm('Reset today\'s water tracking?')) {
+ state.currentMl = 0;
+ state.achievements = [];
+ document.getElementById('achievements').innerHTML = '';
+ updateDisplay();
+ }
+ });
+
+ // Initial display update
+ updateDisplay();
+ });