/* 基本設定 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

.container2 {
    /* max-width: 800px; */
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    overflow: hidden;
}

/* ヘッダー */
.header1 {
    background: linear-gradient(135deg, #04569e 0%, #041c2e 100%);
    color: white;
    padding: 30px;
    text-align: center;
    
}

.header1 h1 {
    font-size: 24px;
    margin-bottom: 20px;
}

/* 科目選択ボタン */
.subject-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.subject-btn {
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: bold;
}

.subject-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

.subject-btn.active {
    background: white;
    color: #4facfe;
    border-color: white;
}

/* プログレスバー */
.progress {
    background: rgba(255,255,255,0.3);
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
    margin-top: 15px;
}

.progress-bar {
    background: white;
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease;
    width: 0%;
}

/* シャッフル設定 */
.shuffle-settings {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.shuffle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #495057;
    user-select: none;
}

.shuffle-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    background-color: #fff;
    border: 2px solid #dee2e6;
    border-radius: 4px;
    margin-right: 10px;
    position: relative;
    transition: all 0.3s ease;
}

.shuffle-label input[type="checkbox"]:checked + .checkmark {
    background-color: #007bff;
    border-color: #007bff;
}

.shuffle-label input[type="checkbox"]:checked + .checkmark::after {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    font-size: 12px;
}

.shuffle-label:hover .checkmark {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

/* 単元選択メニュー */
.unit-menu {
    padding: 40px;
}

.menu-content h2 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 20px;
}

.unit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.unit-card {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.unit-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border-color: #007bff;
}

.unit-card h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 18px;
}

.unit-info {
    margin-bottom: 20px;
}

.unit-info p {
    color: #666;
    font-size: 14px;
    margin-bottom: 8px;
}

.status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
}

.status.ready {
    background: #d4edda;
    color: #155724;
}

.status.preparing {
    background: #fff3cd;
    color: #856404;
}

.start-btn {
     background: linear-gradient(135deg, #04569e 0%, #041c2e 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s ease;
    width: 100%;
}

.start-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(102,126,234,0.3);
}

.start-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* クイズエリア */
.quiz-area {
    padding: 30px;
}

.quiz-header {
    margin-bottom: 20px;
}

.breadcrumb {
    background: #e3f2fd;
    padding: 10px 15px;
    border-radius: 8px;
    color: #1976d2;
    font-size: 14px;
    font-weight: bold;
}

/* 問題文エリア */
.question-area {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    min-height: 200px;
    border: 2px solid #e9ecef;
}

.question-text {
    font-size: 16px;
    line-height: 2.0;
    color: #333;
}

/* 穴埋め部分のスタイル */
.blank {
    display: inline-block;
    background: #6c757d;
    color: white;
    padding: 4px 12px;
    border-radius: 6px;
    font-weight: bold;
    margin: 5px 2px;
    min-width: 80px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.blank.active {
    background: #007bff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.25);
}

.blank.correct {
    background: #28a745;
    animation: correctAnswer 0.5s ease;
}

.blank.incorrect {
    background: #dc3545;
    animation: incorrectAnswer 0.5s ease;
}

@keyframes correctAnswer {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes incorrectAnswer {
    0% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
    100% { transform: translateX(0); }
}

/* 選択肢エリア */
.choices-area {
    margin-bottom: 30px;
    /* background: #000; */
}

.current-question {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 0 8px 8px 0;
    font-weight: bold;
    color: #1976d2;
}

.choices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.choice-btn {
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 12px;
    padding: 15px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    color: #333;
    font-weight: 500;
    background: #e8e0e0;
}

.choice-btn:hover {
    border-color: #007bff;
    background: #f8f9fa;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.choice-btn.correct {
    background: #d4edda;
    border-color: #28a745;
    color: #155724;
}

.choice-btn.incorrect {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}

.choice-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* 解説エリア */
.explanation-area {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 30px;
    display: none;
}

.explanation-area.show {
    display: block;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.explanation-title {
    color: #856404;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
}

.explanation-title::before {
    content: "💡";
    margin-right: 10px;
}

.explanation-text {
    color: #856404;
    line-height: 1.7;
    font-size: 15px;
}

/* ボタンエリア */
.button-area {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

.next-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 150px;
}

.next-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

.next-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.show-answer-btn {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.show-answer-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(255,107,107,0.3);
}

.show-answer-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.back-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.back-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

/* 正答数表示エリア */
.score-area {
    text-align: center;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    border: 2px solid #e9ecef;
}

.score-display {
    font-size: 18px;
    font-weight: bold;
    color: #495057;
}

.score-label {
    margin-right: 10px;
    color: #6c757d;
}

.score-counter {
    color: #007bff;
    font-size: 20px;
    padding: 5px 15px;
    background: white;
    border-radius: 25px;
    border: 2px solid #007bff;
    display: inline-block;
    min-width: 80px;
}

/* 数式表示の調整 */
.math {
    font-family: "Times New Roman", serif;
    font-style: italic;
}

.result-icon {
    font-size: 20px;
    margin-left: 10px;
}
/* フッター */
.footer {
display: none;
}
/* レスポンシブ対応 */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    /* .header {
        padding: 20px;
    }
     */
    .header h1 {
        font-size: 20px;
    }
    
    .subject-selector {
        gap: 8px;
    }
    
    .subject-btn {
        padding: 8px 16px;
        font-size: 12px;
    }
    
    .unit-menu, .quiz-area {
        padding: 20px;
    }
    
    .unit-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .unit-card {
        padding: 20px;
    }
    
    .question-text {
        font-size: 14px;
    }
    
    .choices-grid {
        grid-template-columns: 1fr;
    }
    
    .choice-btn {
        padding: 12px 15px;
        font-size: 14px;
    }
    
    .button-area {
        flex-direction: column;
        align-items: center;
    }
    
    .button-area button {
        width: 100%;
        max-width: 200px;
    }
    
    .score-area {
        padding: 15px;
    }
    
    .score-display {
        font-size: 16px;
    }
    
    .score-counter {
        font-size: 18px;
    }
}

/* 既存のCSSに以下を追加・修正 */

/* スマホサイズでの選択肢エリア固定 */
@media (max-width: 768px) {
    /* 既存のメディアクエリ内容はそのまま残して、以下を追加 */
    
    /* クイズエリア全体の調整 */
    .quiz-area {
        padding: 20px 20px 200px 20px; /* 下部に固定選択肢分の余白を追加 */
    }
    
    /* 選択肢エリア（current-question + choices-grid）を画面下部に固定 */
    .choices-area {
        font-size: 16px;
        position: fixed !important;
        top: 500px !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 450px !important; /* 固定の高さを指定 */
        background: #fff !important;
        border-top: 3px solid #2196f3 !important;
        box-shadow: 0 -5px 20px rgba(0,0,0,0.15) !important;
        padding: 10px !important;
        z-index: 1000 !important;
        /* overflow-y: auto !important; */
        display: flex !important; /* フレックスボックスに変更 */
        flex-direction: column !important; 
        /* box-sizing: border-box !important; */
    }
    
    /* 現在の問題表示（問題 1/5: ○○○）の調整 */
    .current-question {
        background: #e3f2fd !important;
        border-left: 4px solid #2196f3 !important;
        padding: 10px 15px !important;
        margin-bottom: 15px !important;
        border-radius: 0 4px 4px 0 !important;
        font-weight: bold !important;
        color: #1976d2 !important;
        font-size: 14px !important;
        line-height: 1.4 !important;
        display: block !important; /* 強制的に表示 */
        flex-shrink: 0 !important; /* フレックスアイテムとして縮小を防ぐ */
    }
    
    /* 選択肢グリッドの調整 */
    .choices-grid {
        display: grid !important; /* 強制的に表示 */
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 15px !important;
        flex: 1 !important; /* 残りのスペースを全て使用 */
        align-content: start !important; /* グリッドを上から配置 */
    }
    
    /* 選択肢ボタンのサイズ調整 */
    .choice-btn {
        padding: 15px 10px !important;
        font-size: 18px !important;
        border-radius: 8px !important;
        min-height: 60px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        line-height: 1.3 !important;
        word-break: break-word !important;
        background: #f8f9fa !important;
        border: 2px solid #dee2e6 !important;
        color: #333 !important;
        cursor: pointer !important;
    }
    
    .choice-btn:hover {
        border-color: #007bff !important;
        background: #e3f2fd !important;
        transform: none !important; /* hover時の変形を無効化（固定要素のため） */
    }
    
    .choice-btn.correct {
        background: #d4edda !important;
        border-color: #28a745 !important;
        color: #155724 !important;
    }
    
    .choice-btn.incorrect {
        background: #f8d7da !important;
        border-color: #dc3545 !important;
        color: #721c24 !important;
    }
    
    /* ボタンエリアは通常の位置に戻す */
    .button-area {
        flex-direction: column;
        align-items: center;
        margin-bottom: 30px;
    }
    
    .button-area button {
        width: 100%;
        max-width: 200px;
    }
    
    /* 解説エリアの調整（固定エリアと重ならないように） */
    .explanation-area {
        /* margin-bottom: 220px; */
    }
    
    /* スコアエリアの調整 */
    .score-area {
        margin-bottom: 220px;
    }
}

/* より小さい画面（iPhone SE等）用の追加調整 */
@media (max-width: 480px) {
    .quiz-area {
        padding: 15px 15px 190px 15px !important;
    }
    
    .choices-area {
        /* max-height: 140px !important; */
        /* min-height: 120px !important; */
        padding: 8px !important;
    }
    
    .choices-grid {
        grid-template-columns: 1fr !important; /* 小さい画面では1列に */
        gap: 8px !important;
    }
    
    .choice-btn {
        font-size: 16px !important;
        padding: 6px 4px !important;
        min-height: 32px !important;
    }
    
    .current-question {
        font-size: 13px !important;
        padding: 8px 12px !important;
        margin-bottom: 10px !important;
    }
    
    .explanation-area,
    .score-area {
        /* margin-bottom: 200px !important; */
    }
}

/* 数式が含まれる選択肢の調整 */
@media (max-width: 768px) {
    .choice-btn .MathJax {
        font-size: 1em !important;
    }
    
    .choice-btn .MathJax_Display {
        margin: 0 !important;
    }
}


/* 選択肢エリアを非表示にするクラス */
@media (max-width: 768px) {
    .choices-area.hidden {
        display: none !important;
    }
    
    /* 選択肢が非表示の時はクイズエリアの下部余白を削除 */
    .quiz-area.choices-hidden {
        padding-bottom: 20px !important;
    }
    
    /* 選択肢非表示時のアニメーション */
    .choices-area {
        transition: opacity 0.3s ease, transform 0.3s ease !important;
    }
    
    .choices-area.hiding {
        opacity: 0 !important;
        transform: translateY(100%) !important;
    }
}