/* 基础重置 - 移动端优化 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

:root {
    /* 移动端友好的颜色方案 */
    --primary: #6c5ce7;
    --primary-dark: #5a4fcf;
    --secondary: #fd79a8;
    --success: #00b894;
    --danger: #e17055;
    --warning: #fdcb6e;
    --dark: #2d3436;
    --light: #f5f6fa;
    --gray: #636e72;
    --gray-light: #dfe6e9;
    
    /* 移动端阴影 */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
    
    /* 移动端圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    
    /* 安全区域 */
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--light);
    color: var(--dark);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
    padding-bottom: 60px; /* 为底部导航留空间 */
}

/* 移动端头部 */
.mobile-header {
    background: white;
    padding: calc(12px + var(--safe-area-inset-top)) 16px 12px;
    box-shadow: var(--shadow-sm);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.menu-btn, .sound-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--light);
    color: var(--dark);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.menu-btn:active, .sound-btn:active {
    transform: scale(0.95);
    background: var(--gray-light);
}

.logo {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 侧边菜单 */
.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: white;
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: var(--safe-area-inset-top);
    display: flex;
    flex-direction: column;
}

.side-menu.active {
    left: 0;
}

.menu-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--gray-light);
}

.close-menu {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    color: var(--gray);
    font-size: 1.2rem;
    cursor: pointer;
}

.menu-items {
    flex: 1;
    padding: 16px 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    color: var(--dark);
    text-decoration: none;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.menu-item.active {
    background: var(--light);
    color: var(--primary);
    border-right: 4px solid var(--primary);
}

.menu-item:active {
    background: var(--gray-light);
}

.menu-footer {
    padding: 20px;
    border-top: 1px solid var(--gray-light);
}

.user-stats {
    display: flex;
    justify-content: space-around;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--gray);
}

/* 主内容区 */
.main-content {
    padding: 80px 16px 80px;
    max-width: 768px;
    margin: 0 auto;
}

/* 轮播图 */
.game-carousel {
    margin-bottom: 24px;
    position: relative;
}

.carousel-container {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    gap: 12px;
    padding: 0 4px;
    scrollbar-width: none;
}

.carousel-container::-webkit-scrollbar {
    display: none;
}

.carousel-item {
    flex: 0 0 calc(100% - 32px);
    scroll-snap-align: start;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-lg);
    padding: 24px;
    color: white;
    box-shadow: var(--shadow-md);
}

.carousel-item h3 {
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.carousel-item p {
    opacity: 0.9;
    margin-bottom: 16px;
}

.play-btn {
    background: white;
    color: var(--primary);
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.play-btn:active {
    transform: scale(0.95);
}

.carousel-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-light);
    transition: all 0.3s ease;
}

.carousel-dot.active {
    background: var(--primary);
    transform: scale(1.2);
}

/* 快速游戏入口 */
.quick-play {
    margin-bottom: 32px;
}

.section-title {
    font-size: 1.2rem;
    margin-bottom: 16px;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.quick-game-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.quick-card {
    background: white;
    border-radius: var(--radius-md);
    padding: 16px 12px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.quick-card:active {
    transform: scale(0.95);
    box-shadow: var(--shadow-md);
}

.quick-icon {
    width: 48px;
    height: 48px;
    background: var(--light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    font-size: 1.5rem;
    color: var(--primary);
}

.quick-name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.quick-desc {
    font-size: 0.8rem;
    color: var(--gray);
}

/* 游戏网格 */
.games-grid-section {
    margin-bottom: 32px;
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.game-card {
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.game-card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-md);
}

.game-thumbnail {
    height: 120px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
}

.game-info {
    padding: 12px;
}

.game-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.game-desc {
    font-size: 0.8rem;
    color: var(--gray);
    margin-bottom: 8px;
}

.game-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
}

.game-rating {
    color: var(--warning);
}

.game-size {
    color: var(--gray);
}

/* 游戏区域 */
.game-play-area {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    margin-bottom: 24px;
    overflow: hidden;
    display: none;
}

.game-play-area.active {
    display: block;
}

.game-header {
    padding: 16px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.back-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-btn:active {
    background: rgba(255,255,255,0.3);
}

.game-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.game-score {
    font-weight: 600;
}

.game-canvas-container {
    position: relative;
    width: 100%;
    height: 400px;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-placeholder {
    text-align: center;
    color: var(--gray);
    padding: 20px;
}

.game-placeholder i {
    font-size: 4rem;
    margin-bottom: 16px;
    color: var(--gray-light);
}

.game-placeholder .tip {
    font-size: 0.9rem;
    margin-top: 8px;
    color: var(--primary);
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: none;
}

#game-canvas.active {
    display: block;
}

/* 移动端控制按钮 */
.mobile-controls {
    padding: 20px;
    background: var(--light);
    display: flex;
    justify-content: center;
    gap: 20px;
}

.control-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: white;
    color: var(--primary);
    font-size: 1.5rem;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

.control-btn:active {
    transform: scale(0.9);
    box-shadow: var(--shadow-sm);
}

.control-btn.danger {
    background: var(--danger);
    color: white;
}

.control-btn.success {
    background: var(--success);
    color: white;
}

/* 移动端底部导航 */
.mobile-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    padding-bottom: var(--safe-area-inset-bottom);
    z-index: 1000;
}

.footer-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: 60px;
}

.footer-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--gray);
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.footer-nav-item.active {
    color: var(--primary);
}

.footer-nav-item i {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.footer-nav-item:active {
    color: var(--primary-dark);
}

/* 加载动画 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.95);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--gray-light);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 触摸提示 */
.touch-tips {
    position: fixed;
    bottom: 80px;
    right: 16px;
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: float 3s ease-in-out infinite;
    z-index: 100;
}

.tip-icon {
    font-size: 1.2rem;
}

.touch-tips p {
    font-size: 0.9rem;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* 响应式调整 */
@media (max-width: 480px) {
    .games-grid {
        grid-template-columns: 1fr;
    }
    
    .quick-game-cards {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .quick-card {
        padding: 12px 8px;
    }
    
    .control-btn {
        width: 56px;
        height: 56px;
    }
}

/* 横屏优化 */
@media (orientation: landscape) {
    .game-canvas-container {
        height: calc(100vh - 200px);
    }
    
    .mobile-controls {
        padding: 12px;
    }
}