* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

.container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    overflow: hidden;
}

/* 顶部信息栏 */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 6px 12px;
    border-radius: 8px;
    color: white;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.header h1 {
    font-size: 16px;
    text-align: center;
    margin-bottom: 4px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.info {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: bold;
}

/* 游戏区域 */
.game-area {
    flex: 1;
    min-height: 320px;
    max-height: 58vh;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    position: relative;
    background: #f0f0f0;
    border-radius: 10px;
    overflow: hidden;
    padding: 8px;
}

/* 速度控制 */
.speed-control {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px 6px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex-shrink: 0;
    z-index: 5;
}

.speed-control label {
    font-weight: bold;
    color: #667eea;
    font-size: 12px;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: 2px;
}

.speed-btn {
    width: 50px;
    height: 50px;
    border: 2px solid #667eea;
    background: white;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    color: #667eea;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
}

.speed-btn:active {
    transform: scale(0.95);
}

.speed-btn.active {
    background: #667eea;
    color: white;
}

#tetris {
    width: 300px;
    height: 600px;
    max-width: 100%;
    max-height: 100%;
    background: #000;
    border-radius: 8px;
    display: block;
}

/* 游戏结束覆盖层 */
.game-over {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 10;
}

.game-over.show {
    display: flex;
}

.game-over h2 {
    font-size: 36px;
    margin-bottom: 20px;
}

.game-over p {
    font-size: 24px;
    margin-bottom: 15px;
}

.game-over .difficulty-level {
    font-size: 16px;
    color: #aaa;
    margin-bottom: 10px;
}

.game-over .ranking-result {
    font-size: 22px;
    color: #ffd700;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    margin-bottom: 25px;
}

#restartBtn {
    padding: 15px 40px;
    font-size: 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

#restartBtn:active {
    transform: scale(0.95);
    background: #5568d3;
}

/* 控制按键区 */
.controls {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

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

.right-controls {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.arrow-row {
    display: flex;
    gap: 8px;
}

.control-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    touch-action: manipulation;
    min-width: 44px;
    min-height: 44px;
}

.control-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.rotate-btn {
    width: 80px;
    height: 80px;
}

.rotate-btn svg {
    width: 35px;
    height: 35px;
    margin-bottom: 4px;
}

.rotate-btn span {
    font-size: 13px;
    font-weight: bold;
}

.arrow-btn {
    width: 60px;
    height: 60px;
}

.arrow-btn svg {
    width: 26px;
    height: 26px;
}

/* 游戏按钮 */
.game-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-shrink: 0;
}

.game-btn {
    flex: 1;
    padding: 15px;
    font-size: 18px;
    font-weight: bold;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(245, 87, 108, 0.4);
    min-height: 50px;
}

.game-btn:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(245, 87, 108, 0.3);
}

/* 小屏幕优化 */
@media (max-height: 700px) {
    .container {
        padding: 6px;
    }

    .header {
        padding: 5px 10px;
        margin-bottom: 5px;
    }

    .header h1 {
        font-size: 15px;
        margin-bottom: 3px;
    }

    .info {
        font-size: 12px;
    }

    .game-area {
        min-height: 240px;
        max-height: 48vh;
        margin-bottom: 6px;
        padding: 6px;
        gap: 6px;
    }

    .speed-control {
        padding: 8px 5px;
        gap: 6px;
    }

    .speed-btn {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }

    .controls {
        margin-bottom: 6px;
    }

    .rotate-btn {
        width: 70px;
        height: 70px;
    }

    .arrow-btn {
        width: 55px;
        height: 55px;
    }

    .game-btn {
        padding: 10px;
        font-size: 15px;
    }
}

/* 超小屏幕进一步优化 */
@media (max-height: 600px) {
    .container {
        padding: 4px;
    }

    .header {
        padding: 4px 8px;
        margin-bottom: 3px;
    }

    .header h1 {
        font-size: 14px;
        margin-bottom: 2px;
    }

    .info {
        font-size: 11px;
    }

    .game-area {
        min-height: 200px;
        max-height: 42vh;
        margin-bottom: 4px;
        padding: 4px;
        gap: 4px;
    }

    .speed-control {
        padding: 6px 4px;
        gap: 5px;
    }

    .speed-btn {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }

    .controls {
        margin-bottom: 4px;
        gap: 6px;
    }

    .rotate-btn {
        width: 60px;
        height: 60px;
    }

    .rotate-btn svg {
        width: 28px;
        height: 28px;
    }

    .rotate-btn span {
        font-size: 11px;
    }

    .arrow-btn {
        width: 48px;
        height: 48px;
    }

    .arrow-btn svg {
        width: 22px;
        height: 22px;
    }

    .arrow-row {
        gap: 6px;
    }

    .left-controls,
    .right-controls {
        gap: 6px;
    }

    .game-btn {
        padding: 8px;
        font-size: 14px;
    }
}

/* 横屏适配 */
@media (orientation: landscape) {
    .container {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .header {
        width: 100%;
        order: 1;
    }

    .game-area {
        width: 50%;
        order: 2;
        margin-bottom: 0;
        max-height: 70vh;
    }

    .controls {
        width: 50%;
        order: 3;
        flex-direction: column;
        margin-bottom: 0;
    }

    .game-buttons {
        width: 100%;
        order: 4;
    }
}

/* 防止双击缩放 */
button {
    touch-action: manipulation;
}
