* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

body {
    font-family: Arial, sans-serif;
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: white;
    padding: 10px;
}

.game-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 500px;
}

.game-wrapper {
    width: 100%;
    position: relative;
    aspect-ratio: 1/2;
    display: flex;
}

.game-area {
    position: relative;
    width: 100%;
    height: 100%;
    border: 2px solid #ff0000;
    background-color: #000;
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(#ff000033 1px, transparent 1px),
        linear-gradient(90deg, #ff000033 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

#gameBoard {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.side-panel {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.5);
}

.info-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 100px;
}

.preview-box, .hold-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 100px;
}

.info-item {
    font-size: 14px;
    white-space: nowrap;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9);
    color: rgba(255, 255, 255, 0.9);
}

.controls-container {
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.controls-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 0 10px;
}

.direction-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.rotate-row {
    display: flex;
    justify-content: center;
}

.direction-row {
    display: flex;
    gap: 10px;
}

.game-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: flex-end;
}

.top-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.control-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.drop-button {
    display: flex;
    justify-content: center;
}

.control-button {
    padding: 8px 12px;
    font-size: 14px;
    background: transparent;
    border: 2px solid #ff0000;
    color: white;
    cursor: pointer;
    min-width: 80px;
    height: 40px;
    white-space: nowrap;
}

.control-btn {
    width: 45px;
    height: 45px;
    font-size: 20px;
    background: transparent;
    border: 2px solid #ff0000;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 10px;
    text-align: center;
    max-width: 90%;
    width: 300px;
}

.modal-content h2 {
    margin: 0 0 1rem 0;
    color: #333;
}

.modal-content p {
    margin: 1rem 0;
    font-size: 1.2rem;
    color: #666;
}

.modal-buttons {
    display: flex;
    justify-content: space-around;
    margin-top: 1.5rem;
}

.modal-button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

#restartBtn {
    background-color: #4CAF50;
    color: white;
}

#restartBtn:hover {
    background-color: #45a049;
}

#endGameBtn {
    background-color: #f44336;
    color: white;
}

#endGameBtn:hover {
    background-color: #da190b;
}

/* 触摸设备的按钮反馈 */
@media (hover: none) {
    .control-button:active,
    .control-btn:active {
        background-color: rgba(255, 0, 0, 0.3);
    }
}

/* 支持悬停设备的按钮反馈 */
@media (hover: hover) {
    .control-button:hover,
    .control-btn:hover {
        background-color: rgba(255, 0, 0, 0.3);
    }
}

/* 移动端适配 */
@media (max-width: 767px) {
    body {
        padding: 0;
    }

    .game-container {
        height: 100vh;
        justify-content: space-between;
        gap: 0;
    }
    
    .game-wrapper {
        height: 70vh; /* 稍微增加游戏区域高度 */
        aspect-ratio: unset;
        margin: 0 auto;
        max-width: 350px; /* 限制最大宽度，保持比例 */
    }
    
    .side-panel {
        position: absolute;
        top: 10px;
        right: 10px;
        flex-direction: column;
        gap: 15px;
        padding: 10px;
        width: auto;
        background-color: rgba(0, 0, 0, 0.5);
    }
    
    .info-box {
        flex-direction: column;
        gap: 10px;
        min-width: 80px;
    }
    
    .preview-box, .hold-box {
        min-width: 80px;
        gap: 10px;
    }
    
    .controls-container {
        height: 30vh; /* 相应减少控制区域高度 */
        padding: 10px 0;
        justify-content: center;
    }
    
    .controls-wrapper {
        gap: 20px;
    }
    
    .game-controls {
        gap: 12px;
        min-width: 240px;
    }
    
    .control-buttons {
        gap: 8px;
    }
    
    .control-button {
        padding: 6px 10px;
        font-size: 13px;
        min-width: 70px;
        height: 35px;
    }
    
    .control-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    /* 增强按钮触摸反馈 */
    .control-button:active,
    .control-btn:active {
        background-color: rgba(255, 0, 0, 0.5);
        transform: scale(0.95);
    }

    .top-buttons {
        gap: 8px;
    }
}

/* 横屏适配 */
@media (max-width: 767px) and (orientation: landscape) {
    .game-container {
        flex-direction: row;
        height: 100vh;
        padding: 5px;
        gap: 10px;
        align-items: center;
    }
    
    .game-wrapper {
        height: 90vh;
        width: auto;
        aspect-ratio: 1/2;
        margin: 0;
    }
    
    .side-panel {
        position: absolute;
        top: 10px;
        right: 10px;
        flex-direction: column;
        padding: 10px;
        width: auto;
        gap: 15px;
    }
    
    .info-box, .preview-box, .hold-box {
        min-width: 80px;
        gap: 10px;
    }
    
    .controls-container {
        height: auto;
        padding: 0 10px;
    }
    
    .controls-wrapper {
        gap: 30px;
    }
    
    .game-controls {
        min-width: 280px;
    }
    
    .control-button {
        padding: 8px 12px;
        font-size: 14px;
        min-width: 80px;
        height: 40px;
    }
    
    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
}

.drawNextBlock() {
    if (!this.nextBlock) return;
    
    const blockSize = 20; // 更新预览方块大小
    // ... rest of the code ...
}

.drawHoldBlock() {
    if (!this.holdBlock) return;
    
    const blockSize = 20; // 更新暂存方块大小
    // ... rest of the code ...
} 