:root {
    --color-I: #3498db; /* Blue */
    --color-O: #f1c40f; /* Yellow */
    --color-T: #9b59b6; /* Purple */
    --color-L: #e67e22; /* Orange */
    --color-J: #2980b9; /* Darker Blue */
    --color-S: #2ecc71; /* Green */
    --color-Z: #e74c3c; /* Red */
    --grid-color: #e0e0e0;
    --bg-color: #f4f7f9;
    --text-color: #333;
    --panel-bg: #ffffff;
    --border-color: #eeeeee;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    overflow: hidden; /* Prevent all scrollbars */
}

.game-container {
    display: flex;
    flex-direction: column; /* Changed to vertical layout */
    align-items: center; /* Center horizontally */
    justify-content: center; /* Center vertically */
    gap: 1.5rem; /* Gap between elements */
    padding: 2rem; /* Add padding for spacing from edges */
    width: 100%;
    max-width: 720px;
    height: 100vh;
    /* Scale down to fit in viewport */
    transform: scale(0.85);
    transform-origin: center center;
    box-sizing: border-box;
}

.game-main-section {
    display: flex;
    gap: 1.5rem;
    align-items: stretch; /* Changed to stretch alignment */
}

.game-board-container {
    border: 1px solid var(--border-color);
    padding: 8px;
    border-radius: 12px;
    background: var(--panel-bg);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

canvas#game-board {
    display: block;
    border-radius: 8px;
}

.info-panel {
    width: 200px;
    display: flex;
    flex-direction: column;
}

.info-card {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 100%; 
}

.info-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    /* Fixed height to prevent layout changes during language switching */
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Special handling for "Next" area, providing more space */
.info-item:last-child {
    border-bottom: none;
    min-height: 140px; /* More space for next piece canvas */
}

.info-card h2 {
    font-size: 1rem;
    font-weight: 700;
    color: #777;
    margin: 0 0 0.25rem 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    /* Fixed height to prevent layout jumps from text changes */
    height: 20px;
    line-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.info-card p {
    font-size: 2rem;
    margin: 0;
    font-weight: 700;
    color: var(--text-color);
    /* Fixed height for number display */
    height: 32px;
    line-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.info-card-split {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.info-card-split > div {
    text-align: center;
}

.info-card-split h2 {
    font-size: 0.9rem;
}

.info-card-split p {
    font-size: 1.5rem;
}

#next-piece-canvas {
    width: 100%;
    height: 100px;
    margin-top: 0.5rem;
    /* Center the canvas */
    display: block;
}

.controls-card {
    background-color: #fdfdfd;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    font-size: 0.9rem;
    color: #555;
    /* Calculate width: game panel (300px + 16px padding) + gap (1.5rem) + info panel (200px) */
    width: calc(316px + 1.5rem + 200px);
    box-sizing: border-box;
    /* Remove min-height to allow natural sizing */
    /* Allow content to expand naturally */
    margin: 0; /* Remove margin since gap handles spacing */
    position: relative;
}

/* 添加贯穿整个控制区的竖直分隔线 */
.controls-card::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 3rem; /* 从标题下方开始 */
    bottom: 1rem; /* 到底部留一点空间 */
    width: 1px;
    background-color: #ece9e9; /* 更深的颜色，更清晰可见 */
    transform: translateX(-50%);
}

.controls-card h2 {
    font-size: 1rem;
    font-weight: 700;
    color: #777;
    margin: 0 0 1rem 0;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
    /* Fixed height to prevent layout jumps from title changes */
    height: 20px;
    line-height: 20px;
    white-space: nowrap;
    overflow: hidden;
}

.controls-row {
    display: flex;
    justify-content: space-between;
    margin: 0.4rem 0;
    gap: 1rem;
    /* Fixed height to ensure consistency */
    height: 28px;
    align-items: center;
}

.control-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    flex: 0 0 48%;
    max-width: 48%;
    font-size: 0.9rem;
    /* Fixed minimum height to ensure consistency */
    min-height: 24px;
    /* Prevent layout jumps from text length changes */
    white-space: nowrap;
    overflow: hidden;
}

.control-item:empty {
    /* Hide empty control items */
    visibility: hidden;
}

.controls-card .keys {
    color: #666;
    font-weight: 600;
    white-space: nowrap;
    /* Fixed width to prevent layout jumps from key text changes */
    min-width: 80px;
    text-align: right;
}

/* Control item text label styles */
.control-item span:first-child {
    /* Fixed width to prevent layout jumps from text length changes */
    min-width: 50px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.controls-card kbd {
    background-color: #e9ecef;
    border: 1px solid #dee2e6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: #333;
    box-shadow: inset 0 -2px 0 #ccc;
    margin: 0 1px;
    font-size: 0.8rem;
    /* Set minimum width to maintain consistent key display */
    min-width: 20px;
    display: inline-block;
    text-align: center;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--panel-bg);
    padding: 2rem 3rem;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    text-align: center;
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.visible .modal-content {
     transform: scale(1);
}

.modal-content h2 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
}

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

.modal-content button {
    font-family: 'Roboto', sans-serif;
    font-weight: 700;
    background-color: var(--color-I);
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.5px;
}

.modal-content button:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(52, 152, 219, 0.3);
}

@media (max-width: 768px) {
    .game-container {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        padding: 1.5rem;
        transform: scale(0.8); /* Even smaller scale for mobile */
        max-width: 100%;
        height: 100vh;
        justify-content: center; /* Center vertically on mobile too */
    }
    
    .game-main-section {
        flex-direction: column;
        width: 100%;
        align-items: center;
    }
    
    .info-panel {
        order: -1;
        width: 100%;
        flex-direction: row; /* Horizontal layout on mobile */
        justify-content: space-around;
    }
    
    /* Adjust info items for mobile horizontal layout */
    .info-card {
        flex-direction: row;
        padding: 0.5rem;
    }
    
    .info-item {
        flex: 1;
        min-height: 60px; /* Smaller height for mobile */
        margin: 0 0.25rem;
        padding: 0.5rem;
        border-bottom: none;
        border-right: 1px solid var(--border-color);
    }
    
    .info-item:last-child {
        border-right: none;
        min-height: 60px; /* Same height as other items on mobile */
    }
    
    #next-piece-canvas {
        height: 40px; /* Smaller canvas for mobile */
        margin-top: 0.25rem;
    }
    
    .info-card h2 {
        font-size: 0.8rem;
        height: 16px;
        line-height: 16px;
    }
    
    .info-card p {
        font-size: 1.2rem;
        height: 20px;
        line-height: 20px;
    }
    
    .controls-card {
        width: 100%;
        /* Remove all height constraints */
        margin: 0; /* Remove margin */
    }
    
    .controls-row {
        flex-direction: row; /* Keep horizontal layout on mobile */
        flex-wrap: wrap; /* Allow wrapping if needed */
        gap: 0.8rem;
        margin: 0.3rem 0; /* Reduce margin for mobile */
    }
    
    .control-item {
        justify-content: space-between;
        flex: 0 0 45%; /* Make items slightly smaller to fit better */
        font-size: 0.8rem; /* Smaller font for mobile */
    }
}

/* Additional scaling for very small screens */
@media (max-width: 480px) {
    .game-container {
        transform: scale(0.7);
        gap: 0.8rem;
        padding: 1rem;
        height: 100vh;
        justify-content: center; /* Center vertically on very small screens */
    }
    
    .controls-card {
        margin: 0; /* Remove margin */
    }
}

/* Additional scaling for very large screens to ensure no overflow */
@media (min-width: 1200px) {
    .game-container {
        transform: scale(0.9);
    }
}
