body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* ビューポートの高さに合わせる */
    background-color: #f4f4f4;
    margin: 0;
    overflow: hidden; /* スクロールバーを非表示にする */
    box-sizing: border-box; /* paddingやborderをwidth/heightに含める */
}

.quiz-container {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 95%; /* 幅を広げ、余白を確保 */
    max-width: 600px; /* 最大幅を設定 */
    height: 95vh; /* ビューポートの高さの95%に合わせる */
    max-height: 700px; /* 必要に応じて最大高さを設定 */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
}

/* 画面コンテナの基本スタイル (共通部分) */
.screen {
    display: flex;
    flex-direction: column; /* 子要素を縦に並べる */
    align-items: center; /* 子要素を水平方向の中央に配置 */
    justify-content: center; /* 子要素を垂直方向の中央に配置 */
    width: 100%;
    flex-grow: 1;
    min-height: 400px; /* ゲーム画面がこれより小さくならないようにする値 (調整可能) */
}

/* ゲーム情報 (スコアと問題数) のレイアウト */
.game-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 10px;
    margin-bottom: 10px;
    font-size: 1.2em;
    font-weight: bold;
    flex-shrink: 0; /* 縮小しない */
}

/* プログレスバーコンテナ */
.progress-bar-container {
    width: 90%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin: 15px 0;
    overflow: hidden;
    flex-shrink: 0; /* 縮小しない */
}

/* プログレスバーの塗りつぶし部分 */
.progress-bar-fill {
    height: 100%;
    width: 0%;
    background-color: #4CAF50;
    border-radius: 5px;
    transition: width 0.3s ease-in-out;
}

/* ★ここから追加・変更されたCSSです★ */

/* 画像コンテナ */
.image-area {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex-grow: 1; /* 親の空きスペースを埋める */
    max-height: 45%; /* 親（game-screen）の高さの最大45% (調整可能) */
    min-height: 180px; /* 画像エリアの最小高さを確保 (調整可能) */
    margin: 10px 0; /* 上下のマージンを調整 */
}

#quiz-image {
    max-width: 95%; /* 親コンテナに合わせて最大幅 */
    max-height: 100%; /* 親の高さに収まるように */
    width: auto; /* 元のアスペクト比を維持 */
    height: auto; /* 元のアスペクト比を維持 */
    object-fit: contain; /* 画像全体が表示されるように調整 */
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* 入力とボタン、結果表示をまとめるコンテナ */
.input-and-result-area {
    display: flex;
    flex-direction: column; /* 子要素を縦に並べる */
    align-items: center; /* 子要素を中央寄せ */
    width: 100%;
    flex-shrink: 0; /* このコンテナは縮小しない */
    min-height: 160px; /* 入力、ボタン、結果表示が収まる最小高さ (調整可能) */
    padding-bottom: 10px; /* 必要であれば下部に余白 */
}

#answer-input {
    width: calc(100% - 20px);
    padding: 10px;
    margin-bottom: 15px; /* ボタンとの間のスペース */
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    text-align: center;
}

button {
    background-color: #007bff;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    margin-top: 0; /* input-and-result-area内のFlexアイテムなので個別のmargin-topは不要 */
    min-width: 120px;
}

button:hover {
    background-color: #0056b3;
}

#result {
    margin-top: 15px; /* ボタンとの間のスペース */
    font-weight: bold;
    height: 50px; /* 正解/不正解メッセージが確実に収まる高さをピクセル単位で指定 */
    line-height: 50px; /* テキストを垂直方向の中央に配置するため、高さと同じにする */
    width: 100%;
    text-align: center;
    padding: 0;
    box-sizing: border-box;
    flex-shrink: 0; /* この要素は縮小しない */
    overflow: hidden;
}

#result.correct {
    color: green;
}

#result.incorrect {
    color: red;
}

/* カウントダウン表示のスタイル */
#countdown-display {
    font-size: 8em;
    font-weight: bold;
    color: #007bff;
    /* marginを削除または調整し、Flexboxに任せる */
    margin: 0;
}

/* 結果表示のスタイル */
#result-screen h2 {
    color: #333;
    margin-bottom: 15px; /* ここは必要に応じて維持 */
}

#final-score {
    font-size: 1.8em;
    font-weight: bold;
    margin-bottom: 25px; /* ここは必要に応じて維持 */
}

/* スマートフォンでの調整 */
@media (max-width: 768px) {
    .quiz-container {
        padding: 15px;
        width: 98%;
        height: 98vh;
    }

    .screen {
        min-height: 350px;
    }

    .game-info {
        font-size: 1em;
        padding: 0 5px;
    }

    .progress-bar-container {
        margin: 10px 0;
    }

    .image-area {
        min-height: 120px; /* スマホでの画像エリアの最小高さ */
        max-height: 40%;
        margin: 5px 0;
    }

    #quiz-image {
        max-width: 98%;
    }

    .input-and-result-area {
        min-height: 150px; /* スマホでの入力・ボタン・結果エリアの最小高さ */
        padding-bottom: 5px;
    }

    #answer-input {
        font-size: 14px;
        padding: 8px;
        margin-bottom: 10px;
    }

    button {
        padding: 8px 15px;
        font-size: 14px;
        min-width: 100px;
    }

    #result {
        margin-top: 10px;
        height: 50px;
        line-height: 50px;
    }

    #countdown-display {
        font-size: 6em;
    }
}
