import tkinter as tk
from tkinter import ttk, messagebox, font
import random
import json
import os
import time
from datetime import datetime

class WordMemorizer:
    def __init__(self):
        self.window = tk.Tk()
        self.window.title("🎀 卡通英语单词背诵小助手 🎀")
        self.window.geometry("920x620")
        self.window.configure(bg='#FFF0F5')
        
        # 单词库
        self.word_list = [
            {"word": "apple", "meaning": "苹果", "example": "I eat an apple every day."},
            {"word": "book", "meaning": "书", "example": "This is my favorite book."},
            {"word": "cat", "meaning": "猫", "example": "The cat is sleeping."},
            {"word": "dog", "meaning": "狗", "example": "My dog likes to play."},
            {"word": "elephant", "meaning": "大象", "example": "An elephant is very big."},
            {"word": "flower", "meaning": "花", "example": "The flower is beautiful."},
            {"word": "garden", "meaning": "花园", "example": "We play in the garden."},
            {"word": "happy", "meaning": "快乐的", "example": "I am happy today!"},
            {"word": "ice cream", "meaning": "冰淇淋", "example": "I love ice cream."},
            {"word": "jungle", "meaning": "丛林", "example": "Monkeys live in the jungle."},
            {"word": "kite", "meaning": "风筝", "example": "Let's fly a kite."},
            {"word": "lion", "meaning": "狮子", "example": "The lion is king of animals."},
            {"word": "monkey", "meaning": "猴子", "example": "The monkey eats bananas."},
            {"word": "night", "meaning": "夜晚", "example": "Good night, sleep well."},
            {"word": "orange", "meaning": "橙子", "example": "Orange is my favorite fruit."},
            {"word": "panda", "meaning": "熊猫", "example": "Pandas are very cute."},
            {"word": "queen", "meaning": "女王", "example": "She is a kind queen."},
            {"word": "rabbit", "meaning": "兔子", "example": "The rabbit hops quickly."},
            {"word": "sun", "meaning": "太阳", "example": "The sun is shining bright."},
            {"word": "tree", "meaning": "树", "example": "The tree has green leaves."},
            {"word": "umbrella", "meaning": "雨伞", "example": "Take your umbrella, it's raining."},
            {"word": "violin", "meaning": "小提琴", "example": "She plays the violin beautifully."},
            {"word": "water", "meaning": "水", "example": "Please give me some water."},
            {"word": "yellow", "meaning": "黄色的", "example": "The sun is yellow."},
            {"word": "zebra", "meaning": "斑马", "example": "Zebras have black and white stripes."},
            {"word": "beautiful", "meaning": "美丽的", "example": "What a beautiful day!"},
            {"word": "computer", "meaning": "电脑", "example": "I use a computer to study."},
            {"word": "dance", "meaning": "跳舞", "example": "Let's dance together!"},
            {"word": "exercise", "meaning": "锻炼", "example": "Exercise is good for health."},
            {"word": "family", "meaning": "家庭", "example": "I love my family."},
            {"word": "guitar", "meaning": "吉他", "example": "He plays guitar very well."},
            {"word": "hospital", "meaning": "医院", "example": "The hospital is near my home."},
            {"word": "island", "meaning": "岛屿", "example": "We went to a beautiful island."},
            {"word": "juice", "meaning": "果汁", "example": "Would you like some juice?"},
            {"word": "kitchen", "meaning": "厨房", "example": "Mom is cooking in the kitchen."},
            {"word": "library", "meaning": "图书馆", "example": "I read books in the library."},
            {"word": "mountain", "meaning": "山", "example": "The mountain is very high."},
            {"word": "notebook", "meaning": "笔记本", "example": "Write it in your notebook."},
            {"word": "ocean", "meaning": "海洋", "example": "The ocean is deep and blue."},
            {"word": "pencil", "meaning": "铅笔", "example": "Draw with a pencil."},
            {"word": "question", "meaning": "问题", "example": "Do you have any questions?"},
            {"word": "rainbow", "meaning": "彩虹", "example": "Look at the rainbow!"},
            {"word": "school", "meaning": "学校", "example": "I go to school every day."},
            {"word": "teacher", "meaning": "老师", "example": "My teacher is very nice."},
            {"word": "vacation", "meaning": "假期", "example": "Summer vacation is coming!"},
            {"word": "window", "meaning": "窗户", "example": "Open the window, please."},
            {"word": "exciting", "meaning": "令人兴奋的", "example": "This movie is exciting!"},
            {"word": "yummy", "meaning": "美味的", "example": "This cake is yummy!"},
            {"word": "friend", "meaning": "朋友", "example": "She is my best friend."},
            {"word": "music", "meaning": "音乐", "example": "I love listening to music."}
        ]
        
        # 主题颜色配置
        self.themes = {
            '粉色公主': {
                'bg': '#FFF0F5', 'card': '#FFFFFF', 'primary': '#FF69B4',
                'secondary': '#FFB6C1', 'text': '#8B004B', 'accent': '#FF1493',
                'button': '#FF69B4', 'highlight': '#FFE4E1'
            },
            '蓝色海洋': {
                'bg': '#F0F8FF', 'card': '#FFFFFF', 'primary': '#4169E1',
                'secondary': '#87CEEB', 'text': '#000080', 'accent': '#0000CD',
                'button': '#4169E1', 'highlight': '#E6F2FF'
            },
            '森林绿意': {
                'bg': '#F0FFF0', 'card': '#FFFFFF', 'primary': '#228B22',
                'secondary': '#90EE90', 'text': '#006400', 'accent': '#006400',
                'button': '#228B22', 'highlight': '#E8FFE8'
            },
            '紫色梦幻': {
                'bg': '#F8F0FF', 'card': '#FFFFFF', 'primary': '#9370DB',
                'secondary': '#DDA0DD', 'text': '#4B0082', 'accent': '#8A2BE2',
                'button': '#9370DB', 'highlight': '#F0E6FF'
            },
            '橙色活力': {
                'bg': '#FFF5F0', 'card': '#FFFFFF', 'primary': '#FF6347',
                'secondary': '#FFD700', 'text': '#8B4513', 'accent': '#FF4500',
                'button': '#FF6347', 'highlight': '#FFE4D6'
            }
        }
        
        # 当前主题
        self.current_theme = '粉色公主'
        
        # 学习状态
        self.current_words = []
        self.current_index = 0
        self.learned_words = []
        self.favorite_words = []
        self.wrong_words = []
        self.session_stats = {"correct": 0, "wrong": 0, "total": 0}
        
        # 学习模式
        self.study_modes = ['顺序学习', '随机学习', '拼写模式', '快速挑战']
        self.current_mode = '顺序学习'
        
        # 加载保存的数据
        self.load_data()
        
        # 创建界面
        self.setup_ui()
        
        # 初始化单词
        self.load_words_for_session()
        self.show_current_word()
        
    def setup_ui(self):
        """创建用户界面"""
        # 主容器
        main_container = tk.Frame(self.window, bg=self.themes[self.current_theme]['bg'])
        main_container.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)
        
        # 标题栏
        title_frame = tk.Frame(main_container, bg=self.themes[self.current_theme]['bg'])
        title_frame.pack(fill=tk.X, pady=(0, 20))
        
        # 主标题
        self.title_label = tk.Label(title_frame, 
                                  text="🎀 卡通英语单词背诵小助手 🎀",
                                  font=('Comic Sans MS', 28, 'bold'),
                                  fg=self.themes[self.current_theme]['primary'],
                                  bg=self.themes[self.current_theme]['bg'])
        self.title_label.pack()
        
        # 副标题
        self.subtitle_label = tk.Label(title_frame,
                                     text="每天进步一点点，轻松掌握英语单词！ ✨",
                                     font=('Microsoft YaHei', 11),
                                     fg=self.themes[self.current_theme]['text'],
                                     bg=self.themes[self.current_theme]['bg'])
        self.subtitle_label.pack(pady=5)
        
        # 主要内容区
        content_frame = tk.Frame(main_container, bg=self.themes[self.current_theme]['bg'])
        content_frame.pack(fill=tk.BOTH, expand=True)
        
        # 左侧：控制面板
        left_frame = tk.Frame(content_frame, bg=self.themes[self.current_theme]['card'],
                            highlightbackground=self.themes[self.current_theme]['primary'],
                            highlightthickness=2, relief=tk.RAISED)
        left_frame.pack(side=tk.LEFT, fill=tk.Y, padx=(0, 20))
        
        # 右侧：学习区域
        right_frame = tk.Frame(content_frame, bg=self.themes[self.current_theme]['bg'])
        right_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
        
        # === 左侧控制面板 ===
        # 控制面板标题
        control_title = tk.Label(left_frame, text="🎮 控制面板",
                               font=('Microsoft YaHei', 16, 'bold'),
                               bg=self.themes[self.current_theme]['card'],
                               fg=self.themes[self.current_theme]['primary'])
        control_title.pack(pady=15)
        
        # 主题选择
        theme_label = tk.Label(left_frame, text="🎨 选择主题：",
                             font=('Microsoft YaHei', 11, 'bold'),
                             bg=self.themes[self.current_theme]['card'],
                             fg=self.themes[self.current_theme]['text'])
        theme_label.pack(pady=(10, 5))
        
        theme_frame = tk.Frame(left_frame, bg=self.themes[self.current_theme]['card'])
        theme_frame.pack()
        
        for theme_name in self.themes.keys():
            theme_btn = tk.Button(theme_frame, text=theme_name,
                                command=lambda t=theme_name: self.change_theme(t),
                                font=('Microsoft YaHei', 9),
                                bg=self.themes[theme_name]['primary'],
                                fg='white',
                                relief=tk.RAISED,
                                cursor='hand2',
                                width=14, pady=2)
            theme_btn.pack(pady=2)
        
        # 学习模式选择
        mode_label = tk.Label(left_frame, text="📚 学习模式：",
                            font=('Microsoft YaHei', 11, 'bold'),
                            bg=self.themes[self.current_theme]['card'],
                            fg=self.themes[self.current_theme]['text'])
        mode_label.pack(pady=(15, 5))
        
        self.mode_var = tk.StringVar(value=self.current_mode)
        mode_menu = tk.OptionMenu(left_frame, self.mode_var, *self.study_modes,
                                command=self.change_mode)
        mode_menu.config(font=('Microsoft YaHei', 9),
                        bg=self.themes[self.current_theme]['secondary'],
                        fg=self.themes[self.current_theme]['text'],
                        width=14)
        mode_menu.pack(pady=5)
        
        # 进度显示
        progress_label = tk.Label(left_frame, text="📊 学习进度：",
                                font=('Microsoft YaHei', 11, 'bold'),
                                bg=self.themes[self.current_theme]['card'],
                                fg=self.themes[self.current_theme]['text'])
        progress_label.pack(pady=(15, 5))
        
        self.progress_var = tk.StringVar(value="0/50")
        progress_value = tk.Label(left_frame, textvariable=self.progress_var,
                                font=('Microsoft YaHei', 14, 'bold'),
                                bg=self.themes[self.current_theme]['card'],
                                fg=self.themes[self.current_theme]['primary'])
        progress_value.pack()
        
        # 进度条
        self.progress_bar = ttk.Progressbar(left_frame, length=180, mode='determinate')
        self.progress_bar.pack(pady=8)
        
        # 统计数据
        stats_label = tk.Label(left_frame, text="📈 本日统计：",
                             font=('Microsoft YaHei', 11, 'bold'),
                             bg=self.themes[self.current_theme]['card'],
                             fg=self.themes[self.current_theme]['text'])
        stats_label.pack(pady=(15, 5))
        
        self.stats_var = tk.StringVar(value="正确: 0 | 错误: 0")
        stats_value = tk.Label(left_frame, textvariable=self.stats_var,
                             font=('Microsoft YaHei', 10),
                             bg=self.themes[self.current_theme]['card'],
                             fg=self.themes[self.current_theme]['text'])
        stats_value.pack()
        
        # 功能按钮
        fav_btn = tk.Button(left_frame, text="⭐ 查看收藏",
                          command=self.show_favorites,
                          font=('Microsoft YaHei', 10, 'bold'),
                          bg='#FFD700',
                          fg='#8B4513',
                          relief=tk.RAISED,
                          cursor='hand2',
                          width=14, pady=4)
        fav_btn.pack(pady=15)
        
        reset_btn = tk.Button(left_frame, text="🔄 重置进度",
                            command=self.reset_progress,
                            font=('Microsoft YaHei', 10),
                            bg='#FF6666',
                            fg='white',
                            relief=tk.RAISED,
                            cursor='hand2',
                            width=14, pady=4)
        reset_btn.pack(pady=5)
        
        # 状态显示
        self.status_var = tk.StringVar(value="✨ 准备就绪")
        status_label = tk.Label(left_frame, textvariable=self.status_var,
                              font=('Microsoft YaHei', 9),
                              bg=self.themes[self.current_theme]['card'],
                              fg=self.themes[self.current_theme]['text'])
        status_label.pack(pady=15)
        
        # === 右侧学习区域 ===
        # 单词卡片
        card_frame = tk.Frame(right_frame, bg=self.themes[self.current_theme]['card'],
                            highlightbackground=self.themes[self.current_theme]['primary'],
                            highlightthickness=3, relief=tk.RAISED)
        card_frame.pack(fill=tk.BOTH, expand=True, pady=(0, 15))
        
        # 卡片标题
        card_header = tk.Frame(card_frame, bg=self.themes[self.current_theme]['primary'])
        card_header.pack(fill=tk.X)
        
        tk.Label(card_header, text="📝 当前单词",
               font=('Microsoft YaHei', 14, 'bold'),
               bg=self.themes[self.current_theme]['primary'],
               fg='white').pack(pady=8)
        
        # 单词显示区域
        word_area = tk.Frame(card_frame, bg=self.themes[self.current_theme]['card'])
        word_area.pack(fill=tk.BOTH, expand=True, padx=20, pady=15)
        
        # 单词
        self.word_label = tk.Label(word_area, text="Apple",
                                  font=('Comic Sans MS', 38, 'bold'),
                                  bg=self.themes[self.current_theme]['card'],
                                  fg=self.themes[self.current_theme]['primary'])
        self.word_label.pack(pady=15)
        
        # 发音提示
        self.pronounce_label = tk.Label(word_area, text="[ˈæpəl] 点击下方按钮听发音",
                                      font=('Microsoft YaHei', 11),
                                      bg=self.themes[self.current_theme]['card'],
                                      fg='#888888')
        self.pronounce_label.pack(pady=5)
        
        # 释义
        meaning_frame = tk.Frame(word_area, bg=self.themes[self.current_theme]['highlight'],
                                relief=tk.SUNKEN, borderwidth=2)
        meaning_frame.pack(fill=tk.X, pady=10)
        
        self.meaning_label = tk.Label(meaning_frame, text="n. 苹果",
                                    font=('Microsoft YaHei', 15),
                                    bg=self.themes[self.current_theme]['highlight'],
                                    fg=self.themes[self.current_theme]['text'],
                                    pady=8)
        self.meaning_label.pack()
        
        # 例句
        example_frame = tk.Frame(word_area, bg=self.themes[self.current_theme]['card'])
        example_frame.pack(fill=tk.X, pady=8)
        
        tk.Label(example_frame, text="💡 例句：",
               font=('Microsoft YaHei', 10, 'bold'),
               bg=self.themes[self.current_theme]['card'],
               fg=self.themes[self.current_theme]['text']).pack(anchor=tk.W)
        
        self.example_label = tk.Label(example_frame, text="I eat an apple every day.",
                                    font=('Microsoft YaHei', 11, 'italic'),
                                    bg=self.themes[self.current_theme]['card'],
                                    fg=self.themes[self.current_theme]['text'],
                                    wraplength=480)
        self.example_label.pack(anchor=tk.W, pady=5)
        
        # 操作按钮
        button_frame = tk.Frame(right_frame, bg=self.themes[self.current_theme]['bg'])
        button_frame.pack(fill=tk.X)
        
        btn_configs = [
            ("❌ 不认识", self.mark_wrong, '#FF6B6B'),
            ("⭐ 收藏", self.toggle_favorite, '#FFD700'),
            ("✅ 认识了", self.mark_correct, '#51CF66'),
            ("⏭️ 下一个", self.next_word, '#339AF0')
        ]
        
        for text, command, color in btn_configs:
            btn = tk.Button(button_frame, text=text, command=command,
                          font=('Microsoft YaHei', 11, 'bold'),
                          bg=color, fg='white',
                          relief=tk.RAISED, cursor='hand2',
                          width=12, height=2)
            btn.pack(side=tk.LEFT, padx=5, expand=True)
        
        # 底部装饰
        bottom_frame = tk.Frame(self.window, bg=self.themes[self.current_theme]['bg'])
        bottom_frame.pack(fill=tk.X, padx=20, pady=8)
        
        # 卡通装饰
        decorations = ["🌸", "✨", "🎀", "🌟", "💖", "🌈"]
        deco_text = " ".join(decorations)
        tk.Label(bottom_frame, text=deco_text,
               font=('Arial', 14),
               bg=self.themes[self.current_theme]['bg'],
               fg=self.themes[self.current_theme]['primary']).pack()
        
        # 快捷键提示
        shortcut_label = tk.Label(bottom_frame,
                                text="⌨️ 快捷键: A-不认识 | S-收藏 | D-认识 | F-下一个",
                                font=('Microsoft YaHei', 9),
                                bg=self.themes[self.current_theme]['bg'],
                                fg=self.themes[self.current_theme]['text'])
        shortcut_label.pack(pady=3)
        
        # 绑定键盘快捷键
        self.window.bind('<a>', lambda e: self.mark_wrong())
        self.window.bind('<s>', lambda e: self.toggle_favorite())
        self.window.bind('<d>', lambda e: self.mark_correct())
        self.window.bind('<f>', lambda e: self.next_word())
        
    def change_theme(self, theme_name):
        """切换主题"""
        self.current_theme = theme_name
        theme = self.themes[theme_name]
        
        # 更新窗口背景
        self.window.configure(bg=theme['bg'])
        
        # 更新标题
        self.title_label.config(fg=theme['primary'], bg=theme['bg'])
        self.subtitle_label.config(fg=theme['text'], bg=theme['bg'])
        
        # 更新状态
        self.status_var.set(f"已切换到{theme_name}主题 ✨")
        
        # 更新单词显示
        self.word_label.config(fg=theme['primary'])
        self.meaning_label.config(bg=theme['highlight'], fg=theme['text'])
        self.example_label.config(fg=theme['text'])
        
    def change_mode(self, mode):
        """切换学习模式"""
        self.current_mode = mode
        self.current_index = 0
        self.load_words_for_session()
        self.show_current_word()
        self.status_var.set(f"已切换到{mode}模式 📚")
        
    def load_words_for_session(self):
        """加载本次学习的单词"""
        if self.current_mode == '随机学习':
            self.current_words = random.sample(self.word_list, len(self.word_list))
        elif self.current_mode == '拼写模式':
            short_words = [w for w in self.word_list if len(w['word']) <= 6]
            self.current_words = short_words[:20]
        elif self.current_mode == '快速挑战':
            self.current_words = random.sample(self.word_list, 20)
        else:
            self.current_words = self.word_list.copy()
            
        self.update_progress()
        
    def show_current_word(self):
        """显示当前单词"""
        if not self.current_words or self.current_index >= len(self.current_words):
            self.show_completion_message()
            return
            
        word_data = self.current_words[self.current_index]
        
        # 更新显示
        self.word_label.config(text=word_data['word'].upper())
        self.meaning_label.config(text=word_data['meaning'])
        self.example_label.config(text=f"\"{word_data['example']}\"")
        
        # 更新进度
        self.update_progress()
        
    def update_progress(self):
        """更新进度显示"""
        total = len(self.current_words)
        current = min(self.current_index + 1, total)
        
        self.progress_var.set(f"{current}/{total}")
        
        if total > 0:
            progress = (current / total) * 100
            self.progress_bar['value'] = progress
            
        self.stats_var.set(f"正确: {self.session_stats['correct']} | 错误: {self.session_stats['wrong']}")
        
    def mark_correct(self):
        """标记为认识"""
        if not self.current_words or self.current_index >= len(self.current_words):
            return
            
        word = self.current_words[self.current_index]
        
        # 添加到已学列表
        if word not in self.learned_words:
            self.learned_words.append(word)
            
        # 更新统计
        self.session_stats['correct'] += 1
        self.session_stats['total'] += 1
        
        # 保存数据
        self.save_data()
        
        # 显示鼓励语
        encouragements = ["太棒了！🎉", "真厉害！🌟", "继续加油！💪", "好记忆！✨", "Perfect! 🎯"]
        self.status_var.set(random.choice(encouragements))
        
        # 自动跳到下一个
        self.next_word()
        
    def mark_wrong(self):
        """标记为不认识"""
        if not self.current_words or self.current_index >= len(self.current_words):
            return
            
        word = self.current_words[self.current_index]
        
        # 添加到错词本
        if word not in self.wrong_words:
            self.wrong_words.append(word)
            
        # 更新统计
        self.session_stats['wrong'] += 1
        self.session_stats['total'] += 1
        
        # 保存数据
        self.save_data()
        
        # 显示鼓励语
        encouragements = ["别灰心！下次记住！💪", "加油！多复习！📚", "没关系，再看一遍！👀"]
        self.status_var.set(random.choice(encouragements))
        
        # 自动跳到下一个
        self.next_word()
        
    def toggle_favorite(self):
        """切换收藏状态"""
        if not self.current_words or self.current_index >= len(self.current_words):
            return
            
        word = self.current_words[self.current_index]
        
        if word in self.favorite_words:
            self.favorite_words.remove(word)
            self.status_var.set("已取消收藏 ⭐")
        else:
            self.favorite_words.append(word)
            self.status_var.set("已加入收藏 ⭐")
            
        self.save_data()
        
    def next_word(self):
        """下一个单词"""
        if self.current_index < len(self.current_words) - 1:
            self.current_index += 1
            self.show_current_word()
        else:
            self.show_completion_message()
            
    def show_completion_message(self):
        """显示完成消息"""
        self.word_label.config(text="🎉")
        self.meaning_label.config(text="恭喜完成本轮学习！")
        self.example_label.config(text=f"正确: {self.session_stats['correct']} | 错误: {self.session_stats['wrong']}")
        
        # 显示评价
        total = self.session_stats['correct'] + self.session_stats['wrong']
        if total > 0:
            accuracy = (self.session_stats['correct'] / total) * 100
            if accuracy >= 90:
                comment = "太厉害了！你是英语天才！🌟"
            elif accuracy >= 70:
                comment = "做得很好！继续保持！👍"
            elif accuracy >= 50:
                comment = "还不错，多多练习！💪"
            else:
                comment = "需要多加努力哦！加油！📚"
                
            self.status_var.set(comment)
            
        # 重置统计
        self.session_stats = {"correct": 0, "wrong": 0, "total": 0}
        
    def show_favorites(self):
        """显示收藏的单词"""
        if not self.favorite_words:
            messagebox.showinfo("收藏夹", "还没有收藏任何单词哦～")
            return
            
        fav_window = tk.Toplevel(self.window)
        fav_window.title("⭐ 我的收藏")
        fav_window.geometry("450x380")
        fav_window.configure(bg=self.themes[self.current_theme]['bg'])
        
        # 居中显示
        x = self.window.winfo_x() + (self.window.winfo_width() // 2) - 225
        y = self.window.winfo_y() + (self.window.winfo_height() // 2) - 190
        fav_window.geometry(f"+{x}+{y}")
        
        # 标题
        tk.Label(fav_window, text="⭐ 我的收藏单词", 
                font=('Microsoft YaHei', 18, 'bold'),
                bg=self.themes[self.current_theme]['bg'],
                fg=self.themes[self.current_theme]['primary']).pack(pady=15)
        
        # 创建滚动区域
        canvas = tk.Canvas(fav_window, bg=self.themes[self.current_theme]['bg'])
        scrollbar = tk.Scrollbar(fav_window, orient="vertical", command=canvas.yview)
        scrollable_frame = tk.Frame(canvas, bg=self.themes[self.current_theme]['bg'])
        
        scrollable_frame.bind(
            "<Configure>",
            lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
        )
        
        canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
        canvas.configure(yscrollcommand=scrollbar.set)
        
        # 显示收藏的单词
        for i, word in enumerate(self.favorite_words, 1):
            word_frame = tk.Frame(scrollable_frame, 
                                bg=self.themes[self.current_theme]['card'],
                                relief=tk.RAISED, borderwidth=1)
            word_frame.pack(fill=tk.X, padx=15, pady=3)
            
            tk.Label(word_frame, text=f"{i}. {word['word']}", 
                   font=('Comic Sans MS', 12, 'bold'),
                   bg=self.themes[self.current_theme]['card'],
                   fg=self.themes[self.current_theme]['primary']).pack(side=tk.LEFT, padx=8, pady=4)
            
            tk.Label(word_frame, text=word['meaning'], 
                   font=('Microsoft YaHei', 11),
                   bg=self.themes[self.current_theme]['card'],
                   fg=self.themes[self.current_theme]['text']).pack(side=tk.LEFT, padx=8, pady=4)
        
        canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
        
    def reset_progress(self):
        """重置进度"""
        if messagebox.askyesno("确认重置", "确定要重置所有学习进度吗？"):
            self.learned_words = []
            self.favorite_words = []
            self.wrong_words = []
            self.session_stats = {"correct": 0, "wrong": 0, "total": 0}
            self.current_index = 0
            self.load_words_for_session()
            self.show_current_word()
            self.save_data()
            self.status_var.set("学习进度已重置 🔄")
            
    def load_data(self):
        """加载保存的数据"""
        try:
            if os.path.exists('word_data.json'):
                with open('word_data.json', 'r', encoding='utf-8') as f:
                    data = json.load(f)
                    self.learned_words = data.get('learned', [])
                    self.favorite_words = data.get('favorites', [])
                    self.wrong_words = data.get('wrong', [])
        except:
            pass
            
    def save_data(self):
        """保存数据"""
        try:
            data = {
                'learned': self.learned_words,
                'favorites': self.favorite_words,
                'wrong': self.wrong_words,
                'last_update': datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            }
            with open('word_data.json', 'w', encoding='utf-8') as f:
                json.dump(data, f, ensure_ascii=False, indent=2)
        except:
            pass
            
    def run(self):
        """运行程序"""
        self.window.mainloop()

def main():
    """主函数"""
    print("="*60)
    print("🎀 卡通英语单词背诵小助手 v1.0")
    print("="*60)
    print("✨ 功能特色：")
    print("🎨 5种卡通主题颜色")
    print("📚 50个基础英语单词")
    print("⭐ 收藏喜欢的单词")
    print("📊 学习进度跟踪")
    print("⌨️ 键盘快捷键支持")
    print("💾 自动保存学习记录")
    print("="*60)
    print("使用说明：")
    print("1. 选择喜欢的主题颜色")
    print("2. 选择学习模式")
    print("3. 点击'认识了'或'不认识'")
    print("4. 可以收藏重点单词")
    print("5. 快捷键: A/S/D/F")
    print("="*60)
    print("程序启动中...")
    
    app = WordMemorizer()
    app.run()

if __name__ == "__main__":
    main()