/* =========================================================
   カラーテーマ（ライト / ダーク）
   ui-prefs.js が <html data-theme="light|dark"> を設定する
   ========================================================= */
:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --card-bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --correct-bg: #dcfce7;
  --correct-border: #16a34a;
  --wrong-bg: #fee2e2;
  --wrong-border: #dc2626;
  --border: #e5e7eb;
  --hover-bg: #f0f5ff;
  --selected-bg: #e0eaff;
  --selected-hover-bg: #d4e2ff;
  --ok-text: #15803d;
  --ng-text: #b91c1c;
  --mark-ok: #16a34a;
  --mark-ng: #dc2626;
  --mark-none: #9ca3af;
  --thead-bg: #f9fafb;
  --tag-domain-bg: #eef2ff;
  --tag-domain-text: #4338ca;
  --tag-category-bg: #ecfdf5;
  --tag-category-text: #047857;
  --warn-text: #b45309;
  --warn-bg: #fffbeb;
  --warn-border: #fcd34d;
  --quote-bg: #f8fafc;
  --input-bg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.06);
  /* ゲーミフィケーション */
  --gold: #b45309;                 /* 実績・XP などの強調色（文字） */
  --gold-bg: #fef3c7;
  --gold-border: #f59e0b;
  --gold-soft-bg: rgba(245, 158, 11, 0.08);
  --xp-fill-1: #3b82f6;            /* XP バーのグラデーション */
  --xp-fill-2: #8b5cf6;
  --skill-fill-1: #3b82f6;         /* スキルマップのバー */
  --skill-fill-2: #22c55e;
  --hp-fill-1: #dc2626;            /* ボス HP バー */
  --hp-fill-2: #f97316;
  --hud-bg: #1e293b;               /* バトル HUD（ライトでも濃い帯） */
  --hud-text: #f1f5f9;
  --hud-border: #334155;
  --hud-track: rgba(255, 255, 255, 0.18);
  --timer-ok: #22c55e;
  --timer-warn: #eab308;
  --timer-danger: #ef4444;
  --combo-bg: #fef3c7;             /* コンボバッジ（アンバー系 pill） */
  --combo-text: #b45309;
  --combo-border: #fcd34d;
  --combo-word-text: #c2410c;      /* 画面中央のコンボバナーの文字 */
  --rank-c-bg: #9ca3af;
  --rank-d-bg: #4b5563;
  --player-card-bg-1: #eef2ff;     /* プレイヤーカードの背景グラデーション */
  --player-card-bg-2: #e0f2fe;
  --toast-shadow: rgba(0, 0, 0, 0.18);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --card-bg: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --correct-bg: rgba(34, 197, 94, 0.16);
  --correct-border: #22c55e;
  --wrong-bg: rgba(239, 68, 68, 0.18);
  --wrong-border: #ef4444;
  --border: #334155;
  --hover-bg: #253248;
  --selected-bg: #1e3a8a;
  --selected-hover-bg: #1e40af;
  --ok-text: #4ade80;
  --ng-text: #f87171;
  --mark-ok: #4ade80;
  --mark-ng: #f87171;
  --mark-none: #64748b;
  --thead-bg: #243044;
  --tag-domain-bg: #312e81;
  --tag-domain-text: #c7d2fe;
  --tag-category-bg: #064e3b;
  --tag-category-text: #6ee7b7;
  --warn-text: #fcd34d;
  --warn-bg: rgba(252, 211, 77, 0.1);
  --warn-border: rgba(252, 211, 77, 0.45);
  --quote-bg: rgba(148, 163, 184, 0.1);
  --input-bg: #0f172a;
  --shadow: rgba(0, 0, 0, 0.45);
  /* ゲーミフィケーション */
  --gold: #fbbf24;
  --gold-bg: rgba(251, 191, 36, 0.14);
  --gold-border: rgba(251, 191, 36, 0.55);
  --gold-soft-bg: rgba(251, 191, 36, 0.08);
  --xp-fill-1: #60a5fa;
  --xp-fill-2: #a78bfa;
  --skill-fill-1: #60a5fa;
  --skill-fill-2: #4ade80;
  --hp-fill-1: #ef4444;
  --hp-fill-2: #fb923c;
  --hud-bg: #0b1220;
  --hud-text: #f1f5f9;
  --hud-border: #334155;
  --hud-track: rgba(255, 255, 255, 0.12);
  --timer-ok: #4ade80;
  --timer-warn: #facc15;
  --timer-danger: #f87171;
  --combo-bg: rgba(251, 191, 36, 0.15);
  --combo-text: #fcd34d;
  --combo-border: rgba(251, 191, 36, 0.45);
  --combo-word-text: #fed7aa;
  --rank-c-bg: #64748b;
  --rank-d-bg: #475569;
  --player-card-bg-1: #1e3a5f;
  --player-card-bg-2: #1e293b;
  --toast-shadow: rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

/* スマホの画面回転時に文字サイズが勝手に拡大されるのを防ぐ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.container { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }

.app-header { text-align: center; margin-bottom: 24px; position: relative; }
.app-header h1 { margin: 0; font-size: 1.6rem; }
.subtitle { color: var(--muted); margin: 4px 0 0; font-size: 0.9rem; }

/* テーマ切替ボタン（ヘッダー右上） */
.icon-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px var(--shadow);
}

/* !important で display を持つ他のルール（.btn や .user-bar など）より常に優先させる */
.hidden { display: none !important; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  cursor: pointer;
  /* ダブルタップズームを無効化してタップの反応を速くする */
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; }

.start-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 16px 0;
}
select {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  /* 16px 未満だと iOS Safari がフォーカス時に自動ズームするため 1rem を維持する */
  font-size: 1rem;
  max-width: 100%;
  background: var(--input-bg);
  color: var(--text);
}
/* 出題数の自由入力欄（セレクトと同じ見た目に揃える） */
.count-input {
  width: 90px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 1rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}

.quiz-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.domain-tag {
  background: var(--tag-domain-bg);
  color: var(--tag-domain-text);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin: 10px 0 18px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0;
  transition: width 0.3s;
}

/* 問題文（データ中の改行 \n をそのまま表示する） */
#question-text,
.question-text {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: pre-line;
}

.choices { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.choice-btn {
  text-align: left;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  font-size: 0.95rem;
  cursor: pointer;
  line-height: 1.6;
  font-family: inherit;
  color: inherit;
  touch-action: manipulation;
}
.choice-btn:disabled { cursor: default; opacity: 0.75; }
.choice-btn.correct { background: var(--correct-bg); border-color: var(--correct-border); opacity: 1; }
.choice-btn.wrong { background: var(--wrong-bg); border-color: var(--wrong-border); opacity: 1; }

.feedback { border-top: 1px dashed var(--border); padding-top: 14px; margin-bottom: 16px; }
.result-correct { color: var(--ok-text); font-weight: 700; margin: 0 0 8px; }
.result-wrong { color: var(--ng-text); font-weight: 700; margin: 0 0 8px; }
#explanation { margin: 0; font-size: 0.92rem; }

.score { font-size: 1.4rem; font-weight: 700; }

.wrong-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
.wrong-item .q { font-weight: 600; margin: 0 0 6px; }
.wrong-item .a { margin: 0; color: var(--ok-text); }

/* ===== 認証・復習機能 ===== */
.user-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.field { margin: 12px 0; }
.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  box-sizing: border-box;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}
.field input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.error { color: var(--ng-text); font-size: 0.9rem; }

/* 起動時の「読み込み中…」「読み込めませんでした」の表示（boot.js が .muted / .error を切り替える） */
.boot-status { text-align: center; margin: 32px 0; }

.btn.small { padding: 6px 12px; font-size: 0.8rem; }
.btn.secondary {
  background: var(--card-bg);
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.mode-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.recent-results { color: var(--muted); font-size: 0.8rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ===== 途中終了・成績一覧 ===== */
.quiz-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.stats-header h2 { margin: 0; }

h3.stats-domain {
  margin: 22px 0 6px;
  font-size: 0.98rem;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 8px;
  font-size: 0.85rem;
}
.stats-table th,
.stats-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}
.stats-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--thead-bg);
}
.stats-table td.no {
  white-space: nowrap;
  color: var(--muted);
}
.stats-table td.marks { white-space: nowrap; }

.mark {
  display: inline-block;
  width: 1.3em;
  text-align: center;
  font-weight: 700;
}
.mark-ok { color: var(--mark-ok); }
.mark-ng { color: var(--mark-ng); }
.mark-none { color: var(--mark-none); font-weight: 400; }

/* ===== 成績一覧の個別回答ボタン ===== */
.stats-table td.action {
  white-space: nowrap;
  text-align: right;
}
.stats-table .btn.small {
  padding: 4px 12px;
  font-size: 0.78rem;
}

/* ===== カテゴリータグ・成績一覧コントロール ===== */
.category-tag {
  background: var(--tag-category-bg);
  color: var(--tag-category-text);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.stats-controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.stats-controls .start-options {
  margin: 8px 0;
}

/* ===== 形式の指示文（単一選択 / 複数選択） ===== */
.question-instruction {
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.choice-btn.selected {
  border-color: var(--primary);
  background: var(--selected-bg);
  box-shadow: inset 0 0 0 1px var(--primary);
}
/* 選択中は色だけでなく記号でも示す（回答後は正誤の表示と文字の印に切り替える） */
.choice-btn.selected::after {
  content: " ✓";
  font-weight: 700;
  color: var(--primary);
}
.choice-btn.selected:disabled::after { content: none; }
.choice-btn.selected.correct { background: var(--correct-bg); border-color: var(--correct-border); box-shadow: none; }
.choice-btn.selected.wrong { background: var(--wrong-bg); border-color: var(--wrong-border); box-shadow: none; }
/* 回答後の正誤の印（○ 正解 / × あなたの回答） */
.choice-mark { margin-left: 8px; font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.choice-btn.correct .choice-mark { color: var(--ok-text); }
.choice-btn.wrong .choice-mark { color: var(--ng-text); }

/* 部分点つきの問題の採点の目安 */
.result-note {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 4px 0 8px;
}

/* ===== 解説のみ表示 ===== */
.result-info {
  font-weight: 700;
  color: var(--primary);
}

.stats-table .action {
  white-space: nowrap;
}

.stats-table .action .btn + .btn {
  margin-left: 6px;
}

/* フッター（システム構成ページへのリンク・表示切替） */
.app-footer {
  text-align: center;
  margin: 28px 0 8px;
  font-size: 0.85rem;
}
.app-footer a { color: var(--muted); }
.footer-controls { margin: 10px 0 0; }

/* 表示切替などのテキスト風ボタン */
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  touch-action: manipulation;
}

/* 解説下の参考資料（AWS 公式ドキュメント） */
.references { margin-top: 14px; font-size: 0.9rem; }
.references-heading { margin: 0 0 6px; font-weight: 600; color: var(--muted); }
.reference-item { margin: 8px 0; }
.reference-item a { color: var(--primary); word-break: break-all; }
/* リンクが新しいタブで開くことを示す小さな矢印 */
.reference-item a::after { content: " ↗"; font-size: 0.85em; }
.reference-excerpt {
  margin: 6px 0 0;
  padding: 8px 12px;
  border-left: 3px solid var(--border);
  background: var(--quote-bg);
  color: var(--muted);
  font-size: 0.85rem;
}

/* =========================================================
   入力デバイス別の調整
   ========================================================= */

/* ホバー効果はマウス等のポインタがある環境だけに適用する
   （タッチ端末ではタップ後にホバー装飾が残り、選択状態と紛らわしいため） */
@media (hover: hover) and (pointer: fine) {
  .btn.primary:hover { background: var(--primary-hover); }
  .btn.secondary:hover { background: var(--hover-bg); }
  .btn.secondary:disabled:hover { background: var(--card-bg); }
  .choice-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--hover-bg); }
  .choice-btn.selected:hover:not(:disabled) { background: var(--selected-hover-bg); }
  .app-footer a:hover { color: var(--primary); }
  .link-btn:hover { color: var(--primary); }
  .icon-btn:hover { border-color: var(--primary); }
}

/* タッチ端末では小さいボタンのタップ領域を広げる（画面幅に関係なく適用） */
@media (pointer: coarse) {
  .btn.small { padding: 9px 14px; font-size: 0.85rem; }
  .stats-table .btn.small { padding: 8px 14px; font-size: 0.82rem; }
}

/* スマートフォン向けのレイアウトは mobile.css を参照
   （ui-prefs.js が media 属性を切り替えて スマホ版/PC版 の手動切替を実現する） */

/* =========================================================
   ===== ゲーミフィケーション =====
   XP / レベル / ミッション / チャレンジ（ボス戦・タイムアタック）/
   実績 / マイページ と、game-ui.js が生成する演出要素のスタイル。
   色は :root / :root[data-theme="dark"] の変数（--gold, --xp-fill-* など）を使う。
   ========================================================= */

/* ----- ヘッダー: 効果音切替ボタン（テーマ切替の左隣に横並び） ----- */
.icon-btn-second { right: 48px; }

/* ----- プレイヤーカード（ホーム画面上部。クリックでマイページへ） ----- */
.player-card {
  background: linear-gradient(135deg, var(--player-card-bg-1), var(--player-card-bg-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.player-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.pc-top { display: flex; align-items: center; gap: 14px; }
.pc-icon { font-size: 2.2rem; line-height: 1; flex-shrink: 0; }
.pc-main { flex: 1; min-width: 0; }
.pc-level-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  line-height: 1.4;
}
.pc-level { font-size: 1.15rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.pc-title { font-weight: 600; }
.pc-xp-text { font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.pc-side { text-align: right; flex-shrink: 0; line-height: 1.5; }
.streak-flame { font-weight: 700; font-size: 1rem; white-space: nowrap; }
.streak-flame.warning { color: var(--warn-text); }   /* 今日まだ学習していない */
.streak-flame.hot { font-size: 1.2rem; }             /* 7 日以上継続 */
.pc-today { font-size: 0.8rem; white-space: nowrap; }
.pc-hint { margin-top: 8px; font-size: 0.82rem; }
.pc-hint:empty { display: none; }

/* XP バー（プレイヤーカード / 結果画面 / マイページで共用） */
.xp-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0 4px;
}
.xp-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--xp-fill-1), var(--xp-fill-2));
  border-radius: 4px;
  transition: width 0.5s ease-out;
}

/* ----- パネル見出し（ミッション / チャレンジ） ----- */
.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.panel-heading h3 { margin: 0; font-size: 1rem; }

/* ----- 今日のミッション ----- */
.missions { margin-bottom: 18px; }
.mission-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mission-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
}
.mission-check {
  width: 1.3em;
  text-align: center;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--muted);
  flex-shrink: 0;
}
.mission-body { flex: 1; min-width: 0; }
.mission-label { font-size: 0.92rem; font-weight: 600; line-height: 1.5; }
.mission-progress {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 5px;
}
.mission-progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease-out;
}
.mission-count {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.mission-xp {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-bg);
  border: 1px solid var(--gold-border);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}
.mission-item.done { opacity: 0.65; }
.mission-item.done .mission-label { text-decoration: line-through; }
.mission-item.done .mission-check { color: var(--ok-text); }
.mission-item.done .mission-progress-fill { background: var(--ok-text); }

/* ----- チャレンジモード（ボス戦 / タイムアタック） ----- */
.challenge-panel {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.mode-desc { margin: 8px 0; font-size: 0.88rem; color: var(--muted); }
.boss-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.boss-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  color: inherit;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.2s, background-color 0.2s;
}
.boss-btn:active { transform: translateY(1px); }
.boss-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.boss-icon { font-size: 1.6rem; line-height: 1; flex-shrink: 0; }
.boss-body { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.boss-btn .boss-name { font-weight: 700; font-size: 0.9rem; }
.boss-domain { font-size: 0.75rem; }
.boss-wins {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
  flex-shrink: 0;
}
.boss-btn.defeated {
  border-color: var(--gold-border);
  box-shadow: inset 0 0 0 1px var(--gold-border);
}
.ta-btn { margin-top: 2px; }

/* ----- 問題画面: コンボバッジ ----- */
.combo-badge {
  display: inline-block;
  background: var(--combo-bg);
  color: var(--combo-text);
  border: 1px solid var(--combo-border);
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.6;
}
.combo-badge.hot {
  background: linear-gradient(90deg, #ef4444, #f97316);
  color: #fff;
  border-color: transparent;
  animation: pulse 1.2s ease-in-out infinite;
}

/* ----- 問題画面: バトル HUD（ボス戦） ----- */
.battle-hud {
  background: var(--hud-bg);
  color: var(--hud-text);
  border: 1px solid var(--hud-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 10px;
}
.boss-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}
.battle-hud .boss-name { font-weight: 700; }
.boss-hp-text { font-size: 0.85rem; opacity: 0.9; font-variant-numeric: tabular-nums; }
.boss-hp {
  height: 10px;
  background: var(--hud-track);
  border-radius: 5px;
  overflow: hidden;
  margin: 6px 0 8px;
}
.boss-hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--hp-fill-1), var(--hp-fill-2));
  border-radius: 5px;
  transition: width 0.4s ease-out;
}
.hearts { display: flex; gap: 4px; font-size: 1.1rem; line-height: 1; }
.heart { transition: opacity 0.3s, filter 0.3s; }
.heart.lost { filter: grayscale(1); opacity: 0.35; }

/* ----- 問題画面: タイマー HUD（タイムアタック） ----- */
.timer-hud { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.timer-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--timer-ok);
  border-radius: 4px;
  transition: width 0.3s linear, background-color 0.3s;
}
.timer-fill.warn { background: var(--timer-warn); }
.timer-fill.danger {
  background: var(--timer-danger);
  animation: blink 0.6s step-end infinite;
}
.timer-text {
  min-width: 3em;
  text-align: right;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.timer-hud:has(.timer-fill.danger) .timer-text { color: var(--ng-text); }

/* ----- フィードバック: XP 獲得表示 ----- */
.xp-gain {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.xp-total {
  display: inline-block;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--gold);
  line-height: 1.2;
  white-space: nowrap;
}
.xp-gain.xp-animate .xp-total { animation: xp-float 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.xp-gain.big .xp-total { font-size: 1.7rem; }
.xp-parts { font-size: 0.82rem; color: var(--muted); }

/* ----- 結果画面 ----- */
.result-top { display: flex; align-items: center; gap: 18px; margin-bottom: 14px; }
.result-main { flex: 1; min-width: 0; }
.result-main p { margin: 0 0 4px; }
.rank-badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  box-shadow: 0 2px 6px var(--shadow);
}
.rank-S {
  background: linear-gradient(135deg, #fde047, #f59e0b 55%, #d97706);
  color: #7c2d12;
  animation: glow 1.8s ease-in-out infinite;
}
.rank-A { background: linear-gradient(135deg, #a855f7, #3b82f6); }
.rank-B { background: var(--primary); }
.rank-C { background: var(--rank-c-bg); }
.rank-D { background: var(--rank-d-bg); }
.result-mode-note { font-weight: 700; }
.result-mode-note.win { color: var(--ok-text); }
.result-mode-note.lose { color: var(--ng-text); }

.result-xp {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--quote-bg);
}
.result-xp-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.result-xp .stat-value { color: var(--gold); }
.result-level { margin-top: 8px; }
.result-level .xp-bar { margin: 4px 0 0; }

.result-badges,
.result-missions { margin-bottom: 14px; }
.result-badges h3,
.result-missions h3 { margin: 0 0 6px; font-size: 0.95rem; }
.badge-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.badge-chip {
  display: inline-block;
  background: var(--gold-bg);
  color: var(--gold);
  border: 1px solid var(--gold-border);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ----- マイページ ----- */
.profile-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, var(--player-card-bg-1), var(--player-card-bg-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 14px 0;
}
.profile-hero .pc-icon { font-size: 2.6rem; }
#profile-screen > h3 { margin: 22px 0 8px; font-size: 1rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.stat-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
  background: var(--card-bg);
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat-label { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* スキルマップ（ドメイン行は太く、カテゴリ行は少しインデント） */
.skill-map { display: flex; flex-direction: column; gap: 10px; }
.skill-row { padding-left: 14px; }
.skill-row.domain-row { padding-left: 0; margin-top: 6px; }
.skill-row.domain-row:first-child { margin-top: 0; }
.skill-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.88rem;
  line-height: 1.5;
}
.skill-name { min-width: 0; }
.domain-row .skill-name { font-weight: 700; font-size: 0.95rem; }
.skill-stars { color: var(--gold); letter-spacing: 1px; white-space: nowrap; }
.skill-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0;
}
.domain-row .skill-bar { height: 10px; border-radius: 5px; }
.skill-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--skill-fill-1), var(--skill-fill-2));
  border-radius: inherit;
  transition: width 0.5s ease-out;
}
.skill-meta { font-size: 0.78rem; }

/* ボス戦記録 */
.boss-records { display: flex; flex-direction: column; gap: 8px; }
.boss-record {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
  line-height: 1.5;
}
.boss-record .boss-body { display: block; }
.boss-record .boss-name { font-weight: 700; }
.boss-record.defeated { border-color: var(--gold-border); background: var(--gold-soft-bg); }

/* 実績一覧 */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.badge-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
  background: var(--card-bg);
  transition: transform 0.15s, border-color 0.15s;
}
.badge-icon { font-size: 1.8rem; line-height: 1.2; }
.badge-name { font-weight: 700; font-size: 0.85rem; margin-top: 4px; line-height: 1.4; }
.badge-desc { font-size: 0.75rem; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.badge-date { font-size: 0.72rem; margin-top: 4px; }
.badge-card.locked { filter: grayscale(1); opacity: 0.5; }
.badge-card.locked .badge-icon { filter: blur(1.5px); }
.badge-card.new {
  border-color: var(--gold-border);
  background: var(--gold-soft-bg);
  box-shadow: 0 0 0 2px var(--gold-border);
}

/* ----- 演出: レベルアップのオーバーレイ ----- */
.overlay-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay-card {
  position: relative;
  z-index: 1; /* 紙吹雪レイヤーより手前 */
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.overlay-card.pop-in { animation: pop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.levelup-title {
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--gold);
}
.levelup-level {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.1;
  margin: 6px 0;
  color: var(--primary);
}
.levelup-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 18px; }
.overlay-root .confetti-layer { z-index: 0; }

/* ----- 演出: 紙吹雪 ----- */
.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 1200;
  pointer-events: none;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall 2s ease-in forwards;
}
.confetti-piece.round { width: 9px; height: 9px; border-radius: 50%; }

/* ----- 演出: トースト通知（右下） ----- */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 340px;
  pointer-events: none; /* 空きスペースはクリックを通す */
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  box-shadow: 0 4px 16px var(--toast-shadow);
  cursor: pointer;
  pointer-events: auto;
  animation: toast-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.toast.badge-toast { border-left-color: var(--gold-border); }
.toast.mission-toast { border-left-color: var(--ok-text); }
.toast.info-toast { border-left-color: var(--primary); }
.toast.toast-out { animation: toast-out 0.3s ease-in forwards; }
.toast-icon { font-size: 1.4rem; line-height: 1.2; flex-shrink: 0; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 700; }
.toast-text { color: var(--muted); font-size: 0.8rem; }

/* ----- 演出: コンボバナー（画面中央） ----- */
.combo-banner {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  z-index: 1050;
  width: max-content; /* 中央配置でも文言が途中で折り返さないようにする */
  max-width: 92vw;
  pointer-events: none;
  text-align: center;
  opacity: 0;
}
.combo-banner.show { animation: combo-pop 1.2s ease-out both; }
.combo-num {
  display: block;
  font-size: 4rem;
  font-weight: 900;
  line-height: 1;
  color: #f59e0b;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}
.combo-word {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--combo-word-text);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
/* 対応ブラウザではグラデーション文字にする */
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .combo-num {
    background: linear-gradient(180deg, #fde047, #f97316);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
  .levelup-level {
    background: linear-gradient(90deg, var(--xp-fill-1), var(--xp-fill-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}

/* ----- 演出: 揺れ ----- */
.shake { animation: shake 0.4s ease-in-out; }

/* ----- キーフレーム ----- */
@keyframes xp-float {
  0% { opacity: 0; transform: translateY(14px) scale(0.9); }
  60% { opacity: 1; transform: translateY(-4px) scale(1.08); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes combo-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  40% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1.05); }
}
@keyframes pop-in {
  0% { opacity: 0; transform: scale(0.7) translateY(12px); }
  100% { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px) scale(0.96); }
}
@keyframes confetti-fall {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotate(0deg); }
  100% { opacity: 0.9; transform: translate3d(var(--drift, 0px), 105vh, 0) rotate(720deg); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
@keyframes blink {
  50% { opacity: 0.35; }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 6px 1px rgba(245, 158, 11, 0.45); }
  50% { box-shadow: 0 0 20px 6px rgba(245, 158, 11, 0.75); }
}

/* ----- ホバー（マウス等のポインタがある環境のみ） ----- */
@media (hover: hover) and (pointer: fine) {
  .player-card:hover { border-color: var(--primary); }
  .boss-btn:hover { border-color: var(--primary); background: var(--hover-bg); }
  .badge-card:hover:not(.locked) { transform: translateY(-2px); border-color: var(--primary); }
  .toast:hover { border-color: var(--primary); }
}

/* ----- 視差効果を減らす設定: アニメーションを止めて即時表示にする ----- */
@media (prefers-reduced-motion: reduce) {
  .xp-gain.xp-animate .xp-total,
  .combo-banner.show,
  .overlay-card.pop-in,
  .toast,
  .toast.toast-out,
  .confetti-piece,
  .shake,
  .combo-badge.hot,
  .timer-fill.danger,
  .rank-S {
    animation: none !important;
  }
  .combo-banner.show { opacity: 1; }
  .toast.toast-out { opacity: 0; }
  .xp-fill,
  .boss-hp-fill,
  .timer-fill,
  .mission-progress-fill,
  .skill-fill,
  .heart,
  .player-card,
  .boss-btn,
  .badge-card {
    transition: none !important;
  }
}

/* =====================================================================
   OSA 模擬試験（スタート画面の入口・受験画面・スコアカード）
   状態は色だけでなく文字・記号でも示す（✓ / − / 🚩、合格 / 不合格、要復習）
   ===================================================================== */
/* 画面には表示せず、スクリーンリーダーにだけ読ませる */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.btn.danger { background: var(--wrong-border); color: #fff; }
.btn:focus-visible,
.exam-grid-btn:focus-visible,
.exam-history-btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ----- スタート画面の入口パネル ----- */
.exam-panel {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  background: var(--hover-bg);
}
.exam-rules { margin: 8px 0 12px; font-size: 0.88rem; }
.exam-resume {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  background: var(--warn-bg);
}
.exam-resume-text { margin: 0 0 8px; font-weight: 700; color: var(--warn-text); }
.exam-history-heading { margin: 14px 0 6px; font-size: 0.92rem; }
.exam-history { list-style: none; margin: 0; padding: 0; }
.exam-history li + li { margin-top: 6px; }
.exam-history-btn {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: inherit;
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}
.exam-history-empty { font-size: 0.88rem; color: var(--muted); }

/* 合否のラベル（文字と色の両方で示す） */
.pass-badge,
.fail-badge {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid;
}
.pass-badge { color: var(--ok-text); background: var(--correct-bg); border-color: var(--correct-border); }
.fail-badge { color: var(--ng-text); background: var(--wrong-bg); border-color: var(--wrong-border); }

/* ----- 受験画面 ----- */
.exam-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 10px 14px;
  margin: -4px 0 14px;
  border-radius: 10px;
  background: var(--hud-bg);
  color: var(--hud-text);
  font-size: 0.9rem;
}
.exam-title { margin: 0 auto 0 0; font-size: 1rem; color: inherit; }
.exam-bar-item { white-space: nowrap; }
.exam-timer {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 2px 10px;
  border-radius: 999px;
  border: 2px solid var(--timer-ok);
  white-space: nowrap;
}
/* 残り 10 分で警告色、5 分で強調 */
.exam-timer.warn { border-color: var(--timer-warn); color: var(--timer-warn); }
.exam-timer.danger { border-color: var(--timer-danger); background: var(--timer-danger); color: #fff; font-size: 1.05rem; }
.exam-question:focus { outline: none; }
.exam-question:focus-visible { outline: 2px dashed var(--primary); outline-offset: 4px; }
.exam-choices { border: none; margin: 18px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.exam-choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  cursor: pointer;
  line-height: 1.6;
  font-size: 0.95rem;
}
.exam-choice input { margin-top: 0.3em; width: 1.1em; height: 1.1em; flex: 0 0 auto; accent-color: var(--primary); }
.exam-choice:has(input:checked) { border-color: var(--primary); background: var(--selected-bg); box-shadow: inset 0 0 0 1px var(--primary); }
.exam-choice:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
.exam-choice-label { font-weight: 700; }
.exam-nav { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; }
.exam-mark-btn[aria-pressed="true"] { background: var(--warn-bg); color: var(--warn-text); border: 2px solid var(--warn-border); font-weight: 700; }
.exam-tools { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border); }
.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.exam-grid-btn {
  padding: 6px 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: inherit;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.exam-grid-btn.answered { background: var(--correct-bg); border-color: var(--correct-border); }
.exam-grid-btn.marked { background: var(--warn-bg); border-color: var(--warn-border); }
.exam-grid-btn.current { border-width: 3px; border-color: var(--primary); font-weight: 700; }
.exam-legend { font-size: 0.8rem; margin: 8px 0 0; }

/* ----- スコアカード ----- */
.scorecard-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--thead-bg);
}
.scorecard-score { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.scorecard-score small { font-size: 1rem; font-weight: 600; color: var(--muted); }
.scorecard-verdict .pass-badge,
.scorecard-verdict .fail-badge { font-size: 1.1rem; padding: 3px 14px; }
.scorecard-meta { margin: 0; padding: 0; list-style: none; font-size: 0.88rem; }
.scorecard-meta li { margin: 2px 0; }
.scorecard-note { width: 100%; margin: 0; font-size: 0.85rem; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.score-table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* 80% 未満の分野（色に加えて「要復習」の文字を添える） */
.score-table tr.below-line td { background: var(--wrong-bg); }
.below-line-tag { margin-left: 6px; font-size: 0.78rem; font-weight: 700; color: var(--ng-text); white-space: nowrap; }
.weak-list { margin: 6px 0; padding-left: 1.3em; }
.weak-list li { margin: 4px 0; }
.scorecard-filter { display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 10px; font-size: 0.9rem; cursor: pointer; }
.review-item {
  border: 1px solid var(--border);
  border-left-width: 6px;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 10px 0;
}
.review-item.full { border-left-color: var(--correct-border); }
.review-item.partial { border-left-color: var(--warn-border); }
.review-item.zero { border-left-color: var(--wrong-border); }
.review-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 0.85rem; }
.review-status { font-weight: 700; }
.review-item.full .review-status { color: var(--ok-text); }
.review-item.partial .review-status { color: var(--warn-text); }
.review-item.zero .review-status { color: var(--ng-text); }
.review-question { margin: 8px 0; font-weight: 600; white-space: pre-line; }
.review-choices { list-style: none; margin: 6px 0; padding: 0; font-size: 0.9rem; }
.review-choices li { margin: 4px 0; padding: 4px 8px; border-radius: 6px; border: 1px solid transparent; }
.review-choices li.is-correct { background: var(--correct-bg); border-color: var(--correct-border); }
.review-choices li.is-wrong-pick { background: var(--wrong-bg); border-color: var(--wrong-border); }
.review-mark { font-size: 0.78rem; font-weight: 700; margin-left: 6px; white-space: nowrap; }
.review-explanation { font-size: 0.9rem; margin: 8px 0 0; white-space: pre-line; }
