/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    overflow: hidden;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* 背景装饰 */
.bg-decoration {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.bg-decoration::before {
    content: '';
    position: absolute;
    top: -100px;
    right: -100px;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
    border-radius: 50%;
}

.bg-decoration::after {
    content: '';
    position: absolute;
    bottom: -50px;
    left: -50px;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    border-radius: 50%;
}

/* 通用页面容器 */
.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 2px;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateX(100%);
    z-index: 10;
}

.page.active {
    opacity: 1;
    transform: translateX(0);
    z-index: 20;
}

.page.prev {
    transform: translateX(-100%);
}

/* ========== 首页样式 ========== */
#homePage {
    justify-content: space-between;
    align-items: center;
    text-align: center;
    position: relative;
    padding: 0;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}

#homePage::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(circle at 20% 20%, rgba(255,255,255,0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(255,255,255,0.1) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(255,255,255,0.05) 0%, transparent 60%);
    animation: bgFloat 20s ease-in-out infinite;
    pointer-events: none;
}

@keyframes bgFloat {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(-2%, -2%) rotate(3deg); }
}

.home-container {
    padding: 15px 24px 20px 24px;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 10;
}

/* 动态单词网格展示 */
.demo-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 4px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.demo-tile {
    width: 38px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    border-radius: 5px;
    color: white;
    font-size: 10px;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(79, 172, 254, 0.4);
    animation: tileFloat 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

.demo-tile.match-a {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 2px 6px rgba(240, 147, 251, 0.4);
    animation: matchPulse 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

.demo-tile.match-b {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    box-shadow: 0 2px 6px rgba(67, 233, 123, 0.4);
    animation: matchPulse 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

.demo-tile.match-c {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    box-shadow: 0 2px 6px rgba(250, 112, 154, 0.4);
    animation: matchPulse 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

.demo-tile.match-d {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
    animation: matchPulse 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

.demo-tile.match-e {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.4);
    animation: matchPulse 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

.demo-tile.match-f {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #555;
    box-shadow: 0 2px 6px rgba(168, 237, 234, 0.4);
    animation: matchPulse 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

@keyframes tileFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-3px) scale(1.02); }
}

@keyframes matchPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    25% {
        transform: scale(1.08);
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.6);
    }
    50% {
        transform: scale(0.3);
        opacity: 0.3;
    }
    75% {
        transform: scale(0.3);
        opacity: 0;
    }
    76% {
        transform: scale(1);
        opacity: 1;
    }
}

.game-icon {
    font-size: 80px;
    margin-bottom: 10px;
    display: inline-block;
    animation: iconFloat 3s ease-in-out infinite;
    filter: drop-shadow(0 8px 16px rgba(0,0,0,0.2));
}

@keyframes iconFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.05); }
}

.home-title {
    font-size: 64px;
    font-weight: 800;
    color: #fff;
    margin-bottom: 8px;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    letter-spacing: 2px;
}

.home-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 30px;
    line-height: 1.4;
    font-weight: 500;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 年级选择区 */
.grade-section {
    width: 100%;
    max-width: 340px;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 15px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.grade-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.grade-btn {
    width: 100%;
    padding: 16px 12px;
    border: none;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255,255,255,0.3);
    border: 1px solid rgba(255, 255, 255, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.grade-btn:nth-child(1) {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.9) 0%, rgba(118, 75, 162, 0.9) 100%);
}

.grade-btn:nth-child(2) {
    background: linear-gradient(135deg, rgba(240, 147, 251, 0.9) 0%, rgba(245, 87, 108, 0.9) 100%);
}

.grade-btn:nth-child(3) {
    background: linear-gradient(135deg, rgba(79, 172, 254, 0.9) 0%, rgba(0, 242, 254, 0.9) 100%);
}

.grade-btn:nth-child(4) {
    background: linear-gradient(135deg, rgba(67, 233, 123, 0.9) 0%, rgba(56, 249, 215, 0.9) 100%);
}

.grade-btn:nth-child(5) {
    background: linear-gradient(135deg, rgba(250, 112, 154, 0.9) 0%, rgba(254, 225, 64, 0.9) 100%);
}

.grade-btn:nth-child(6) {
    background: linear-gradient(135deg, rgba(168, 237, 234, 0.9) 0%, rgba(254, 214, 227, 0.9) 100%);
    color: #555;
}

.grade-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.grade-btn:active {
    transform: translateY(0) scale(0.98);
}

.grade-name {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 2px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.grade-desc {
    font-size: 11px;
    opacity: 0.9;
    font-weight: 500;
}

/* 署名 */
.credit {
    width: 100%;
    text-align: center;
    margin-top: 10px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    z-index: 30;
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* ========== 游戏页样式 ========== */
#gamePage {
    padding: 0;
    padding-top: calc(env(safe-area-inset-top, 0) + 0px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0) + 60px);
    display: flex;
    flex-direction: column;
}

/* 顶部统计栏 - 极紧凑 */
.game-header {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 3px 8px;
    border-radius: 6px;
    margin-bottom: 0px;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    font-size: 12px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.stat-label {
    font-size: 9px;
    opacity: 0.85;
    margin-bottom: 1px;
}

.stat-value {
    font-size: 14px;
    font-weight: bold;
}

.stat-divider {
    width: 1px;
    height: 22px;
    background: rgba(255, 255, 255, 0.3);
    margin: 0 5px;
}

/* 进度条 - 极紧凑 */
.progress-container {
    background: rgba(255, 255, 255, 0.2);
    height: 2px;
    border-radius: 1px;
    overflow: hidden;
    margin-bottom: 0px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #43e97b, #38f9d7);
    width: 0%;
    transition: width 0.3s ease;
}

/* 游戏板容器 - 自适应屏幕大小，更紧凑 */
.game-board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1px;
    overflow: hidden;
    min-height: 0;
    z-index: 10;
}

.game-board {
    display: grid;
    gap: 2px;
    background: rgba(255, 255, 255, 0.95);
    padding: 6px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    /* 4列×7行的竖直布局（28格，14对单词） */
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(7, 1fr);
    /* 紧凑布局，充分利用屏幕宽度 */
    width: calc(100vw - 16px);
    height: calc((100vw - 16px) * 7 / 4);
    max-width: 360px;
    max-height: 630px;
    z-index: 1;
}

/* 所有年级统一使用4×7布局 */
.game-board.hard {
    /* 保持与默认相同的4×7布局 */
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(7, 1fr);
    height: calc((100vw - 16px) * 7 / 4);
    max-height: 630px;
}

/* 单词卡片 - 填满网格，增大字体 */
.word-tile {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(145deg, #4facfe, #00f2fe);
    border: 2px solid #4facfe;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    padding: 4px;
    position: relative;
    overflow: hidden;
    color: white;
    user-select: none;
    -webkit-user-select: none;
    /* 让卡片占满网格 */
    width: 100%;
    height: 100%;
}

.word-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.word-tile:hover::before {
    left: 100%;
}

.word-tile:active {
    transform: scale(0.95);
}

.word-tile.selected {
    background: linear-gradient(145deg, #fa709a, #fee140);
    border-color: #fa709a;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(250, 112, 154, 0.8);
    z-index: 10;
}

.word-tile.matched {
    background: linear-gradient(145deg, #95a5a6, #7f8c8d);
    border-color: #7f8c8d;
    animation: matchSuccess 0.6s ease;
    pointer-events: none;
    opacity: 0.7;
}

.word-tile.wrong {
    background: linear-gradient(145deg, #e74c3c, #c0392b);
    border-color: #c0392b;
    animation: wrongShake 0.5s ease;
}

@keyframes matchSuccess {
    0% { transform: scale(1.05); }
    50% { transform: scale(1.08) rotate(2deg); }
    100% { transform: scale(0) rotate(360deg); opacity: 0; }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

.word-emoji {
    font-size: 19px;
    margin-bottom: 1px;
    line-height: 1;
}

.word-content {
    font-size: 14px;
    font-weight: bold;
    line-height: 1.1;
    word-break: break-word;
}

/* 控制按钮 - 极紧凑布局 */
.game-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 3px;
    margin-top: 0px;
    position: relative;
    z-index: 1;
    padding-bottom: 2px;
}

.control-btn {
    height: 36px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    z-index: 9999;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.control-btn:active::before {
    left: 100%;
}

.control-btn.home {
    background: linear-gradient(45deg, #34495e, #2c3e50);
}

.control-btn.pause {
    background: linear-gradient(45deg, #f39c12, #e67e22);
}

.control-btn.restart {
    background: linear-gradient(45deg, #95a5a6, #7f8c8d);
}

.control-btn.music {
    background: linear-gradient(45deg, #4facfe, #00f2fe);
}


.control-btn:active {
    transform: scale(0.98);
}

/* ========== 游戏结束页样式 ========== */
#gameEndPage {
    justify-content: center;
    align-items: center;
}

.end-content {
    background: rgba(255, 255, 255, 0.98);
    padding: 25px 18px;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 320px;
    width: 100%;
    text-align: center;
}

.end-icon {
    font-size: 55px;
    margin-bottom: 12px;
    animation: celebrate 1s ease-in-out;
}

@keyframes celebrate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.end-title {
    font-size: 22px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 6px;
}

.end-subtitle {
    font-size: 12px;
    color: #7f8c8d;
    margin-bottom: 18px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 18px;
}

.stat-card {
    background: linear-gradient(135deg, #4facfe, #00f2fe);
    padding: 12px;
    border-radius: 10px;
    color: white;
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
}

.stat-card.highlight {
    background: linear-gradient(135deg, #fa709a, #fee140);
}

.stat-card .stat-label {
    font-size: 10px;
    opacity: 0.9;
    margin-bottom: 3px;
}

.stat-card .stat-value {
    font-size: 18px;
    font-weight: bold;
}

.achievement {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 11px;
    font-weight: bold;
    animation: achievementGlow 2s ease-in-out infinite;
}

@keyframes achievementGlow {
    0%, 100% { box-shadow: 0 0 10px rgba(231, 76, 60, 0.5); }
    50% { box-shadow: 0 0 20px rgba(231, 76, 60, 0.8); }
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 16px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.action-btn:active::before {
    left: 100%;
}

.action-btn.primary {
    background: linear-gradient(45deg, #43e97b, #38f9d7);
    color: white;
    box-shadow: 0 5px 15px rgba(67, 233, 123, 0.4);
}

.action-btn.secondary {
    background: linear-gradient(45deg, #95a5a6, #7f8c8d);
    color: white;
}

.action-btn:active {
    transform: scale(0.98);
}

/* 横屏提示 */
.orientation-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: white;
}

.warning-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotate 2s linear infinite;
}

.orientation-warning p {
    font-size: 18px;
    text-align: center;
    padding: 0 40px;
}

/* 响应式适配 */
@media (max-width: 380px) {
    .home-title { font-size: 52px; }
    .demo-grid { padding: 6px; gap: 3px; margin-bottom: 10px; }
    .demo-tile { width: 34px; height: 28px; font-size: 9px; }
    .word-tile { font-size: 12px; }
    .word-content { font-size: 12px; }
    .grade-btn { padding: 12px 8px; }
    .home-container { padding: 10px 16px 12px 16px; }
    .grade-buttons { gap: 8px; }
    .grade-name { font-size: 14px; }
    .grade-desc { font-size: 9px; }
    .home-subtitle { font-size: 12px; margin-bottom: 15px; }
    .credit { font-size: 10px; }
}

@media (max-width: 320px) {
    .home-title { font-size: 44px; }
    .demo-grid { padding: 5px; gap: 2px; margin-bottom: 8px; }
    .demo-tile { width: 30px; height: 24px; font-size: 8px; border-radius: 4px; }
    .home-container { padding: 8px 12px 10px 12px; }
    .home-subtitle { font-size: 11px; margin-bottom: 12px; }
    .grade-section { max-width: 100%; }
    .grade-btn { padding: 10px 6px; border-radius: 10px; }
    .grade-name { font-size: 13px; }
    .credit { font-size: 9px; }
}
