/* 全局变量与基础 */
:root {
    --grid-cols: 8; 
    --grid-rows: 8;
    --piece-gap: 4px;
    --board-bg: #2d2d44;
    --cell-bg: #4a4a6a;
    --font-color: #f0f0f0;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #1a1a2e;
    color: var(--font-color);
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

/* 游戏主容器 */
.game-container {
    width: 95vw;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    box-sizing: border-box;
}

/* 顶部状态栏 */
.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
}

.score-board, .level-display {
    font-size: 1.1rem;
    background-color: var(--board-bg);
    padding: 8px 16px;
    border-radius: 8px;
    white-space: nowrap;
    text-align: center;
    flex-shrink: 0;
}

#restart-btn {
    padding: 8px 16px;
    font-size: 1rem;
    color: var(--font-color);
    background-color: #e94560;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
#restart-btn:hover {
    background-color: #c6334c;
}

/* 棋盘布局 */
#game-board {
    width: 100%;
    position: relative;
    background-color: var(--board-bg);
    border-radius: 10px;
    padding: 10px;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(var(--grid-cols), 1fr);
    grid-template-rows: repeat(var(--grid-rows), 1fr);
    gap: var(--piece-gap);
    aspect-ratio: 1 / 1;
    touch-action: none;
}

/* 棋子 */
.piece {
    width: 100%;
    height: 100%;
    background-color: var(--cell-bg);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(20px, 5vw, 30px);
    cursor: pointer;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s;
    user-select: none;
    position: relative;
    z-index: 5;
}

/* 选中状态 */
.piece.selected {
    transform: scale(1.1);
    box-shadow: 0 0 15px yellow;
    z-index: 10;
}

/* 消除动画 */
@keyframes pop {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}
.piece.matched {
    animation: pop 0.3s ease-out forwards;
    z-index: 1;
}

/* 粒子效果 */
.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background-color: #ffd700;
    border-radius: 50%;
    pointer-events: none;
    z-index: 20;
    animation: particle-explode 0.7s ease-out forwards;
}
@keyframes particle-explode {
    from { transform: translate(0, 0) scale(1); opacity: 1; }
    to { transform: translate(var(--x), var(--y)) scale(0); opacity: 0; }
}

/* 移动端适配 */
@media (max-width: 768px) {
    .game-container {
        height: 100vh;
        height: 100dvh;
        padding: 10px 15px;
    }
    #game-board {
        aspect-ratio: unset;
        flex-grow: 1;
        min-height: 0;
    }
}
/* 超窄屏优化 */
@media (max-width: 400px) {
    .score-board, .level-display, #restart-btn {
        font-size: 0.9rem;
        padding: 6px 10px;
    }
}
