/* =========================
   解説ページ 共通CSS
   ========================= */

:root {
  --text: #222;
  --imp: #ff0000;
  /* 赤：重要 */
  --sub: #0000ff;
  /* 青：入試に出るが周辺 */
  --line: #222;
  --bg-box: #fafafa;
}

html,
body {
  background-color: #fff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  line-height: 1.85;
  color: var(--text);
  margin: 16px;
}

/* =========================
   空欄（クリックで表示/非表示）
   ========================= */
/* 見た目用。挙動は js-blank が担当 */
/* 空欄の基本形 */
.blank {
  --blank-inline-gap: 0.5em;
  display: inline-block;
  position: relative;
  top: 0;
  background: #fff;

  /* 下線 */
  border-bottom: 2px solid #222;

  /* data-answer の文字数に応じて幅を可変化 */
  min-width: calc((var(--blank-ch, 4) * 1em) + (var(--blank-inline-gap) * 2));

  /* タップしやすさ */
  padding: 0;
  cursor: pointer;
  user-select: none;
  text-align: center;
  vertical-align: -0.2em;
  line-height: 1.2;
  min-height: 1.2em;
  color: transparent;

  /* 見た目調整 */
  border-radius: 2px;
}

/* クリック判定を上下に約1cm拡張（左右はそのまま） */
.blank::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -1cm;
  bottom: -1cm;
}

/* 答え文字は疑似要素で重ねる。下線位置は常に固定。 */
.blank::after {
  content: attr(data-display-answer);
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(2px + 0.02em);
  text-align: center;
  box-sizing: border-box;
  padding-left: var(--blank-inline-gap);
  padding-right: var(--blank-inline-gap);
  white-space: nowrap;
  line-height: 1;
  color: currentColor;
  opacity: 0;
}

.blank:hover {
  background: #fff;
}

/* 開いて答えが表示されている状態（JSが is-open を付ける） */
.blank.is-open {
  /* 下線は消さない */
  border-bottom: 2px solid #222;

  /* 答えが読みやすいよう少し強調 */
  color: var(--text);
  background: #fff;
}

.blank.is-open::after {
  opacity: 1;
  font-weight: 700;
}

/* data-color に応じた表示色（JSがクラス付与） */
.blank.is-open.answer-red {
  color: var(--imp);
}

.blank.is-open.answer-blue {
  color: var(--sub);
}

/* キーボード操作のフォーカス可視化（tabindex が付く） */
.blank:focus {
  outline: 2px solid rgba(21, 101, 192, 0.45);
  outline-offset: 2px;
}

/* =========================
   重要語・周辺語（色）
   ========================= */
.important {
  color: var(--imp);
  font-weight: 700;
}

.sub {
  color: var(--sub);
  font-weight: 600;
}

/* =========================
   四角で囲む（最重要・定義）
   ========================= */
.box {
  display: inline-block;
  padding: .15em .45em;
  margin: 0 .1em;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--bg-box);
  font-weight: 700;
}

/* =========================
   ボタン類
   ========================= */
button {
  padding: .45em .85em;
  font-size: 0.95rem;
  cursor: pointer;
  margin-right: .5em;
}

/* 解説ページ：レイアウト外枠 */
.kaisetsu h1,
.kaisetsu h2,
.kaisetsu h3,
.kaisetsu h4 {
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
}

.kaisetsu {
  width: min(920px, calc(100% - 40px));
  margin: 0 auto;
  padding: 14px 0 60px;
}

.kaisetsu-head {
  margin: 12px 0 18px;
  padding: 14px 16px;
  border: 1px solid rgba(15, 23, 42, .10);
  border-radius: 14px;
  background: rgba(255, 255, 255, .85);
}

.kaisetsu-kicker {
  margin: 0 0 6px;
  color: rgba(15, 23, 42, .65);
  font-weight: 700;
  letter-spacing: .2px;
}

.kaisetsu-title {
  margin: 0;
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
  font-size: 1.35rem;
  line-height: 1.25;
}

.kaisetsu-h2 {
  margin: 1.2em 0 .4em;
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  padding-left: .6em;
  border-left: 5px solid rgba(0, 0, 0, .5);
}

.kaisetsu-h3 {
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
  margin: .9em 0 .6em;
}

.kaisetsu-h4 {
  margin: 1.1em 0 .4em;
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
  font-size: 1.02rem;
  font-weight: 800;
  opacity: .9;
}

.kaisetsu-outline {
  margin: .6em 0 1.2em;
  padding: 10px 12px;
  border: 1px solid rgba(15, 23, 42, .12);
  border-radius: 10px;
  background: #fff;
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
}

.kaisetsu-outline * {
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
}

.kaisetsu-outline-title {
  margin: 0 0 8px;
  display: inline-block;
  padding: 4px 10px;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: .02em;
  color: #0f172a;
  border-left: 4px solid #0f172a;
  background: rgba(15, 23, 42, .06);
  border-radius: 6px;
}

.kaisetsu-outline-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.kaisetsu-outline-list li {
  margin: 0;
}

.kaisetsu-outline-list details {
  display: block;
}

.kaisetsu-outline-summary {
  cursor: pointer;
}

.kaisetsu-outline-sublist {
  margin: 6px 0 0 18px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
}

.kaisetsu-outline-list a {
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid rgba(15, 23, 42, .15);
  border-radius: 999px;
  color: #0f172a;
  text-decoration: none;
  font-size: .92rem;
  font-weight: 600;
  line-height: 1.3;
}

.kaisetsu-outline-list > li > details > summary > a,
.kaisetsu-outline-list > li > a {
  font-size: 1rem;
  font-weight: 700;
}

.kaisetsu-outline-sublist a {
  font-size: .9rem;
  font-weight: 600;
}

.kaisetsu-outline-list a:hover {
  background: rgba(15, 23, 42, .06);
}

.kaisetsu-h2 {
  scroll-margin-top: 90px;
}

/* 本文読みやすさ */
.kaisetsu-body {
  font-family: "MS Mincho", "ＭＳ 明朝", serif;
  font-size: 1.02rem;
  line-height: 1.9;
}

.kaisetsu-body p {
  margin: .7em 0;
}

.kaisetsu-body p {
  white-space: pre-wrap;
}

.kaisetsu-body p.is-spacer {
  margin: .35em 0;
  min-height: .6em;
}

/* 学習ガイド */
.kaisetsu-learning-guide {
  margin: 14px 0 18px;
  padding: 14px 16px 16px;
  border: 1px solid rgba(37, 99, 235, .16);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(37, 99, 235, .08), rgba(255, 255, 255, .98) 58%);
  box-shadow: 0 18px 36px rgba(15, 23, 42, .06);
}

.kaisetsu-learning-guide-title {
  margin: 0 0 10px;
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
  font-size: .95rem;
  font-weight: 800;
  letter-spacing: .04em;
  color: #1d4ed8;
}

.kaisetsu-learning-guide-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.kaisetsu-learning-guide-item {
  padding: 12px 14px;
  border: 1px solid rgba(15, 23, 42, .10);
  border-radius: 12px;
  background: rgba(255, 255, 255, .92);
}

.kaisetsu-learning-guide-label {
  display: block;
  margin-bottom: 6px;
  font-size: .82rem;
  font-weight: 700;
  color: rgba(15, 23, 42, .62);
}

.kaisetsu-learning-guide-value {
  display: block;
  font-size: .98rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.45;
}

/* 問い */
.question-box {
  position: relative;
  margin: 14px 0 18px;
  padding: 18px 16px 14px;
  border: 1px solid rgba(37, 99, 235, .18);
  border-left: 6px solid #2563eb;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(37, 99, 235, .07), rgba(255, 255, 255, .96) 62%);
  box-shadow: 0 16px 28px rgba(15, 23, 42, .06);
}

.question-box::before {
  content: attr(data-label);
  position: absolute;
  top: -0.85em;
  left: 14px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eff6ff;
  border: 1px solid rgba(37, 99, 235, .18);
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
  font-size: .75rem;
  font-weight: 800;
  color: #1d4ed8;
  letter-spacing: .02em;
}

.question-box p {
  margin: 0;
  white-space: normal;
}

.question-box p + p {
  margin-top: .45em;
}

.question-box-primary {
  border-left-color: #0f766e;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, .10), rgba(255, 255, 255, .97) 62%);
}

.question-box-primary::before {
  background: #ecfdf5;
  border-color: rgba(15, 118, 110, .18);
  color: #0f766e;
}

.question-box-section {
  margin-top: 20px;
  margin-bottom: 14px;
}

/* セクションカード */
.kaisetsu-section {
  margin: 24px 0;
  padding: 18px 18px 20px;
  border: 1px solid rgba(15, 23, 42, .10);
  border-radius: 18px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 18px 38px rgba(15, 23, 42, .05);
}

.kaisetsu-section > .kaisetsu-h2,
.kaisetsu-section > h2 {
  margin-top: 0;
}

.kaisetsu-section > :last-child {
  margin-bottom: 0;
}

.kaisetsu-section .word-textbox:not(.question-box) {
  border-color: rgba(15, 23, 42, .16);
  background: linear-gradient(180deg, rgba(248, 250, 252, .96), rgba(255, 255, 255, .98));
}

/* Word由来部品：38.php直書きstyleの移植先 */
.word-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: .95em;
}

.word-table td,
.word-table th {
  border: 1px solid rgba(0, 0, 0, .18);
  padding: 8px 10px;
  vertical-align: top;
  white-space: pre-wrap;
}

.word-textbox {
  border: 1px solid rgba(0, 0, 0, .30);
  padding: 10px 12px;
  margin: 12px 0;
  background: rgba(255, 255, 255, .9);
  border-radius: 10px;
  white-space: pre-wrap;
}

.word-image {
  margin: 12px 0;
}

.kaisetsu-figure {
  margin: 14px 0 18px;
  padding: 12px;
  border: 1px solid rgba(15, 23, 42, .10);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(248, 250, 252, .95), rgba(255, 255, 255, .98));
}

.kaisetsu-figure-link {
  display: block;
  border-radius: 12px;
  overflow: hidden;
}

.word-image img {
  max-width: 100%;
  height: auto;
  display: block;
}

.kaisetsu-figure-link img {
  transition: transform .22s ease;
}

.kaisetsu-figure-link:hover img {
  transform: scale(1.01);
}

.kaisetsu-figure-caption {
  margin: 10px 2px 0;
  font-size: .9rem;
  line-height: 1.6;
  color: rgba(15, 23, 42, .72);
}

/* 表：スマホで潰れないよう横スクロール（table-wrapを使う場合） */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.kaisetsu-table-card {
  margin: 18px 0;
  padding: 12px 14px 14px;
  border: 1px solid rgba(15, 23, 42, .10);
  border-radius: 16px;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 14px 32px rgba(15, 23, 42, .05);
}

.kaisetsu-table-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.kaisetsu-table-title {
  margin: 0;
  font-family: "MS Gothic", "ＭＳ ゴシック", sans-serif;
  font-size: .98rem;
  font-weight: 800;
  color: #0f172a;
}

.kaisetsu-table-hint {
  margin: 0;
  font-size: .82rem;
  color: rgba(15, 23, 42, .62);
}

.kaisetsu-table-card .table-wrap {
  margin: 0 -2px;
  padding-bottom: 4px;
}

.kaisetsu-table-card .word-table {
  margin: 0;
  background: #fff;
}

.kaisetsu-table-card .word-table th {
  background: rgba(248, 250, 252, .95);
  font-weight: 700;
}

.kaisetsu-table-card .word-table th[scope="row"] {
  position: sticky;
  left: 0;
  z-index: 1;
  background: rgba(248, 250, 252, .98);
}

.table-wrap table {
  min-width: 640px;
}

/* 空欄の視認性：空文字でも“空欄だ”と分かるように薄背景 */
.blank {
  background: rgba(0, 0, 0, .02);
}

.blank:hover {
  background: rgba(0, 0, 0, .05);
}

/* =========================
   印刷（必要なら）
   ========================= */
@media print {
  body {
    margin: 0;
  }

  button {
    display: none;
  }

  .blank:hover {
    background: transparent;
  }

  .blank:focus {
    outline: none;
  }

  .blank {
    border-bottom: 1px solid #000;
  }

  .blank::before {
    content: none;
  }
}

@media (max-width: 720px) {
  .kaisetsu {
    width: min(100%, calc(100% - 20px));
  }

  .kaisetsu-learning-guide-grid {
    grid-template-columns: 1fr;
  }

  .question-box {
    padding: 16px 14px 12px;
  }

  .kaisetsu-section {
    padding: 14px;
    border-radius: 14px;
  }

  .kaisetsu-figure {
    padding: 10px;
  }

  .kaisetsu-table-card {
    padding: 12px;
  }

  .kaisetsu-table-head {
    flex-direction: column;
  }
}
