/* 连连看背单词游戏样式 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    width: 95%;
}

.header {
    text-align: center;
    margin-bottom: 30px;
}

.header h1 {
    color: #333;
    font-size: 2.5em;
    margin-bottom: 10px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text; /* 兼容性建议：标准属性 */
    color: transparent; /* 配合背景裁剪显示渐变文字 */
}

/* 页面内容通用样式 */
.page-content {
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

/* 页面指引文字 */
.page-instruction {
    font-size: 1.2em;
    color: #666;
    margin-bottom: 30px;
    font-weight: 500;
}

/* Unit按钮容器 */
.unit-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    justify-items: center;
    margin-bottom: 30px;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 20px;
}

/* Unit按钮样式 */
.unit-btn {
    width: 100%;
    max-width: 220px;
    padding: 18px 30px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.unit-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
    background: linear-gradient(45deg, #5a67d8, #6b46c1);
}

.unit-btn:active {
    transform: translateY(0);
}

/* 无Unit数据提示 */
.no-units {
    color: #999;
    font-size: 1.1em;
    text-align: center;
    padding: 40px 0;
}

/* 页面切换容器 */
#unitSelectionPage {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#gamePage {
    min-height: 400px;
    display: block;
    text-align: center;
    width: 100%; /* 确保宽度与container相同 */
    max-width: 100%; /* 移除最大宽度限制 */
    padding: 0; /* 移除内边距 */
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* 游戏头部区域 - 左中右布局 */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 30px;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    flex-wrap: wrap;
    padding: 0 20px;
}

.unit-select {
    padding: 12px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    background: white;
    min-width: 200px;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-start {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
}

.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
}

.btn-reset {
    background: linear-gradient(45deg, #ff6b6b, #ee5a52);
    color: white;
}

.btn-reset:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 107, 107, 0.3);
}

/* 返回按钮样式 */
.btn-back {
    background: linear-gradient(45deg, #4a5568, #2d3748);
    color: white;
}

.btn-back:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(74, 85, 104, 0.3);
}

.game-info {
    flex: 1;
    text-align: center;
    font-size: 18px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 15px;
}

.game-area {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 15px;
    margin-top: 20px;
    max-width: 1200px; /* 增加最大宽度以增大整体面积 */
    margin-left: auto;
    margin-right: auto;
    padding: 20px 10px; /* 减小左右边距 */
    box-sizing: border-box;
    overflow: hidden;
}

.card {
    aspect-ratio: 5/2; /* 减小高度，之前是4/3 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease; /* 更快的反馈 */
    font-size: 16px;
    color: white;
    text-align: center;
    padding: 12px;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    user-select: none;
    position: relative; /* 支持 z-index 和伪元素 */
    box-sizing: border-box;
    overflow: hidden;
    word-break: break-word;
    max-width: 100%;
}

.card:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.card.selected {
    transform: scale(1.1);
    border: 3px solid #DAA520; /* 金色边框 */
    box-shadow: 0 0 20px rgba(218, 165, 32, 0.65);
    z-index: 3;
    outline: 3px solid #FFD700; /* 额外金色描边 */
    outline-offset: 2px;
}

/* 提升选择器优先级，避免 :hover 影响 transform */
.game-area .card.selected {
    transform: translateY(-3px) scale(1.12);
}

.card.matched {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

.card.english {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
}

.card.chinese {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    animation: modalAppear 0.5s ease;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.7);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal h2 {
    color: #4CAF50;
    margin-bottom: 20px;
    font-size: 2em;
}

#errorModal h2 {
    color: #ff6b6b;
}

.modal p {
    color: #666;
    margin-bottom: 30px;
    font-size: 1.2em;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.modal-btn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    max-width: 200px;
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.modal-btn:first-child {
    background: linear-gradient(45deg, #ff9800, #f57c00);
}

.modal-btn:first-child:hover {
    box-shadow: 0 5px 15px rgba(255, 152, 0, 0.3);
}

.loading {
    text-align: center;
    color: #666;
    font-size: 18px;
    margin: 40px 0;
}

/* iPad/平板适配（iPad Air 等，纵向约 820px，横向约 1180px）*/
@media (min-width: 768px) and (max-width: 1024px) {
    .game-area {
        /* 保持7列布局 */
        grid-template-columns: repeat(7, 1fr);
        gap: 16px;
        max-width: 1000px;
    }
    .card {
        font-size: 18px;
        padding: 18px;
    }
    
    /* 保持4列布局 */
    .unit-buttons {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
        max-width: 800px;
    }
    
    .unit-btn {
        font-size: 16px;
        padding: 15px 15px;
    }
    
    /* 平板上保持游戏头部水平布局 */
}

@media (max-width: 768px) {
    .game-area {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        gap: 8px;
        margin: 0;
        padding: 10px;
        max-width: 100%;
    }

    .game-area .card {
        width: 100%;
        margin: 0;
    }
    
    .controls {
        flex-direction: column;
    }
    
    .unit-select {
        min-width: 100%;
    }
    
    .unit-buttons {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        max-width: 100%;
    }
    
    .unit-btn {
        font-size: 14px;
        padding: 12px 12px;
    }
    
    .page-content {
        padding: 0 10px;
    }
    
    .page-instruction {
        font-size: 1.1em;
    }
    
    /* 小屏幕游戏头部保持水平布局 */
    .game-info {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .unit-buttons {
        grid-template-columns: 1fr;
    }
    
    .unit-btn {
        max-width: 100%;
    }
    
    .header h1 {
        font-size: 2em;
    }
}