/* 
  记忆卡牌游戏 - 样式表
  文件名: style.css
  最后更新: 2023-10-01
  作者: [你的名字]
  主题: 绿色+黄色配色方案
*/

/* ============================================
   1. 重置与基础样式 (RESET & BASE STYLES)
   这些样式重置浏览器默认样式，设置全局基础
   ============================================ */

/* 通用选择器：重置所有元素的内外边距，使用border-box盒模型 */
* {
    margin: 0;                     /* 移除默认外边距 */
    padding: 0;                    /* 移除默认内边距 */
    box-sizing: border-box;        /* 盒模型：宽度包含内边距和边框 */
}

/* 页面主体样式 - 改为绿色+黄色渐变 */
body {
    font-family: 'Poppins', sans-serif;  /* 使用Poppins字体，无衬线字体为备选 */
    background: linear-gradient(135deg, #2E7D32 0%, #FFEB3B 100%); /* 绿色到黄色渐变背景 */
    min-height: 100vh;                    /* 最小高度为视口高度，确保撑满屏幕 */
    display: flex;                        /* 使用Flex布局 */
    justify-content: center;              /* 水平居中 */
    align-items: center;                  /* 垂直居中 */
    padding: 20px;                        /* 内边距，避免内容贴边 */
    color: #333;                          /* 默认文字颜色（深灰色） */
}

/* 
   主容器：包裹整个游戏界面
   修改max-width可调整游戏最大宽度
   修改background-color的rgba最后值（0.95）可调整透明度
*/
.container {
    max-width: 900px;                     /* 最大宽度，在大屏幕上不会过宽 */
    width: 100%;                          /* 宽度100%，自适应父容器 */
    background-color: rgba(255, 255, 255, 0.95); /* 白色背景，95%透明度 */
    border-radius: 20px;                  /* 圆角边框 */
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2); /* 阴影效果：水平偏移0，垂直15px，模糊35px */
    padding: 30px;                        /* 内边距 */
    text-align: center;                   /* 文本居中 */
}

/* ============================================
   2. 头部样式 (HEADER STYLES)
   游戏标题和副标题区域
   ============================================ */

/* 头部容器 */
header {
    margin-bottom: 25px;                  /* 底部外边距，与下方内容分隔 */
}

/* 主标题样式 */
header h1 {
    color: #1B5E20;                       /* 深绿色标题 */
    font-size: 2.5rem;                    /* 字体大小（2.5倍根元素字体大小） */
    margin-bottom: 8px;                   /* 底部外边距 */
    display: flex;                        /* Flex布局，用于图标和文字排列 */
    align-items: center;                  /* 垂直居中对齐 */
    justify-content: center;              /* 水平居中对齐 */
    gap: 15px;                            /* 子元素之间的间隔 */
}

/* 标题中的图标样式 */
header h1 i {
    color: #FFC107;                       /* 黄色图标 */
}

/* 副标题样式 */
.subtitle {
    color: #388E3C;                       /* 中等绿色 */
    font-size: 1.1rem;                    /* 字体大小 */
}

/* ============================================
   3. 游戏统计区域 (GAME STATISTICS)
   显示时间、步数和匹配对数的统计面板
   ============================================ */

/* 统计区域容器：Flex布局，居中，允许换行 */
.game-stats {
    display: flex;                        /* Flex布局 */
    justify-content: center;              /* 水平居中 */
    gap: 30px;                            /* 子元素之间的间隔 */
    margin-bottom: 25px;                  /* 底部外边距 */
    flex-wrap: wrap;                      /* 允许换行，适应小屏幕 */
}

/* 单个统计盒子样式 - 改为绿色+黄色渐变 */
.stat-box {
    background: linear-gradient(135deg, #4CAF50, #8BC34A); /* 绿色渐变背景 */
    color: white;                         /* 文字颜色为白色 */
    padding: 15px 25px;                   /* 内边距：上下15px，左右25px */
    border-radius: 12px;                  /* 圆角 */
    min-width: 120px;                     /* 最小宽度，防止内容过窄 */
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3); /* 绿色阴影 */
    transition: transform 0.3s ease;      /* 鼠标悬停时的动画效果：0.3秒缓动 */
}

/* 鼠标悬停效果：向上移动5px */
.stat-box:hover {
    transform: translateY(-5px);
}

/* 统计标签（如"时间"、"步数"） */
.stat-label {
    font-size: 0.9rem;                    /* 较小字体 */
    opacity: 0.9;                         /* 轻微透明 */
    margin-bottom: 5px;                   /* 底部外边距 */
}

/* 统计数值（如"00:00"、"0"） */
.stat-value {
    font-size: 1.8rem;                    /* 大字体 */
    font-weight: 600;                     /* 中等加粗 */
}

/* ============================================
   4. 游戏控制区域 (GAME CONTROLS)
   包含重置按钮和难度选择器
   ============================================ */

/* 控制区域容器：Flex布局，两端对齐，允许换行 */
.game-controls {
    display: flex;                        /* Flex布局 */
    justify-content: space-between;       /* 两端对齐 */
    align-items: center;                  /* 垂直居中对齐 */
    margin-bottom: 30px;                  /* 底部外边距 */
    flex-wrap: wrap;                      /* 允许换行 */
    gap: 20px;                            /* 子元素之间的间隔（当换行时生效） */
}

/* 按钮通用样式 - 改为黄色渐变 */
.btn {
    background: linear-gradient(135deg, #FFC107, #FF9800); /* 黄色渐变 */
    color: #1B5E20;                       /* 深绿色文字 */
    border: none;                         /* 无边框 */
    padding: 12px 25px;                   /* 内边距 */
    border-radius: 50px;                  /* 圆形边框（50px实现胶囊形状） */
    font-size: 1rem;                      /* 字体大小 */
    font-weight: 600;                     /* 加粗字体，提高可读性 */
    cursor: pointer;                      /* 鼠标指针变为手型 */
    display: flex;                        /* Flex布局，用于图标和文字排列 */
    align-items: center;                  /* 垂直居中对齐 */
    gap: 10px;                            /* 图标和文字之间的间隔 */
    transition: all 0.3s ease;            /* 所有属性变化都有0.3秒缓动过渡 */
    box-shadow: 0 5px 15px rgba(255, 193, 7, 0.3); /* 黄色阴影 */
}

/* 按钮悬停效果 */
.btn:hover {
    transform: translateY(-3px);          /* 向上移动3px */
    box-shadow: 0 8px 20px rgba(255, 193, 7, 0.5); /* 加深阴影 */
}

/* 按钮内的图标 */
.btn i {
    font-size: 1.1rem;                    /* 图标稍大于文字 */
}

/* 难度选择器容器 */
.difficulty {
    display: flex;                        /* Flex布局 */
    align-items: center;                  /* 垂直居中对齐 */
    gap: 10px;                            /* 标签和下拉框之间的间隔 */
    font-weight: 500;                     /* 中等加粗 */
    color: #1B5E20;                       /* 深绿色文字 */
}

/* 难度选择下拉框 */
#difficulty {
    padding: 10px 15px;                   /* 内边距 */
    border-radius: 8px;                   /* 圆角 */
    border: 2px solid #4CAF50;            /* 绿色边框 */
    background-color: white;              /* 白色背景 */
    font-weight: 500;                     /* 中等加粗 */
    cursor: pointer;                      /* 手型指针 */
    transition: all 0.3s;                 /* 所有属性变化过渡0.3秒 */
    color: #1B5E20;                       /* 深绿色文字 */
}

/* 下拉框获得焦点时的样式 */
#difficulty:focus {
    outline: none;                        /* 移除默认轮廓线 */
    border-color: #388E3C;                /* 加深绿色边框 */
}

/* ============================================
   5. 游戏面板 (GAME BOARD)
   卡片布局区域
   ============================================ */

/* 游戏面板：使用CSS Grid布局 */
.game-board {
    display: grid;                        /* Grid布局 */
    grid-template-columns: repeat(4, 1fr); /* 4列，每列等宽 */
    gap: 15px;                            /* 卡片之间的间隔 */
    margin-bottom: 30px;                  /* 底部外边距 */
    justify-content: center;              /* 水平居中（如果卡片总宽度小于容器） */
}

/* ============================================
   6. 卡片样式 (CARD STYLES)
   卡片翻转效果和状态样式
   ============================================ */

/* 卡片容器 */
.card {
    height: 120px;                        /* 固定高度 */
    border-radius: 12px;                  /* 圆角 */
    perspective: 1000px;                  /* 3D透视距离，影响翻转的立体感 */
    cursor: pointer;                      /* 手型指针，表示可点击 */
    transition: transform 0.3s;           /* 卡片悬停时的缩放过渡效果 */
}

/* 鼠标悬停在卡片上时，卡片内部阴影加深 */
.card:hover .card-inner {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* 卡片内部容器：实现3D翻转效果 */
.card-inner {
    position: relative;                   /* 相对定位，用于子元素的绝对定位 */
    width: 100%;                          /* 宽度100%父容器 */
    height: 100%;                         /* 高度100%父容器 */
    text-align: center;                   /* 文字居中 */
    transition: transform 0.6s;           /* 翻转动画：0.6秒 */
    transform-style: preserve-3d;         /* 保持3D变换 */
    border-radius: 12px;                  /* 圆角（继承自.card） */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); /* 默认阴影 */
}

/* 卡片翻转状态：旋转180度显示正面 */
.card.flipped .card-inner {
    transform: rotateY(180deg);
}

/* 卡片匹配成功状态：改变阴影颜色为绿色 */
.card.matched .card-inner {
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.6); /* 绿色阴影 */
}

/* 卡片正面和背面的通用样式 */
.card-front, .card-back {
    position: absolute;                   /* 绝对定位，重叠在一起 */
    width: 100%;                          /* 宽度100%父容器 */
    height: 100%;                         /* 高度100%父容器 */
    -webkit-backface-visibility: hidden;  /* Safari前缀：隐藏背面 */
    backface-visibility: hidden;          /* 隐藏背面（当旋转180度时） */
    border-radius: 12px;                  /* 圆角 */
    display: flex;                        /* Flex布局，用于居中内容 */
    justify-content: center;              /* 水平居中 */
    align-items: center;                  /* 垂直居中 */
    font-size: 2.5rem;                    /* 图标大小 */
}

/* 卡片正面样式（显示图标）- 改为绿色渐变 */
.card-front {
    background: linear-gradient(135deg, #4CAF50, #8BC34A); /* 绿色渐变 */
    color: white;                         /* 白色图标 */
    transform: rotateY(180deg);           /* 初始旋转180度（隐藏） */
}

/* 卡片背面样式（显示问号）- 改为黄色渐变 */
.card-back {
    background: linear-gradient(135deg, #FFF9C4, #FFEB3B); /* 黄色渐变 */
    color: #F57C00;                       /* 橙色问号 */
}

/* 卡片背面的问号图标 */
.card-back i {
    font-size: 2.2rem;                    /* 图标大小 */
    opacity: 0.8;                         /* 80%透明度 */
}

/* ============================================
   7. 消息弹窗 (MESSAGE MODAL)
   游戏结束时的弹窗
   ============================================ */

/* 消息弹窗容器：固定定位，覆盖整个屏幕 */
.message {
    display: none;                        /* 默认隐藏 */
    position: fixed;                      /* 固定定位 */
    top: 0;
    left: 0;
    width: 100%;                          /* 全宽 */
    height: 100%;                         /* 全高 */
    background-color: rgba(0, 0, 0, 0.7); /* 黑色半透明遮罩 */
    z-index: 100;                         /* 确保在最上层 */
    justify-content: center;              /* 水平居中 */
    align-items: center;                  /* 垂直居中 */
}

/* 消息内容区域 */
.message-content {
    background: linear-gradient(135deg, #FFFFFF, #FFF9C4); /* 白色到浅黄色渐变背景 */
    padding: 40px;                        /* 内边距 */
    border-radius: 20px;                  /* 圆角 */
    max-width: 500px;                     /* 最大宽度 */
    width: 90%;                           /* 宽度90%，适应小屏幕 */
    text-align: center;                   /* 文字居中 */
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3); /* 深色阴影 */
    animation: popIn 0.5s ease;           /* 弹出动画 */
    border: 3px solid #4CAF50;            /* 绿色边框 */
}

/* 弹窗弹出动画 */
@keyframes popIn {
    0% { 
        transform: scale(0.7);            /* 起始：缩放70% */
        opacity: 0;                       /* 起始：完全透明 */
    }
    100% { 
        transform: scale(1);              /* 结束：正常大小 */
        opacity: 1;                       /* 结束：完全不透明 */
    }
}

/* 弹窗标题 */
.message-content h2 {
    color: #1B5E20;                       /* 深绿色标题 */
    margin-bottom: 15px;                  /* 底部外边距 */
    font-size: 2.2rem;                    /* 大字体 */
}

/* 弹窗正文 */
.message-content p {
    color: #388E3C;                       /* 中等绿色 */
    margin-bottom: 25px;                  /* 底部外边距 */
    font-size: 1.2rem;                    /* 稍大字体 */
}

/* 弹窗按钮样式 */
.message-content .btn {
    margin: 0 auto;                       /* 水平居中 */
}

/* ============================================
   8. 页脚 (FOOTER)
   页面底部信息
   ============================================ */

footer {
    margin-top: 20px;                     /* 顶部外边距，与上方内容分隔 */
    color: #388E3C;                       /* 中等绿色文字 */
    font-size: 0.9rem;                    /* 较小字体 */
}

/* ============================================
   9. 响应式设计 (RESPONSIVE DESIGN)
   适应平板和手机的样式
   ============================================ */

/* 平板设备（屏幕宽度小于768px） */
@media (max-width: 768px) {
    .container {
        padding: 20px;                    /* 减少内边距 */
    }
    
    header h1 {
        font-size: 2rem;                  /* 缩小标题字体 */
    }
    
    .game-board {
        grid-template-columns: repeat(4, 1fr); /* 保持4列布局 */
        gap: 10px;                        /* 减少卡片间隔 */
    }
    
    .card {
        height: 90px;                     /* 缩小卡片高度 */
    }
    
    .card-front, .card-back {
        font-size: 2rem;                  /* 缩小图标大小 */
    }
    
    .stat-box {
        min-width: 100px;                 /* 缩小统计盒子最小宽度 */
        padding: 12px 20px;               /* 调整内边距 */
    }
    
    .stat-value {
        font-size: 1.5rem;                /* 缩小统计数字字体 */
    }
}

/* 手机设备（屏幕宽度小于480px） */
@media (max-width: 480px) {
    .game-board {
        grid-template-columns: repeat(4, 1fr); /* 保持4列布局 */
    }
    
    .card {
        height: 75px;                     /* 进一步缩小卡片高度 */
    }
    
    .game-stats {
        gap: 15px;                        /* 减少统计盒子之间的间隔 */
    }
    
    .stat-box {
        min-width: 80px;                  /* 进一步缩小统计盒子最小宽度 */
        padding: 10px 15px;               /* 调整内边距 */
    }
    
    .game-controls {
        flex-direction: column;           /* 垂直排列控制元素 */
        align-items: stretch;             /* 拉伸子元素宽度 */
    }
    
    .btn {
        justify-content: center;          /* 按钮内容居中 */
    }
}

/* ============================================
   10. 新增样式：游戏完成动画效果
   ============================================ */

/* 游戏完成时的庆祝动画 */
@keyframes celebration {
    0% { 
        transform: scale(1); 
        box-shadow: 0 0 0 rgba(76, 175, 80, 0.7);
    }
    50% { 
        transform: scale(1.05); 
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.9);
    }
    100% { 
        transform: scale(1); 
        box-shadow: 0 0 0 rgba(76, 175, 80, 0.7);
    }
}

/* 游戏完成时应用庆祝动画到容器 */
.container.game-completed {
    animation: celebration 2s ease-in-out 3; /* 重复3次，每次2秒 */
}

/* 匹配成功时卡片的脉冲效果 */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.card.matched .card-inner {
    animation: pulse 0.5s ease-in-out; /* 匹配成功时脉冲效果 */
}