/* ============================================================
   中学数学 まるごとテキスト 共通スタイル
   - 画面用 + 印刷用 (@media print)
   - 5分野: 数と式(青) / 方程式(紫) / 関数(緑) / 図形(橙) / データ(赤)
   - iPad 最低限配慮（pointer:coarse, dvh, viewport-fit）
   ============================================================ */

:root {
  --c-bg: #fbfaf6;
  --c-paper: #ffffff;
  --c-ink: #222;
  --c-sub: #555;
  --c-line: #d8d3c4;

  /* 共通アクセント（後で分野色で上書き） */
  --c-accent: #2c6fbb;
  --c-accent-light: #e7f0fa;
  --c-accent-dark: #1f5187;

  /* 5分野カラー */
  --c-num:  #2c6fbb;   --c-num-light:  #e7f0fa;   --c-num-dark:  #1f5187;  /* 数と式：青 */
  --c-eq:   #9a4ec0;   --c-eq-light:   #f3e8ff;   --c-eq-dark:   #6b2d8a;  /* 方程式：紫 */
  --c-fn:   #2a7a3a;   --c-fn-light:   #e7f5ea;   --c-fn-dark:   #176a44;  /* 関数：緑 */
  --c-geo:  #d97706;   --c-geo-light:  #fdf3e2;   --c-geo-dark:  #a05604;  /* 図形：橙 */
  --c-data: #c0392b;   --c-data-light: #fdecea;   --c-data-dark: #922b21;  /* データ：赤 */

  --c-warn: #b94a48;
  --c-ok:   #2a7a3a;
  --c-note: #e0bb1f;

  --font-jp: "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-en: "Georgia", "Times New Roman", serif;
}

/* 分野ごとのアクセント色上書き */
body.subject-num  { --c-accent: var(--c-num);  --c-accent-light: var(--c-num-light);  --c-accent-dark: var(--c-num-dark); }
body.subject-eq   { --c-accent: var(--c-eq);   --c-accent-light: var(--c-eq-light);   --c-accent-dark: var(--c-eq-dark); }
body.subject-fn   { --c-accent: var(--c-fn);   --c-accent-light: var(--c-fn-light);   --c-accent-dark: var(--c-fn-dark); }
body.subject-geo  { --c-accent: var(--c-geo);  --c-accent-light: var(--c-geo-light);  --c-accent-dark: var(--c-geo-dark); }
body.subject-data { --c-accent: var(--c-data); --c-accent-light: var(--c-data-light); --c-accent-dark: var(--c-data-dark); }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-jp);
  line-height: 1.8;
  font-size: 16px;
  min-height: 100vh;
  min-height: 100dvh;  /* iOS Safari の URL バー対応 */
}

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 28px 100px;
  background: var(--c-paper);
  min-height: 100vh;
  min-height: 100dvh;
  box-shadow: 0 0 24px rgba(0,0,0,.05);
}

/* ---------- ナビ ---------- */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--c-line);
  padding-bottom: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 8px;
}
.top-nav .home-link {
  color: var(--c-accent);
  text-decoration: none;
  font-weight: bold;
}
.top-nav .home-link:hover { text-decoration: underline; }
.subject-badge {
  background: var(--c-accent);
  color: white;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: bold;
}

h1.book-title { font-size: 28px; margin: 0 0 8px; letter-spacing: 1px; }
.book-sub { color: var(--c-sub); margin-top: 0; }

/* ---------- 目次 ---------- */
.toc {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  margin: 24px 0 40px;
}
.toc li a {
  display: block;
  padding: 14px 18px;
  background: var(--c-accent-light);
  border-left: 4px solid var(--c-accent);
  color: var(--c-ink);
  text-decoration: none;
  border-radius: 4px;
  transition: background .15s;
}
.toc li a:hover { background: rgba(0,0,0,.04); }
.toc .unit-no {
  display: inline-block;
  font-weight: bold;
  color: var(--c-accent);
  margin-right: 8px;
  font-family: var(--font-en);
  min-width: 60px;
}

/* 5分野カード */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 24px 0;
}
.subject-card {
  display: block;
  padding: 24px 20px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--c-ink);
  border-left: 6px solid;
  transition: transform .15s;
}
.subject-card:hover, .subject-card:active { transform: translateY(-2px); }
.subject-card .name { font-size: 22px; font-weight: bold; margin-bottom: 6px; }
.subject-card .sub  { font-size: 13px; color: var(--c-sub); }
.subject-card.num  { background: var(--c-num-light);  border-color: var(--c-num); }
.subject-card.num  .name { color: var(--c-num); }
.subject-card.eq   { background: var(--c-eq-light);   border-color: var(--c-eq); }
.subject-card.eq   .name { color: var(--c-eq); }
.subject-card.fn   { background: var(--c-fn-light);   border-color: var(--c-fn); }
.subject-card.fn   .name { color: var(--c-fn); }
.subject-card.geo  { background: var(--c-geo-light);  border-color: var(--c-geo); }
.subject-card.geo  .name { color: var(--c-geo); }
.subject-card.data { background: var(--c-data-light); border-color: var(--c-data); }
.subject-card.data .name { color: var(--c-data); }

/* ---------- 単元本体 ---------- */
.unit {
  border-top: 3px solid var(--c-accent);
  padding-top: 24px;
  margin-top: 60px;
  /* 古い iPad のスクロール軽減 */
  content-visibility: auto;
  contain-intrinsic-size: auto 800px;
}
.unit h2 {
  font-size: 26px;
  margin: 0 0 8px;
  color: var(--c-accent);
}
.unit .goal {
  background: #fff8df;
  border-left: 4px solid var(--c-note);
  padding: 12px 16px;
  margin: 16px 0 28px;
  border-radius: 4px;
  font-size: 15px;
}
.unit .goal::before { content: "🎯 この単元のゴール: "; font-weight: bold; }

.unit h3 {
  font-size: 21px;
  margin: 40px 0 14px;
  padding: 8px 0 4px;
  border-bottom: 2px solid var(--c-accent);
}
.unit h4 { font-size: 17px; margin: 24px 0 10px; color: var(--c-accent-dark); }

/* ---------- 解説枠 ---------- */
.explain {
  background: #fafafa;
  padding: 16px 20px;
  border-radius: 8px;
  margin: 12px 0;
  border: 1px solid var(--c-line);
}
.explain p { margin: 8px 0; }

.lead { font-size: 16px; color: var(--c-sub); margin: 8px 0 16px; }

.note { font-size: 14px; color: var(--c-sub); margin-top: 8px; }
.note::before { content: "📝 "; }

/* ---------- 図カード（SVG主役） ---------- */
.figure {
  background: white;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  padding: 16px;
  margin: 20px 0;
  text-align: center;
  /* 古い iPad で SVG が多いページの描画軽減 */
  content-visibility: auto;
  contain-intrinsic-size: auto 320px;
}
.figure svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}
.figure .caption {
  margin-top: 8px;
  font-size: 14px;
  color: var(--c-sub);
  text-align: center;
}
.figure .fig-no {
  display: inline-block;
  background: var(--c-accent);
  color: white;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: bold;
  font-family: var(--font-en);
  margin-bottom: 8px;
}
.figure.wide { background: var(--c-accent-light); border-color: var(--c-accent); }

/* ---------- コラム（5種） ---------- */
.column {
  background: #fff8df;
  border-left: 6px solid var(--c-note);
  padding: 16px 20px;
  margin: 24px 0;
  border-radius: 4px 8px 8px 4px;
}
.column h4 { margin: 0 0 8px; color: #876200; font-size: 17px; }
.column h4::before { content: "💡 "; }
.column p { margin: 6px 0; }

/* ✨ 目からウロコ（紫） */
.column.aha { background: #f3e8ff; border-left-color: #9a4ec0; }
.column.aha h4 { color: #6b2d8a; }
.column.aha h4::before { content: "✨ "; }

/* 💎 本質を見抜く / 数学者の目（緑） */
.column.insight { background: #e7f5ea; border-left-color: #2a7a3a; }
.column.insight h4 { color: #176a44; }
.column.insight h4::before { content: "💎 "; }

/* ⚠ よくある間違い（赤） */
.column.warn { background: #fff0f0; border-left-color: #b94a48; }
.column.warn h4 { color: #8a2a28; }
.column.warn h4::before { content: "⚠️ "; }

/* 🔁 別解（ピンク／旧 video 枠の転用） */
.column.alt { background: #fff0fa; border-left-color: #c879c8; }
.column.alt h4 { color: #8a2a8a; }
.column.alt h4::before { content: "🔁 "; }

/* ---------- 数式・解法ステップ ---------- */

/* インライン数式枠（コピペで電卓検算しやすく） */
.formula {
  display: inline-block;
  font-family: var(--font-en);
  background: #f7f7f2;
  border: 1px solid var(--c-line);
  border-radius: 4px;
  padding: 1px 8px;
  margin: 0 2px;
  font-size: 1.02em;
  white-space: nowrap;
}
.formula.block {
  display: block;
  padding: 10px 14px;
  margin: 10px auto;
  text-align: center;
  font-size: 1.1em;
  white-space: normal;
}
.formula .hl     { background: #fff3a3; padding: 0 3px; border-radius: 3px; }
.formula .hl-red { background: #ffd4d0; color: #8a2a28; padding: 0 3px; border-radius: 3px; }
.formula .hl-blu { background: #d6e8fb; color: #1f5187; padding: 0 3px; border-radius: 3px; }
.formula .hl-grn { background: #d6efdd; color: #176a44; padding: 0 3px; border-radius: 3px; }

/* 分数表示 */
.frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  font-size: .85em;
  margin: 0 2px;
  line-height: 1.1;
}
.frac > .num { border-bottom: 1.2px solid currentColor; padding: 0 4px 1px; }
.frac > .den { padding: 1px 4px 0; }

/* 解法ステップ */
.solution-steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 12px 0;
  border-left: 3px solid var(--c-accent);
  background: #fafafa;
  border-radius: 0 6px 6px 0;
}
.solution-steps > li {
  position: relative;
  padding: 10px 14px 10px 50px;
  border-bottom: 1px dotted var(--c-line);
  counter-increment: step;
}
.solution-steps > li:last-child { border-bottom: none; }
.solution-steps > li::before {
  content: "Step " counter(step);
  position: absolute;
  left: 8px;
  top: 12px;
  background: var(--c-accent);
  color: white;
  font-family: var(--font-en);
  font-size: 11px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  line-height: 1;
}
.solution-steps .why {
  display: block;
  font-size: 13px;
  color: var(--c-sub);
  margin-top: 4px;
}
.solution-steps .why::before { content: "↳ なぜ? "; color: var(--c-accent); font-weight: bold; }

/* 「解法ステップ」ボタン */
.steps-toggle {
  background: var(--c-accent);
  color: white;
  border: none;
  padding: 4px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-left: 4px;
}
.steps-toggle:hover, .steps-toggle:active { background: var(--c-accent-dark); }
.steps-row {
  display: none;
  margin-top: 8px;
}
.steps-row.show { display: block; }

/* ---------- 用語ボックス ---------- */
.term-box {
  border: 1px solid var(--c-line);
  border-radius: 6px;
  padding: 14px 18px;
  margin: 16px 0;
  background: #fff;
}
.term-box h4 { margin-top: 0; color: var(--c-accent); }
.term-list { list-style: none; padding: 0; margin: 0; }
.term-list li {
  display: flex;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dotted var(--c-line);
}
.term-list li:last-child { border-bottom: none; }
.term-list .term {
  font-weight: bold;
  color: var(--c-accent);
  min-width: 120px;
}
.term-list .ruby { font-size: 11px; color: var(--c-sub); display: block; }
.term-list .desc { flex: 1; font-size: 14px; }

/* ---------- 練習問題（紙ベース） ---------- */
.drill {
  background: #fff;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  padding: 18px 22px;
  margin: 20px 0;
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}
.drill > h4 {
  margin-top: 0;
  color: var(--c-accent);
  border-bottom: 1px solid var(--c-accent-light);
  padding-bottom: 6px;
}
.drill ol { padding-left: 24px; }
.drill li { margin: 16px 0; line-height: 2.0; }
.drill .qid {
  display: inline-block;
  background: var(--c-accent-light);
  color: var(--c-accent);
  padding: 1px 8px;
  border-radius: 4px;
  font-family: var(--font-en);
  font-size: 12px;
  font-weight: bold;
  margin-right: 4px;
  cursor: pointer;
}
.drill .qid:hover, .drill .qid:active { background: var(--c-accent); color: white; }

/* インライン ⭕❌❓ ボタン */
.qid-actions {
  display: inline-flex;
  gap: 3px;
  margin-right: 8px;
  vertical-align: middle;
}
.qid-actions .qm {
  width: 26px;
  height: 22px;
  border: 1.5px solid;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  line-height: 1;
  transition: all .12s;
}
.qid-actions .qm-o { border-color: var(--c-ok); }
.qid-actions .qm-o:hover, .qid-actions .qm-o:active { background: #e7f5ea; }
.qid-actions .qm-x { border-color: var(--c-warn); }
.qid-actions .qm-x:hover, .qid-actions .qm-x:active { background: #fff0f0; }
.qid-actions .qm-q { border-color: #888; }
.qid-actions .qm-q:hover, .qid-actions .qm-q:active { background: #f5f5f5; }

/* 記録済み問題行のハイライト */
.drill li.rec-o {
  background: linear-gradient(to right, #e7f5ea 0%, #e7f5ea 4px, transparent 4px);
  padding-left: 8px; margin-left: -8px; border-radius: 3px;
}
.drill li.rec-x {
  background: linear-gradient(to right, #fff0f0 0%, #fff0f0 4px, transparent 4px);
  padding-left: 8px; margin-left: -8px; border-radius: 3px;
}
.drill li.rec-q {
  background: linear-gradient(to right, #f5f5f5 0%, #f5f5f5 4px, transparent 4px);
  padding-left: 8px; margin-left: -8px; border-radius: 3px;
}

/* 戻りリンク */
.return-link {
  display: inline-block;
  margin: 6px 0 0;
  padding: 4px 12px;
  background: #f3e8ff;
  border-left: 3px solid #9a4ec0;
  border-radius: 0 4px 4px 0;
  color: #6b2d8a;
  text-decoration: none;
  font-size: 12px;
  font-weight: bold;
}
.return-link:hover, .return-link:active { background: #9a4ec0; color: white; }
.return-link::before { content: "💡 "; }

/* 入試頻出マーカー */
.exam-hot {
  display: inline-block;
  background: linear-gradient(135deg, #ffd54f, #ff8800);
  color: white;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: bold;
  margin-right: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.exam-hot::before { content: "⭐ "; }

/* 再挑戦リスト */
.retry-group {
  background: white;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
}
.retry-group h4 {
  margin: 0 0 10px;
  color: var(--c-warn);
  font-size: 14px;
  border-bottom: 1px solid #f8d7d3;
  padding-bottom: 6px;
}
.retry-list {
  list-style: none; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
}
.retry-list li { border-radius: 4px; }
.retry-list li.retry-stuck { background: #fff0f0; border-left: 3px solid var(--c-warn); }
.retry-list li.retry-trying { background: #fff8df; border-left: 3px solid var(--c-note); }
.retry-list li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  text-decoration: none;
  color: var(--c-ink);
  font-size: 13px;
}
.retry-list li a:hover { background: rgba(0,0,0,.04); }
.retry-list .retry-qid { font-family: var(--font-en); font-weight: bold; color: var(--c-warn); }
.retry-list .retry-mark { font-size: 14px; }
.retry-list .retry-state { margin-left: auto; font-size: 11px; color: var(--c-sub); }

/* 書き込み欄 */
.write-line {
  display: inline-block;
  border-bottom: 1.5px solid #333;
  min-width: 80px;
  height: 1.3em;
  vertical-align: bottom;
  margin: 0 4px;
}
.write-line.wide { display: block; width: 100%; margin: 6px 0; min-width: auto; }
.write-line.tall { height: 2.6em; }

.choice {
  display: inline-block;
  margin: 0 14px 0 0;
}
.choice::before { content: "（  ） "; }

.q-show {
  background: #888;
  color: white;
  border: none;
  padding: 4px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-left: 4px;
}
.q-show:hover, .q-show:active { background: #555; }

.answer-row {
  display: none;
  background: #f0f8f0;
  padding: 8px 12px;
  margin-top: 8px;
  border-left: 3px solid var(--c-ok);
  font-size: 14px;
  border-radius: 0 4px 4px 0;
}
.answer-row.show { display: block; }
.answer-row strong { color: var(--c-ok); }

/* ---------- ⭕×記録ウィジェット（フローティング） ---------- */
.record-toggle {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: var(--c-accent);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  z-index: 999;
}
.record-toggle:hover, .record-toggle:active { transform: scale(1.05); }

.record-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 320px;
  background: white;
  border: 2px solid var(--c-accent);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  z-index: 1000;
  display: none;
}
.record-panel.show { display: block; }
.record-panel h4 { margin: 0 0 10px; color: var(--c-accent); font-size: 15px; }
.record-panel .close-btn {
  position: absolute;
  top: 8px; right: 10px;
  background: none; border: none;
  font-size: 18px; cursor: pointer; color: #999;
}
.record-panel .qid-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--c-line);
  border-radius: 4px;
  font-size: 14px;
  font-family: var(--font-en);
  margin-bottom: 10px;
  box-sizing: border-box;
}
.record-panel .qid-hint { font-size: 11px; color: var(--c-sub); margin: -6px 0 8px; }
.record-panel .result-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}
.record-panel .result-buttons button {
  padding: 10px;
  border: 2px solid;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
}
.record-panel .btn-correct { border-color: var(--c-ok); color: var(--c-ok); }
.record-panel .btn-correct:hover, .record-panel .btn-correct:active { background: #e7f5ea; }
.record-panel .btn-wrong   { border-color: var(--c-warn); color: var(--c-warn); }
.record-panel .btn-wrong:hover, .record-panel .btn-wrong:active { background: #fff0f0; }
.record-panel .btn-unknown { border-color: #888; color: #555; }
.record-panel .btn-unknown:hover, .record-panel .btn-unknown:active { background: #f5f5f5; }

.record-panel .recent {
  border-top: 1px solid var(--c-line);
  padding-top: 8px;
  margin-top: 4px;
}
.record-panel .recent h5 { margin: 0 0 6px; font-size: 12px; color: var(--c-sub); }
.record-panel .recent-list {
  list-style: none; padding: 0; margin: 0;
  max-height: 140px;
  overflow-y: auto;
}
.record-panel .recent-list li {
  display: flex; justify-content: space-between;
  padding: 3px 0; font-size: 12px;
  border-bottom: 1px dotted #eee;
}
.record-panel .recent-list .id { font-family: var(--font-en); color: var(--c-sub); }
.record-panel .recent-list .mark { font-weight: bold; }
.record-panel .recent-list .mark.o { color: var(--c-ok); }
.record-panel .recent-list .mark.x { color: var(--c-warn); }
.record-panel .recent-list .mark.q { color: #888; }
.record-panel .toast {
  font-size: 12px; color: var(--c-ok); text-align: center;
  height: 16px; margin-bottom: 4px;
}
.record-panel .panel-actions {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 12px;
}
.record-panel .panel-actions a { color: var(--c-accent); text-decoration: none; }
.record-panel .panel-actions a:hover { text-decoration: underline; }

/* 単元末の集計 */
.unit-summary {
  background: var(--c-accent-light);
  border-radius: 8px;
  padding: 16px 20px;
  margin: 30px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.unit-summary .label { font-weight: bold; color: var(--c-accent); }
.unit-summary .stat { font-family: var(--font-en); font-size: 17px; }
.unit-summary .stat .num { font-size: 24px; font-weight: bold; color: var(--c-accent); }
.unit-summary .retry-link {
  background: var(--c-accent);
  color: white;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
}
.unit-summary .retry-link:hover, .unit-summary .retry-link:active { background: var(--c-accent-dark); }

/* ---------- 苦手マップ ---------- */
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  margin: 16px 0;
}
.map-cell {
  border: 1px solid var(--c-line);
  border-radius: 4px;
  padding: 8px 10px;
  background: #fafafa;
  text-align: center;
  font-size: 12px;
}
.map-cell.state-untouched { background: #f0f0f0; color: #999; }
.map-cell.state-trying    { background: #fff8df; border-color: #e0bb1f; }
.map-cell.state-once-ok   { background: #e7f5ea; border-color: var(--c-ok); }
.map-cell.state-mastered  { background: var(--c-ok); color: white; border-color: var(--c-ok); }
.map-cell.state-stuck     { background: #fff0f0; border-color: var(--c-warn); }
.map-cell .qid-label { font-family: var(--font-en); font-weight: bold; display: block; font-size: 11px; }
.map-cell .latest    { font-size: 18px; margin-top: 2px; }

.map-legend {
  display: flex; gap: 14px;
  flex-wrap: wrap;
  font-size: 13px;
  margin: 16px 0;
}
.map-legend span { display: inline-flex; align-items: center; gap: 4px; }
.map-legend .dot {
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 3px;
  border: 1px solid #ccc;
}

/* ---------- 印刷モード切替パネル ---------- */
.print-panel-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  background: #666;
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  z-index: 999;
}
.print-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: white;
  border: 2px solid var(--c-accent);
  border-radius: 8px;
  padding: 14px 18px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  z-index: 1000;
  font-size: 13px;
  display: none;
}
.print-panel.show { display: block; }
.print-panel h4 { margin: 0 0 8px; color: var(--c-accent); font-size: 14px; }
.print-panel label { display: block; margin: 4px 0; cursor: pointer; }
.print-panel input[type="radio"] { margin-right: 6px; }
.print-panel .print-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  background: var(--c-accent);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.print-panel .close-btn {
  position: absolute;
  top: 4px; right: 8px;
  background: none; border: none;
  font-size: 16px; cursor: pointer; color: #999;
}

/* 印刷モード：問題冊子 */
body.mode-questions .answer-row,
body.mode-questions .q-show,
body.mode-questions .steps-toggle,
body.mode-questions .steps-row {
  display: none !important;
}
body.mode-questions .qid-actions { display: none !important; }

/* 印刷モード：解答編 */
body.mode-answer-key .hero,
body.mode-answer-key .lead,
body.mode-answer-key .explain,
body.mode-answer-key .figure,
body.mode-answer-key .column,
body.mode-answer-key .term-box,
body.mode-answer-key .toc,
body.mode-answer-key .controls,
body.mode-answer-key .unit-summary,
body.mode-answer-key .unit > .goal,
body.mode-answer-key .unit > p,
body.mode-answer-key .unit > h3,
body.mode-answer-key .unit > h4 {
  display: none !important;
}
body.mode-answer-key .drill .write-line,
body.mode-answer-key .drill .q-show,
body.mode-answer-key .drill .steps-toggle,
body.mode-answer-key .drill .choice,
body.mode-answer-key .qid-actions {
  display: none !important;
}
body.mode-answer-key .drill .answer-row {
  display: inline-block !important;
  background: transparent !important;
  border: none !important;
  border-left: 2px solid var(--c-ok);
  padding: 0 8px !important;
  margin: 0 0 0 8px !important;
  font-weight: bold;
  color: var(--c-ok);
}
body.mode-answer-key .drill .steps-row {
  display: block !important;
  margin-top: 4px;
}
body.mode-answer-key .book-title::after {
  content: " — 解答編";
  color: var(--c-warn);
  font-size: 0.7em;
}

/* 記録ハイライトは印刷時には消す */
@media print {
  .drill li.rec-o, .drill li.rec-x, .drill li.rec-q {
    background: none !important;
    padding-left: 0 !important;
    margin-left: 0 !important;
  }
}

/* ---------- @media print ---------- */
@media print {
  @page { size: A4; margin: 16mm 14mm; }
  body { background: white; font-size: 11pt; }
  .page { box-shadow: none; max-width: none; padding: 0; }
  .top-nav, .q-show, .steps-toggle, .print-hide,
  .print-panel, .print-panel-toggle,
  .record-toggle, .record-panel { display: none !important; }
  .unit { page-break-before: always; content-visibility: visible; }
  .unit:first-of-type { page-break-before: avoid; }
  h2, h3, h4 { page-break-after: avoid; }
  .figure, .drill li, .column, .solution-steps { page-break-inside: avoid; }
  a { color: black; text-decoration: none; }
  .write-line { border-bottom: 1px solid black; }
  body:not(.mode-answer-key) .answer-row { display: none !important; }
  body:not(.mode-answer-key) .steps-row { display: none !important; }
}

/* ---------- ヒーロー（intro用） ---------- */
.hero {
  background: linear-gradient(135deg, var(--c-accent) 0%, var(--c-accent-dark) 100%);
  color: white;
  padding: 32px 28px;
  border-radius: 8px;
  margin-bottom: 32px;
}
.hero h1 { margin: 0 0 8px; font-size: 28px; }
.hero p { margin: 4px 0; opacity: .95; }

.big-section {
  margin: 56px 0;
  padding-top: 24px;
  border-top: 3px double var(--c-accent);
}
.big-section > h2 {
  font-size: 26px;
  color: var(--c-accent);
  margin: 0 0 8px;
}

/* 大きな表 */
.big-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}
.big-table th, .big-table td {
  border: 1px solid var(--c-line);
  padding: 8px 12px;
  vertical-align: top;
  font-size: 14px;
}
.big-table th {
  background: var(--c-accent-light);
  color: var(--c-accent);
  text-align: left;
}

/* 並列カード */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}
.compare-card {
  background: white;
  border: 2px solid var(--c-accent-light);
  border-radius: 8px;
  padding: 14px 18px;
}
.compare-card h4 { margin-top: 0; color: var(--c-accent); }
.compare-card.alt { border-color: #ffdcc8; }
.compare-card.alt h4 { color: #c46a2e; }

/* ---------- iPad / タッチデバイス向け（最低限） ---------- */
@media (pointer: coarse) {
  .qid-actions .qm {
    width: 44px;
    height: 40px;
    font-size: 16px;
  }
  .q-show, .steps-toggle {
    padding: 10px 18px;
    font-size: 15px;
  }
  .return-link {
    padding: 10px 16px;
    font-size: 14px;
    margin: 10px 0;
  }
  .record-toggle, .print-panel-toggle {
    width: 60px;
    height: 60px;
  }
  .drill .qid { padding: 4px 12px; font-size: 13px; }
}

@media (max-width: 600px) {
  .compare-grid { grid-template-columns: 1fr; }
  .record-panel { width: calc(100vw - 40px); right: 20px; }
  .page { padding: 24px 16px 100px; }
}
