/*
 * materials-common.css
 * さんすうひろば 教材共通スタイル
 *
 * ━━ 使い方 ━━
 * 各教材HTMLの <head> 内に以下を記述し、
 * その後の <style> でテーマカラーをオーバーライドする。
 *
 *   <link rel="stylesheet" href="/css/materials-common.css">
 *   <style>
 *     :root {
 *       --theme-primary: #1a8cd8;
 *       --theme-bg: linear-gradient(...);
 *       ...
 *     }
 *     （この教材固有のスタイルをここに書く）
 *   </style>
 */

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   CSS変数（テーマカラーのデフォルト値）
   各教材の <style> 内で :root を使ってオーバーライドする
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
:root {
  --theme-primary: #ff6b9d;           /* メインカラー（タイトル・レッスン見出し等） */
  --theme-bg: linear-gradient(135deg, #ffe0ec 0%, #fff5cc 50%, #d4f5ee 100%); /* 背景 */
  --theme-card-shadow: rgba(255,107,157,0.2); /* タイトルカードの影 */
  --theme-speech-bg: #fff5cc;         /* 吹き出しの背景色 */
  --theme-speech-border: #ffd93d;     /* 吹き出しの枠色 */
  --theme-score-grad: linear-gradient(90deg, #ffd93d, #ff9eb5); /* スコアバーのグラデーション */
  --theme-ctrl-bg: #4ecdc4;           /* コントロールボタンのデフォルト色 */
  --theme-ctrl-shadow: #2c9a92;       /* コントロールボタンの影 */
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   カテゴリバッジ（教材のホーム画面の タイトル上に表示）
   4カテゴリ：計算 / 図形 / データの活用 / 変化と関係
   配色は lib/materials.ts の categories と一致させる
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.category-badge {
  display: inline-block;
  font-size: clamp(13px, 1.8vw, 16px);
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 10px;
  letter-spacing: 0.05em;
  line-height: 1.4;
  border: 2px solid currentColor;
  background: #fff;
}
.category-badge.cat-keisan { color: #e65100; background: #fff3e0; }
.category-badge.cat-zukei  { color: #1565c0; background: #e3f2fd; }
.category-badge.cat-data   { color: #2e7d32; background: #e8f5e9; }
.category-badge.cat-henka  { color: #6a1b9a; background: #f3e5f5; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   リセット・基本
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ふりがな（<ruby>）の見え方
   ボタンや見出し内で 行送りが大きく崩れないように調整
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
ruby {
  ruby-align: center;
}
ruby rt {
  font-size: 0.5em;       /* ふりがなを 親の半分の大きさに */
  font-weight: 500;       /* 親が900でもふりがなは標準寄り */
  letter-spacing: 0;
  line-height: 1;         /* ふりがな自身は行送りを増やさない */
  user-select: none;
}

html, body {
  height: 100%;
  overflow: hidden;
  /* UD フォント（CLAUDE.md ルール準拠） */
  font-family: "BIZ UDPGothic", "BIZ UDGothic", "UDデジタル教科書体 NK-R", "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN W4", "Meiryo", sans-serif;
  background: var(--theme-bg);
  color: #3d3d5c;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   アプリコンテナ・画面管理
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
#app {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
}

.screen { display: none; max-width: 900px; margin: 0 auto; }
.screen.active { display: block; animation: fadeIn 0.4s ease; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   アニメーション
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@keyframes fadeIn  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop     { 0% { transform: scale(0.8); } 50% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes shake   { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes bounce  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   タイトル画面
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.title-card {
  background: white;
  border-radius: 30px;
  padding: 40px 30px;
  box-shadow: 0 10px 40px var(--theme-card-shadow);
  text-align: center;
}

/* UD準拠：タイトル文字 */
.main-title {
  font-size: clamp(30px, 5.5vw, 48px);
  font-weight: 900;
  color: var(--theme-primary);
  margin-bottom: 10px;
  text-shadow: 3px 3px 0 #ffd93d;
  letter-spacing: 2px;
}

.sub-title {
  font-size: clamp(18px, 2.8vw, 24px);
  color: #6c7293;
  margin-bottom: 30px;
  font-weight: 700;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin-top: 20px;
}

.menu-btn {
  border: none;
  border-radius: 24px;
  padding: 28px 16px;
  font-size: clamp(18px, 2.8vw, 24px);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  color: white;
  font-family: inherit;
  box-shadow: 0 6px 0 rgba(0,0,0,0.15);
}
.menu-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }
.menu-btn .emoji { display: block; font-size: 1.8em; margin-bottom: 8px; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   レッスンカード共通
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.lesson-card {
  background: white;
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.08);
  margin-bottom: 20px;
}

.lesson-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

/* UD準拠：レッスン見出し */
.lesson-title {
  font-size: clamp(22px, 3.6vw, 32px);
  font-weight: 900;
  color: var(--theme-primary);
}

/* もどるボタン（全教材共通・完全一致） */
.back-btn {
  background: #ffd93d;
  border: none;
  border-radius: 50px;
  padding: 12px 24px;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  color: #3d3d5c;
  font-family: inherit;
  box-shadow: 0 4px 0 #d4a800;
  white-space: nowrap;
}
.back-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #d4a800; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   吹き出し（UD準拠）
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.speech {
  background: var(--theme-speech-bg);
  border-radius: 20px;
  padding: 24px 28px;       /* UD: 24px以上 */
  margin-bottom: 16px;
  font-size: clamp(22px, 3.2vw, 28px);  /* UD: 22px以上 */
  line-height: 2.0;          /* UD: 2.0以上 */
  position: relative;
  border: 4px solid var(--theme-speech-border);  /* UD: 4px以上 */
  letter-spacing: 0.05em;    /* UD: 0.05em */
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ステージ（図・アニメーション表示エリア）
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.stage {
  background: #f4f8ff;
  border-radius: 20px;
  padding: 16px;
  text-align: center;
  margin: 14px 0;
  border: 2px dashed #a8ccee;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   コントロール・ボタン
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 14px 0;
}

.ctrl-btn {
  background: var(--theme-ctrl-bg);
  border: none;
  border-radius: 50px;
  padding: 14px 26px;
  font-size: clamp(17px, 2.4vw, 21px);
  font-weight: 800;
  color: white;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 0 var(--theme-ctrl-shadow);
}
.ctrl-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--theme-ctrl-shadow); }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   クイズ選択肢（UD準拠）
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}

/* UD準拠：選択肢ボタン */
.quiz-option {
  background: white;
  border: 5px solid #a8ccee;    /* UD: 4px以上 */
  border-radius: 18px;
  padding: 15px 22px;            /* 横の余白は キープ、縦を つめて 4択を 低くする */
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  text-align: center;
  font-size: clamp(20px, 3vw, 26px);  /* UD: 20px以上 */
  font-weight: 700;
  color: #3d3d5c;
  line-height: 1.6;             /* UD: 1.6以上 */
}
/* 選択肢が「図（角の絵など）」のとき、縦に 大きく なりすぎないよう 高さを おさえる */
.quiz-option svg { max-height: 108px; width: auto; display: block; margin: 0 auto; }
.quiz-option:active  { transform: scale(0.97); }
.quiz-option.correct { border-color: #4ecdc4; background: #d4f5ee; animation: pop 0.4s; }
.quiz-option.wrong   { border-color: #ff6b9d; background: #ffe0ec; animation: shake 0.4s; }
.quiz-option.disabled { pointer-events: none; opacity: 0.6; }

.quiz-option .label {
  display: inline-block;
  background: #ffd93d;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  line-height: 44px;
  font-weight: 900;
  color: #3d3d5c;
  margin-bottom: 10px;
  font-size: 22px;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   フィードバック（UD準拠）
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.feedback {
  text-align: center;
  font-size: clamp(26px, 4.2vw, 36px);  /* UD: 26px以上 */
  font-weight: 900;
  margin: 14px 0;
  min-height: 50px;                       /* UD: 50px以上 */
}
.feedback.ok { color: #4ecdc4; animation: bounce 0.6s; }
.feedback.ng { color: #ff6b9d; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   スコアバー・進捗
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.score-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--theme-score-grad);
  color: white;
  border-radius: 50px;
  padding: 12px 24px;
  margin-bottom: 16px;
  font-weight: 800;
  font-size: clamp(17px, 2.4vw, 21px);
  box-shadow: 0 4px 0 rgba(0,0,0,0.12);
}

.progress {
  background: rgba(255,255,255,0.4);
  border-radius: 50px;
  height: 14px;
  flex: 1;
  margin: 0 14px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: white;
  border-radius: 50px;
  transition: width 0.4s;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   結果画面
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.result-card {
  background: white;
  border-radius: 30px;
  padding: 36px 24px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}
.result-card .big {
  font-size: clamp(50px, 10vw, 84px);
  font-weight: 900;
  color: var(--theme-primary);
  text-shadow: 3px 3px 0 #ffd93d;
  margin: 14px 0;
}
.stars { font-size: clamp(40px, 7vw, 60px); margin: 10px 0; letter-spacing: 6px; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ヒント・補足（UD準拠）
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.hint {
  font-size: clamp(18px, 2.6vw, 22px);  /* UD: 18px以上 */
  color: #4a4a6a;                         /* UD: 薄すぎない色 */
  margin-top: 8px;
  font-weight: 600;
  line-height: 1.9;                       /* UD: 1.9以上 */
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   iPad横画面（ランドスケープ）共通対応
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@media (orientation: landscape) {
  #app {
    padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  }
  .screen { max-width: 1100px; }

  /* タイトル画面 */
  .title-card  { padding: 22px 30px; }
  .main-title  { font-size: clamp(26px, 4.2vw, 42px); margin-bottom: 6px; }
  .sub-title   { font-size: clamp(15px, 2vw, 20px); margin-bottom: 14px; }
  .menu-grid   { grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 12px; }
  .menu-btn    { padding: 18px 10px; font-size: clamp(15px, 2vw, 20px); }
  .menu-btn .emoji { font-size: 1.4em; margin-bottom: 4px; }

  /* レッスンカード */
  .lesson-card   { padding: 16px 22px; margin-bottom: 12px; border-radius: 22px; }
  .lesson-header { margin-bottom: 12px; }
  .lesson-title  { font-size: clamp(19px, 2.8vw, 28px); }
  .back-btn      { padding: 9px 20px; font-size: 16px; }

  /* 吹き出し */
  .speech {
    padding: 14px 20px;
    margin-bottom: 10px;
    font-size: clamp(17px, 2.1vw, 21px);
    line-height: 1.9;
    border-radius: 16px;
    letter-spacing: 0.05em;
  }

  /* ステージ */
  .stage { padding: 10px; margin: 8px 0; border-radius: 16px; }

  /* コントロール */
  .controls { margin: 8px 0; gap: 8px; }
  .ctrl-btn  { padding: 10px 20px; font-size: clamp(14px, 1.9vw, 18px); }

  /* クイズ */
  .quiz-options { gap: 10px; margin-top: 10px; }
  .quiz-option  { padding: 14px; border-width: 4px; font-size: clamp(17px, 2vw, 21px); line-height: 1.6; }
  .quiz-option .label { width: 36px; height: 36px; line-height: 36px; font-size: 18px; margin-bottom: 5px; }

  /* フィードバック */
  .feedback { font-size: clamp(20px, 2.8vw, 26px); margin: 6px 0; min-height: 44px; }

  /* スコアバー */
  .score-bar { padding: 9px 18px; margin-bottom: 10px; font-size: clamp(14px, 2vw, 18px); }
  .progress  { height: 11px; }

  /* ヒント */
  .hint { font-size: clamp(15px, 1.8vw, 19px); line-height: 1.9; }

  /* 結果 */
  .result-card      { padding: 22px; }
  .result-card .big { font-size: clamp(40px, 7vw, 64px); margin: 8px 0; }
  .stars            { font-size: clamp(30px, 5.5vw, 48px); margin: 6px 0; }
}

/* iPad mini等、横画面で高さがとくに狭い場合 */
@media (orientation: landscape) and (max-height: 720px) {
  .speech   { font-size: 15px; line-height: 1.8; padding: 10px 16px; }
  .menu-btn { padding: 12px 8px; }
  .ctrl-btn { padding: 7px 12px; }
}
