/*
[仕様メモ / styles.css]

役割:
- 全画面の共通スタイル。

主要クラス:
- レイアウト: .wrap, .card, .meta, .kx
- タイトル: .title-screen, .app-title, .btn, .btn-primary, .btn-secondary
- ミニチェッカー: .mini-checker + .cell(.red/.blue/.gray/.none)
- 凡例: .legend(.l-red/.l-blue/.l-gray/.l-none)
- チェッカー: .checker-title-page, .genre-list, .card-grid, .btn-prob(+ 色バリエーション)
- 学習: .progress-rail, .progress-bar
- スワイプ: .swipe-shell / .swipe-center / .swipe-card（カード色は .red/.blue/.gray/.none で切替）

注意:
- #titleCheckerGrid / #checkerGrid には .mini-checker を必ず併用（同じ見た目）。
- MathJax は --math-scale でスケール調整（index.html から設定）。
*/

/* ====== Theme / Base ====== */
:root {
  --bg:#0b0c10; --card:#151820; --ink:#e7eef7; --muted:#aab4c3; --accent:#3abff8;
  --math-scale: 0.90;
}
html,body {
  margin:0; padding:0; background:var(--bg); color:var(--ink);
  font-family: system-ui,-apple-system,"Segoe UI",Roboto,"Hiragino Sans","Noto Sans JP",sans-serif;
}
header { padding:16px 20px; border-bottom:1px solid #202534; display:flex; align-items:center; gap:12px; }
.logo { font-weight:700; cursor:pointer; text-decoration:none; color:var(--ink); }
.wrap { max-width:980px; margin:0 auto; padding:20px; }
.mjx-container { font-size: calc(1em * var(--math-scale)); }

/* ====== Cards / UI atoms ====== */
.card { background:var(--card); border-radius:12px; padding:16px; }
.meta { font-size:13px; color:var(--muted); }
select.select, button.ghost {
  background:#1b2740; color:#e7eef7; border:1px solid #2a3b66; border-radius:8px;
  padding:8px 14px; cursor:pointer; transition:0.2s;
}
button.ghost:hover, select.select:focus { background:#2a3b66; }
.kx { font-size: calc(20px * var(--math-scale)); line-height:1.6; }

/* ====== Title screen ====== */
.title-screen {
  display:flex; flex-direction:column; align-items:center; justify-content:flex-start;
  gap:20px; color:#fff;
}
.app-title { font-size:28px; font-weight:700; margin-bottom:10px; }

/* Title buttons */
.btn { font-size:16px; font-weight:600; padding:8px 16px; border-radius:8px; border:none; cursor:pointer; }
.btn-primary { background:#2b5bd9; color:#fff; } .btn-primary:hover { background:#3b6cff; }
.btn-secondary { background:#444; color:#fff; } .btn-secondary:hover { background:#666; }

/* ====== Mini Checker (共通で使用) ====== */
.mini-checker {
  display: grid;
  grid-template-columns: repeat(10, 18px);
  grid-auto-rows: 18px;
  gap: 2px;
  justify-content: center;
}
.mini-checker .cell {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid #2a3248;
}
.mini-checker .cell.red  { background: #ef4444; border-color: #b91c1c; }
.mini-checker .cell.blue { background: #3b82f6; border-color: #1d4ed8; }
.mini-checker .cell.gray { background: #4b5563; border-color: #374151; }
.mini-checker .cell.none { background: transparent; }

/* ====== Mini-checker (共通CSS) ====== */
#titleCheckerGrid, #checkerGrid {
  display:grid; grid-template-columns: repeat(10, 18px);
  grid-auto-rows:18px; gap:2px; justify-content:center;
}
.cell { width:18px; height:18px; border-radius:3px; border:1px solid #2a3248; }
.cell.red  { background:#ef4444; border-color:#b91c1c; }
.cell.blue { background:#3b82f6; border-color:#1d4ed8; }
.cell.gray { background:#4b5563; border-color:#374151; }
.cell.none { background:transparent; }

/* 凡例 */
.legend { display:inline-block; width:12px; height:12px; border-radius:2px; border:1px solid #2a3248; }
.l-red  { background:#ef4444; border-color:#b91c1c; }
.l-blue { background:#3b82f6; border-color:#1d4ed8; }
.l-gray { background:#4b5563; border-color:#374151; }
.l-none { background:transparent; }

/* タイトル側コンテナの装飾 */
.title-checker {
  background:#151820; border-radius:12px; padding:16px 24px; text-align:center;
  cursor:pointer; transition: transform .2s ease, box-shadow .2s ease;
  width: fit-content; margin: 0 auto 8px;
}
.title-checker:hover { transform:scale(1.02); box-shadow:0 0 8px rgba(255,255,255,0.2); }
.checker-title { font-size:20px; font-weight:600; color:#e7eef7; margin-bottom:10px; }

/* ランダム一問ボタン */
.title-buttons { display:flex; flex-direction:column; align-items:center; gap:12px; }
.title-buttons-row { display:flex; gap:12px; justify-content:center; }
#btnRandomOne { min-width:240px; padding:16px 24px; font-size:1.1rem; border-radius:10px; }

/* ====== Checker page extras ====== */
.checker-title-page { font-size:20px; font-weight:600; color:#e7eef7; text-align:center; margin-bottom:10px; letter-spacing:.03em; }
.genre-list { display:flex; flex-direction:column; gap:22px; }
.genre-row  { display:flex; flex-direction:column; gap:10px; }
.genre-title{ font-weight:600; color:#e7eef7; }

.card-grid {
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap:12px;
}
.btn-prob {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:10px; padding:12px; border-radius:12px;
  border:1px solid #2a3b66; background:#121a2c; color:#e7eef7;
  text-align:center; min-height:72px; cursor:pointer;
  transition:transform .06s ease, filter .2s ease; padding:8px 10px;
}
.btn-prob:hover { filter:brightness(1.08); }
.btn-prob:active { transform: translateY(1px); }
.btn-red  { background:#3a0c0c; border-color:#c54a4a; }
.btn-blue { background:#0d1b3a; border-color:#3c6ef0; }
.btn-gray { background:#1e2228; border-color:#475063; color:#d3d8e0; }
.btn-none { background:transparent; border-style:dashed; color:#9aa3b2; }
.btn-prob .prob   { font-size: calc(14px * var(--math-scale)); line-height:1.45; }
.btn-prob .caption{ font-size:12px; color:var(--muted); }

/* ====== Learn page extras ====== */
.progress-rail { height:10px; background:#101626; border:1px solid #2a3248; border-radius:999px; overflow:hidden; margin-top:10px; }
.progress-bar  { display:block; height:100%; background:linear-gradient(90deg,#3abff8,#60a5fa); width:0%; }

/* === PDFリンク & フッター === */
.pdf-links { margin-top:24px; text-align:center; display:flex; justify-content:center; gap:24px; font-size:.9rem; }
.pdf-links a { color:#a3b4d9; text-decoration:none; transition:color .2s; }
.pdf-links a:hover { color:#fff; text-decoration:underline; }
.app-footer { margin-top:40px; padding:12px 0; text-align:center; font-size:.8rem; color:#8b92a9; border-top:1px solid #2a3248; }

/* ======= Learn Page Modal ======= */
#modalContainer {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 200;
}
#modalContainer.is-open { display:flex; }
.modal-backdrop { position:absolute; inset:0; background:rgba(0,0,0,0.6); backdrop-filter:blur(2px); }
.modal-card {
  position: relative;
  background: var(--card, #fff);
  color: var(--ink, #000);
  border-radius: 12px;
  padding: 24px;
  width: min(90vw, 640px);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 201;
}
/* モーダルで body_learn.html を表示する際、不要要素は隠す */
.modal-card .learn-header,
.modal-card #perItemStat,
.modal-card #btnNext { display: none !important; }

/* 学習カードとモーダル内の数式縮小 */
#qBox mjx-container,
#pBox mjx-container,
#aBox mjx-container,
#eBox mjx-container,
#modalContainer mjx-container { font-size: 0.8em; }

/* ========== Swipe ========== */
.swipe-area { touch-action: pan-y pan-x; }
.policy { margin-top:12px; padding-top:8px; border-top:1px dashed #64748b; }

/* タイトル→スワイプ導線のボタンレイアウト */
.title-actions { display:flex; gap:.5rem; }
.title-actions .btn { min-width:160px; }

/* 全体センター */
.swipe-shell { display:flex; flex-direction:column; align-items:center; }
.swipe-row, .swipe-info { width:min(900px,95vw); }

/* 横スクロール抑止 */
html, body { overflow-x: hidden; }

/* === Swipe: レイアウト === */
.swipe-shell { display:flex; flex-direction:column; align-items:center; }
.swipe-row, .swipe-info { width:min(980px, 95vw); }

/* カードのセンタリング */
.swipe-center { width:100%; display:flex; justify-content:center; }

/* ★ スワイプカード：幅=コンテナの50%、高さは中身に十分（min-heightだけ） */
#swCardMount > .swipe-card,
.swipe-card {
  width: min(50%, 520px);     /* 画面が広い時は 50%、狭い時は 520px を上限に */
  min-height: 220px;          /* 数式が入る最低高。必要なら調整可 */
  margin: 12px auto;
  padding: 18px 16px;
  border-radius: 12px;
  border: 1px solid #2a3248;

  display:flex; flex-direction:column; align-items:center; justify-content:center;
  text-align:center;

  color:#fff;
  background:#111827;
  overflow:hidden;
}

/* カード内の領域は幅いっぱいに。MathJaxは中央へ */
.swipe-card .swipe-area { width:100%; max-width:100%; }
.swipe-card mjx-container { margin:0 auto; max-width:100%; }

/* ★ カード色：チェッカー寄りの落ち着いた色調 */
.swipe-card.red  { background:#3a0c0c; border-color:#c54a4a; }
.swipe-card.blue { background:#0d1b3a; border-color:#3c6ef0; }
.swipe-card.gray { background:#1e2228; border-color:#475063; }
.swipe-card.none { background:transparent; border-style:dashed; color:#d0d6e3; }

/* カードの外に出す方針/解答 */
#swAnswerWrap { display:flex; flex-direction:column; align-items:center; gap:10px; margin-top:10px; }
.sw-out { width:min(980px, 95vw); text-align:center; }
.sw-out mjx-container { margin:0 auto; }

/* 進捗UI */
.sw-stats { margin-top:6px; display:flex; gap:12px; opacity:.9; }
.sw-prog  { margin-top:6px; width:100%; }
.sw-prog .bar  { height:8px; background:#1f2937; border-radius:6px; overflow:hidden; }
.sw-prog .prog { height:8px; width:0; background:#93c5fd; transition:width .2s ease; }
.sw-prog .num  { margin-top:4px; font-size:.9rem; opacity:.85; }

/* =======================================================
   [SWIPE FINAL OVERRIDES]  ← 末尾に置く。既存定義の上に被せるだけ
   変更内容:
   - カードサイズを固定: 横200px × 縦120px
   - 中身（数式）の完全センター配置
   - 以前の幅/余白指定を無効化（!important で上書き）
   - 色クラスは背景・枠線のみ変更（文字色は白のまま）
   - 方針/解答（カード外）を中央寄せ
   ======================================================= */

/* カード本体（式だけ/中央寄せ/サイズ固定） */
#swCardMount > .swipe-card,
.swipe-card {
  width: 200px !important;           /* ← 指定サイズ */
  height: 120px !important;          /* ← 指定サイズ */
  padding: 0 !important;
  margin: 12px auto !important;
  border-radius: 16px !important;
  border: 1px solid #2a3248 !important;

  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;

  color: #fff !important;            /* 文字は白固定 */
  background: #111827 !important;    /* ベース色（後の色クラスで上書き可） */
  overflow: hidden !important;
}

/* カード内ラッパ（数式をど真ん中に） */
.swipe-card .swipe-area {
  width: 100% !important;
  height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}
.swipe-card mjx-container { margin: 0 auto !important; max-width: 95% !important; }

/* 正答率に応じた色（背景&枠のみを落ち着いた配色で） */
.swipe-card.red  { background: #3a0c0c !important; border-color: #c54a4a !important; }
.swipe-card.blue { background: #0d1b3a !important; border-color: #3c6ef0 !important; }
.swipe-card.gray { background: #1e2228 !important; border-color: #475063 !important; }
.swipe-card.none { background: transparent !important; border-style: dashed !important; color: #d0d6e3 !important; }

/* 方針/解答（カードの外。中央寄せ） */
#swAnswerWrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; margin-top: 10px;
}
.sw-out { width: min(900px, 95vw); text-align: center; }
.sw-out mjx-container { margin: 0 auto; }

/* 横スクロール抑止（既にどこかにあれば重複OK） */
html, body { overflow-x: hidden; }

/* =======================================================
   [SWIPE SIZE OVERRIDES v2]  ← 末尾に追加
   変更:
   - カード幅: 220px
   - カード高: 120px
   - 既存 min-height を無効化（120px に揃える）
   - 枠線込みの厳密サイズにするため border-box
   ======================================================= */
#swCardMount > .swipe-card,
.swipe-card {
  box-sizing: border-box !important;
  width: 220px !important;
  height: 120px !important;
  min-height: 120px !important;   /* ← これで古い min-height:220px を無効化 */
  padding: 0 !important;
  margin: 12px auto !important;
  border-radius: 16px !important;
  border: 1px solid #2a3248 !important;

  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;

  color: #fff !important;
  background: #111827 !important;   /* JS側で色を上書き */
  overflow: hidden !important;
}

/* 数式をど真ん中に */
.swipe-card .swipe-area {
  width: 100% !important;
  height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}
.swipe-card mjx-container { margin: 0 auto !important; max-width: 95% !important; }

/* =======================================================
   [SWIPE ANIMATIONS]
   ======================================================= */

/* 横スワイプ: 右/左に飛ばす */
.swipe-card.anim-leave-right { animation: swipeLeaveRight .18s ease forwards; }
.swipe-card.anim-leave-left  { animation: swipeLeaveLeft  .18s ease forwards; }
@keyframes swipeLeaveRight { to { transform: translateX(120%); opacity: 0.0; } }
@keyframes swipeLeaveLeft  { to { transform: translateX(-120%); opacity: 0.0; } }

/* 次カードのワイプイン（中央に出る） */
.swipe-card.anim-enter { animation: swipeEnter .18s ease forwards; opacity: 0; transform: scale(.98); }
@keyframes swipeEnter { to { transform: scale(1); opacity: 1; } }

/* 上下プル（最大5%ずらして戻す） */
.swipe-card.anim-pull-up    { animation: pullUp .18s ease; }
.swipe-card.anim-pull-down  { animation: pullDown .18s ease; }
@keyframes pullUp   { 50% { transform: translateY(-5%); } 100% { transform: translateY(0); } }
@keyframes pullDown { 50% { transform: translateY( 5%); } 100% { transform: translateY(0); } }

/* =======================================================
   [SWIPE TOUCH CONTROL] ← 末尾に追加するだけ
   目的: 上下スワイプがスクロールに負けないようにする
   ======================================================= */
.swipe-card .swipe-area{
  /* ブラウザのスクロール/ナビ操作を抑止してイベントを全部受け取る */
  touch-action: none !important;
}

/* ついでに端末のオーバースクロールで引っ張られないように */
html, body {
  overscroll-behavior: contain;
}

/* =======================================================
   [SWIPE ANSWER CENTER OVERRIDE]
   目的: 方針/解答のブロックを強制センタリング
   ======================================================= */
#swAnswerOut, #swPolicyOut {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  min-height: 8px; /* 内容が小さくても上下センターに見えるように */
}
#swAnswerOut mjx-container,
#swPolicyOut mjx-container {
  margin: 0 auto !important;
}

/* =========================
   [SWIPE centerline fix]
   目的: 文字+数式の混在を中央に寄せる
   ========================= */
#swPolicyOut, #swAnswerOut {
  /* flexを使わない。行内を中央寄せ */
  display: block !important;
  text-align: center !important;
}

/* ラップ要素（JSで挿入）を行内ブロックにして全体を中央へ */
.sw-centerline {
  display: inline-block !important;
  text-align: left; /* 数式内の改行やインラインは自然に */
}

/* MathJax も念のため中央に */
#swPolicyOut mjx-container,
#swAnswerOut mjx-container {
  margin: 0 auto !important;
}