* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* 移除移动端点击高亮 */
}

html, body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-attachment: fixed;
    position: relative;
    overflow-x: hidden;
    touch-action: manipulation; /* 优化触摸事件 */
    padding: 10px;
}

/* 添加背景网格效果 */
body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(78, 205, 196, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(78, 205, 196, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    z-index: -1;
}

.game-container {
    text-align: center;
    padding: 20px;
    background: rgba(26, 26, 46, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    border: 1px solid rgba(78, 205, 196, 0.3);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 60px rgba(78, 205, 196, 0.1);
    animation: containerFloat 3s ease-in-out infinite;
    width: 100%;
    max-width: 100%;
}

@keyframes containerFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

h1 {
    margin-bottom: 30px;
    color: #ff6b6b;
    font-size: 3.5em;
    font-weight: 800;
    text-shadow: 
        0 0 10px rgba(255, 107, 107, 0.5),
        0 0 20px rgba(255, 107, 107, 0.3),
        0 0 30px rgba(255, 107, 107, 0.1);
    letter-spacing: 2px;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        text-shadow: 
            0 0 10px rgba(255, 107, 107, 0.5),
            0 0 20px rgba(255, 107, 107, 0.3);
    }
    to {
        text-shadow: 
            0 0 20px rgba(255, 107, 107, 0.7),
            0 0 30px rgba(255, 107, 107, 0.5),
            0 0 40px rgba(255, 107, 107, 0.3);
    }
}

.game-wrapper {
    display: flex;
    gap: 40px;
    justify-content: center;
    margin-bottom: 30px;
    align-items: flex-start;
}

#tetris {
    border: 3px solid #4ecdc4;
    background-color: rgba(10, 10, 10, 0.8);
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.3);
    transition: all 0.3s ease;
}

#tetris:hover {
    box-shadow: 0 0 30px rgba(78, 205, 196, 0.5);
    border-color: #45b7aa;
}

.game-info {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 180px;
}

.next-block, .score, .level, .lines {
    background: linear-gradient(135deg, rgba(42, 42, 42, 0.8) 0%, rgba(26, 26, 46, 0.8) 100%);
    padding: 20px;
    border-radius: 10px;
    border: 2px solid rgba(78, 205, 196, 0.3);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.next-block:hover, .score:hover, .level:hover, .lines:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    border-color: rgba(78, 205, 196, 0.5);
}

.next-block h3, .score h3, .level h3, .lines h3 {
    margin-bottom: 15px;
    color: #4ecdc4;
    font-size: 1.3em;
    font-weight: 600;
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(78, 205, 196, 0.3);
}

#nextBlock {
    background-color: rgba(10, 10, 10, 0.8);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 5px;
    display: block;
    margin: 0 auto;
}

#scoreDisplay, #levelDisplay, #linesDisplay {
    font-size: 2em;
    font-weight: bold;
    color: #ffd166;
    text-shadow: 0 0 10px rgba(255, 209, 102, 0.3);
    transition: all 0.3s ease;
}

/* 分数变化时的动画 */
@keyframes scorePopup {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); color: #ff6b6b; }
    100% { transform: scale(1); }
}

.score-change {
    animation: scorePopup 0.5s ease;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

button {
    padding: 12px 20px;
    background: linear-gradient(135deg, #4ecdc4 0%, #45b7aa 100%);
    color: #1a1a1a;
    border: none;
    border-radius: 25px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(78, 205, 196, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

button::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: all 0.6s ease;
}

button:hover:not(:disabled)::before {
    left: 100%;
}

button:hover:not(:disabled) {
    background: linear-gradient(135deg, #45b7aa 0%, #3a9f96 100%);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(78, 205, 196, 0.5);
}

button:active:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(78, 205, 196, 0.4);
}

button:disabled {
    background: linear-gradient(135deg, #666666 0%, #555555 100%);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.game-instructions {
    background: linear-gradient(135deg, rgba(42, 42, 42, 0.8) 0%, rgba(26, 26, 46, 0.8) 100%);
    padding: 25px;
    border-radius: 10px;
    border: 2px solid rgba(78, 205, 196, 0.3);
    max-width: 600px;
    margin: 0 auto;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
}

.game-instructions h3 {
    margin-bottom: 15px;
    color: #4ecdc4;
    font-size: 1.3em;
    font-weight: 600;
    text-shadow: 0 0 10px rgba(78, 205, 196, 0.3);
}

.game-instructions p {
    font-size: 1em;
    line-height: 1.6;
    color: #cccccc;
    margin-bottom: 10px;
}

/* 移动端触摸控制 */
.mobile-controls {
    display: none; /* 默认隐藏，在移动端显示 */
    margin-top: 20px;
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 10px;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.control-button {
    background: #4ecdc4;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 20px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    min-width: 60px;
    min-height: 60px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.2);
}

.control-button:active {
    background: #45b7aa;
    transform: scale(0.95);
}

/* 确保大尺寸的触摸区域 */
#rotateButton, #hardDropButton {
    min-width: 200px;
    padding: 15px 20px;
}

/* 游戏画布容器 - 确保在移动设备上正确缩放 */
.canvas-container {
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
    position: relative;
}

/* 响应式设计 - 优化移动端完整显示 */
@media (max-width: 768px) {
    /* 基础样式调整 */
    body {
        padding: 0;
        margin: 0;
        overflow: hidden;
        height: 100vh;
        width: 100vw;
    }
    
    /* 游戏容器全屏适配 */
    .game-container {
        padding: 5px;
        margin: 0;
        border-radius: 0;
        width: 100vw;
        height: 100vh;
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        overflow: hidden;
    }
    
    /* 标题优化 */
    h1 {
        font-size: 1.2rem;
        margin: 5px 0;
        padding: 0;
        flex-shrink: 0;
    }
    
    /* 游戏区域布局 - 优化空间分配 */
    .game-wrapper {
        flex-direction: column;
        align-items: center;
        gap: 5px;
        flex: 1;
        overflow: hidden;
        width: 100%;
        display: flex;
        flex-direction: column;
    }
    
    /* 画布容器优化 - 确保正确比例和大小 */
    .canvas-container {
        width: 100%;
        max-width: 280px;
        margin: 0 auto;
        position: relative;
        flex-shrink: 0;
    }
    
    #tetris {
        width: 100%;
        height: auto;
        display: block;
        max-height: 50vh;
    }
    
    /* 游戏信息区域 - 精简布局 */
    .game-info {
        width: 100%;
        max-width: 100%;
        margin: 0;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
        padding: 5px;
        flex-shrink: 0;
    }
    
    /* 信息卡片样式优化 */
    .next-block, .score, .level, .lines, .high-score {
        min-width: calc(50% - 4px);
        padding: 4px;
        margin: 0;
        font-size: 0.8rem;
    }
    
    .next-block h3, .score h3, .level h3, .lines h3, .high-score h3 {
        font-size: 0.8rem;
        margin-bottom: 2px;
    }
    
    #nextBlock {
        max-width: 60px;
        max-height: 60px;
    }
    
    /* 分数显示优化 */
    #scoreDisplay, #levelDisplay, #linesDisplay, #highScoreDisplay {
        font-size: 1rem;
    }
    
    /* 控制按钮样式优化 */
    .controls {
        margin-top: 5px;
        margin-bottom: 5px;
        gap: 5px;
    }
    
    button {
        padding: 6px 10px;
        font-size: 0.8rem;
        min-width: 60px;
    }
    
    /* 移动端触摸控制 - 优化布局和大小 */
    .mobile-controls {
        display: block;
        margin-top: auto;
        padding: 5px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .control-row {
        gap: 10px;
        margin-bottom: 8px;
        justify-content: center;
    }
    
    /* 触摸按钮大小优化 */
    .control-button {
        min-width: 60px;
        min-height: 60px;
        font-size: 1.1rem;
        padding: 8px;
        margin: 0;
    }
    
    #rotateButton, #hardDropButton {
        min-width: 120px;
        min-height: 50px;
    }
    
    /* 隐藏游戏说明 */
    .game-instructions {
        display: none;
    }
}

/* 小屏幕移动设备优化 - 确保完整显示 */
@media (max-width: 480px) {
    .game-container {
        padding: 2px;
    }
    
    h1 {
        font-size: 1.1rem;
    }
    
    .game-info {
        gap: 3px;
        padding: 3px;
    }
    
    .next-block, .score, .level, .lines, .high-score {
        min-width: calc(50% - 3px);
        padding: 3px;
    }
    
    .control-button {
        min-width: 55px;
        min-height: 55px;
        font-size: 1rem;
        padding: 5px;
    }
    
    #rotateButton, #hardDropButton {
        min-width: 100px;
        min-height: 45px;
    }
    
    /* 画布进一步优化 */
    .canvas-container {
        width: 95%;
        max-width: 220px;
    }
    
    #tetris {
        max-height: 45vh;
    }
    
    /* 控制行间距优化 */
    .control-row {
        gap: 8px;
        margin-bottom: 6px;
    }
}