* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

:root {
    font-size: 16px;
}

body {
    background: linear-gradient(135deg, #f0f9ff 0%, #e6f7ff 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem;
    color: #333;
    overflow-x: hidden;
}

/* 浮动元素样式 */
.floating-elements {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.floating-element {
    position: absolute;
    font-size: 2rem;
    opacity: 0.2;
    animation: float 15s infinite ease-in-out;
}

@keyframes float {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg);
    }
    25% {
        transform: translate(2vw, 5vh) rotate(90deg);
    }
    50% {
        transform: translate(-2vw, 10vh) rotate(180deg);
    }
    75% {
        transform: translate(3vw, 5vh) rotate(270deg);
    }
}

/* 页面容器样式 */
.page {
    display: none;
    width: 100%;
    max-width: 56.25rem;
    margin: 0 auto;
    position: relative;
    z-index: 2;
}

.page.active {
    display: block;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(1.25rem); }
    to { opacity: 1; transform: translateY(0); }
}

/* 顶部按钮样式 */
.top-buttons {
    position: absolute;
    top: 0.625rem;
    left: 0.625rem;
    display: flex;
    gap: 0.625rem;
    z-index: 1000;
}

.top-btn {
    background: #4a6fa5;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.9375rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    box-shadow: 0 0.125rem 0.3125rem rgba(0, 0, 0, 0.2);
    z-index: 1001;
    min-width: 3rem;
    min-height: 2.5rem;
}

.top-btn:focus {
    outline: 0.125rem solid #d4af37;
    outline-offset: 0.125rem;
}

.top-btn:hover {
    background: #3d5a80;
    transform: translateY(-0.125rem);
}

/* 主题选择页面样式 */
.theme-selection {
    text-align: center;
    padding: 5rem 1.25rem;
}

.game-title {
    font-size: 2.8rem;
    color: #4a6fa5;
    margin-bottom: 0.9375rem;
    font-weight: 800;
}

.game-slogan {
    font-size: 1.2rem;
    color: #6b7280;
    margin-bottom: 2.5rem;
    font-style: italic;
}

.theme-selection h2 {
    font-size: 1.5rem;
    color: #6b7280;
    margin-bottom: 1.5625rem;
}

.theme-buttons {
    display: flex;
    justify-content: center;
    gap: 1.5625rem;
}

.theme-btn {
    background: #e0e7ff;
    color: #4a6fa5;
    border: none;
    padding: 0.75rem 1.5625rem;
    border-radius: 3.125rem;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    transition: all 0.3s;
    width: 8.75rem;
    min-width: 3rem;
    min-height: 3rem;
}

.theme-btn:focus {
    outline: 0.125rem solid #d4af37;
    outline-offset: 0.125rem;
}

.theme-btn:hover {
    background: #4a6fa5;
    color: white;
    transform: translateY(-0.3125rem);
    box-shadow: 0 0.625rem 1.25rem rgba(0, 0, 0, 0.1);
}

/* 游戏页面样式 */
.game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 1.25rem;
    padding: 1.25rem;
    box-shadow: 0 0.625rem 1.5625rem rgba(0, 0, 0, 0.08);
    position: relative;
}

.level-info {
    text-align: center;
    margin-bottom: 0.9375rem;
    font-size: 1.2rem;
    color: #6b7280;
    font-weight: 600;
}

.game-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    background: rgba(255, 255, 255, 0.7);
    padding: 0.75rem;
    border-radius: 0.625rem;
    box-shadow: 0 0.1875rem 0.625rem rgba(0, 0, 0, 0.05);
}

.info-item {
    text-align: center;
    flex: 1;
}

.info-label {
    font-size: 0.85rem;
    opacity: 0.7;
    margin-bottom: 0.25rem;
}

.info-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: #4a6fa5;
}

#memory-board {
    margin: 0.9375rem auto;
    display: grid;
    gap: 0.5rem;
    justify-content: center;
}

/* 第一关3×4网格布局 */
#memory-board.level-1 {
    grid-template-columns: repeat(4, 4.375rem);
    grid-template-rows: repeat(3, 4.375rem);
}

/* 第二关4×8网格布局 */
#memory-board.level-2 {
    grid-template-columns: repeat(8, 4.375rem);
    grid-template-rows: repeat(4, 4.375rem);
}

.memory-card {
    background: linear-gradient(135deg, #4a6fa5, #6187c4);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    cursor: pointer;
    transition: all 0.3s;
    color: transparent;
    user-select: none;
    box-shadow: 0 0.1875rem 0.5rem rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    min-width: 3rem;
    min-height: 3rem;
}

.memory-card:focus {
    outline: 0.125rem solid #d4af37;
    outline-offset: 0.125rem;
}

.memory-card::before {
    content: '?';
    position: absolute;
    color: white;
    font-size: 1.6rem;
    font-weight: bold;
}

.memory-card.flipped {
    background: linear-gradient(135deg, #ffecb3, #ffe082);
    color: #333;
    transform: rotateY(180deg);
}

.memory-card.flipped::before {
    content: '';
}

.memory-card .symbol-text {
    font-size: 1.8rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.memory-card.flipped .symbol-text {
    opacity: 1;
}

.memory-card svg {
    width: 60%;
    height: 60%;
    opacity: 0;
    transition: opacity 0.3s;
}

.memory-card.flipped svg {
    opacity: 1;
}

/* 配对成功消失动画 */
.memory-card.matched {
    animation: disappear 0.5s forwards;
    will-change: transform;
}

@keyframes disappear {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.1); }
    100% { opacity: 0; transform: scale(0); visibility: hidden; }
}

.controls {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin: 1.25rem 0 0.3125rem;
}

.control-btn {
    padding: 0.5rem 1rem;
    border-radius: 3.125rem;
    border: none;
    background: #4a6fa5;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    min-width: 3rem;
    min-height: 2.5rem;
}

.control-btn:focus {
    outline: 0.125rem solid #d4af37;
    outline-offset: 0.125rem;
}

.control-btn:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
}

.control-btn:hover:not(:disabled) {
    background: #3d5a80;
    transform: translateY(-0.125rem);
}

.results {
    display: none;
    text-align: center;
    background: white;
    padding: 1.25rem;
    border-radius: 0.9375rem;
    box-shadow: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.15);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    width: 80%;
    max-width: 20rem;
    animation: popIn 0.5s ease-out;
}

@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.results h2 {
    margin-bottom: 0.75rem;
    color: #4a6fa5;
    font-size: 1.5rem;
}

.memory-level {
    font-size: 2.2rem;
    font-weight: bold;
    color: #4a6fa5;
    margin: 0.5rem 0;
}

.difficulty-popup {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    text-align: center;
    animation: popIn 0.6s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.difficulty-text {
    font-size: 2.8rem;
    font-weight: 900;
    background: linear-gradient(45deg, #ff4757, #ff6b81);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0.125rem 0.125rem 0.25rem rgba(0, 0, 0, 0.2);
}

.fade-out {
    animation: fadeOut 1.5s ease-out forwards;
    will-change: transform;
}

@keyframes fadeOut {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* 小度设备适配样式 */
/* 7英寸小度屏适配 */
@media (device-width: 1024px) and (device-height: 600px) {
    .game-container { padding: 1rem !important; }
    .control-btn, .top-btn, .theme-btn { font-size: 0.875rem !important; }
    .game-title { font-size: 1.5rem !important; }
    #memory-board.level-1 {
        grid-template-columns: repeat(4, 3.5rem);
        grid-template-rows: repeat(3, 3.5rem);
    }
    #memory-board.level-2 {
        grid-template-columns: repeat(8, 3.2rem);
        grid-template-rows: repeat(4, 3.2rem);
    }
    .memory-card {
        font-size: 1.5rem;
        min-width: 2.5rem;
        min-height: 2.5rem;
    }
    .memory-card .symbol-text {
        font-size: 1.5rem;
    }
}

/* 10英寸小度屏适配 */
@media (device-width: 1280px) and (device-height: 800px) {
    .game-container { padding: 1.5rem !important; }
    .control-btn, .top-btn, .theme-btn { font-size: 1rem !important; }
    .game-title { font-size: 1.75rem !important; }
    #memory-board.level-1 {
        grid-template-columns: repeat(4, 4rem);
        grid-template-rows: repeat(3, 4rem);
    }
    #memory-board.level-2 {
        grid-template-columns: repeat(8, 3.7rem);
        grid-template-rows: repeat(4, 3.7rem);
    }
    .memory-card {
        font-size: 1.6rem;
        min-width: 2.8rem;
        min-height: 2.8rem;
    }
    .memory-card .symbol-text {
        font-size: 1.6rem;
    }
}

/* 遥控器设备禁用hover样式 */
@media (pointer: coarse) {
    .game-btn:hover, .function-entry:hover, 
    .memory-card:hover, .control-btn:hover, 
    .top-btn:hover, .theme-btn:hover {
        background-color: inherit !important;
        transform: none !important;
    }
}

/* 低性能设备禁用非必要动画 */
@media (prefers-reduced-motion: reduce) {
    .memory-card.matched, .fade-out, .page.active {
        animation: none !important;
    }
}

@media (max-width: 37.5rem) {
    :root {
        font-size: 14px;
    }
    
    .game-title {
        font-size: 2.2rem;
    }
    
    #memory-board.level-1 {
        grid-template-columns: repeat(4, 3.75rem);
        grid-template-rows: repeat(3, 3.75rem);
    }
    
    #memory-board.level-2 {
        grid-template-columns: repeat(4, 3.125rem);
        grid-template-rows: repeat(8, 3.125rem);
    }
    
    .memory-card {
        font-size: 1.5rem;
    }
    
    .memory-card .symbol-text {
        font-size: 1.5rem;
    }
    
    .difficulty-text {
        font-size: 2.2rem;
    }
    
    .controls {
        flex-wrap: wrap;
    }
    
    .control-btn {
        flex: 1;
        min-width: 5.625rem;
        font-size: 0.85rem;
        padding: 0.375rem 0.75rem;
    }
    
    .top-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }
}