body {
    margin: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-image: url('tetback.jpg');
    background-size: cover;
    background-position: center;
    font-family: sans-serif;
    padding: 1vh;
    box-sizing: border-box;
}

#main-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    height: 98vh;
}

#game-container {
    position: relative;
    height: 100%;
    aspect-ratio: 320 / 600;
    display: flex;
    flex-direction: column; 
}

#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 101;
    cursor: pointer;
    padding: 20px;
    box-sizing: border-box;
}
#start-content {
    text-align: center;
    background-color: rgba(30, 30, 30, 0.8);
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 380px;
}
#start-content h1 {
    margin: 0 0 15px 0;
    font-size: 2.5em;
}
#start-content h3 {
    margin-top: 0;
    margin-bottom: 10px;
    border-bottom: 1px solid #fff;
    padding-bottom: 5px;
}
.start-prompt {
    font-size: 1.5em;
    animation: pulse 1.5s infinite;
    margin-top: 20px;
}

.ranking-notice {
    font-size: 0.9em;
    color: #ccc;
    margin-top: 15px;
    margin-bottom: 0;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

#ranking-tabs {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 10px;
}
.ranking-tab-button {
    padding: 5px 8px;
    border: 1px solid #777;
    background-color: #555;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
}
.ranking-tab-button.active {
    background-color: #aaeaff;
    color: #000;
    border-color: #fff;
}


#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    display: none; 
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
    box-sizing: border-box;
}

#game-over-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    background-color: rgba(30, 30, 30, 0.8);
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 350px;
}
#game-over-content h2 { margin: 0; }
.final-score-text { font-size: 1.5em; font-weight: bold; margin: 5px 0; }

#new-highscore-form { text-align: center; }
#new-highscore-form p { margin: 5px 0; }
#player-name {
    padding: 8px;
    border-radius: 5px;
    border: none;
    margin-right: 5px;
}

#save-score-button, #restart-button, #back-to-title-button {
    padding: 10px 20px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #999;
    background-color: #f0f0f0;
    -webkit-tap-highlight-color: transparent;
    color: #333;
    flex-grow: 1;
}

#restart-button { background-color: #aaeaff; }
#back-to-title-button { background-color: #ddd; }

#save-score-button:active, #restart-button:active, #back-to-title-button:active { background-color: #ccc; }

.game-over-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
    margin-top: 15px;
}


#ranking-list {
    list-style-type: none;
    padding: 0;
    width: 100%;
    height: 150px; 
    overflow-y: auto;
    background-color: rgba(0,0,0,0.2);
    border-radius: 5px;
}
#ranking-list li {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    margin-bottom: 2px;
    border-radius: 3px;
    text-align: left;
}
#ranking-list li .rank-name {
    font-weight: bold;
}

#personal-ranking-container {
    width: 100%;
    text-align: center;
}
#personal-ranking-list {
    list-style-type: none;
    padding: 0;
    width: 100%;
    max-height: 160px;
    overflow-y: auto;
    background-color: rgba(0,0,0,0.2);
    border-radius: 5px;
    margin-top: 10px;
}
#personal-ranking-list li {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    margin-bottom: 2px;
    border-radius: 3px;
    text-align: left;
}
#personal-ranking-list li .rank-name {
    font-weight: bold;
}

#canvas-container {
    border: 1px solid #333;
    width: 100%;
    flex-grow: 1;
    display: flex;
    background-color: transparent;
    min-height: 0;
}

#canvas-container > canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ★★★ UI全体の高さとレイアウトを変更 ★★★ */
#ui-container {
    display: flex;
    flex-direction: column; /* 上下2段に */
    justify-content: space-around;
    padding: 5px;
    background-color: rgba(221, 221, 221, 0.8);
    box-sizing: border-box;
    z-index: 10;
    height: 135px; /* 高さを広げる */
    width: 100%;
    gap: 10px; /* 上段と下段の隙間 */
}

/* ★★★ 上段：操作ボタンのスタイル ★★★ */
#buttons-container {
    display: flex;
    width: 100%;
    gap: 10px;
}

#rotate-button, #drop-button {
    flex-grow: 1; /* ボタンが横幅いっぱいに広がるように */
    padding: 12px 0; /* ボタンの縦幅を大きく */
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
    border: 1px solid #999;
    background-color: #f0f0f0;
    -webkit-tap-highlight-color: transparent;
}
#drop-button {
    background-color: #ffdada;
}
#rotate-button:active, #drop-button:active {
    background-color: #ccc;
}

/* ★★★ 下段：情報表示のスタイル ★★★ */
#info-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

#score-container {
    font-size: 0.8em;
    font-weight: bold;
    text-align: left;
}

#next-blocks-container {
    display: flex;
    gap: 4px;
    align-items: center;
}

.next-block-canvas {
    border: 1px solid #777;
    background-color: rgba(0,0,0,0.05);
}


/* --- スマートフォン向けレスポンシブ対応 --- */
@media (max-width: 768px) {
    #main-wrapper {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        height: 95vh;
        width: 100%;
    }

    #game-container {
        width: 100%;
        height: auto;
        flex-grow: 1;
        flex-shrink: 1;
        min-height: 0;
    }
}