/* =========================================
   全テンプレート共通 - index改善案2
   1. 基本設定（PC・スマホ共通のベース）
   ========================================= */
:root {
    /* ここを変えるだけでサイト全体の文字サイズ基準が変わる */
    --font-size-base: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 20px;

    /* 余白の基準 */
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
}

html {
    font-size: var(--font-size-base); /* 基本サイズ */
}

body {
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    line-height: 1.6;
    color: #333;
    margin: 0;
    padding: 0;
    background-color: #f9f9f9;
}

/* =========================================
   2. タブレット・PC向けの調整
      (画面幅が 768px 以上の場合の上書き)
   ========================================= */
@media screen and (min-width: 768px) {
    :root {
        /* PCやタブレットでは少し文字を大きくする */
        --font-size-base: 17px;
        --font-size-lg: 20px;
        --font-size-xl: 24px;
    }
}

/* =========================================
   3. 共通クラス（どのページでも使える部品）
   ========================================= */

/* 問題文などのテキスト */
.text-body {
    font-size: 1rem; /* htmlの文字サイズ(16px or 17px)の1倍 */
    line-height: 1.8;
}

/* 見出し */
.text-title {
    font-size: 1.25rem; /* ベースの1.25倍 */
    font-weight: bold;
    margin-bottom: var(--spacing-md);
}

/* ボタン（カード型） */
.btn-card {
    display: block;
    padding: var(--spacing-md);
    font-size: 1.1rem; /* ベースの1.1倍 */
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    text-align: center;
    text-decoration: none;
    color: #333;
}

/* =========================================
   4. メインメニュー（main_selection）・一覧表示向け
      グリッド・カード・フォントサイズ（index改善案 レイアウト1）
   ========================================= */
.selection-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* デフォルト（スマホ）2列 */
    gap: 12px;
    margin-bottom: 30px;
}
/* スマホ：メイン選択・一覧カードは2列で固定 */
@media screen and (max-width: 767px) {
    .selection-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media screen and (min-width: 768px) {
    .selection-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}
.selection-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 20px 10px;
    min-height: 60px;
    text-decoration: none;
    color: #333;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: transform 0.2s;
}
.selection-card:active,
.selection-card:hover {
    background: #f0f8ff;
}
.selection-card:active {
    transform: scale(0.98);
}
/* カード内メイン文字（修正1: main-text / sub-text にも対応） */
.selection-main-text,
.main-text {
    font-size: 19px;
    font-weight: bold;
    margin-bottom: 4px;
}
@media screen and (min-width: 768px) {
    .selection-main-text,
    .main-text {
        font-size: 20px;
    }
}
.selection-sub-text,
.sub-text {
    font-size: 12px;
    color: #888;
}
@media screen and (min-width: 768px) {
    .selection-sub-text,
    .sub-text {
        font-size: 13px;
    }
}
.section-title {
    font-size: 20px;
    font-weight: bold;
    margin: 20px 0 10px;
}
@media screen and (min-width: 768px) {
    .section-title {
        font-size: 22px;
    }
}

/* フェーズ1: メイン選択タブ（年度別 / 問番別 / カスタム） */
.main-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}
.main-tabs .tab-btn {
    padding: 12px 20px;
    border: none;
    background: #f5f5f5;
    color: #666;
    font-size: 1rem;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}
.main-tabs .tab-btn:hover {
    background: #eee;
    color: #333;
}
.main-tabs .tab-btn.active {
    background: #fff;
    color: #764ba2;
    font-weight: bold;
    border-bottom-color: #764ba2;
}
.tab-panel {
    display: none;
}
.tab-panel.is-active {
    display: block;
}

/* フェーズ3: 一覧の並べ替えリンク */
.sort-links {
    margin-top: 12px;
    font-size: 0.95rem;
}
.sort-links .sort-label {
    margin-right: 6px;
    opacity: 0.95;
}
.sort-links .sort-link {
    color: rgba(255,255,255,0.9);
    text-decoration: underline;
}
.sort-links .sort-link:hover {
    color: #fff;
}
.sort-links .sort-link.is-current {
    font-weight: bold;
    text-decoration: none;
}
.sort-links .sort-sep {
    margin: 0 8px;
    opacity: 0.8;
}

/* フェーズ4: 図表ボタン（FAB）大型化・枚数バッジ */
.fab-images {
    position: fixed;
    right: 16px;
    bottom: 24px;
    z-index: 200;
    min-width: 64px;
    min-height: 64px;
    padding: 12px 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
}
.fab-images:hover {
    opacity: 0.95;
    transform: scale(1.05);
}
.fab-images .fab-badge {
    font-size: 11px;
    opacity: 0.95;
    margin-top: 2px;
}

/* フェーズ4: 課目4 アコーディオン（問番別タブ内） */
.subject-elect-details {
    grid-column: 1 / -1;
}
.subject-elect-summary {
    list-style: none;
    cursor: pointer;
    text-align: center;
}
.subject-elect-summary::-webkit-details-marker { display: none; }
.subject-elect-inner {
    margin-top: 12px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
}
.subject-elect-note {
    margin-bottom: 12px;
    font-size: 0.95rem;
    color: #555;
}
.subject-elect-btn {
    margin-top: 16px;
}

/* =========================================
   5. 問題一覧（index / question_number_list）向け
      カード化・タップ領域・プレビュー（index改善案 レイアウト1）
   ========================================= */
.question-list {
    list-style: none;
    padding: 0;
}
/* 一覧カード（メイン選択・年度別・問番別・カテゴリ別等）はグリッドで2列表示 */
.question-list.question-list-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 30px;
}
@media screen and (min-width: 768px) {
    .question-list.question-list-cards {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 16px;
    }
}
.question-list.question-list-cards li {
    margin-bottom: 0;
}
.question-list li {
    margin-bottom: 16px;
}
.question-item {
    background: #fff;
    border-bottom: 1px solid #eee;
    padding: 16px;
    display: block;
    text-decoration: none;
    color: #333;
    position: relative;
}
.question-list li:nth-child(even) .question-item {
    background: #fafafa;
}
/* 修正2: 問題一覧をメインメニューと同じ白カードに（ゼブラなし） */
.question-list-cards li:nth-child(even) .question-item,
.question-list-cards li:nth-child(odd) .question-item {
    background: #fff;
}
.question-item:hover {
    background: #f0f8ff;
}
/* 一覧カード＋冒頭を見る（回数・最初の小問1つのみ・フォント小さくしすぎない） */
.question-card-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.question-card-wrap .selection-card {
    flex: 0 0 auto;
}
.peek-details {
    margin-top: 4px;
    font-size: 13px;
}
.peek-summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.peek-summary::-webkit-details-marker { display: none; }
.peek-text {
    font-size: 14px;
    line-height: 1.6;
    color: #444;
    margin-top: 8px;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #eee;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.25s ease-out, opacity 0.2s ease-out, margin 0.2s ease-out;
}
.peek-details[open] .peek-text {
    max-height: 320px;
    opacity: 1;
    transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
}
@media screen and (min-width: 768px) {
    .peek-text {
        font-size: 15px;
    }
}
.q-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.q-number {
    font-size: 18px;
    font-weight: bold;
    color: #007bff;
}
@media screen and (min-width: 768px) {
    .q-number {
        font-size: 18px;
    }
}
.status-badge {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    background: #eee;
    color: #666;
}
.status-badge.done {
    background: #d4edda;
    color: #155724;
}
.q-preview {
    font-size: 16px;
    line-height: 1.6;
    color: #555;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
@media screen and (min-width: 768px) {
    .question-list li {
        margin-bottom: 12px;
    }
    .question-item {
        padding: 20px 24px;
        border: 1px solid #ddd;
        border-radius: 8px;
        margin-bottom: 0;
        border-bottom: none;
    }
    .question-list li:nth-child(even) .question-item {
        background: #fff;
    }
    .question-list li:nth-child(odd) .question-item {
        background: #fff;
    }
    .question-item:hover {
        background: #f0f8ff;
    }
    .q-preview {
        font-size: 17px;
    }
    .status-badge {
        font-size: 13px;
    }
}

/* 苦手（赤系）: 実力不足 */
.blank-status-weak { background-color: #ffcdd2 !important; border-color: #e53935 !important; color: #b71c1c !important; }
/* 普通（黄系）: まだ不安定 */
.blank-status-normal { background-color: #fff9c4 !important; border-color: #fbc02d !important; color: #827717 !important; }
/* 得意（緑系）: 定着している */
.blank-status-strong { background-color: #c8e6c9 !important; border-color: #43a047 !important; color: #1b5e20 !important; }
/* 未挑戦（青/グレー）: デフォルト */

/* 選択中の解答欄の強調表示 */
.blank-btn.focus {
    background-color: #fff9c4 !important; /* 明るい黄色 */
    border-color: #fbc02d !important;    /* 濃い黄色 */
    color: #827717 !important;
    box-shadow: 0 0 0 4px rgba(251, 192, 45, 0.4); /* 外側に光るエフェクト */
    transform: scale(1.1); /* わずかに大きくして「選択中」を主張 */
    z-index: 10;
    position: relative;
    transition: all 0.2s ease;
}

/* 不要になったモーダル内の文脈表示エリアを消す */
.choice-modal .modal-context {
    display: none !important;
}

/* 文脈が消えた分、ヘッダー行のバランスを調整 */
.choice-modal .modal-header-row {
    justify-content: space-between;
    padding: 8px 16px;
}

/* ドラッグ可能にするための設定 */
#calculator-widget, .images-modal {
    position: fixed;
    touch-action: none; /* スマホのスクロールと干渉させない */
    user-select: none;
}

/* 電卓のヘッダー（ドラッグハンドル） */
.calc-handle {
    height: 24px;
    background: #333;
    border-radius: 10px 10px 0 0;
    cursor: move;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: -12px -12px 10px -12px;
}
.calc-handle::after {
    content: "::::";
    color: #666;
}

/* 図表モーダルのドラッグハンドル（タブエリアをハンドルにする） */
.images-tabs {
    cursor: move;
    user-select: none;
}

/* 図表エリアのサイズ固定用（JSで高さを上書きします） */
#images-content {
    min-width: 320px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
}

#images-content img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.ai-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.9em;
}
.ai-btn.secondary { background: #6c757d; text-decoration: none; }
.ai-btn.external { background: #17a2b8; }
.explanation-box { box-shadow: 0 2px 8px rgba(0,0,0,0.1); line-height: 1.7; }