* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    padding: 10px;
    overflow: hidden;
}

.game-container {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
}

.game-header {
    text-align: center;
    padding: 8px 0;
}

.game-header h1 {
    font-size: 1.8rem;
    margin-bottom: 3px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    background: linear-gradient(to right, #ff8a00, #da1b60);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stats-container {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 1rem;
}

.game-board {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
}

.tetris-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(20, 1fr);
    gap: 1px;
    width: 200px;
    height: 400px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    padding: 4px;
}

.cell {
    background: rgba(30, 30, 50, 0.5);
    border-radius: 2px;
    transition: all 0.1s ease;
}

.preview-container {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 120px;
    position: relative;
}

.preview-container h3 {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #ffcc00;
    text-align: center;
    transition: opacity 0.3s ease;
}

#countdown {
    font-size: 2.5rem;
    font-weight: bold;
    color: #4caf50;
    text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
    transition: all 0.3s;
}

#mission-complete {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    font-weight: bold;
    color: #4caf50;
    text-align: center;
    display: none;
    animation: pulse 1.5s infinite;
    width: 100%;
    padding: 0 8px;
    box-sizing: border-box;
    word-wrap: break-word;
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 8px;
}

.game-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.control-btn {
    background: linear-gradient(to bottom, #4a4a8a, #2a2a5a);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
    flex: 1;
    min-width: 80px;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.4);
}

.control-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#start-btn {
    background: linear-gradient(to bottom, #4CAF50, #2E7D32);
}

#pause-btn {
    background: linear-gradient(to bottom, #FF9800, #EF6C00);
}

#end-btn {
    background: linear-gradient(to bottom, #F44336, #C62828);
}

.directional-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 8px;
    max-width: 240px;
    margin: 0 auto;
}

.dir-btn {
    background: linear-gradient(to bottom, #5D6D7E, #34495E);
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.dir-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.4);
}

.dir-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#up-btn {
    grid-column: 2;
    grid-row: 1;
}

#left-btn {
    grid-column: 1;
    grid-row: 2;
}

#down-btn {
    grid-column: 2;
    grid-row: 2;
}

#right-btn {
    grid-column: 3;
    grid-row: 2;
}

.game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    display: none;
}

.game-over h2 {
    font-size: 2.2rem;
    color: #ff3333;
    margin-bottom: 16px;
    text-shadow: 0 0 8px rgba(255, 0, 0, 0.5);
}

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

.restart-btn {
    background: linear-gradient(to bottom, #2196F3, #0D47A1);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
    margin-top: 15px;
    width: auto;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.restart-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.instructions {
    text-align: center;
    margin-top: 12px;
    font-size: 0.8rem;
    color: #aaa;
    line-height: 1.4;
}

/* Block colors */
.i-block { background-color: #00f0f0; }
.j-block { background-color: #0000f0; }
.l-block { background-color: #f0a000; }
.o-block { background-color: #f0f000; }
.s-block { background-color: #00f000; }
.t-block { background-color: #a000f0; }
.z-block { background-color: #f00000; }

/* Animation for placed blocks */
@keyframes placeBlock {
    0% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.placed {
    animation: placeBlock 0.2s ease-out;
}

@keyframes pulse {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.countdown-warning {
    color: #ff9800 !important;
    text-shadow: 0 0 10px rgba(255, 152, 0, 0.5) !important;
}

.countdown-critical {
    color: #f44336 !important;
    text-shadow: 0 0 10px rgba(244, 67, 54, 0.5) !important;
    animation: pulse 0.5s infinite;
}

.countdown-complete {
    font-size: 2.5rem;
    font-weight: bold;
    color: #ff5722;
    text-shadow: 0 0 15px rgba(255, 87, 34, 0.7);
    animation: pulse 1s infinite;
}

/* 媒体查询确保在小屏幕上也能正常显示 */
@media (max-height: 700px) {
    .tetris-grid {
        height: 320px;
        width: 160px;
    }
    
    .preview-container {
        width: 90px;
        height: 100px;
        padding: 8px;
    }
    
    #countdown {
        font-size: 2rem;
    }
    
    #mission-complete {
        font-size: 0.9rem;
    }
    
    .dir-btn {
        width: 50px;
        height: 50px;
        font-size: 1.1rem;
    }
    
    .control-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .game-over h2 {
        font-size: 1.8rem;
    }
    
    .game-over p {
        font-size: 1.2rem;
    }
    
    .restart-btn {
        padding: 10px 20px;
        font-size: 1rem;
    }
}